Cleaning up ts.rs.
[?]
CrEcTsRjb1hHQjHuumqRfqdbVV4X58iLEubi4noaDPFa
Jul 22, 2021, 12:50 PM
EHEK63WARL6PGYZMCSOH53JXOYPHNGWZO4QP5RKODPIQJ53IWDDQCDependencies
- [2]
XPXYFEZMFinished code for building TSJson struct. - [3]
5B2HBV3JCompleted first try at ts Json data-structure. - [4]
2CCG6KUPRedo time-series spec. - [5]
TTR5IFSGWorking on building generic TSSpec. - [6]
SAHJYVNBRemoved checking functionality. - [7]
XI5ALEH6Take advantage of keytree FromStr functionality. - [8]
K4CH53V4Added GPL2 license, included missing source files. - [9]
TSY4YBBZChanged ts Spec datastructures to new format. - [10]
SPSFTMLRCompleted loading ts_data from specification. - [11]
BB2T6X3XImproved documentation. - [*]
GQVS55HIFinished generate_ts_spec() function. - [*]
GUXZCEWWAdded Country enum. - [*]
4MG5JFXTFirst record.
Change contents
- replacement in src/ts.rs at line 25
pub struct Json(BTreeMap<(Country, DataType, usize), (Vec<SeriesJson>, Vec<GraphicJson>)>);pub struct Json(BTreeMap<(Country, DataType, usize), PageValue>);impl Json {pub fn into_ts_data(&self) -> Result<TSData, Error> {let mut map: BTreeMap<(Country, DataType, usize), String> = BTreeMap::new();for (key, value) in self.0.iter() {let json = serde_json::to_string(&value).map_err(|_| {failed_to_serialize_to_json(file!(),line!(),)})?;map.insert(*key, json);}Ok(TSData(map))}}pub struct TSData(pub BTreeMap<(Country, DataType, usize), String>);// The JSON that is served for a given page.#[derive(Debug, Serialize)]pub struct PageValue {country: Country,data_type: DataType,index: usize,seriess: Vec<SeriesJson>,graphics: Vec<GraphicJson>,first_date: MonthlyDate,last_date: MonthlyDate,max: f32,min: f32,height: f32,} - edit in src/ts.rs at line 126
height_opt, - replacement in src/ts.rs at line 137
// Iterate over graphics on one page// Build series data from series specification.// We want to build a BTreeMap<SeriesId, SeriesJson> from a BTreeMap<SeriesId, SeriesSpec>for (i, (series_id, series_spec)) in seriess.iter().enumerate() {m_series.insert(series_id.clone(),(i,page_spec.into_series_json(series_id, *country, root_path)?,));}//Build graphics from graphics specification. - edit in src/ts.rs at line 157
height_opt, - edit in src/ts.rs at line 168
// Iterate over series_ids and build series_json first. There is a one-to-one// correspondence between SeriesSpec and SeriesJson so we can use the indices in// SeriesSpec to build GraphicJson.// Push SeriesJson Vec<SeriesJson>for (i, series_id) in series_ids.iter().enumerate() {m_series.insert(series_id.clone(),(i,page_spec.into_series_json(series_id, *country, root_path)?,));} - edit in src/ts.rs at line 176
// Construct indices for series in GraphicJson - edit in src/ts.rs at line 179
// We have - replacement in src/ts.rs at line 182
let series_ref = match m_series.get(series_id) {Some((series_ref, _)) => series_ref,// dbg!(&series_id);let ix = match m_series.get(series_id) {Some((ix, _)) => ix, - replacement in src/ts.rs at line 193
graphic_json.series_ref.push(*series_ref);// dbg!(ix);graphic_json.series_ref.push(*ix); - replacement in src/ts.rs at line 205
// collection of SeriesJsons and the collection of GraphicsJsons into Json.// collection of SeriesJsons and the collection of GraphicJsons into Json. - replacement in src/ts.rs at line 214
json.insert((*country, *data_type, *index), (v_series, v_graphics));let first_date = v_series.iter().map(|series_json| series_json.rts.first_date()).min().unwrap();let last_date = v_series.iter().map(|series_json| series_json.rts.last_date()).max().unwrap();let max = v_series.iter().map(|series_json| series_json.rts.max(0)).fold(f32::NEG_INFINITY, |a, b| a.max(b));let min = v_series.iter().map(|series_json| series_json.rts.min(0)).fold(f32::INFINITY, |a, b| a.min(b));let height = match height_opt {Some(h) => *h,None => GRAPHIC_HEIGHT,};let page_value = PageValue {country: *country,data_type: *data_type,index: *index,seriess: v_series,graphics: v_graphics,first_date: MonthlyDate(first_date),last_date: MonthlyDate(last_date),max: max,min: min,height: height,};json.insert((*country, *data_type, *index), page_value); - edit in src/ts.rs at line 298
pub height_opt: Option<f32>, - edit in src/ts.rs at line 335
- edit in src/ts.rs at line 353
height_opt: self.opt_value("page::height")?, - edit in src/ts.rs at line 435
pub height_opt: Option<f32>, - edit in src/ts.rs at line 446
height_opt: self.opt_value("graphic::height")?, - edit in src/ts.rs at line 460[3.2378]→[3.2378:2389](∅→∅),[3.2389]→[3.3857:3901](∅→∅),[3.3901]→[3.2429:2472](∅→∅),[3.2429]→[3.2429:2472](∅→∅)
}if let Some(h) = &self.height_opt {kt.push_value(1, "height", h); - replacement in src/main.rs at line 60
ts_spec.into_json(&root_dir).unwrap();ts_spec.into_json(&root_dir).unwrap().into_ts_data(); - replacement in src/lib.rs at line 229
#[derive(Clone, Serialize)]#[derive(Clone, Debug, Serialize)] - edit in src/lib.rs at line 481
height_opt: None, - edit in src/lib.rs at line 488
height_opt: None, - edit in src/lib.rs at line 513
height_opt: None, - replacement in src/error.rs at line 108
"[ui_date:06:{}:{}] Could not find graphic reference [{}] in series.","[ui_data:06:{}:{}] Could not find graphic reference [{}] in series.", - edit in src/error.rs at line 115
pub fn failed_to_serialize_to_json(code_file: &str,code_line: u32) -> Error{Error(format!("[ui_data:07:{}:{}] Failed to serialize to json.",code_file,code_line,))}