Integrate date_range with transforms.

[?]
CrEcTsRjb1hHQjHuumqRfqdbVV4X58iLEubi4noaDPFa
Jul 23, 2021, 5:14 AM
PK7JY27R55PZON4SPFLJBX66IAE47SXBRAGDHXM4SN6TKZXO5LMAC

Dependencies

  • [2] PQKGZNQG Added class field to GraphicJson.
  • [3] EHEK63WA Cleaning up ts.rs.
  • [4] XI5ALEH6 Take advantage of keytree FromStr functionality.
  • [5] SPSFTMLR Completed loading ts_data from specification.
  • [6] TSY4YBBZ Changed ts Spec datastructures to new format.
  • [7] E2T2A74Y Added class field to GraphicSpec.
  • [8] 5B2HBV3J Completed first try at ts Json data-structure.
  • [9] SAHJYVNB Removed checking functionality.
  • [10] 2CCG6KUP Redo time-series spec.
  • [11] BB2T6X3X Improved documentation.
  • [12] XPXYFEZM Finished code for building TSJson struct.
  • [13] GQVS55HI Finished generate_ts_spec() function.
  • [14] K4CH53V4 Added GPL2 license, included missing source files.
  • [15] TTR5IFSG Working on building generic TSSpec.
  • [16] UUD3CJZL Making error handling more comprehensive.
  • [*] 4MG5JFXT First record.

