blob: 560a6f3e08f276b1bfb758eae7278b4dd331a043 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)
}
|