From 5477f91bb92e8b29587471639a0bbacf3396816e Mon Sep 17 00:00:00 2001 From: Jelson Rodrigues Date: Thu, 30 Oct 2025 12:03:23 -0300 Subject: [PATCH] chore: gather user name and evaluation as a dataframe --- src/groupped_repport.rs | 52 ++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/groupped_repport.rs b/src/groupped_repport.rs index 9ca95dd..f7d70c5 100644 --- a/src/groupped_repport.rs +++ b/src/groupped_repport.rs @@ -5,6 +5,7 @@ use itertools::Itertools; use polars::prelude::buffer::validate_utf8; use polars::prelude::*; use reqwest; +use serde::Deserialize; use walkdir; use std::time::Duration; use std::env; @@ -31,6 +32,14 @@ struct CsvEvaluation { ID_TALK: String } +// impl TryFrom::> for CsvEvaluation { +// type Error = &'static str; + +// fn try_from(value: csv::DeserializeRecordsIter<&[u8], CsvHeader>) -> Result { +// todo!() +// } +// } + fn main() { match dotenv::dotenv().ok() { Some(_) => println!("Environment variables loaded from .env file"), @@ -170,11 +179,20 @@ fn main() { let mut deserialized_iter = reader.deserialize::(); - let correctly_parsed = deserialized_iter.all(|value| { - value.is_ok() && value.unwrap().PONTOS.is_some() - }); + 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 !correctly_parsed { return None; } + if columns.len() != 9 { return None;} // Parse id talk from file_path // filename example is: CC - Erraoander Quintana - 515578 - 20251020515578.csv @@ -189,25 +207,21 @@ fn main() { filename.as_str() ).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); - // a.for_each(|val| { println!("{:?}", val)}); + 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"); - // println!("{:?}", a); - - // Do validation on CSV parsed - // let records_parsed = reader.records(); - - // if records_parsed.try_len().expect("Failed to obtain lenght") != 9 { return None; } - - // reader.records().for_each(|record| println!("{:?}", record)); - - - return Some(()); + println!("{:?}", df); + // Create a dataframe with the evaluation columns plus the talk id + + // 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)); }) - .for_each(|_value| {}); + .for_each(|username| {}); // println!("{:?}", files_inside_folder_on_date); return Some(());