Correcao na regex v2 + Alteracao das colunas para 8 sem/men; Alteracao no prompt de saniticacao
This commit is contained in:
@@ -16,8 +16,8 @@ PROTOCOLO;1;O agente informou o protocolo.;Aqui está o protocolo do teu atendim
|
|||||||
USO DO PORTUGUÊS;1;O agente utilizou português correto.;Aqui está o protocolo do teu atendimento: 2510.3624;Para manter o cadastro atualizado, poderia me confirmar se o e-mail continua sendo janainads.sls@gmail.com e se o telefone do titular do cadastro permanece (53) 98446-2208?
|
USO DO PORTUGUÊS;1;O agente utilizou português correto.;Aqui está o protocolo do teu atendimento: 2510.3624;Para manter o cadastro atualizado, poderia me confirmar se o e-mail continua sendo janainads.sls@gmail.com e se o telefone do titular do cadastro permanece (53) 98446-2208?
|
||||||
PACIÊNCIA E EDUCAÇÃO;1;O agente foi paciente e educado.;Obrigado pela confirmação.;Certo, um bom final de semana! 😊
|
PACIÊNCIA E EDUCAÇÃO;1;O agente foi paciente e educado.;Obrigado pela confirmação.;Certo, um bom final de semana! 😊
|
||||||
DISPONIBILIDADE;1;O agente demonstrou disponibilidade.;Caso tenha alguma dúvida, nos contate. A equipe da NovaNet está sempre aqui para te ajudar.😊;Certo, um bom final de semana! 😊
|
DISPONIBILIDADE;1;O agente demonstrou disponibilidade.;Caso tenha alguma dúvida, nos contate. A equipe da NovaNet está sempre aqui para te ajudar.😊;Certo, um bom final de semana! 😊
|
||||||
CONHECIMENTO TÉCNICO;1;O agente identificou que não havia problemas nos equipamentos.;Verifiquei aqui os equipamentos e não identifiquei nenhum problema com eles.;A potência recebida pelo equipamento está normal e as configurações do roteador estão todas corretas.
|
ESCLARECIMENTO;1;O agente manteve o cliente informado durante todo o processo.; Esclareceu situaçãoo de instabilidade e envio de fatura, mantendo cliente informado. Atualizou cliente sobre o andamento e próximos passos.
|
||||||
DIDATISMO;1;O agente foi didático ao orientar o cliente.;Certo, tu poderia se conectar na rede do primeiro roteador e verificar se ocorre algum problema?;Entendi, pode ser algum problema neste segundo roteador, tu pode estar reiniciando ele na tomada para caso seja algum travamento.
|
|
||||||
100%
|
100%
|
||||||
|
|
||||||
A resposta sua deve ser:
|
A resposta sua deve ser:
|
||||||
@@ -30,8 +30,7 @@ PROTOCOLO;1
|
|||||||
USO DO PORTUGUÊS;1
|
USO DO PORTUGUÊS;1
|
||||||
PACIÊNCIA E EDUCAÇÃO;1
|
PACIÊNCIA E EDUCAÇÃO;1
|
||||||
DISPONIBILIDADE;1
|
DISPONIBILIDADE;1
|
||||||
CONHECIMENTO TÉCNICO;1
|
ESCLARECIMENTO;1
|
||||||
DIDATISMO;1
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Exemplo 02:
|
Exemplo 02:
|
||||||
@@ -43,10 +42,8 @@ Dado o seguinte arquivo de entrada:
|
|||||||
05,1,Uso correto do português,"Todas as mensagens foram escritas em português formal e correto, inclusive com 'tu' permitido. (12:10:05‑13:03:08)"
|
05,1,Uso correto do português,"Todas as mensagens foram escritas em português formal e correto, inclusive com 'tu' permitido. (12:10:05‑13:03:08)"
|
||||||
06,1,Uso de linguagem paciente e educada,"Aguarde meu retorno, por gentileza; me informe, por gentileza; obrigado pela confirmação. (12:10:13‑13:03:07)"
|
06,1,Uso de linguagem paciente e educada,"Aguarde meu retorno, por gentileza; me informe, por gentileza; obrigado pela confirmação. (12:10:13‑13:03:07)"
|
||||||
07,1,Disponibilidade expressa,"Caso tenha alguma dúvida, nos contate. A equipe da NovaNet está sempre aqui para te ajudar. (13:03:08)"
|
07,1,Disponibilidade expressa,"Caso tenha alguma dúvida, nos contate. A equipe da NovaNet está sempre aqui para te ajudar. (13:03:08)"
|
||||||
08,1,Conhecimento técnico,"Identificou mau contato no cabo, instruiu reconexões, avaliou ordem de serviço, cotou peças. (12:25:44‑12:57:10)"
|
08,1,Esclarecimento,"Um momento irei verificar os valores.Andressa, tem valores em aberto conosco desde 2021, em caso de pagamento hoje o valor é de R$358,95. (12:25:56‑12:26:06)"
|
||||||
09,1,Didático,"Desconecte o cabo LAN/WAN passo a passo e me informe quando terminar. (12:25:56‑12:26:06)"
|
09,2,Tempo de espera excedido, 2 ocorrências,"Intervalos superiores a 5 min: 12:55:17‑13:01:15 (5 min 58 s) e 12:27:51‑12:54:11 (26 min 20 s)"
|
||||||
10,1,Eclaração diagnóstica,"Fez diagnóstico de mau contato no cabo e ofereceu ordem de serviço sem custo. (12:55:17‑13:01:15)"
|
|
||||||
11,2,Tempo de espera excedido, 2 ocorrências,"Intervalos superiores a 5 min: 12:55:17‑13:01:15 (5 min 58 s) e 12:27:51‑12:54:11 (26 min 20 s)"
|
|
||||||
|
|
||||||
A resposta sua deve ser:
|
A resposta sua deve ser:
|
||||||
```csv
|
```csv
|
||||||
@@ -67,9 +64,6 @@ Dado o seguinte arquivo de entrada:
|
|||||||
Identificação e abertura do atendimento,1,
|
Identificação e abertura do atendimento,1,
|
||||||
Confirmação de dados do cliente,1,
|
Confirmação de dados do cliente,1,
|
||||||
Verificação do histórico e do plano do cliente,1,
|
Verificação do histórico e do plano do cliente,1,
|
||||||
Análise e diagnóstico da falha na conectividade,1,
|
|
||||||
Verificação e teste de equipamentos,1,
|
|
||||||
Sugestão de solução de conectividade,1,
|
|
||||||
Escala de serviço,1,
|
Escala de serviço,1,
|
||||||
Encerramento de atendimento,1,
|
Encerramento de atendimento,1,
|
||||||
Follow-up,1,
|
Follow-up,1,
|
||||||
@@ -87,8 +81,7 @@ PROTOCOLO;
|
|||||||
USO DO PORTUGUÊS;
|
USO DO PORTUGUÊS;
|
||||||
PACIÊNCIA E EDUCAÇÃO;
|
PACIÊNCIA E EDUCAÇÃO;
|
||||||
DISPONIBILIDADE;
|
DISPONIBILIDADE;
|
||||||
CONHECIMENTO TÉCNICO;
|
ESCLARECIMENTO;
|
||||||
DIDATISMO;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -103,8 +96,7 @@ PROTOCOLO;1
|
|||||||
USO DO PORTUGUÊS;1
|
USO DO PORTUGUÊS;1
|
||||||
PACIÊNCIA E EDUCAÇÃO;1
|
PACIÊNCIA E EDUCAÇÃO;1
|
||||||
DISPONIBILIDADE;1
|
DISPONIBILIDADE;1
|
||||||
CONHECIMENTO TÉCNICO;1
|
ESCLARECIMENTO;1
|
||||||
DIDATISMO;1
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Abaixo está a avaliação que deve ser processada
|
Abaixo está a avaliação que deve ser processada
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ fn main() {
|
|||||||
})
|
})
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
|
|
||||||
if columns.len() != 9 {
|
if columns.len() != 8 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +265,8 @@ fn main() {
|
|||||||
// filename example is: CC - Erraoander Quintana - 515578 - 20251020515578.csv
|
// filename example is: CC - Erraoander Quintana - 515578 - 20251020515578.csv
|
||||||
// id talk is the last information, so in the example is: 20251020515578
|
// id talk is the last information, so in the example is: 20251020515578
|
||||||
let regex_filename =
|
let regex_filename =
|
||||||
regex::Regex::new(r"(FIN - )((\w+\s*)+) - (\d+) - (\d+).csv").unwrap();
|
// regex::Regex::new(r"(FIN - )((\w+\s*)+) - (\d+) - (\d+).csv").unwrap();
|
||||||
|
regex::Regex::new(r"FIN - (.+?) - (\d+) - (\d+)\.csv").unwrap();
|
||||||
|
|
||||||
let filename = file_path_csv
|
let filename = file_path_csv
|
||||||
.file_name()
|
.file_name()
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ fn main() {
|
|||||||
})
|
})
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
|
|
||||||
if columns.len() != 9 {
|
if columns.len() != 8 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +259,8 @@ fn main() {
|
|||||||
// filename example is: FIN - Lais Mota - 515578 - 20251020515578.csv
|
// filename example is: FIN - Lais Mota - 515578 - 20251020515578.csv
|
||||||
// id talk is the last information, so in the example is: 20251020515578
|
// id talk is the last information, so in the example is: 20251020515578
|
||||||
let regex_filename =
|
let regex_filename =
|
||||||
regex::Regex::new(r"(FIN - )((\s*\w+\s*)+) - (\d+) - (\d+).csv").unwrap();
|
//regex::Regex::new(r"(FIN - )((\s*\w+\s*)+) - (\d+) - (\d+).csv").unwrap();
|
||||||
|
regex::Regex::new(r"FIN - (.+?) - (\d+) - (\d+)\.csv").unwrap();
|
||||||
|
|
||||||
let filename = file_path_csv
|
let filename = file_path_csv
|
||||||
.file_name()
|
.file_name()
|
||||||
@@ -270,10 +271,10 @@ fn main() {
|
|||||||
.expect("Failed to do regex capture");
|
.expect("Failed to do regex capture");
|
||||||
|
|
||||||
let user_name = found_regex_groups_in_filename
|
let user_name = found_regex_groups_in_filename
|
||||||
.get(2)
|
.get(1)
|
||||||
.expect("Failed to get the id from regex maches");
|
.expect("Failed to get the id from regex maches");
|
||||||
let talk_id = found_regex_groups_in_filename
|
let talk_id = found_regex_groups_in_filename
|
||||||
.get(5)
|
.get(3)
|
||||||
.expect("Failed to get the id from regex maches");
|
.expect("Failed to get the id from regex maches");
|
||||||
|
|
||||||
let excelence_percentual = columns
|
let excelence_percentual = columns
|
||||||
|
|||||||
493
src/groupped_repport_weekly.rs.save
Normal file
493
src/groupped_repport_weekly.rs.save
Normal file
@@ -0,0 +1,493 @@
|
|||||||
|
use std::fmt::Debug;
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
use polars::prelude::*;
|
||||||
|
use reqwest;
|
||||||
|
use std::env;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use csv;
|
||||||
|
|
||||||
|
pub mod send_mail_util;
|
||||||
|
pub mod zip_directory_util;
|
||||||
|
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
struct CsvHeader {
|
||||||
|
CATEGORIA: String,
|
||||||
|
PONTOS: Option<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
struct CsvEvaluation {
|
||||||
|
APRESENTAÇÃO: u8,
|
||||||
|
CONFIRMAÇÃO_DE_EMAIL: u8,
|
||||||
|
CONFIRMAÇÃO_DE_TELEFONE: u8,
|
||||||
|
PROTOCOLO: u8,
|
||||||
|
USO_DO_PORTUGUÊS: u8,
|
||||||
|
PACIÊNCIA_E_EDUCAÇÃO: u8,
|
||||||
|
DISPONIBILIDADE: u8,
|
||||||
|
CONHECIMENTO_TÉCNICO: u8,
|
||||||
|
DIDATISMO: u8,
|
||||||
|
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"),
|
||||||
|
None => eprintln!("Failed to load .env file, using defaults"),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read environment variables
|
||||||
|
let OLLAMA_URL = env::var("OLLAMA_URL").unwrap_or("localhost".to_string());
|
||||||
|
let OLLAMA_PORT = env::var("OLLAMA_PORT")
|
||||||
|
.unwrap_or("11432".to_string())
|
||||||
|
.parse::<u16>()
|
||||||
|
.unwrap_or(11432);
|
||||||
|
let OLLAMA_AI_MODEL_DATA_SANITIZATION = env::var("OLLAMA_AI_MODEL_DATA_SANITIZATION")
|
||||||
|
.expect("Missing environment variable OLLAMA_AI_MODEL_DATA_SANITIZATION");
|
||||||
|
let BOT_EMAIL = env::var("BOT_EMAIL").expect("BOT_EMAIL has not been set!");
|
||||||
|
let BOT_EMAIL_PASSWORD =
|
||||||
|
env::var("BOT_EMAIL_PASSWORD").expect("BOT_EMAIL_PASSWORD has not been set!");
|
||||||
|
|
||||||
|
let ip_address = ipaddress::IPAddress::parse(OLLAMA_URL.to_string());
|
||||||
|
let OLLAMA_SANITIZED_IP = match ip_address {
|
||||||
|
Ok(ip) => {
|
||||||
|
if ip.is_ipv4() {
|
||||||
|
OLLAMA_URL.clone()
|
||||||
|
} else {
|
||||||
|
format!("[{}]", OLLAMA_URL.clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => OLLAMA_URL.clone(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the current day in the format YYYY-MM-DD
|
||||||
|
let current_date = chrono::Local::now();
|
||||||
|
let formatted_date = current_date.format("%Y-%m-%d").to_string();
|
||||||
|
|
||||||
|
let current_date = chrono::Local::now();
|
||||||
|
let first_day_of_current_week = current_date
|
||||||
|
.date_naive()
|
||||||
|
.week(chrono::Weekday::Sun)
|
||||||
|
.first_day();
|
||||||
|
let current_date_minus_one_week = first_day_of_current_week
|
||||||
|
.checked_sub_days(chrono::Days::new(1))
|
||||||
|
.expect("Failed to subtract one day");
|
||||||
|
let first_day_of_last_week = current_date_minus_one_week
|
||||||
|
.week(chrono::Weekday::Sun)
|
||||||
|
.first_day();
|
||||||
|
let last_day_of_last_week = current_date_minus_one_week
|
||||||
|
.week(chrono::Weekday::Sun)
|
||||||
|
.last_day();
|
||||||
|
|
||||||
|
let previous_week_folder_names = std::fs::read_dir(std::path::Path::new("./evaluations"))
|
||||||
|
.expect("Failed to read directory ./evaluations")
|
||||||
|
.filter_map_ok(|entry| {
|
||||||
|
if entry.metadata().unwrap().is_dir() {
|
||||||
|
Some(entry.file_name())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter_map_ok(|entry_string_name| {
|
||||||
|
let regex_match_date =
|
||||||
|
regex::Regex::new(r"(\d{4}-\d{2}-\d{2})").expect("Failed to build regex");
|
||||||
|
|
||||||
|
let filename = entry_string_name.to_str().unwrap();
|
||||||
|
let matches_find = regex_match_date.find(filename);
|
||||||
|
|
||||||
|
match matches_find {
|
||||||
|
Some(found) => {
|
||||||
|
let date = chrono::NaiveDate::parse_from_str(found.as_str(), "%Y-%m-%d");
|
||||||
|
return Some((date.unwrap().week(chrono::Weekday::Sun), entry_string_name));
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter_map_ok(|(week, directory_string)| {
|
||||||
|
let first_day_of_week_in_folder_name = week.first_day();
|
||||||
|
|
||||||
|
if first_day_of_last_week == first_day_of_week_in_folder_name {
|
||||||
|
return Some(directory_string);
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
})
|
||||||
|
.filter_map(|value| {
|
||||||
|
if value.is_ok() {
|
||||||
|
return Some(value.unwrap());
|
||||||
|
} else {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.sorted()
|
||||||
|
.collect_vec();
|
||||||
|
|
||||||
|
println!("{:?}", previous_week_folder_names);
|
||||||
|
|
||||||
|
let prompt_data_sanitization = std::fs::read_to_string("./PROMPT_DATA_SANITIZATION.txt")
|
||||||
|
.expect("Failed to read PROMPT_DATA_SANITIZATION.txt");
|
||||||
|
let client = reqwest::blocking::Client::new();
|
||||||
|
|
||||||
|
let groupped_values = 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 groupped_by_user_on_day = 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(".csv")
|
||||||
|
&& !entry_file_name_as_str.contains("response_time.csv")
|
||||||
|
})
|
||||||
|
.filter_map(|value| {
|
||||||
|
if value.is_ok() {
|
||||||
|
return Some(value.unwrap());
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.map(|file_name_csv| {
|
||||||
|
println!("{:?}", file_name_csv.path());
|
||||||
|
let file_contents = std::fs::read_to_string(file_name_csv.path())
|
||||||
|
.expect("Failed to read CSV file");
|
||||||
|
|
||||||
|
let ollama_api_request = client
|
||||||
|
.post(format!(
|
||||||
|
"http://{OLLAMA_SANITIZED_IP}:{OLLAMA_PORT}/api/generate"
|
||||||
|
))
|
||||||
|
.body(
|
||||||
|
serde_json::json!({
|
||||||
|
"model": OLLAMA_AI_MODEL_DATA_SANITIZATION,
|
||||||
|
"prompt": format!("{prompt_data_sanitization} \n{file_contents}"),
|
||||||
|
"temperature": 0.0, // Get predictable and reproducible output
|
||||||
|
"stream": false,
|
||||||
|
})
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let result = ollama_api_request.timeout(Duration::from_secs(3600)).send();
|
||||||
|
|
||||||
|
match result {
|
||||||
|
Ok(response) => {
|
||||||
|
println!("Response: {:?}", response);
|
||||||
|
let response_json = response
|
||||||
|
.json::<serde_json::Value>()
|
||||||
|
.expect("Failed to deserialize response to JSON");
|
||||||
|
let ai_response = response_json["response"]
|
||||||
|
.as_str()
|
||||||
|
.expect("Failed to get AI response as string");
|
||||||
|
|
||||||
|
let ai_response = ai_response.to_string();
|
||||||
|
|
||||||
|
let ai_response = if let Some(resp) = ai_response
|
||||||
|
.strip_prefix(" ")
|
||||||
|
.unwrap_or(&ai_response)
|
||||||
|
.strip_prefix("```csv\n")
|
||||||
|
{
|
||||||
|
resp.to_string()
|
||||||
|
} else {
|
||||||
|
ai_response
|
||||||
|
};
|
||||||
|
let ai_response = if let Some(resp) = ai_response
|
||||||
|
.strip_suffix(" ")
|
||||||
|
.unwrap_or(&ai_response)
|
||||||
|
.strip_suffix("```")
|
||||||
|
{
|
||||||
|
resp.to_string()
|
||||||
|
} else {
|
||||||
|
ai_response
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok((ai_response, file_name_csv));
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
println!("Error {error}");
|
||||||
|
return Err(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter_map_ok(|(ai_repsonse, file_path_csv)| {
|
||||||
|
let mut reader = csv::ReaderBuilder::new()
|
||||||
|
.has_headers(true)
|
||||||
|
.delimiter(b';')
|
||||||
|
.from_reader(ai_repsonse.as_bytes());
|
||||||
|
|
||||||
|
let mut deserialized_iter = reader.deserialize::<CsvHeader>();
|
||||||
|
|
||||||
|
let mut columns = deserialized_iter
|
||||||
|
.filter_ok(|value| value.PONTOS.is_some())
|
||||||
|
.map_ok(|value| {
|
||||||
|
let col =
|
||||||
|
Column::new(value.CATEGORIA.into(), [value.PONTOS.unwrap() as u32]);
|
||||||
|
col
|
||||||
|
})
|
||||||
|
.filter_map(|value| {
|
||||||
|
if value.is_ok() {
|
||||||
|
return Some(value.unwrap());
|
||||||
|
}
|
||||||
|
None
|
||||||
|
})
|
||||||
|
.collect_vec();
|
||||||
|
|
||||||
|
if columns.len() != 9 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse id talk from file_path
|
||||||
|
// filename example is: FIN - Lais Mota - 515578 - 20251020515578.csv
|
||||||
|
// id talk is the last information, so in the example is: 20251020515578
|
||||||
|
let regex_filename =
|
||||||
|
//regex::Regex::new(r"(FIN - )((\s*\w+\s*)+) - (\d+) - (\d+).csv").unwrap();
|
||||||
|
|
||||||
|
let filename = file_path_csv
|
||||||
|
.file_name()
|
||||||
|
.into_string()
|
||||||
|
.expect("Failed to convert file name as Rust &str");
|
||||||
|
let found_regex_groups_in_filename = regex_filename
|
||||||
|
.captures(filename.as_str())
|
||||||
|
.expect("Failed to do regex capture");
|
||||||
|
|
||||||
|
let user_name = found_regex_groups_in_filename
|
||||||
|
.get(2)
|
||||||
|
.expect("Failed to get the id from regex maches");
|
||||||
|
let talk_id = found_regex_groups_in_filename
|
||||||
|
.get(5)
|
||||||
|
.expect("Failed to get the id from regex maches");
|
||||||
|
|
||||||
|
let excelence_percentual = columns
|
||||||
|
.iter()
|
||||||
|
.map(|col| col.as_materialized_series().u32().unwrap().sum().unwrap())
|
||||||
|
.sum::<u32>() as f32
|
||||||
|
/ columns.iter().len() as f32
|
||||||
|
* 100.0;
|
||||||
|
columns.push(Column::new(
|
||||||
|
"PERCENTUAL DE EXELENCIA".into(),
|
||||||
|
[format!("{excelence_percentual:.2}")],
|
||||||
|
));
|
||||||
|
|
||||||
|
columns.push(Column::new("ID_TALK".into(), [talk_id.clone().as_str()]));
|
||||||
|
|
||||||
|
let df = polars::frame::DataFrame::new(columns)
|
||||||
|
.expect("Failed to concatenate into a dataframe");
|
||||||
|
|
||||||
|
// return a tuple with the dataframe and the user name, so it can be correctly merged after
|
||||||
|
return Some((user_name.as_str().to_owned(), df));
|
||||||
|
})
|
||||||
|
.filter_map(|res| {
|
||||||
|
if res.is_ok() {
|
||||||
|
return Some(res.unwrap());
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
})
|
||||||
|
.into_group_map()
|
||||||
|
.into_iter()
|
||||||
|
.map(|(name, eval_dataframe_vec)| {
|
||||||
|
let groupped_df = eval_dataframe_vec
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.reduce(|acc, e| acc.vstack(&e).unwrap())
|
||||||
|
.expect("Failed to concatenate dataframes");
|
||||||
|
(name, groupped_df)
|
||||||
|
})
|
||||||
|
.into_group_map();
|
||||||
|
|
||||||
|
dbg!(&groupped_by_user_on_day);
|
||||||
|
return Some(groupped_by_user_on_day);
|
||||||
|
})
|
||||||
|
.filter_map(|res| {
|
||||||
|
if res.is_ok() {
|
||||||
|
return Some(res.unwrap());
|
||||||
|
}
|
||||||
|
return None;
|
||||||
|
})
|
||||||
|
.reduce(|mut acc, mut e| {
|
||||||
|
e.iter_mut().for_each(|(key, val)| {
|
||||||
|
if acc.contains_key(key) {
|
||||||
|
acc.get_mut(key)
|
||||||
|
.expect("Failed to obtain key that should already be present")
|
||||||
|
.append(val);
|
||||||
|
} else {
|
||||||
|
acc.insert(key.to_owned(), val.to_owned());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
acc
|
||||||
|
})
|
||||||
|
.and_then(|groupped_hashmap_df| {
|
||||||
|
let result = groupped_hashmap_df
|
||||||
|
.iter()
|
||||||
|
.map(|(key, val)| {
|
||||||
|
let dfs = val
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.reduce(|acc, e| acc.vstack(&e).unwrap())
|
||||||
|
.expect("Failed to concatenate dataframes");
|
||||||
|
(key.clone(), dfs)
|
||||||
|
})
|
||||||
|
.collect_vec();
|
||||||
|
return Some(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Setup groupped folder
|
||||||
|
if !std::fs::exists(format!("./groupped/")).unwrap() {
|
||||||
|
std::fs::create_dir(format!("./groupped")).expect("Failed to create directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup previous week folder
|
||||||
|
if !std::fs::exists(format!(
|
||||||
|
"./groupped/{first_day_of_last_week} - {last_day_of_last_week}"
|
||||||
|
))
|
||||||
|
.unwrap()
|
||||||
|
{
|
||||||
|
std::fs::create_dir(format!(
|
||||||
|
"./groupped/{first_day_of_last_week} - {last_day_of_last_week}"
|
||||||
|
))
|
||||||
|
.expect("Failed to create directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
match groupped_values {
|
||||||
|
Some(mut val) => {
|
||||||
|
val.iter_mut().for_each(|(agent, groupped_evaluations)| {
|
||||||
|
let mut save_file_csv = std::fs::File::create(format!(
|
||||||
|
"./groupped/{first_day_of_last_week} - {last_day_of_last_week}/{agent}.csv"
|
||||||
|
))
|
||||||
|
.expect("Could not create csv file for saving");
|
||||||
|
CsvWriter::new(&mut save_file_csv)
|
||||||
|
.include_header(true)
|
||||||
|
.with_separator(b';')
|
||||||
|
.finish(groupped_evaluations)
|
||||||
|
.expect("Failed to save Groupped DataFrame to CSV File");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
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}"
|
||||||
|
)),
|
||||||
|
std::path::Path::new(&format!(
|
||||||
|
"./groupped/{first_day_of_last_week} - {last_day_of_last_week}.zip"
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
|
||||||
|
let recipients = "Wilson da Conceição Oliveira <wilson.oliveira@nova.net.br>, nicolas.borges@nova.net.br";
|
||||||
|
println!("Trying to send mail... {recipients}");
|
||||||
|
send_mail_util::send_mail_util::send_email(
|
||||||
|
&format!(
|
||||||
|
"Relatório agrupado dos atendimentos da fila do Financeiro N2 - semana {first_day_of_last_week} - {last_day_of_last_week}"
|
||||||
|
),
|
||||||
|
&BOT_EMAIL,
|
||||||
|
&BOT_EMAIL_PASSWORD,
|
||||||
|
recipients,
|
||||||
|
&format!("./groupped/{first_day_of_last_week} - {last_day_of_last_week}.zip"),
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user