Ignorar chats que iniciam com template + response_time semana e mensal

This commit is contained in:
2025-11-21 13:40:41 -03:00
parent d48f2b86aa
commit 7753beacaf
6 changed files with 930 additions and 61 deletions

View File

@@ -31,6 +31,20 @@ struct CsvEvaluation {
ID_TALK: String,
}
//inclusão de estrutura para agrupar o response_time.cvs
#[derive(Debug, serde::Deserialize)]
struct ResponseTimeRecord {
NOME: String,
ID_TALK: String,
#[serde(rename = "TEMPO DE RESPOSTA")]
TEMPO_DE_RESPOSTA: u32,
#[serde(rename = "TRANFERENCIA PELO BOT")]
TRANFERENCIA_PELO_BOT: String,
#[serde(rename = "PRIMEIRA RESPOSTA DO AGENTE")]
PRIMEIRA_RESPOSTA_DO_AGENTE: String,
}
//fim da inclusão
fn main() {
match dotenv::dotenv().ok() {
Some(_) => println!("Environment variables loaded from .env file"),
@@ -369,6 +383,93 @@ fn main() {
None => {}
}
//inclusão nova para agrupar o response_time.csv
// Processar response_time.csv separadamente
let response_times_data = previous_week_folder_names
.iter()
.map(|folder_name| {
let folder_base_path = std::path::Path::new("./evaluations");
let folder_date_path = folder_base_path.join(folder_name);
std::fs::read_dir(folder_date_path)
})
.filter_map_ok(|files_inside_folder_on_date| {
let response_time_files = files_inside_folder_on_date
.filter_ok(|entry| {
let entry_file_name_as_str = entry
.file_name()
.into_string()
.expect("Failed to get filename as a String");
entry_file_name_as_str.ends_with("response_time.csv")
})
.filter_map(|value| {
if value.is_ok() {
return Some(value.unwrap());
}
None
})
.map(|file_path| {
println!("Processing response time file: {:?}", file_path.path());
let mut rdr = csv::ReaderBuilder::new()
.delimiter(b';')
.has_headers(true)
.from_reader(std::fs::File::open(file_path.path()).unwrap());
let records: Vec<ResponseTimeRecord> = rdr
.deserialize()
.filter_map(Result::ok)
.collect();
records
})
.flat_map(|records| records)
.collect_vec();
Some(response_time_files)
})
.filter_map(|res| {
if res.is_ok() {
return Some(res.unwrap());
}
return None;
})
.flat_map(|records| records)
.collect_vec();
// Salvar response times consolidados
if !response_times_data.is_empty() {
let response_time_file_path = format!(
"./groupped/{first_day_of_last_week} - {last_day_of_last_week}/response_times_consolidated.csv"
);
let mut wtr = csv::WriterBuilder::new()
.delimiter(b';')
.from_path(response_time_file_path)
.expect("Failed to create response times CSV");
// Escrever cabeçalho
wtr.write_record(&["NOME", "ID_TALK", "TEMPO DE RESPOSTA", "TRANFERENCIA PELO BOT", "PRIMEIRA RESPOSTA DO AGENTE"])
.expect("Failed to write header");
for record in response_times_data {
wtr.write_record(&[
&record.NOME,
&record.ID_TALK,
&record.TEMPO_DE_RESPOSTA.to_string(),
&record.TRANFERENCIA_PELO_BOT,
&record.PRIMEIRA_RESPOSTA_DO_AGENTE,
]).expect("Failed to write record");
}
wtr.flush().expect("Failed to flush writer");
println!("Response times consolidated successfully!");
} else {
println!("No response time data found for the period.");
}
// --- FIM DA ADIÇÃO ---
//fim da inclusão
zip_directory_util::zip_directory_util::zip_source_dir_to_dst_file(
std::path::Path::new(&format!(
"./groupped/{first_day_of_last_week} - {last_day_of_last_week}"
@@ -378,7 +479,7 @@ fn main() {
)),
);
let recipients = "Wilson da Conceição Oliveira <wilson.oliveira@nova.net.br>, Isadora G. Moura de Moura <isadora.moura@nova.net.br>";
let recipients = "Wilson da Conceição Oliveira <wilson.oliveira@nova.net.br>, nicolas.borges@nova.net.br, Isadora G. Moura de Moura <isadora.moura@nova.net.br>";
println!("Trying to send mail... {recipients}");
send_mail_util::send_mail_util::send_email(
&format!(