diff options
Diffstat (limited to 'src/web_frontend/chart.rs')
| -rw-r--r-- | src/web_frontend/chart.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/web_frontend/chart.rs b/src/web_frontend/chart.rs new file mode 100644 index 0000000..c5948fe --- /dev/null +++ b/src/web_frontend/chart.rs @@ -0,0 +1,61 @@ +use parsers::csv::CsvFile; +use banking::Account; +//use parsers::ini::IniFile; +use std::collections::HashMap; +use rocket_contrib::templates::Template; +use rocket::response::NamedFile; +use std::path::{PathBuf, Path}; +use rocket::request::Form; +use rocket::http::RawStr; +use regex::Regex; +use chrono::{NaiveDate, Utc}; +use chrono::Datelike; + +#[derive(Serialize)] +struct ChartContext { + account_name : String, + groups : HashMap<String, f32> +} + + +#[get("/chart")] +fn chart_handler() -> rocket_contrib::templates::Template { + // read group config + let chart_file = "data/giro"; + let chart_config = IniFile::from_file(chart_file); + let ini_file; + match chart_config { + Ok(file) => ini_file = file, + Err(e) => panic!("could not read group file {:?}", e) + } + let mut groups = HashMap::new(); + for (section_name, entries) in ini_file.sections { + let mut complete = 0.0; + println!("section name: {}", section_name); + for entrie in entries { + for val in entrie.values { + if entrie.name.is_empty() || val.is_empty() { + continue + } + println!("entrie is : {}", entrie.name); + let transactions = CsvFile::from_file("data/t.csv", ";", true); + let t : Vec<banking::Transaction> ; + match transactions { + Ok(trans) => t = banking::Transaction::from_sparkasse_csv_file(trans), + Err(e) => panic!("could not read file {:?}", e) + } + let re = Regex::new(&val).unwrap(); + let tmp = t.into_iter().filter(|transaction| + re.is_match(&transaction.sender_name) ) + .fold(0.0, |acc, x| acc + x.amount); + complete = complete + tmp.abs(); + } + } + groups.insert(section_name, complete); + // ALSO INSERT OTHER, AKA THE REST + } + let context = ChartContext { account_name : String::from("Girokonto"), + groups : groups }; + Template::render("chart", context) +} + |
