Adição de data manual
This commit is contained in:
114
src/main.rs
114
src/main.rs
@@ -125,6 +125,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
// Get the current day in the format YYYY-MM-DD
|
// Get the current day in the format YYYY-MM-DD
|
||||||
let current_date = chrono::Local::now();
|
let current_date = chrono::Local::now();
|
||||||
let formatted_date = current_date.format("%Y-%m-%d").to_string();
|
let formatted_date = current_date.format("%Y-%m-%d").to_string();
|
||||||
@@ -183,6 +185,54 @@ fn main() -> anyhow::Result<()> {
|
|||||||
))
|
))
|
||||||
.expect("Failed to response_time.csv");
|
.expect("Failed to response_time.csv");
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// --- NOVO: processar argumento de linha de comando para data específica ---
|
||||||
|
use std::env;
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
let target_day = if args.len() > 1 {
|
||||||
|
// Se um argumento foi passado, interpretar como YYYY-MM-DD
|
||||||
|
let naive_date = NaiveDate::parse_from_str(&args[1], "%Y-%m-%d")
|
||||||
|
.expect("Formato de data inválido. Use YYYY-MM-DD");
|
||||||
|
// Converter para DateTime com hora 00:00:00 do fuso local
|
||||||
|
naive_date.and_hms_opt(0, 0, 0).unwrap()
|
||||||
|
} else {
|
||||||
|
// Comportamento padrão: dia anterior ao atual
|
||||||
|
(chrono::Local::now() - chrono::Duration::days(1)).naive_local()
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Processando o dia: {}", target_day.format("%Y-%m-%d"));
|
||||||
|
|
||||||
|
// Definir início e fim do dia (para consultas na API)
|
||||||
|
let day_start = target_day; // já 00:00
|
||||||
|
let day_end = target_day
|
||||||
|
.with_hour(23).unwrap()
|
||||||
|
.with_minute(59).unwrap()
|
||||||
|
.with_second(59).unwrap();
|
||||||
|
|
||||||
|
let formatted_day = target_day.format("%Y-%m-%d").to_string();
|
||||||
|
let formatted_day_start = day_start.format("%Y-%m-%d %H:%M").to_string();
|
||||||
|
let formatted_day_end = day_end.format("%Y-%m-%d %H:%M").to_string();
|
||||||
|
|
||||||
|
println!("Início do dia: {}", formatted_day_start);
|
||||||
|
println!("Fim do dia: {}", formatted_day_end);
|
||||||
|
|
||||||
|
// Criar pasta com o nome do dia processado
|
||||||
|
if !std::fs::exists(format!("./evaluations/{formatted_day}")).unwrap() {
|
||||||
|
std::fs::create_dir(format!("./evaluations/{formatted_day}"))
|
||||||
|
.expect("Failed to create directory");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Criar arquivo response_time.csv se não existir
|
||||||
|
if !std::fs::exists(format!("./evaluations/{formatted_day}/response_time.csv")).unwrap() {
|
||||||
|
let _ = std::fs::File::create_new(format!(
|
||||||
|
"./evaluations/{formatted_day}/response_time.csv"
|
||||||
|
))
|
||||||
|
.expect("Failed to create response_time.csv");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Read system prompt
|
// Read system prompt
|
||||||
let prompt = std::fs::read_to_string("PROMPT.txt").unwrap();
|
let prompt = std::fs::read_to_string("PROMPT.txt").unwrap();
|
||||||
@@ -196,8 +246,10 @@ fn main() -> anyhow::Result<()> {
|
|||||||
&PIPERUN_API_URL,
|
&PIPERUN_API_URL,
|
||||||
&client,
|
&client,
|
||||||
&access_token,
|
&access_token,
|
||||||
formatted_day_before_at_midnight,
|
// formatted_day_before_at_midnight,
|
||||||
formatted_day_before_at_23_59_59,
|
formatted_day_start,
|
||||||
|
// formatted_day_before_at_23_59_59,
|
||||||
|
formatted_day_end,
|
||||||
);
|
);
|
||||||
|
|
||||||
println!("Number of consolidated talks: {}", talks_array.len());
|
println!("Number of consolidated talks: {}", talks_array.len());
|
||||||
@@ -332,10 +384,6 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let json = messages.unwrap();
|
let json = messages.unwrap();
|
||||||
let talk_histories = &json["talk_histories"];
|
let talk_histories = &json["talk_histories"];
|
||||||
|
|
||||||
// dbg!(&talk_histories);
|
|
||||||
|
|
||||||
// talk_histories.as_array().unwrap().into_iter().enumerate().for_each(|(pos, message_obj)|{println!("{}: {}", pos, message_obj["message"])});
|
|
||||||
|
|
||||||
// find the bot transfer message
|
// find the bot transfer message
|
||||||
let bot_transfer_message = talk_histories
|
let bot_transfer_message = talk_histories
|
||||||
.as_array()
|
.as_array()
|
||||||
@@ -352,7 +400,6 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let message = message_object["message"]
|
let message = message_object["message"]
|
||||||
.as_str()
|
.as_str()
|
||||||
.expect("Failed to decode message as string");
|
.expect("Failed to decode message as string");
|
||||||
//let found = message.find("Atendimento transferido para a fila [NovaNet -> Atendimento -> Financeiro NVL2]");
|
|
||||||
let found = message.find("Atendimento entregue da fila de espera para o agente [FIN - ");
|
let found = message.find("Atendimento entregue da fila de espera para o agente [FIN - ");
|
||||||
found.is_some()
|
found.is_some()
|
||||||
});
|
});
|
||||||
@@ -441,7 +488,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let mut response_time_file = std::fs::OpenOptions::new()
|
let mut response_time_file = std::fs::OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.open(format!(
|
.open(format!(
|
||||||
"./evaluations/{formatted_day_before}/response_time.csv"
|
// "./evaluations/{formatted_day_before}/response_time.csv"
|
||||||
|
"./evaluations/{formatted_day}/response_time.csv"
|
||||||
))
|
))
|
||||||
.expect("Failed to open response time file for write");
|
.expect("Failed to open response time file for write");
|
||||||
response_time_file
|
response_time_file
|
||||||
@@ -519,7 +567,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
std::fs::write(
|
std::fs::write(
|
||||||
format!(
|
format!(
|
||||||
"./evaluations/{}/{} - {} - {}.csv",
|
"./evaluations/{}/{} - {} - {}.csv",
|
||||||
formatted_day_before, user_name, talk_id, tracking_number
|
//formatted_day_before, user_name, talk_id, tracking_number
|
||||||
|
formatted_day, user_name, talk_id, tracking_number
|
||||||
),
|
),
|
||||||
csv_response,
|
csv_response,
|
||||||
)
|
)
|
||||||
@@ -527,7 +576,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
std::fs::write(
|
std::fs::write(
|
||||||
format!(
|
format!(
|
||||||
"./evaluations/{}/{} - {} - {} - prompt.txt",
|
"./evaluations/{}/{} - {} - {} - prompt.txt",
|
||||||
formatted_day_before, user_name, talk_id, tracking_number
|
//formatted_day_before, user_name, talk_id, tracking_number
|
||||||
|
formatted_day, user_name, talk_id, tracking_number
|
||||||
),
|
),
|
||||||
format!("{prompt} \n{talk}"),
|
format!("{prompt} \n{talk}"),
|
||||||
)
|
)
|
||||||
@@ -540,24 +590,28 @@ fn main() -> anyhow::Result<()> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Compress folder into zip
|
// Compress folder into zip
|
||||||
let source_dir_str = format!("./evaluations/{formatted_day_before}");
|
//let source_dir_str = format!("./evaluations/{formatted_day_before}");
|
||||||
let output_zip_file_str = format!("./evaluations/{formatted_day_before}.zip");
|
let source_dir_str = format!("./evaluations/{formatted_day}");
|
||||||
|
//let output_zip_file_str = format!("./evaluations/{formatted_day_before}.zip");
|
||||||
|
let output_zip_file_str = format!("./evaluations/{formatted_day}.zip");
|
||||||
let source_dir = std::path::Path::new(source_dir_str.as_str());
|
let source_dir = std::path::Path::new(source_dir_str.as_str());
|
||||||
let output_zip_file = std::path::Path::new(output_zip_file_str.as_str());
|
let output_zip_file = std::path::Path::new(output_zip_file_str.as_str());
|
||||||
zip_directory_util::zip_directory_util::zip_source_dir_to_dst_file(source_dir, output_zip_file);
|
zip_directory_util::zip_directory_util::zip_source_dir_to_dst_file(source_dir, output_zip_file);
|
||||||
|
|
||||||
|
/*
|
||||||
// Send folder to email
|
// Send folder to email
|
||||||
let recipients = "Wilson da Conceição Oliveira <wilson.oliveira@nova.net.br>, nicolas.borges@nova.net.br";
|
let recipients = "Wilson da Conceição Oliveira <wilson.oliveira@nova.net.br>, nicolas.borges@nova.net.br";
|
||||||
// let recipients = "Wilson da Conceição Oliveira <wilson.oliveira@nova.net.br>, nicolas.borges@nova.net.br";
|
let recipients = "Wilson da Conceição Oliveira <wilson.oliveira@nova.net.br>, nicolas.borges@nova.net.br";
|
||||||
println!("Trying to send email... Recipients {recipients}");
|
println!("Trying to send email... Recipients {recipients}");
|
||||||
|
|
||||||
send_mail_util::send_mail_util::send_email(
|
send_mail_util::send_mail_util::send_email(
|
||||||
&format!("Avaliacao atendimentos da fila Financeiro NVL2 do dia {formatted_day_before}"),
|
&format!("Avaliacao atendimentos da fila Financeiro NVL2 do dia {formatted_day_before}"),
|
||||||
&BOT_EMAIL,
|
&BOT_EMAIL,
|
||||||
&BOT_EMAIL_PASSWORD,
|
&BOT_EMAIL_PASSWORD,
|
||||||
recipients,
|
recipients,
|
||||||
&output_zip_file_str,
|
&output_zip_file_str,
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -566,8 +620,10 @@ fn get_piperun_chats_on_date(
|
|||||||
PIPERUN_API_URL: &String,
|
PIPERUN_API_URL: &String,
|
||||||
client: &reqwest::blocking::Client,
|
client: &reqwest::blocking::Client,
|
||||||
access_token: &String,
|
access_token: &String,
|
||||||
formatted_day_before_at_midnight: String,
|
//formatted_day_before_at_midnight: String,
|
||||||
formatted_day_before_at_23_59_59: String,
|
formatted_day_start: String,
|
||||||
|
//formatted_day_before_at_23_59_59: String,
|
||||||
|
formatted_day_end: String,
|
||||||
) -> Vec<serde_json::Value> {
|
) -> Vec<serde_json::Value> {
|
||||||
let start_of_talk_code: String = "talk_start".to_string();
|
let start_of_talk_code: String = "talk_start".to_string();
|
||||||
let support_queue_id: String = "16".to_string();
|
let support_queue_id: String = "16".to_string();
|
||||||
@@ -586,8 +642,10 @@ fn get_piperun_chats_on_date(
|
|||||||
("page", page.clone()),
|
("page", page.clone()),
|
||||||
("perPage", per_page.clone()),
|
("perPage", per_page.clone()),
|
||||||
("report_type", report_type.clone()),
|
("report_type", report_type.clone()),
|
||||||
("start_date", formatted_day_before_at_midnight.clone()),
|
// ("start_date", formatted_day_before_at_midnight.clone()),
|
||||||
("end_date", formatted_day_before_at_23_59_59.clone()),
|
("start_date", formatted_day_start.clone()),
|
||||||
|
//("end_date", formatted_day_before_at_23_59_59.clone()),
|
||||||
|
("end_date", formatted_day_end.clone()),
|
||||||
("date_range_type", start_of_talk_code.clone()),
|
("date_range_type", start_of_talk_code.clone()),
|
||||||
("queue_id[]", support_queue_id.clone()),
|
("queue_id[]", support_queue_id.clone()),
|
||||||
]);
|
]);
|
||||||
@@ -642,8 +700,10 @@ fn get_piperun_chats_on_date(
|
|||||||
("page", page_to_request.to_string()),
|
("page", page_to_request.to_string()),
|
||||||
("perPage", per_page.clone()),
|
("perPage", per_page.clone()),
|
||||||
("report_type", report_type.clone()),
|
("report_type", report_type.clone()),
|
||||||
("start_date", formatted_day_before_at_midnight.clone()),
|
//("start_date", formatted_day_before_at_midnight.clone()),
|
||||||
("end_date", formatted_day_before_at_23_59_59.clone()),
|
("start_date", formatted_day_start.clone()),
|
||||||
|
//("end_date", formatted_day_before_at_23_59_59.clone()),
|
||||||
|
("end_date", formatted_day_end.clone()),
|
||||||
("date_range_type", start_of_talk_code.clone()),
|
("date_range_type", start_of_talk_code.clone()),
|
||||||
("queue_id[]", support_queue_id.clone()),
|
("queue_id[]", support_queue_id.clone()),
|
||||||
]);
|
]);
|
||||||
|
|||||||
Reference in New Issue
Block a user