forked from jelson.rodrigues/piperun-bot
chore: calculate excelence percentual for chats
This commit is contained in:
@@ -262,6 +262,17 @@ fn main() {
|
||||
.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)
|
||||
@@ -369,13 +380,13 @@ fn main() {
|
||||
|
||||
let recipients = "Wilson da Conceição Oliveira <wilson.oliveira@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!(
|
||||
"Relatório agrupado dos atendimentos 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"),
|
||||
);
|
||||
// send_mail_util::send_mail_util::send_email(
|
||||
// &format!(
|
||||
// "Relatório agrupado dos atendimentos 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"),
|
||||
// );
|
||||
}
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@@ -10,8 +10,8 @@ use serde_json::{self, json};
|
||||
|
||||
use std::io::prelude::*;
|
||||
|
||||
pub mod zip_directory_util;
|
||||
pub mod send_mail_util;
|
||||
pub mod zip_directory_util;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
match dotenv::dotenv().ok() {
|
||||
@@ -529,7 +529,13 @@ fn main() -> anyhow::Result<()> {
|
||||
let recipients = "Wilson da Conceição Oliveira <wilson.oliveira@nova.net.br>, Isadora G. Moura de Moura <isadora.moura@nova.net.br>";
|
||||
println!("Trying to send email... Recipients {recipients}");
|
||||
|
||||
send_mail_util::send_mail_util::send_email(&format!("Avaliacao atendimentos {formatted_day_before}"), &BOT_EMAIL, &BOT_EMAIL_PASSWORD, recipients, &output_zip_file_str);
|
||||
send_mail_util::send_mail_util::send_email(
|
||||
&format!("Avaliacao atendimentos {formatted_day_before}"),
|
||||
&BOT_EMAIL,
|
||||
&BOT_EMAIL_PASSWORD,
|
||||
recipients,
|
||||
&output_zip_file_str,
|
||||
);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -1,70 +1,69 @@
|
||||
pub mod zip_directory_util {
|
||||
|
||||
use std::io::prelude::*;
|
||||
use zip::write::SimpleFileOptions;
|
||||
use std::io::prelude::*;
|
||||
use zip::write::SimpleFileOptions;
|
||||
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use walkdir::{DirEntry, WalkDir};
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use walkdir::{DirEntry, WalkDir};
|
||||
|
||||
fn zip_dir<T>(
|
||||
it: &mut dyn Iterator<Item = DirEntry>,
|
||||
prefix: &Path,
|
||||
writer: T,
|
||||
method: zip::CompressionMethod,
|
||||
) where
|
||||
T: Write + Seek,
|
||||
{
|
||||
let mut zip = zip::ZipWriter::new(writer);
|
||||
let options = SimpleFileOptions::default()
|
||||
.compression_method(method)
|
||||
.unix_permissions(0o755);
|
||||
fn zip_dir<T>(
|
||||
it: &mut dyn Iterator<Item = DirEntry>,
|
||||
prefix: &Path,
|
||||
writer: T,
|
||||
method: zip::CompressionMethod,
|
||||
) where
|
||||
T: Write + Seek,
|
||||
{
|
||||
let mut zip = zip::ZipWriter::new(writer);
|
||||
let options = SimpleFileOptions::default()
|
||||
.compression_method(method)
|
||||
.unix_permissions(0o755);
|
||||
|
||||
let prefix = Path::new(prefix);
|
||||
let mut buffer = Vec::new();
|
||||
for entry in it {
|
||||
let path = entry.path();
|
||||
let name = path.strip_prefix(prefix).unwrap();
|
||||
let path_as_string = name
|
||||
.to_str()
|
||||
.map(str::to_owned)
|
||||
.expect("Failed to parse path");
|
||||
let prefix = Path::new(prefix);
|
||||
let mut buffer = Vec::new();
|
||||
for entry in it {
|
||||
let path = entry.path();
|
||||
let name = path.strip_prefix(prefix).unwrap();
|
||||
let path_as_string = name
|
||||
.to_str()
|
||||
.map(str::to_owned)
|
||||
.expect("Failed to parse path");
|
||||
|
||||
// Write file or directory explicitly
|
||||
// Some unzip tools unzip files with directory paths correctly, some do not!
|
||||
if path.is_file() {
|
||||
println!("adding file {path:?} as {name:?} ...");
|
||||
zip.start_file(path_as_string, options)
|
||||
.expect("Failed to add file");
|
||||
let mut f = File::open(path).unwrap();
|
||||
// Write file or directory explicitly
|
||||
// Some unzip tools unzip files with directory paths correctly, some do not!
|
||||
if path.is_file() {
|
||||
println!("adding file {path:?} as {name:?} ...");
|
||||
zip.start_file(path_as_string, options)
|
||||
.expect("Failed to add file");
|
||||
let mut f = File::open(path).unwrap();
|
||||
|
||||
f.read_to_end(&mut buffer).expect("Failed to read file");
|
||||
zip.write_all(&buffer).expect("Failed to write file");
|
||||
buffer.clear();
|
||||
} else if !name.as_os_str().is_empty() {
|
||||
// Only if not root! Avoids path spec / warning
|
||||
// and mapname conversion failed error on unzip
|
||||
println!("adding dir {path_as_string:?} as {name:?} ...");
|
||||
zip.add_directory(path_as_string, options)
|
||||
.expect("Failed to add directory");
|
||||
f.read_to_end(&mut buffer).expect("Failed to read file");
|
||||
zip.write_all(&buffer).expect("Failed to write file");
|
||||
buffer.clear();
|
||||
} else if !name.as_os_str().is_empty() {
|
||||
// Only if not root! Avoids path spec / warning
|
||||
// and mapname conversion failed error on unzip
|
||||
println!("adding dir {path_as_string:?} as {name:?} ...");
|
||||
zip.add_directory(path_as_string, options)
|
||||
.expect("Failed to add directory");
|
||||
}
|
||||
}
|
||||
}
|
||||
zip.finish().expect("Failed to ZIP");
|
||||
}
|
||||
|
||||
pub fn zip_source_dir_to_dst_file(src_dir: &Path, dst_file: &Path) {
|
||||
if !Path::new(src_dir).is_dir() {
|
||||
panic!("src_dir must be a directory");
|
||||
zip.finish().expect("Failed to ZIP");
|
||||
}
|
||||
|
||||
let method = zip::CompressionMethod::Stored;
|
||||
let path = Path::new(dst_file);
|
||||
let file = File::create(path).unwrap();
|
||||
pub fn zip_source_dir_to_dst_file(src_dir: &Path, dst_file: &Path) {
|
||||
if !Path::new(src_dir).is_dir() {
|
||||
panic!("src_dir must be a directory");
|
||||
}
|
||||
|
||||
let walkdir = WalkDir::new(src_dir);
|
||||
let it = walkdir.into_iter();
|
||||
|
||||
zip_dir(&mut it.filter_map(|e| e.ok()), src_dir, file, method);
|
||||
}
|
||||
let method = zip::CompressionMethod::Stored;
|
||||
let path = Path::new(dst_file);
|
||||
let file = File::create(path).unwrap();
|
||||
|
||||
let walkdir = WalkDir::new(src_dir);
|
||||
let it = walkdir.into_iter();
|
||||
|
||||
zip_dir(&mut it.filter_map(|e| e.ok()), src_dir, file, method);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user