Working on building generic TSSpec.
[?]
Jul 6, 2021, 2:29 AM
TTR5IFSG25VNBQ2F2FNOLUMTEIHVBHFOEXYB2ZWEHWOURUV4GJMQCDependencies
- [2]
XI5ALEH6Take advantage of keytree FromStr functionality. - [3]
IKPVWWLKFilter unemployment rate series. - [4]
GQVS55HIFinished generate_ts_spec() function. - [5]
5POF332LWorking on fn cpi_included(). - [6]
77SIQZ3ESeparating out spec generation. - [7]
2SABVMY3Finished into_json() functionality. - [8]
AT753JPOSelected US unemployment series. - [9]
GUXZCEWWAdded Country enum. - [10]
U4VCAFXQAdded data_type to TSSpec key. - [11]
CUADTSHQSave csv data as multiple files. - [12]
AIFRDCG2Split off countries mod into a separate crate. - [13]
4MG5JFXTFirst record. - [14]
4QOTH75IFixed UI specification code. - [15]
UCSU3QE4Created keytree generator for u and cpi. - [16]
LVMGQJGHFinished framework for checking series specifications with data.
Change contents
- edit in src/serve_ui.rs at line 3
use std::collections::HashMap; - edit in src/serve_ui.rs at line 10
};use time_series::{RegularTimeSeries, - edit in src/serve_ui.rs at line 19
};use crate::check_data::{IndexedCheckedDataSpec, - edit in src/serve_ui.rs at line 27
/// The top-level datastructure, served as JSON, that specifies all the data required to build a UI/// plot.pub struct UIJson(HashMap<(Country, usize), UIGraphicJson>); - replacement in src/serve_ui.rs at line 32
// pub struct UIJson(HashMap<(Country Index),Vec<Graphic>impl UIJson { - replacement in src/serve_ui.rs at line 34
// Do we want meta for each line?/// Create an empty `UIJson`.pub fn new() -> Self {UIJson(HashMap::new())}/// Insert a `UIGraphicJson` into `UIJson`. If the country already exists, increment the index/// in the key until a space is available.pub fn insert(&mut self, ui_graphic_json: UIGraphicJson) {let mut ix = 0;while self.0.get(&(ui_graphic_json.country, 0)).is_none() {ix += 1;}self.0.insert((ui_graphic_json.country, ix), ui_graphic_json);}}/// A UI plot. `UIGraphicJson` can be serialized to JSON.pub struct UIGraphicJson {country: Country,title: String,lines: Vec<UILineJson>,} - edit in src/serve_ui.rs at line 57
/// A line in a UI plot. `UILineJson` can be serialized to JSON.pub struct UILineJson {data: RegularTimeSeries<2>,} - replacement in src/serve_ui.rs at line 66
/// ui_graphic:/// time_series:/// data_type: u/// series: AUSURAMS_a/// transform: ident/// time_series:/// data_type: i/// series: _/// transform: ident/// country: Australia/// index: 0////// time_series:/// data_type: u/// series: AUSURAMS_a/// time_series:/// data_type: i/// series: _/// line: - edit in src/serve_ui.rs at line 78
/// transform: indent - edit in src/serve_ui.rs at line 81
impl UISpec {// Convert UISpec into UIJson.pub (crate) fn into_json(&self,data_spec: &IndexedCheckedDataSpec,root_path: &str) -> Result<UIJson, Error>{let mut ui_json = UIJson::new();for ui_graphic_spec in &self.0 {let ui_graphic_json = ui_graphic_spec.into_json(data_spec,root_path,)?;ui_json.insert(ui_graphic_json);}Ok(ui_json)}} - edit in src/serve_ui.rs at line 142
impl UIGraphicSpec {pub (crate) fn into_json(&self,data_spec: &IndexedCheckedDataSpec,root_path: &str) -> Result<UIGraphicJson, Error>{let mut v = Vec::new();for line_spec in &self.line {let x_time_series_spec = &self.time_series[line_spec.x];let y_time_series_spec = &self.time_series[line_spec.y];let line_json = line_spec.into_json(data_spec,x_time_series_spec,y_time_series_spec,root_path,).unwrap();v.push(line_json);}Ok(UIGraphicJson {country: self.country,title: self.title.clone(),lines: v,})}} - replacement in src/serve_ui.rs at line 200
x: SeriesId,y: SeriesId,x: usize,y: usize, - replacement in src/serve_ui.rs at line 203
end_date: Option<MonthlyDate>,end_date: Option<MonthlyDate>,transform2: Transform2,}impl UILineSpec {pub (crate) fn into_json(&self,data: &IndexedCheckedDataSpec,x: &UITimeSeriesSpec,y: &UITimeSeriesSpec,root_path: &str) -> Result<UILineJson, Error>{x.assert_data_type(DataType::U)?;y.assert_data_type(DataType::Inf)?;let x_data = x.time_series_data(data, root_path)?;let y_data = y.time_series_data(data, root_path)?;let range = MonthlyDate::range(&self.start_date, &self.end_date);let xy_data = match self.transform2 {Transform2::Zip => {let mut xy_data = x_data.zip_one_one(y_data);xy_data.with_range(&range);xy_data}};Ok(UILineJson {data: xy_data,})} - replacement in src/serve_ui.rs at line 245
x: self.value("line::x")?,y: self.value("line::y")?,start_date: self.opt_value("line::start_date")?,end_date: self.opt_value("line::end_date")?,x: self.value("line::x")?,y: self.value("line::y")?,start_date: self.opt_value("line::start_date")?,end_date: self.opt_value("line::end_date")?,transform2: self.value("line::transform2")?, - replacement in src/serve_ui.rs at line 255
/// `Transform`s may include joining data, interpolation etc.pub enum Transform {/// Transforms from a TimeSeries<1> to another TimeSeries<1>.pub enum Transform1 { - replacement in src/serve_ui.rs at line 261
impl FromStr for Transform {impl FromStr for Transform1 { - replacement in src/serve_ui.rs at line 266
"ident" => Ok(Transform::Ident),_ => Err(parse_transform(s)),"ident" => Ok(Transform1::Ident),_ => Err(parse_transform1(s)),}}}/// Transforms from two TimeSeries<1> to a TimeSeries<2>.pub enum Transform2 {///Zip,}impl FromStr for Transform2 {type Err = Error;fn from_str(s: &str) -> Result<Self, Self::Err> {match s {"zip" => Ok(Transform2::Zip),_ => Err(parse_transform2(s)), - edit in src/serve_ui.rs at line 296
start_date: Option<MonthlyDate>,end_date: Option<MonthlyDate>, - replacement in src/serve_ui.rs at line 297
series: String,transform: Transform,series_id: SeriesId,transform1: Transform1,}impl UITimeSeriesSpec {pub (crate) fn assert_data_type(&self, data_type: DataType) -> Result<(), Error> {if self.data_type == data_type {Ok(())} else {Err(data_type_mismatch(&self.data_type.to_string(), &data_type.to_string()))}}pub (crate) fn time_series_data(&self,data: &IndexedCheckedDataSpec,root_path: &str) -> Result<RegularTimeSeries<1>, Error>{data.time_series_data(self.series_id.clone(),root_path)} - edit in src/serve_ui.rs at line 327
/// transform: ident - replacement in src/serve_ui.rs at line 335
start_date: self.opt_value("time_series::start_date")?,end_date: self.opt_value("time_series::end_date")?,series: self.value("time_series::series")?,transform: self.value("time_series::transform")?,series_id: self.value("time_series::series")?,transform1: self.value("time_series::transform1")?, - replacement in src/serve_ts.rs at line 19
use crate::DataType;use crate::{DataType,SeriesId,}; - replacement in src/serve_ts.rs at line 60
pub (crate) fn from_file(path: &str) -> Self {/// Read from file.pub fn from_file(path: &str) -> Self { - edit in src/serve_ts.rs at line 88
- replacement in src/serve_ts.rs at line 157
/// ```text/// ``` - replacement in src/serve_ts.rs at line 159
/// country:/// name: Australia/// graphic:/// series:/// id: AUSURANAA/// id: AUSURAQS/// id: AUSURHARMADSMEI/// id: AUSURHARMMDSMEI/// country: Australia/// index: 0/// graphic:/// series:/// series_id: AUSURANAA/// data_type: u/// series:/// data_type: u/// series_id: AUSURAQS/// series:/// data_type: u/// series_id: AUSURHARMADSMEI/// series:/// data_type: u/// series_id: AUSURHARMMDSMEI - replacement in src/serve_ts.rs at line 179
pub data_type: DataType,pub index: usize, - replacement in src/serve_ts.rs at line 189
data_type: key.data_type,index: key.index, - edit in src/serve_ts.rs at line 194
pub (crate) fn push(&mut self, ts_graphic_spec: TSGraphicSpec) {self.graphics.push(ts_graphic_spec)} - replacement in src/serve_ts.rs at line 201
data_type: self.data_type,index: self.index, - edit in src/serve_ts.rs at line 213
kt.push_keyvalue(1, "data_type", &self.data_type.to_string()); - replacement in src/serve_ts.rs at line 225
country: self.value("country::country")?,data_type: self.value("country::data_type")?,graphics: self.vec_at("country::graphic")?,country: self.value("page::country")?,index: self.value("page::index")?,graphics: self.vec_at("page::graphic")?, - replacement in src/serve_ts.rs at line 233
////// ```/// graphic:/// series:/// series_id: AUSURANAA/// data_type: u/// series:/// data_type: u/// series_id: AUSURAQS/// series:/// data_type: u/// series_id: AUSURHARMADSMEI/// series:/// data_type: u/// series_id: AUSURHARMMDSMEI/// ``` - replacement in src/serve_ts.rs at line 254
pub series_ids: Vec<String>,pub series: Vec<TSSeriesSpec>, - replacement in src/serve_ts.rs at line 262
series_ids: Vec::new(),series: Vec::new(), - replacement in src/serve_ts.rs at line 266
pub (crate) fn push(&mut self, id: &str) {self.series_ids.push(id.to_string())pub (crate) fn push(&mut self, series: TSSeriesSpec) {self.series.push(series) - replacement in src/serve_ts.rs at line 278
for series_id in &self.series_ids {for series in &self.series { - replacement in src/serve_ts.rs at line 280
let ts = data_spec.time_series_data(series_id.clone(), root_path)?;let ts = data_spec.time_series_data(series.series_id.clone(), root_path)?; - replacement in src/serve_ts.rs at line 282
let meta = data_spec.meta(series_id.to_string(), root_path);let meta = data_spec.meta(&series.series_id, root_path); - replacement in src/serve_ts.rs at line 305
for id in &self.series_ids {kt.push_keyvalue(2, "id", &id);for series in &self.series {kt.push_keytree(2, series.keytree()); - replacement in src/serve_ts.rs at line 319
series_ids: self.vec_value("graphic::data")?,series: self.vec_at("graphic::series")?,})}}/// Component of `TSGraphicSpec`./// ```text/// series:/// data_type: u/// series_id: AUSURHARMADSMEI/// ```pub struct TSSeriesSpec {///data_type: DataType,series_id: SeriesId,}impl TSSeriesSpec {/// Return a new `TSSeries`.pub fn new(data_type: DataType, series_id: SeriesId) -> Self {TSSeriesSpec {data_type,series_id,}}}impl<'a> TryInto<TSSeriesSpec> for KeyTreeRef<'a> {type Error = keytree::Error;fn try_into(self) -> Result<TSSeriesSpec, Self::Error> {Ok(TSSeriesSpec {data_type: self.value("series::data_type")?,series_id: self.value("series::series_id")?, - edit in src/serve_ts.rs at line 360
impl IntoKeyTree for TSSeriesSpec {fn keytree(&self) -> KeyTreeString {let mut kt = KeyTreeString::new();kt.push_key(0, "series");kt.push_keyvalue(1, "data_type", &self.data_type.to_string());kt.push_keyvalue(1, "series_id", &self.series_id.to_string());kt}} - replacement in src/serve_ts.rs at line 377
pub struct TSJson(HashMap<PageKey, Vec<GraphicJson>>);#[derive(Debug)]pub struct TSJson(pub HashMap<PageKey, String>); - replacement in src/serve_ts.rs at line 392
None => { self.0.insert(*key, value); },None => {self.0.insert(*key,serde_json::to_string(&value).unwrap(),);}, - replacement in src/serve_ts.rs at line 403
#[derive(Serialize)]#[derive(Debug, Serialize)] - replacement in src/serve_ts.rs at line 412
#[derive(Serialize)]#[derive(Debug, Serialize)] - replacement in src/serve_ts.rs at line 431
pub data_type: DataType,pub country: Country, - replacement in src/serve_ts.rs at line 433
pub country: Country,pub index: usize,}impl PageKey {/// Return a new `PageKey`.pub fn new(country: Country, index: usize) -> Self {PageKey { country, index }} - replacement in src/serve_ts.rs at line 448
data_type: self.value("key::data_type")?,index: self.value("key::index")?, - replacement in src/main.rs at line 1
// use std::convert::TryInto;// use std::fs;use std::convert::TryInto;use std::fs; - replacement in src/main.rs at line 4
// use fred_api::Fred;// use keytree::serialize::IntoKeyTree;use countries::Country;use fred_api::Fred;use keytree::serialize::IntoKeyTree; - replacement in src/main.rs at line 8
// use countries::Country;// use ui_data::*;use ui_data::*; - replacement in src/main.rs at line 10
// use ui_data::serve_ts::*;use ui_data::check_data::*;use ui_data::serve_ts::*;use ui_data::serve_ui::*; - replacement in src/main.rs at line 15
// let root_dir = shellexpand::tilde("~/test_data/cpi");let root_dir = shellexpand::tilde("~/test_data"); - replacement in src/main.rs at line 17
// // "usa;interest",// // "prime",// // "australia;interest" -> nothing// for item in Fred::tags_series("australia;interest")// .unwrap()// .series()// .iter()// {// println!("{}", item);// // println!("{}", item.tags());// }// let spec_path = shellexpand::tilde("~/currency.engineering/source_spec.keytree");// let data_path = shellexpand::tilde("~/test_data");// Read in the data specification.let data_spec = CheckedDataSpec::from_file("checked_data.keytree").into_indexed();let ts_spec = TSSpec::from_file("ts_spec.keytree"); - replacement in src/main.rs at line 21[3.10088]→[3.10088:10145](∅→∅),[3.10145]→[3.11651:11765](∅→∅),[3.11765]→[3.12632:12755](∅→∅),[3.12755]→[3.11801:11802](∅→∅),[3.11801]→[3.11801:11802](∅→∅),[3.11802]→[3.3018:3051](∅→∅)
// spec_to_data::save_data(&spec_path, &data_path);// println!("{}", build_data_spec().keytree());let spec = DataSpec::from_file("source_data.keytree");let mut checked = spec.check();checked.write("/home/dyppb/test_data");// let ts_data = SourceData::new();checked.bootstrap_ts_spec();let ts_json = ts_spec.into_json(&data_spec, &root_dir); - replacement in src/lib.rs at line 3
//! Collect unemployment rate, inflation rate and interest rate data server side.//! Collect unemployment rate, inflation rate and interest rate data server side, then serve this//! data as JSON in a format suitable for building UI graphics using D3. - replacement in src/lib.rs at line 6
//! ### Step 1. Build Spec//! ## Step 1. Find the data of Fred and build a spec for it. - replacement in src/lib.rs at line 22
//! ### Step 2. Check Data//! ## Step 2. Build a generic data specification. - replacement in src/lib.rs at line 33
//! println!("{}", build_data_spec().keytree());//! println!("{}", build_generic_data_spec().keytree()); - replacement in src/lib.rs at line 64
//! ### Step 2. Check and Save Data//! ## Step 3. Check the data in the data specification. - replacement in src/lib.rs at line 88
//! Check each data series, to see if the data is well-formed. Save the output specification.//! Check each data series, to see if the data is well-formed.//! ```//! let spec = DataSpec::from_file("source_data.keytree");//! println!("{}", spec.check().keytree());//! ```//! Save the output specification in `checked_data.keytree`. - replacement in src/lib.rs at line 95
//! ### Step 3*. Bootstrap TSPageSpec.//! ## Step 4. Use the data specification to write data to file. - edit in src/lib.rs at line 97
//! To generate a generic time-series specification, - replacement in src/lib.rs at line 98
//! checked_data_spec//! .from_file("data_spec.keytree")//! .bootstrap_ts_spec;//! ```//! The specification will look something like//! let checked = CheckedDataSpec::from_file("checked_data.keytree");//! checked.write("/full/path/to/data");//! ```//!//! If there is a break in the connection we can use - replacement in src/lib.rs at line 104
//! page://! country://! name: Australia//! graphic://! series://! id: AUSURANAA//! id: AUSURAQS//! id: AUSURHARMADSMEI//! id: AUSURHARMMDSMEI//! checked.resume_write(Series::new("GBRURNAA"), "/full/path/to/data")//! ```//! to resume.//!//! ## Step 5. Generate a generic time-series graphics specification.//!//! This is used to generate time-series plots. Once it is generated in full, then it can be edited//! manually.//!//! ```text//! checked.generic_ts_spec() - edit in src/lib.rs at line 116
//! Once it has been generated with the full set of data, we want to be able to edit it manually. - replacement in src/lib.rs at line 117
//! ### Step 3. Serve Time-series//! ## Step 6. Serve Time-series - replacement in src/lib.rs at line 124
//! The procedure is generally to read in the specification in `ts_spec.keytree`, and to read in the//! The procedure is generally to read in the specification in `ts_spec.keytree`. - edit in src/lib.rs at line 127
//! - replacement in src/lib.rs at line 129
//! // Read in the data specification.//! let data_spec = CheckedData::from_file("data_spec.keytree").indexed();//!//! // Read in the time-series specification.//! let data_spec = CheckedDataSpec::from_file("checked_data.keytree").into_indexed(); - edit in src/lib.rs at line 131
//! ```//!//! Take both specifications and load data from "/full/path/to/data". - replacement in src/lib.rs at line 135
//! // Load all data to memory. The server uses `ts_json` as a data-store to respond to data//! // requests.//! let ts_json = ts_spec.into_json(data_spec);//! ```//! let ts_json = ts_spec.into_json(data_spec, "/full/path/to/data"); - replacement in src/lib.rs at line 145
//! ### Step 5. Serve UI Scatterplots//! ## Step 7. Serve UI Scatterplots - edit in src/lib.rs at line 174
impl MonthlyDate {/// Create a time_series::DateRange.pub fn range(date_opt1: &Option<MonthlyDate>,date_opt2: &Option<MonthlyDate>) -> time_series::DateRange{time_series::DateRange::new(date_opt1.as_ref().map(|date| date.0),date_opt2.as_ref().map(|date| date.0),)}} - edit in src/lib.rs at line 200
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize)] - edit in src/lib.rs at line 202
impl SeriesId { - edit in src/lib.rs at line 205
/// Create a new SeriesId from a string.pub fn new(s: &str) -> Self {SeriesId(s.to_string())}} - edit in src/lib.rs at line 219
impl fmt::Display for SeriesId {fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {write!(f, "{}", self.0)}} - replacement in src/lib.rs at line 226
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize)]#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] - edit in src/lib.rs at line 238
- replacement in src/lib.rs at line 269
pub fn title(series_id: &str) -> String {pub fn title(series_id: &SeriesId) -> String { - replacement in src/lib.rs at line 271
let seriess = match Fred::series(series_id) {let seriess = match Fred::series(&series_id.to_string()) { - replacement in src/check_data.rs at line 1
use std::collections::HashMap;use std::collections::{BTreeMap,HashMap,}; - replacement in src/check_data.rs at line 26
use crate::DataType;use crate::{DataType,SeriesId,}; - edit in src/check_data.rs at line 38
TSSeriesSpec, - replacement in src/check_data.rs at line 48
println!("{}", series_spec.id);match Fred::series(&series_spec.id) {println!("{}", series_spec.series_id);match Fred::series(&series_spec.series_id.to_string()) { - replacement in src/check_data.rs at line 52
data_type: series_spec.data_type,country: series_spec.country,id: series_spec.id.clone(),error: "ok".to_string(),data_type: series_spec.data_type,country: series_spec.country,series_id: series_spec.series_id.clone(),error: "ok".to_string(), - replacement in src/check_data.rs at line 62
data_type: series_spec.data_type,country: series_spec.country,id: series_spec.id.clone(),error: err.to_string(),data_type: series_spec.data_type,country: series_spec.country,series_id: series_spec.series_id.clone(),error: err.to_string(), - replacement in src/check_data.rs at line 81
index: HashMap<String, usize>,index: HashMap<SeriesId, usize>, - edit in src/check_data.rs at line 85
/// Get data_type and country of a given series_id.pub (crate) fn get(&self, series_id: SeriesId) -> (DataType, Country) {let index = self.index.get(&series_id).unwrap();let data_type = self.data.0[*index].data_type;let country = self.data.0[*index].country;(data_type, country)}/// Return a generic time-series graphics specification.////// ```text/// ts_spec:/// page:/// country: Australia/// index: 0/// graphic:/// series:/// series_id: AUSURANAA/// data_type: u/// series:/// data_type: u/// series_id: AUSURAQS/// series:/// data_type: u/// series_id: AUSURHARMADSMEI/// series:/// data_type: u/// series_id: AUSURHARMMDSMEI/// ```/// TSSpec/// TSPageSpec/// country/// index/// TSGraphicSpec/// height/// TSSeriesSpec////// IndexedCheckedDataSpec/// CheckedDataSpec/// CheckedSourceSeries/// DataType/// Country/// SeriesId///pub fn generic_ts_spec(&self) -> TSSpec {let mut map: BTreeMap<(DataType, Country), Vec<SeriesId>> = BTreeMap::new();for (series_id, _) in self.index.iter() {let (data_type, country) = self.get(series_id.clone());match map.get_mut(&(data_type, country)) {Some(value) => value.push(series_id.clone()),None => {map.insert((data_type, country), vec!(series_id.clone()));},};}// build TSSpeclet ts_spec = TSSpec::new();for ((data_type, country), series_ids) in map {let mut ts_spec = TSSpec::new();let mut ts_graphic_spec = TSGraphicSpec::new();for series_id in series_ids {let ts_series_spec = TSSeriesSpec::new(data_type, series_id);ts_graphic_spec.push(ts_series_spec);}; - edit in src/check_data.rs at line 158
let page_key = PageKey::new(country, 0);let mut ts_page_spec = TSPageSpec::new(page_key, vec!(ts_graphic_spec));ts_spec.push(ts_page_spec);};ts_spec} - replacement in src/check_data.rs at line 168
series_id: String,series_id: SeriesId, - replacement in src/check_data.rs at line 175
println!("Series {} not found in IndexedCheckedDataSpec::index.", series_id);println!("Series {} not found in IndexedCheckedDataSpec::index.", series_id.to_string()); - replacement in src/check_data.rs at line 184
spec_has_error_status(&series_id, &checked_series.error.clone())spec_has_error_status(&series_id.to_string(), &checked_series.error.clone()) - replacement in src/check_data.rs at line 192
checked_series.country,checked_series.country.as_path(), - replacement in src/check_data.rs at line 198
.map_err(|_| time_series_not_regular(&checked_series.id.clone()))?.map_err(|_| time_series_not_regular(&checked_series.series_id.to_string()))? - replacement in src/check_data.rs at line 203
pub fn meta(&self, series_id: String, root_path: &str) -> SeriesMetaData {pub fn meta(&self, series_id: &SeriesId, root_path: &str) -> SeriesMetaData { - replacement in src/check_data.rs at line 216
"{}/{}/{}/{}.csv","{}/{}/{}/{}.meta", - replacement in src/check_data.rs at line 219
checked_series.country,checked_series.country.as_path(), - edit in src/check_data.rs at line 239
- edit in src/check_data.rs at line 249
// We need to change the arrangement. We update the checked_data.keytree from files. We have a// resume function which takes the same checked_data.keytree and writes from a SeriesId. We have// another function with goes through the files to update the time-stamp. - replacement in src/check_data.rs at line 257
/// save_data_csv("LRUNTTTTSIQ156S");/// let mut checked = CheckedDataSpec::from_file("checked_data.keytree");/// checked.write(&root_dir); - replacement in src/check_data.rs at line 262
pub fn write(&mut self, root_path: &str) {pub fn write(&self, root_path: &str) {for series in &self.0 {series.write_data(root_path);series.write_meta(root_path);}}/// Same as `write()` except that it starts in the specification at `series_id`. Useful if there/// is a break in the connection when writing.pub fn resume_write(&self, series_id: SeriesId, root_path: &str) { - replacement in src/check_data.rs at line 274
for series in &mut self.0 {for series in self.0.iter().skip_while( | checked |{checked.series_id != series_id}){ - edit in src/check_data.rs at line 281
println!("{}", self.keytree()) - replacement in src/check_data.rs at line 285
let mut h: HashMap<String, usize> = HashMap::new();let mut h: HashMap<SeriesId, usize> = HashMap::new(); - replacement in src/check_data.rs at line 287
h.insert(series.id.clone(), i);h.insert(series.series_id.clone(), i); - edit in src/check_data.rs at line 294[3.14236]→[3.14236:14348](∅→∅),[3.14348]→[3.3079:3117](∅→∅),[3.3117]→[3.14385:14386](∅→∅),[3.14385]→[3.14385:14386](∅→∅),[3.14386]→[3.3118:3184](∅→∅),[3.3184]→[3.14455:14456](∅→∅),[3.14455]→[3.14455:14456](∅→∅),[3.14456]→[3.15183:15215](∅→∅),[3.15183]→[3.15183:15215](∅→∅),[3.15215]→[3.14457:14665](∅→∅),[3.14665]→[3.15382:15397](∅→∅),[3.15382]→[3.15382:15397](∅→∅),[3.15397]→[3.14666:14725](∅→∅),[3.14725]→[3.3185:3327](∅→∅),[3.3327]→[3.14875:15042](∅→∅),[3.14875]→[3.14875:15042](∅→∅),[3.15042]→[3.3328:3480](∅→∅),[3.3480]→[3.15207:15241](∅→∅),[3.15207]→[3.15207:15241](∅→∅),[3.15241]→[3.15397:15407](∅→∅),[3.15397]→[3.15397:15407](∅→∅),[3.15407]→[3.15242:15243](∅→∅),[3.15243]→[3.3481:3523](∅→∅),[3.3523]→[3.15289:15290](∅→∅),[3.15289]→[3.15289:15290](∅→∅),[3.15290]→[3.3524:3643](∅→∅),[3.3643]→[3.15433:15445](∅→∅),[3.15433]→[3.15433:15445](∅→∅),[3.15445]→[3.3644:3686](∅→∅),[3.3686]→[3.15407:15413](∅→∅),[3.15492]→[3.15407:15413](∅→∅),[3.15407]→[3.15407:15413](∅→∅)
/// Takes `checked_data.keytree` and builds a collection of graphics,/// each plotting 1 time-series.pub fn bootstrap_ts_spec(&self) {let mut h: HashMap<PageKey, TSPageSpec> = HashMap::new();for series in &self.0 {// Check that there are no errors in the CheckedDataSpec series.if series.error.to_lowercase() != "ok" {println!("{}", series.keytree());panic!();};// Insert the series into the TSGraphicSpec.match h.get_mut(&series.key()) {Some(page_spec) => {page_spec.graphics[0].push(&series.id);},None => {let mut ts_graphic_spec = TSGraphicSpec::new();ts_graphic_spec.push(&series.id);let ts_page_spec = TSPageSpec::new(series.key(), vec!(ts_graphic_spec));h.insert(series.key(), ts_page_spec);}}}// Build TSSpec from the hashmap.let mut ts_spec = TSSpec(Vec::new());for (key, page_spec) in h {ts_spec.push(page_spec);};println!("{}", ts_spec.keytree())} - replacement in src/check_data.rs at line 309
kt.push_key(0, "seriess");kt.push_key(0, "page"); - replacement in src/check_data.rs at line 328
pub id: String,pub series_id: SeriesId, - edit in src/check_data.rs at line 365[3.3688]→[3.11260:11282](∅→∅),[3.11282]→[3.3688:3831](∅→∅),[3.3688]→[3.3688:3831](∅→∅),[3.3831]→[3.15845:15846](∅→∅),[3.15845]→[3.15845:15846](∅→∅)
/// Return a key.pub fn key(&self) -> PageKey {PageKey {data_type: self.data_type,country: self.country,}} - replacement in src/check_data.rs at line 366
pub fn write_data(&mut self, root_path: &str) {pub fn write_data(&self, root_path: &str) { - replacement in src/check_data.rs at line 370
let observations = match Fred::series_observations(&self.id) {let observations = match Fred::series_observations(&self.series_id.to_string()) { - replacement in src/check_data.rs at line 397
self.id,self.series_id, - edit in src/check_data.rs at line 399
self.time_stamp = Some(TimeStamp::now()); - edit in src/check_data.rs at line 401
println!("Writing {}", filename); - replacement in src/check_data.rs at line 408
pub fn write_meta(&mut self, root_path: &str) {pub fn write_meta(&self, root_path: &str) { - replacement in src/check_data.rs at line 410
let meta = match Fred::series(&self.id) {let meta = match Fred::series(&self.series_id.to_string()) { - replacement in src/check_data.rs at line 416
id: self.id.clone(),series_id: self.series_id.clone(), - replacement in src/check_data.rs at line 440
self.id,self.series_id, - edit in src/check_data.rs at line 444
println!("Writing {}", filename); - replacement in src/check_data.rs at line 455
kt.push_keyvalue(1, "id", &self.id);kt.push_keyvalue(1, "series_id", &self.series_id.to_string()); - edit in src/check_data.rs at line 479
let country: Country = self.value("series::country")?; - replacement in src/check_data.rs at line 484
id: self.value("series::id")?,series_id: self.value("series::series_id")?, - replacement in src/check_data.rs at line 501
/// id: AUSCPALTT01IXNBQ/// series_id: AUSCPALTT01IXNBQ - replacement in src/check_data.rs at line 509
#[derive(Serialize)]#[derive(Debug, Serialize)] - replacement in src/check_data.rs at line 512
id: String,series_id: SeriesId, - replacement in src/check_data.rs at line 526
series_id: String,series_id: SeriesId, - replacement in src/check_data.rs at line 551
id: self.value("series_meta::id")?,series_id: self.value("series_meta::series_id")?, - replacement in src/check_data.rs at line 568
kt.push_keyvalue(1, "id", &self.id);kt.push_keyvalue(1, "series_id", &self.series_id.to_string()); - edit in src/check_data.rs at line 579[3.21249]
// self.time_stamp = Some(TimeStamp::now()); - replacement in src/build_spec.rs at line 21
use crate::DataType;use crate::{DataType,SeriesId,}; - replacement in src/build_spec.rs at line 63
/// println!("{}", generic_cpi_series_spec(&Country::NewZealand, "cpi_series.keytree"));/// println!("{}", generic_cpi_series_spec(Country::NewZealand, "cpi_series.keytree")); - replacement in src/build_spec.rs at line 65
pub fn generic_cpi_series_spec(country: &Country) -> SeriesItems {pub fn generic_cpi_series_spec(country: Country) -> SeriesItems { - replacement in src/build_spec.rs at line 448
match Fred::tags_series(&to_tag("cpi", &country)) {match Fred::tags_series(&to_tag("cpi", country)) { - replacement in src/build_spec.rs at line 462
fn to_tag(tag: &str, country: &Country) -> String {fn to_tag(tag: &str, country: Country) -> String { - edit in src/build_spec.rs at line 468
}/// Return relevant inflation rate series for a country. This function first selects all series with/// a certain tag pattern, and then applies required phrases and exclusionary phrases./// ```/// println!("{}", generic_inf_series_spec(Country::Canada));/// ```pub fn generic_inf_series_spec(country: Country) -> SeriesItems {if let Country::UnitedStates = country {// Need to use a different search technique for US data.let exclude_phrase = vec!("Producer Price Index","Projections","Export Price Index","Implicit Price Deflator","Employment Cost Index","Contributions to","Inflation Expectation","Equity Market","excluding food and energy","Excluding Food and Energy","excluding Food and Energy","Urban","Sticky","Opinion","Consumer Price Index","Personal Consumption","Private Consumption",);// let one_of = vec!(// "Unemployment Rate for United States",// "Unemployment Rate: Aged 15 and Over: All Persons for the United States",// "Unemployment Rate: Aged 15-74: All Persons for the United States",// "Harmonized Unemployment Rate: Total: All Persons for the United States",// "Unemployment Rate - 18 Years and Over",// );let tag_series = Fred::tags_series("inflation;usa;nation").unwrap().seriess;tag_series.exclude_phrases(exclude_phrase)// .equals_one_of(one_of)} else {let (exclude_phrase, include_phrase) = match country {Country::Australia => {(vec!("Opinion",),vec!("Inflation",),)},Country::Austria => {(vec!("Opinion",),vec!("Inflation",),)},Country::Belgium => {(vec!("Opinion",),vec!("Inflation",),)},Country::Canada => {(vec!("Opinion",),vec!("Inflation",),)},Country::Chile => {(vec!("Opinion",),vec!("Inflation",),)},Country::CzechRepublic => {(vec!("Opinion",),vec!("Inflation",),)},Country::Denmark => {(vec!("Opinion",),vec!("Inflation",),)},Country::Estonia => {(vec!("Opinion",),vec!("Inflation",),)},Country::Finland => {(vec!("Opinion",),vec!("Inflation",),)},Country::France => {(vec!("Opinion",),vec!("Inflation",),)},Country::Germany => {(vec!("Opinion",),vec!("Inflation",),)},Country::Greece => {(vec!("Opinion",),vec!("Inflation",),)},Country::Ireland => {(vec!("Opinion",),vec!("Inflation",),)},Country::Israel => {(vec!(),vec!("Inflation",),)},Country::Italy => {(vec!("Opinion",),vec!("Inflation",),)},Country::Japan => {(vec!(),vec!("Inflation",),)},Country::Latvia => {(vec!(),vec!("Inflation",),)},Country::Netherlands => {(vec!("Opinion",),vec!("Inflation",),)},Country::NewZealand => {(vec!(),vec!("Inflation",),)},Country::Norway => {(vec!(),vec!("Inflation",),)},Country::Poland => {(vec!("Opinion",),vec!("Inflation",),)},Country::Serbia => {(vec!(),vec!("Inflation",),)},Country::SouthKorea => {(vec!(),vec!("Inflation",),)},Country::Spain => {(vec!("Opinion",),vec!("Inflation",),)},Country::Sweden => {(vec!("Opinion",),vec!("Inflation",),)},Country::Switzerland => {(vec!("Opinion",),vec!("Inflation",),)},Country::UnitedKingdom => {(vec!("Opinion","Consumer Price Inflation",),vec!("Inflation",),)},Country::UnitedStates => {(vec!(),vec!("",),)},_ => {panic!()},};match Fred::tags_series(&to_tag("inflation", country)) {Ok(tags_series) => {tags_series.seriess.exclude_phrases(exclude_phrase).only_include(include_phrase)},Err(err) => {println!("{}", err);panic!();},}} - replacement in src/build_spec.rs at line 806
/// println!("{}", unemployment_series(&Country::Canada, "u_series.keytree"));/// println!("{}", unemployment_series(Country::Canada, "u_series.keytree")); - replacement in src/build_spec.rs at line 808
pub fn generic_u_series_spec(country: &Country) -> SeriesItems {pub fn generic_u_series_spec(country: Country) -> SeriesItems { - edit in src/build_spec.rs at line 1312
/// Build a generic specification of one datatype and country.pub fn data_spec_for_country(data_type: DataType, country: Country) -> DataSpec {let mut seriess = DataSpec(Vec::new());match data_type {DataType::U => {for series_item in generic_u_series_spec(country).iter() {seriess.0.push(SourceSeries {data_type: DataType::U,country,series_id: SeriesId::new(&series_item.id.clone()),})}println!("{} {}", country, data_type);},DataType::Inf => {for series_item in generic_inf_series_spec(country).iter() {seriess.0.push(SourceSeries {data_type: DataType::Inf,country,series_id: SeriesId::new(&series_item.id.clone()),})}println!("{} {}", country, data_type);},DataType::Cpi => {for series_item in generic_cpi_series_spec(country).iter() {seriess.0.push(SourceSeries {data_type: DataType::Cpi,country,series_id: SeriesId::new(&series_item.id.clone()),})}println!("{} {}", country, data_type);},DataType::Int => {},}seriess}/// Build a generic specification for all data. Output looks like - replacement in src/build_spec.rs at line 1364
/// id: AUSURAMS/// series_id: AUSURAMS - replacement in src/build_spec.rs at line 1366
pub fn build_data_spec() -> DataSpec {pub fn build_generic_data_spec() -> DataSpec { - edit in src/build_spec.rs at line 1368
let data_type = DataType::U; - replacement in src/build_spec.rs at line 1369
println!("{}", country);for series_item in generic_u_series_spec(&country).iter() {seriess.0.push(SourceSeries {data_type,country,id: series_item.id.clone(),})}}seriess.append(&mut data_spec_for_country(DataType::U, country));}for country in countries_with_data() {seriess.append(&mut data_spec_for_country(DataType::Cpi, country));}for country in countries_with_data() {seriess.append(&mut data_spec_for_country(DataType::Inf, country));} - edit in src/build_spec.rs at line 1380
/// A generic specification of all data series. Output looks like - edit in src/build_spec.rs at line 1397
- replacement in src/build_spec.rs at line 1398
// /// Read in source_data.keytree, download series, and return// /// `CheckedSourceSeries`.// pub fn update(&self) {// for series in &self.0 {// let data = match Fred::series(&series.id) {// Ok(data) => println!("{}", data.keytree()),// Err(err) => println!("{:?}", err),// };// }// }/// Append `other` to `Self`.pub fn append(&mut self, other: &mut DataSpec) {self.0.append(&mut other.0)} - edit in src/build_spec.rs at line 1427
- replacement in src/build_spec.rs at line 1428
pub data_type: DataType,pub data_type: DataType, - replacement in src/build_spec.rs at line 1430
pub country: Country,pub country: Country, - replacement in src/build_spec.rs at line 1432
pub id: String,pub series_id: SeriesId, - replacement in src/build_spec.rs at line 1441
kt.push_keyvalue(1, "id", &self.id);kt.push_keyvalue(1, "series_id", &self.series_id.to_string()); - replacement in src/build_spec.rs at line 1454
id: self.value("series::id")?,series_id: self.value("series::series_id")?,