File size: 2,077 Bytes
a23538f 04d6660 a23538f 04d6660 a23538f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AlignRequest {
pub audio_base64: String,
pub text: String,
#[serde(default = "default_language")]
pub language: String,
#[serde(default = "default_pass_number")]
pub pass_number: i32,
pub client_id: Option<String>,
}
fn default_language() -> String {
"english".to_string()
}
fn default_pass_number() -> i32 {
1
}
#[derive(Debug, Deserialize)]
pub struct CancelRequest {
pub client_id: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct JobQuery {
pub slim: Option<bool>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum JobStatus {
Queued,
Running,
Completed,
Failed,
Abandoned,
}
impl JobStatus {
pub fn as_str(&self) -> &'static str {
match self {
JobStatus::Queued => "queued",
JobStatus::Running => "running",
JobStatus::Completed => "completed",
JobStatus::Failed => "failed",
JobStatus::Abandoned => "abandoned",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WordTimestamp {
pub word: String,
pub start: f64,
pub end: f64,
}
#[derive(Debug, Clone)]
pub struct Job {
pub id: String,
pub request: AlignRequest,
pub status: JobStatus,
pub created_at: DateTime<Utc>,
pub started_at: Option<DateTime<Utc>>,
pub terminal_at: Option<DateTime<Utc>>,
pub result: Option<Vec<WordTimestamp>>,
pub error: Option<String>,
pub client_id: Option<String>,
pub audio_duration: f64,
pub wav_path: String,
pub cleaned_text: String,
}
#[derive(Debug, Default)]
pub struct Metrics {
pub total_submitted: i32,
pub total_completed: i32,
pub total_failed: i32,
pub total_abandoned: i32,
pub total_cancelled: i32,
pub start_time: Option<DateTime<Utc>>,
}
impl Metrics {
pub fn new() -> Self {
Self {
start_time: Some(Utc::now()),
..Default::default()
}
}
} |