chore: gather user name and evaluation as a dataframe

This commit is contained in:
2025-10-30 12:03:23 -03:00
parent ca406b4601
commit 5477f91bb9

View File

@@ -5,6 +5,7 @@ use itertools::Itertools;
use polars::prelude::buffer::validate_utf8; use polars::prelude::buffer::validate_utf8;
use polars::prelude::*; use polars::prelude::*;
use reqwest; use reqwest;
use serde::Deserialize;
use walkdir; use walkdir;
use std::time::Duration; use std::time::Duration;
use std::env; use std::env;
@@ -31,6 +32,14 @@ struct CsvEvaluation {
ID_TALK: String ID_TALK: String
} }
// impl TryFrom::<csv::DeserializeRecordsIter<&[u8], CsvHeader>> for CsvEvaluation {
// type Error = &'static str;
// fn try_from(value: csv::DeserializeRecordsIter<&[u8], CsvHeader>) -> Result<Self, Self::Error> {
// todo!()
// }
// }
fn main() { fn main() {
match dotenv::dotenv().ok() { match dotenv::dotenv().ok() {
Some(_) => println!("Environment variables loaded from .env file"), Some(_) => println!("Environment variables loaded from .env file"),
@@ -170,11 +179,20 @@ fn main() {
let mut deserialized_iter = reader.deserialize::<CsvHeader>(); let mut deserialized_iter = reader.deserialize::<CsvHeader>();
let correctly_parsed = deserialized_iter.all(|value| { let mut columns = deserialized_iter.filter_ok(|value| {
value.is_ok() && value.unwrap().PONTOS.is_some() 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 !correctly_parsed { return None; } if columns.len() != 9 { return None;}
// Parse id talk from file_path // Parse id talk from file_path
// filename example is: CC - Erraoander Quintana - 515578 - 20251020515578.csv // filename example is: CC - Erraoander Quintana - 515578 - 20251020515578.csv
@@ -189,25 +207,21 @@ fn main() {
filename.as_str() filename.as_str()
).expect("Failed to do regex capture"); ).expect("Failed to do regex capture");
let talk_id = found_regex_groups_in_filename.get(5).expect("Failed to get the id from regex maches").clone(); 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");
println!("{:?}", talk_id); columns.push(Column::new("ID_TALK".into(), [talk_id.clone().as_str()]));
// a.for_each(|val| { println!("{:?}", val)});
let df = polars::frame::DataFrame::new(columns).expect("Failed to concatenate into a dataframe");
// println!("{:?}", a); println!("{:?}", df);
// Create a dataframe with the evaluation columns plus the talk id
// Do validation on CSV parsed
// let records_parsed = reader.records(); // 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));
// if records_parsed.try_len().expect("Failed to obtain lenght") != 9 { return None; }
// reader.records().for_each(|record| println!("{:?}", record));
return Some(());
}) })
.for_each(|_value| {}); .for_each(|username| {});
// println!("{:?}", files_inside_folder_on_date); // println!("{:?}", files_inside_folder_on_date);
return Some(()); return Some(());