forked from jelson.rodrigues/piperun-bot
chore: gather user name and evaluation as a dataframe
This commit is contained in:
@@ -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::<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() {
|
||||
match dotenv::dotenv().ok() {
|
||||
Some(_) => println!("Environment variables loaded from .env file"),
|
||||
@@ -170,11 +179,20 @@ fn main() {
|
||||
|
||||
let mut deserialized_iter = reader.deserialize::<CsvHeader>();
|
||||
|
||||
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()]));
|
||||
|
||||
// println!("{:?}", a);
|
||||
let df = polars::frame::DataFrame::new(columns).expect("Failed to concatenate into a dataframe");
|
||||
|
||||
// Do validation on CSV parsed
|
||||
// let records_parsed = reader.records();
|
||||
println!("{:?}", df);
|
||||
// Create a dataframe with the evaluation columns plus the talk id
|
||||
|
||||
// if records_parsed.try_len().expect("Failed to obtain lenght") != 9 { return None; }
|
||||
|
||||
// reader.records().for_each(|record| println!("{:?}", record));
|
||||
|
||||
|
||||
return Some(());
|
||||
// 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(());
|
||||
|
||||
Reference in New Issue
Block a user