Cleaning up ts.rs.

[?]
CrEcTsRjb1hHQjHuumqRfqdbVV4X58iLEubi4noaDPFa
Jul 22, 2021, 12:50 PM
EHEK63WARL6PGYZMCSOH53JXOYPHNGWZO4QP5RKODPIQJ53IWDDQC

Dependencies

  • [2] XPXYFEZM Finished code for building TSJson struct.
  • [3] 5B2HBV3J Completed first try at ts Json data-structure.
  • [4] 2CCG6KUP Redo time-series spec.
  • [5] TTR5IFSG Working on building generic TSSpec.
  • [6] SAHJYVNB Removed checking functionality.
  • [7] XI5ALEH6 Take advantage of keytree FromStr functionality.
  • [8] K4CH53V4 Added GPL2 license, included missing source files.
  • [9] TSY4YBBZ Changed ts Spec datastructures to new format.
  • [10] SPSFTMLR Completed loading ts_data from specification.
  • [11] BB2T6X3X Improved documentation.
  • [*] GQVS55HI Finished generate_ts_spec() function.
  • [*] GUXZCEWW Added Country enum.
  • [*] 4MG5JFXT First record.

Change contents

  • replacement in src/ts.rs at line 25
    [3.194][2.0:92]()
    pub struct Json(BTreeMap<(Country, DataType, usize), (Vec<SeriesJson>, Vec<GraphicJson>)>);
    [3.194]
    [3.267]
    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
    [3.882]
    [3.882]
    height_opt,
  • replacement in src/ts.rs at line 137
    [3.1056][2.554:603]()
    // Iterate over graphics on one page
    [3.1056]
    [2.603]
    // 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
    [3.1165][3.1165:1197]()
    height_opt,
  • edit in src/ts.rs at line 168
    [3.1523][2.605:1266]()
    // 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
    [3.1736]
    [3.1736]
    // Construct indices for series in GraphicJson
  • edit in src/ts.rs at line 179
    [3.1737]
    [3.1737]
    // We have
  • replacement in src/ts.rs at line 182
    [3.1783][2.1376:1506]()
    let series_ref = match m_series.get(series_id) {
    Some((series_ref, _)) => series_ref,
    [3.1783]
    [2.1506]
    // dbg!(&series_id);
    let ix = match m_series.get(series_id) {
    Some((ix, _)) => ix,
  • replacement in src/ts.rs at line 193
    [2.1826][2.1826:1889]()
    graphic_json.series_ref.push(*series_ref);
    [2.1826]
    [3.1892]
    // dbg!(ix);
    graphic_json.series_ref.push(*ix);
  • replacement in src/ts.rs at line 205
    [2.2106][2.2106:2194]()
    // collection of SeriesJsons and the collection of GraphicsJsons into Json.
    [2.2106]
    [2.2194]
    // collection of SeriesJsons and the collection of GraphicJsons into Json.
  • replacement in src/ts.rs at line 214
    [2.2422][2.2422:2503]()
    json.insert((*country, *data_type, *index), (v_series, v_graphics));
    [2.2422]
    [3.2119]
    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
    [3.635]
    [3.2183]
    pub height_opt: Option<f32>,
  • edit in src/ts.rs at line 335
    [3.3112]
    [3.3112]
  • edit in src/ts.rs at line 353
    [3.9164]
    [3.3349]
    height_opt: self.opt_value("page::height")?,
  • edit in src/ts.rs at line 435
    [3.3533][3.3533:3566]()
    pub height_opt: Option<f32>,
  • edit in src/ts.rs at line 446
    [3.3669][3.3669:3737]()
    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
    [2.3012][2.3012:3059]()
    ts_spec.into_json(&root_dir).unwrap();
    [2.3012]
    [3.11459]
    ts_spec.into_json(&root_dir).unwrap().into_ts_data();
  • replacement in src/lib.rs at line 229
    [3.2488][3.4683:4711]()
    #[derive(Clone, Serialize)]
    [3.2488]
    [3.2488]
    #[derive(Clone, Debug, Serialize)]
  • edit in src/lib.rs at line 481
    [3.4837]
    [3.4871]
    height_opt: None,
  • edit in src/lib.rs at line 488
    [3.4951][3.4951:4985]()
    height_opt: None,
  • edit in src/lib.rs at line 513
    [3.5308][3.5308:5346]()
    height_opt: None,
  • replacement in src/error.rs at line 108
    [3.9762][3.9762:9841]()
    "[ui_date:06:{}:{}] Could not find graphic reference [{}] in series.",
    [3.9762]
    [3.9841]
    "[ui_data:06:{}:{}] Could not find graphic reference [{}] in series.",
  • edit in src/error.rs at line 115
    [3.9908]
    [3.16201]
    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,
    ))
    }