Debugging DataSelector
[?]
Jul 9, 2021, 8:45 AM
A6ZAYJNBYFXPUTCHTQDGAWUZIYOXNO3IJBN73ZX6PEJ3T4NMNOGQCDependencies
- [2]
SAHJYVNBRemoved checking functionality. - [3]
AT753JPOSelected US unemployment series. - [4]
GQVS55HIFinished generate_ts_spec() function. - [5]
AIFRDCG2Split off countries mod into a separate crate. - [6]
U4VCAFXQAdded data_type to TSSpec key. - [7]
2SABVMY3Finished into_json() functionality. - [8]
TTR5IFSGWorking on building generic TSSpec. - [9]
77SIQZ3ESeparating out spec generation. - [10]
XI5ALEH6Take advantage of keytree FromStr functionality. - [11]
LVMGQJGHFinished framework for checking series specifications with data. - [12]
CUADTSHQSave csv data as multiple files. - [13]
JTX5OHWHAdded USA CPI. - [14]
GUXZCEWWAdded Country enum. - [15]
4MG5JFXTFirst record. - [16]
5POF332LWorking on fn cpi_included().
Change contents
- file deletion: check_data.rs
use std::collections::{BTreeMap,HashMap,};use std::convert::TryInto;use std::fs;use serde::Serialize;use time::OffsetDateTime;use countries::Country;use fred_api::{Fred,};use keytree::{KeyTree, KeyTreeRef};use keytree::serialize::{IntoKeyTree,KeyTreeString,};use time_series::{RegularTimeSeries,TimeSeries,};use crate::serve_ts::{TSGraphicSpec,TSPageSpec,};impl DataSpec {/// Check for errors that might have occurred somewhere along the toolchain.let mut builder = CheckedDataSpec(Vec::new());}builder// This is a specification for CheckedData/// ```/// series:/// data_type: u/// country: United States/// id: LRUNTTTTUSQ156S/// ```impl<'a> TryInto<CheckedDataSpec> for KeyTreeRef<'a> {Ok()}}impl IntoKeyTree for CheckedDataSpec {fn keytree(&self) -> KeyTreeString {let mut kt = KeyTreeString::new();for series in &self.0 {kt.push_keytree(1, series.keytree());}kt}}/// `CheckedSourceSeries` is a code representation of the 'checked_data.keytree' specification file./// It acts as the gate-keeper to the data on disk.pub struct CheckedSourceSeries {impl IntoKeyTree for CheckedSourceSeries {fn keytree(&self) -> KeyTreeString {let mut kt = KeyTreeString::new();kt.push_key(0, "series");kt}}impl<'a> TryInto<CheckedSourceSeries> for KeyTreeRef<'a> {type Error = keytree::Error;fn try_into(self) -> Result<CheckedSourceSeries, keytree::Error> {Ok(CheckedSourceSeries{})}}data_type: self.value("series::data_type")?,country: self.value("series::country")?,series_id: self.value("series::series_id")?,drop_first: self.opt_value("series::drop_first")?,let country: Country = self.value("series::country")?;// let time_stamp = match date_str {// Some(date_str) => {// Some(OffsetDateTime::parse(date_str, "%Y %T").unwrap())// },// None => None,// };kt.push_value(1, "data_type", &self.data_type.to_string());kt.push_value(1, "country", &self.country.to_string());kt.push_value(1, "series_id", &self.series_id.to_string());kt.push_opt_value(1, "drop_first", self.drop_first);pub data_type: DataType,///pub country: Country,//////}pub drop_first: Option<usize>,pub series_id: SeriesId,///kt.push_key(0, "page");CheckedDataSpec(self.vec_at("seriess::series")?)fn try_into(self) -> Result<CheckedDataSpec, Self::Error> {type Error = keytree::Error;pub struct CheckedDataSpec(pub Vec<CheckedSourceSeries>);}}for series_spec in &self.0 {let checked_series = CheckedSourceSeries {data_type: series_spec.data_type,country: series_spec.country,series_id: series_spec.series_id.clone(),drop_first: None,};builder.0.push(checked_series);pub fn into_checked(&self) -> CheckedDataSpec {TSSeriesSpec,TSSpec,PageKey,use crate::build_spec::{DataSpec,};use crate::error::*;use crate::{DataType,SeriesId,};use std::str::FromStr; - replacement in src/main.rs at line 1[3.10]→[3.8660:8700](∅→∅),[3.8700]→[3.11575:11576](∅→∅),[3.12506]→[3.11575:11576](∅→∅),[3.11575]→[3.11575:11576](∅→∅),[3.11576]→[3.8701:8725](∅→∅)
use std::convert::TryInto;use std::fs;use countries::Country;use countries::*; - edit in src/main.rs at line 5
use countries::Country;use ui_data::DataType; - edit in src/main.rs at line 11
use ui_data::fred::*; - replacement in src/main.rs at line 16
let spec = DataSpec::from_file("source_data.keytree");println!("{}", spec.keytree());println!("{}", DataSelector::from_file("series_selector.keytree").resume_into_data_spec(Country::UnitedKingdom, DataType::Inf).unwrap().keytree()); - replacement in src/lib.rs at line 6
//! ## Step 1. Find the data of Fred and build a spec for it.//! ## Step 1. Build a generic data specification. - replacement in src/lib.rs at line 8[3.11918]→[3.11918:12035](∅→∅),[3.12035]→[3.10391:10572](∅→∅),[3.10391]→[3.10391:10572](∅→∅),[3.10572]→[3.12036:12116](∅→∅)
//! Probably the most effective way to find stuff, is to search on tags and then filter on series//! title, such as//! ```//! for item in Fred::tags_series("usa;interest")//! .unwrap()//! .series()//! .has_phrase("Prime")//! .iter()//! {//! println!("{}", item);//! }//! ```//! The filters such as `has_phrase` are found in the `fred_api` crate.//! The data series selector specification looks like - replacement in src/lib.rs at line 10[3.12120]→[3.9415:9466](∅→∅),[3.9466]→[3.12174:12570](∅→∅),[3.12844]→[3.12174:12570](∅→∅),[3.12174]→[3.12174:12570](∅→∅),[3.12570]→[2.1757:1810](∅→∅)
//! ## Step 2. Build a generic data specification.//!//! The results of Step 1 are integrated into algorithms in the `build_spec` module. These can then//! be used to generate collections of series.//!//! These specifications are then edited by hand, and cannot be programatically regenerated after//! editting. To modify the spec. programmatically, a newly generated `Keytree` string can be//! manually appended.//!//! Example://! ```//! println!("{}", generic_data_spec().keytree());//! ```text//! selectors://! series://! country: Australia,//! data_type: u//! tag: unemployment//! none_of: Male//! none_of: Female//! none_of: 55-64//! none_of: 25-54//! none_of: 15-24//! none_of: 20 to 24//! none_of: Youth//! none_of: Women//! none_of: Teenagers//! not_any_of: Rate//!//! series://! country: Austria,//! data_type: u//! tag: unemployment//! none_of: Male//! none_of: Female//! none_of: 55-64//! none_of: 25-54//! none_of: 15-24 - replacement in src/lib.rs at line 37
//! Save the output as file `source_data.keytree`. Then//! To take the data series selector specification and output a data series specification, use//! - replacement in src/lib.rs at line 40
//! let spec = DataSpec::from_file("source_data.keytree");//! println!("{}", spec.keytree());//! println!("{}", DataSpec::from_selector(`series_selector.keytree`).unwrap().keytree()); - replacement in src/lib.rs at line 42
//! The specification will look something like,//!//! Copy the output from the terminal and paste the results in `source_data.keytree`.//! The data series specification `source_data.keytree` will look something like//! - replacement in src/lib.rs at line 70
//! ## Step 3. Use the data specification to write data to file.//! ## Step 2. Use the data specification to write data to file. - replacement in src/lib.rs at line 72
//! let checked = DataSpec::from_file("source_data.keytree");//! let source = DataSpec::from_file("source_data.keytree"); - replacement in src/lib.rs at line 82
//! ## Step 5. Generate a generic time-series graphics specification.//! ## Step 3. Generate a generic time-series graphics specification. - replacement in src/lib.rs at line 84
//! This is used to generate time-series plots. Once it is generated in full, then it can be edited//! manually.//! The generated specification specifies the time-series graphics. - replacement in src/lib.rs at line 91
//! ## Step 6. Serve Time-series//! ## Step 4. Serve Time-series - replacement in src/lib.rs at line 93
//! The structure of JSON which is served to the client is determined by `Serialize`-able data//! structures. The top structure is `TSJson`. The `ts_spec.keytree` file specifies the graphics on//! each page, and what data each graphic uses. The `ts_spec.keytree` file is deserialized into//! `TSSpec`.//! This step converts the specification in JSON data and meta-data that is served to the client.//! The client Javascript then builds the graphics dynamically. Take both specifications and load//! data from "/full/path/to/data". - edit in src/lib.rs at line 97[3.13021]→[3.10440:10522](∅→∅),[3.10522]→[3.7191:7297](∅→∅),[3.7191]→[3.7191:7297](∅→∅),[3.7297]→[3.10523:10528](∅→∅)
//! The procedure is generally to read in the specification in `ts_spec.keytree`.//! `data_spec.keytree` which specifies data available, and also acts as a gate-keeper for that//! data.//! - replacement in src/lib.rs at line 98
//! let data_spec = CheckedDataSpec::from_file("checked_data.keytree").into_indexed();//! let data_spec = DataSpec::from_file("checked_data.keytree").into_indexed(); - replacement in src/lib.rs at line 102
//! Take both specifications and load data from "/full/path/to/data".//! Then `TSSpec` uses `IndexedDataSpec` as an argument to be converted into `TSJson`. - replacement in src/lib.rs at line 107
//! Then `TSSpec` uses `IndexedCheckedDataSpec` as an argument to be converted into `TSJson`.//!//!//! We want to serve data to clients in a particular way depending on the client (time-series or//! scatter plots). Each client-facing data-structure has its own specification. The two//! specifications interact.//! All JSON is generated at server startup into an immutable `HashMap` in memory. - replacement in src/lib.rs at line 109
//! ## Step 7. Serve UI Scatterplots//! ## Step 5. Serve UI Scatterplots - replacement in src/lib.rs at line 424
let v: Vec<SeriesSpec> = self.vec_at("series::series")?;let v: Vec<SeriesSpec> = self.vec_at("seriess::series")?;