Change contents

  • replacement in src/ts.rs at line 15
    [3.7908][2.23:99]()
    use crate::{ DataType, MonthlyDate, SeriesId, SeriesMetaData, SeriesSpec };
    [3.7908]
    [3.1114]
    use crate::{ DataType, DateRange, MonthlyDate, SeriesId, SeriesMetaData, SeriesSpec };
  • replacement in src/ts.rs at line 65
    [3.321][2.100:130]()
    class: GraphicClass,
    [3.321]
    [3.93]
    category: GraphicCategory,
  • edit in src/ts.rs at line 78
    [3.467]
    [3.467]
    series_id: SeriesId,
  • edit in src/ts.rs at line 142
    [2.199]
    [3.1308]
    // if m_series.contains_key(series_id) {
    // println!("Duplicate series_id");
    // panic!()
    // };
  • replacement in src/ts.rs at line 162
    [3.1134][3.0:31]()
    class_opt,
    [3.1134]
    [3.1134]
    category_opt,
  • replacement in src/ts.rs at line 177
    [3.1330][2.200:557]()
    let class = match class_opt {
    None => GraphicClass::Source,
    Some(GraphicClass::Cleaned) => GraphicClass::Cleaned,
    Some(GraphicClass::Collated) => GraphicClass::Collated,
    Some(GraphicClass::Source) => GraphicClass::Source,
    [3.1330]
    [2.557]
    let category = match category_opt {
    None => GraphicCategory::Source,
    Some(GraphicCategory::Cleaned) => GraphicCategory::Cleaned,
    Some(GraphicCategory::Collated) => GraphicCategory::Collated,
    Some(GraphicCategory::Source) => GraphicCategory::Source,
  • replacement in src/ts.rs at line 187
    [2.700][2.700:795]()
    if let GraphicClass::Source = class { graphic_spec.assert_has_one_series()? };
    [2.700]
    [2.795]
    if let GraphicCategory::Source = category {
    if !graphic_spec.assert_has_one_series() {
    return Err(expected_graphic_has_one_series(
    file!(),
    line!(),
    &country.to_string(),
    &data_type.to_string(),
    *index,
    ))
    }
    };
  • replacement in src/ts.rs at line 199
    [2.796][3.32:308](),[3.1330][3.32:308]()
    let text_spec = match graphic_spec.class_opt {
    Some(GraphicClass::Cleaned) => TextSpec::Link,
    Some(GraphicClass::Collated) => TextSpec::Link,
    Some(GraphicClass::Source) => TextSpec::Meta,
    [2.796]
    [3.308]
    let text_spec = match graphic_spec.category_opt {
    Some(GraphicCategory::Cleaned) => TextSpec::Link,
    Some(GraphicCategory::Collated) => TextSpec::Link,
    Some(GraphicCategory::Source) => TextSpec::Meta,
  • replacement in src/ts.rs at line 209
    [3.1577][2.799:838]()
    class: class,
    [3.1577]
    [3.1577]
    category: category,
  • edit in src/ts.rs at line 220
    [3.1783][3.1724:1765]()
    // dbg!(&series_id);
  • edit in src/ts.rs at line 365
    [3.2947]
    [3.2947]
    series_id: series_spec.series_id.clone(),
  • replacement in src/ts.rs at line 461
    [2.867][3.552:576](),[3.552][3.552:576]()
    pub enum GraphicClass {
    [2.867]
    [3.576]
    pub enum GraphicCategory {
  • replacement in src/ts.rs at line 472
    [3.826][3.826:858]()
    impl FromStr for GraphicClass {
    [3.826]
    [3.858]
    impl FromStr for GraphicCategory {
  • replacement in src/ts.rs at line 477
    [3.949][2.868:924](),[2.924][3.1004:1111](),[3.1004][3.1004:1111]()
    "collation" => Ok(GraphicClass::Collated),
    "source" => Ok(GraphicClass::Source),
    "cleaned" => Ok(GraphicClass::Cleaned),
    [3.949]
    [3.1111]
    "collation" => Ok(GraphicCategory::Collated),
    "source" => Ok(GraphicCategory::Source),
    "cleaned" => Ok(GraphicCategory::Cleaned),
  • replacement in src/ts.rs at line 485
    [3.1860][3.1219:1256]()
    impl fmt::Display for GraphicClass {
    [3.1860]
    [3.1256]
    impl fmt::Display for GraphicCategory {
  • replacement in src/ts.rs at line 488
    [3.1348][2.925:977](),[2.977][3.1399:1498](),[3.1399][3.1399:1498]()
    GraphicClass::Collated => "collation",
    GraphicClass::Source => "source",
    GraphicClass::Cleaned => "cleaned",
    [3.1348]
    [3.1498]
    GraphicCategory::Collated => "collation",
    GraphicCategory::Source => "source",
    GraphicCategory::Cleaned => "cleaned",
  • replacement in src/ts.rs at line 508
    [3.9473][3.1546:1588](),[3.1588][3.3497:3533](),[3.9473][3.3497:3533](),[3.3566][3.3566:3601]()
    pub class_opt: Option<GraphicClass>,
    pub title_opt: Option<String>,
    pub series_ids: Vec<SeriesId>,
    [3.9473]
    [2.978]
    pub category_opt: Option<GraphicCategory>,
    pub title_opt: Option<String>,
    pub series_ids: Vec<SeriesId>,
  • replacement in src/ts.rs at line 514
    [2.1000][2.1000:1271]()
    pub (crate) fn assert_has_one_series(&self) -> Result<(), Error> {
    if self.series_ids.len() != 1 {
    Err(expected_graphic_has_one_series(
    file!(),
    line!(),
    ))
    } else {
    Ok(())
    }
    [2.1000]
    [2.1271]
    pub (crate) fn assert_has_one_series(&self) -> bool {
    self.series_ids.len() == 1
  • replacement in src/ts.rs at line 525
    [3.1845][3.1589:1656]()
    class_opt: self.opt_value("graphic::class")?,
    [3.1845]
    [3.3602]
    category_opt: self.opt_value("graphic::category")?,
  • replacement in src/ts.rs at line 538
    [3.7063][3.1657:1704]()
    if let Some(class) = &self.class_opt {
    [3.7063]
    [3.1704]
    if let Some(class) = &self.category_opt {
  • edit in src/ts.rs at line 562
    [3.3358]
    [3.8105]
    DateRange(DateRange),
  • edit in src/ts.rs at line 585
    [3.4176]
    [3.4252]
    Transform::DateRange(date_range)
    => write!(f, "{}", date_range.to_string()),
  • replacement in src/lib.rs at line 205
    [3.4283][3.1762:1780]()
    GraphicClass,
    [3.4283]
    [3.4177]
    GraphicCategory,
  • replacement in src/lib.rs at line 249
    [3.4737][3.4208:4232]()
    #[derive(Clone, Debug)]
    [3.4737]
    [3.4754]
    #[derive(Clone, Copy, Debug, Serialize)]
  • edit in src/lib.rs at line 275
    [3.5413]
    [3.5413]
    }
    }
    impl fmt::Display for DateRange {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    let s = match (self.0.first_date(), self.0.last_date()) {
    (None, None) => {
    format!(
    "open"
    )
    },
    (Some(d1), None) => {
    format!(
    "from {}-{}-01",
    d1.year(),
    d1.month(),
    )
    },
    (None, Some(d2)) => {
    format!(
    "to {}-{}-01",
    d2.year(),
    d2.month()
    )
    },
    (Some(d1), Some(d2)) => {
    format!(
    "between {}-{}-01 and {}-{}-01",
    d1.year(),
    d1.month(),
    d2.year(),
    d2.month(),
    )
    },
    };
    write!(f, "{}", s)
  • replacement in src/lib.rs at line 523
    [3.4990][3.1781:1839](),[3.1839][3.4917:4951](),[3.4990][3.4917:4951](),[3.4985][3.4985:5025]()
    class_opt: Some(GraphicClass::Collated),
    title_opt: None,
    series_ids: Vec::new(),
    [3.4990]
    [3.5182]
    category_opt: Some(GraphicCategory::Collated),
    title_opt: None,
    series_ids: Vec::new(),
  • edit in src/lib.rs at line 536
    [3.5476][3.5476:5542]()
    date_range: DateRange::new(&None, &None),
  • replacement in src/lib.rs at line 547
    [3.5840][3.1840:1900](),[3.1900][3.5270:5308](),[3.5840][3.5270:5308](),[3.5346][3.5346:5416]()
    class_opt: Some(GraphicClass::Source),
    title_opt: None,
    series_ids: vec!(series_spec.series_id.clone()),
    [3.5840]
    [3.6078]
    category_opt: Some(GraphicCategory::Source),
    title_opt: None,
    series_ids: vec!(series_spec.series_id.clone()),
  • edit in src/lib.rs at line 724
    [3.8023][3.5891:5926]()
    pub date_range: DateRange,
  • replacement in src/lib.rs at line 808
    [3.5144][3.5144:5221]()
    let mut rts = self.read_data_without_transform(country, root_path)?;
    [3.5144]
    [3.6855]
    let rts = self.read_data_without_transform(country, root_path)?;
  • replacement in src/lib.rs at line 830
    [3.7629][3.7629:7647]()
    }
    [3.7629]
    [3.7647]
    },
    Transform::DateRange(range) => rts.range(&range.0),
  • edit in src/lib.rs at line 834
    [3.2037][3.7663:7707]()
    rts.with_range(&self.date_range.0);
  • edit in src/lib.rs at line 1151
    [3.12084][3.8469:8729]()
    if let Some(first_date) = self.date_range.first_date() {
    kt.push_value(1, "first_date", first_date);
    }
    if let Some(last_date) = self.date_range.last_date() {
    kt.push_value(1, "last_date", last_date);
    };
  • edit in src/lib.rs at line 1172
    [3.9056]
    [3.12311]
    let date_range = DateRange::new(&first_date, &last_date);
    let mut transforms: Vec<Transform> = self.vec_value("series::transforms")?;
    if first_date.is_some() || last_date.is_some() {
    transforms.push(Transform::DateRange(date_range));
    }
  • replacement in src/lib.rs at line 1185
    [3.12532][3.9122:9258]()
    date_range: DateRange::new(&first_date, &last_date),
    transforms: self.vec_value("series::transforms")?,
    [3.12532]
    [3.12532]
    transforms: transforms,
  • edit in src/fred.rs at line 17
    [3.6396][3.9259:9274]()
    DateRange,
  • edit in src/fred.rs at line 116
    [3.9392][3.9340:9406]()
    date_range: DateRange::new(&None, &None),
  • edit in src/fred.rs at line 169
    [3.11229][3.9520:9586]()
    date_range: DateRange::new(&None, &None),
  • replacement in src/error.rs at line 31
    [2.1421][2.1421:1450]()
    code_line: u32) -> Error
    [2.1421]
    [2.1450]
    code_line: u32,
    country: &str,
    data_type: &str,
    index: usize) -> Error
  • replacement in src/error.rs at line 37
    [2.1471][2.1471:1553]()
    "[ui_date:02:{}:{}] Expected source graphic to have exactly one series.",
    [2.1471]
    [2.1553]
    "[ui_date:02:{}:{}] [{} {} {}] Expected source graphic to have exactly one series.",
  • edit in src/error.rs at line 40
    [2.1591]
    [3.15073]
    country,
    data_type,
    index,