summaryrefslogtreecommitdiff
path: root/src/web_frontend
diff options
context:
space:
mode:
Diffstat (limited to 'src/web_frontend')
-rw-r--r--src/web_frontend/asset_risk_chart.rs47
-rw-r--r--src/web_frontend/mod.rs1
2 files changed, 48 insertions, 0 deletions
diff --git a/src/web_frontend/asset_risk_chart.rs b/src/web_frontend/asset_risk_chart.rs
new file mode 100644
index 0000000..560a6f3
--- /dev/null
+++ b/src/web_frontend/asset_risk_chart.rs
@@ -0,0 +1,47 @@
+use std::collections::HashMap;
+use rocket_contrib::templates::Template;
+use crate::parsers::ini::IniFile;
+use crate::parsers::csv::CsvFile;
+use chrono::Utc;
+
+
+#[derive(Serialize)]
+pub struct AssetRiskContext {
+ risk_category : Vec<RiskCategory>
+}
+
+#[derive(Serialize)]
+pub struct RiskCategory{
+ name : String,
+ balance : f32
+}
+
+#[get("/asset/risk_chart")]
+pub fn asset_risk_chart_handler() -> rocket_contrib::templates::Template {
+ let asset_file = "data/asset.ini";
+ let asset = crate::banking::asset::Asset::from_ini_file(asset_file);
+
+ let mut acc : Vec<RiskCategory> = Vec::new();
+
+ let today = Utc::today().naive_utc();
+
+ for account in asset.iter() {
+ println!("{}", account.riskCategory);
+ let mut found = false;
+ for mut t in &mut acc {
+ if t.name == account.riskCategory {
+ found = true;
+ t.balance = t.balance + account.get_balance(today);
+ }
+ }
+ if !found {
+ acc.push( RiskCategory {
+ name : account.riskCategory.to_string(),
+ balance : account.get_balance(today)
+ });
+ }
+ }
+
+ let context = AssetRiskContext { risk_category : acc };
+ Template::render("asset_risk_chart", context)
+}
diff --git a/src/web_frontend/mod.rs b/src/web_frontend/mod.rs
index 3f58227..3dbc693 100644
--- a/src/web_frontend/mod.rs
+++ b/src/web_frontend/mod.rs
@@ -2,6 +2,7 @@ pub mod transactions;
pub mod balance;
pub mod chart;
pub mod asset;
+pub mod asset_risk_chart;
mod util;
use rocket::response::NamedFile;
use std::path::{PathBuf, Path};