Created keytree generator for u and cpi.

[?]
Jun 1, 2021, 10:19 PM
UCSU3QE4352YC4VOVI7GCSTNNA5FAHYURNJLJQEHY32BB6S3CZVAC

Dependencies

  • [2] AIFRDCG2 Split off countries mod into a separate crate.
  • [3] 4MG5JFXT First record.
  • [4] IKPVWWLK Filter unemployment rate series.
  • [5] AT753JPO Selected US unemployment series.
  • [6] 5POF332L Working on fn cpi_included().
  • [7] GUXZCEWW Added Country enum.
  • [8] CUADTSHQ Save csv data as multiple files.
  • [9] LURDUHBI Finished series filter for CPI.

Change contents

  • replacement in src/main.rs at line 5
    [2.24][3.44:59](),[3.44][3.44:59](),[3.25][3.10:26](),[3.10][3.10:26](),[3.26][3.22:47](),[3.47][3.87:115](),[3.87][3.87:115](),[3.126][3.126:138](),[3.37][3.59:84](),[3.138][3.59:84](),[3.26][3.59:84](),[3.59][3.59:84](),[3.66][3.107:110](),[3.107][3.107:110]()
    use ui_data::{
    cpi_series,
    countries_with_data,
    save_unemployment_data,
    to_tag,
    unemployment_series,
    };
    [2.24]
    [3.110]
    use ui_data::*;
  • replacement in src/main.rs at line 8
    [3.127][3.88:146](),[3.146][3.174:219](),[3.174][3.174:219](),[3.219][3.147:244](),[3.244][3.139:222](),[3.222][3.333:365](),[3.333][3.333:365](),[3.365][3.48:250](),[3.250][3.617:626](),[3.617][3.617:626](),[3.626][3.251:787](),[3.787][3.705:714](),[3.705][3.705:714](),[3.906][3.906:907](),[3.907][3.788:853](),[3.853][3.986:987](),[3.986][3.986:987](),[3.987][3.854:939](),[3.939][3.1046:1047](),[3.1046][3.1046:1047](),[3.1047][3.940:1033](),[3.1033][3.1108:1109](),[3.1108][3.1108:1109](),[3.1109][3.1034:1128](),[3.1128][3.223:224](),[3.1143][3.223:224](),[3.224][3.1129:1189](),[3.1189][3.275:276](),[3.275][3.275:276](),[3.329][3.1143:1144](),[3.1143][3.1143:1144](),[3.1144][3.1190:1252](),[3.1252][3.383:384](),[3.383][3.383:384](),[3.384][3.1253:1418](),[3.1418][3.532:542](),[3.532][3.532:542](),[3.542][3.1419:1440](),[3.1440][3.1208:1209](),[3.591][3.1208:1209](),[3.1208][3.1208:1209](),[3.1209][3.1441:1481](),[3.1481][3.83:84](),[3.633][3.83:84](),[3.83][3.83:84](),[3.84][2.25:97](),[3.1551][3.1260:1261](),[2.97][3.1260:1261](),[3.703][3.1260:1261](),[3.55][3.1260:1261](),[3.148][3.1260:1261](),[3.1260][3.1260:1261](),[3.1261][2.98:148](),[2.148][3.1552:1553](),[3.1261][3.1552:1553](),[3.1553][2.149:150]()
    // let data = unemployment_series(Country::Slovenia);
    // unemployment_data("LFHU24TTSIM647S");
    // let u = unemployment_data("LRUNTTTTSIQ156S");
    // inflation_series(Country::Slovenia);
    // save_data_csv("SVNCPHPLA01GPM");
    // save_series_meta("SVNCPHPLA01GPM");
    // println!("{:?}", data);
    // save_unemployment_data(&Country::SouthKorea);
    // for country in countries_with_data().iter() {
    // println!("\n{}", country.to_string());
    // save_unemployment_data(&country);
    // }
    // save_data_csv("LRHUTTTTNZA156N");
    // println!("{}", to_tag("unemployment", &Country::UnitedStates));
    // println!("{}", to_tag("unemployment", &Country::UnitedStates));
    // println!("{}", unemployment_series(&Country::NewZealand));
    // println!("{}", Fred::series_tags("NZLURHARMQDSMEI").unwrap().one_line());
    // Category attack
    // for i in 0..1000 {
    // match Fred::category(i) {
    // Ok(category) => println!("{}\n{}", i, category),
    // Err(json_err) => {},
    // }
    // }
    // let seriess = unemployment_series(&Country::NewZealand);
    // for series in seriess.iter() {
    // println!("{}", series.id);
    // }
    // let tag_seriess = Fred::tags_series("unemployment;rate;usa;nation").unwrap().seriess;
    // for tag_series in tag_seriess.iter() {
    // println!("{}", tag_series);
    // }
    // println!("{:?}", Fred::category_series(10).unwrap())
    // let series = Fred::series("LRHU24TTUSA156N").unwrap();
    // match Fred::series_tags("LRHU24TTUSA156N") {
    // Ok(series_tags) => println!("{}", series_tags),
    // Err(json_err) => println!("{}", json_err),
    // }
    // Relevant tags
    // unemployment, rate, nation, usa
    // println!("{}", unemployment_series(&Country::UnitedStates));
    save_unemployment_data(&Country::NewZealand);
    [3.127]
    [3.292]
    let root_dir = shellexpand::tilde("~/test_data");
    // save_all_cpi_data(&format!("{}/{}", root_dir, "/cpi"));
    // save_all_cpi_data_after(&Country::Israel, &format!("{}/{}", root_dir, "/cpi/israel"));
    // println!("{}", cpi_series(&Country::NewZealand));
    generate_keytree(&format!("{}/generated.keytree", root_dir));
  • edit in src/main.rs at line 14
    [3.294][3.1554:1591]()
    // Do searches by looking at titles
  • edit in src/lib.rs at line 3
    [3.799]
    [3.799]
    use std::env;
  • edit in src/lib.rs at line 7
    [2.175]
    [3.478]
  • replacement in src/lib.rs at line 11
    [3.1274][3.1274:1309]()
    /// Save FRED data to disk as csv.
    [3.1088]
    [3.1309]
    /// Save FRED data to disk as csv, using full path.
  • edit in src/lib.rs at line 23
    [3.1666][3.1666:1714]()
    let save_path = format!("./data/{}", path);
  • replacement in src/lib.rs at line 49
    [3.2188][3.2188:2249]()
    fs::create_dir_all(&save_path).unwrap();
    [3.2188]
    [3.2249]
    fs::create_dir_all(&path).unwrap();
  • replacement in src/lib.rs at line 53
    [3.2358][3.2358:2397]()
    save_path,
    [3.2358]
    [3.2397]
    path,
  • replacement in src/lib.rs at line 68
    [3.2739][3.2739:2788]()
    fs::create_dir_all(&save_path).unwrap();
    [3.2739]
    [3.2788]
    fs::create_dir_all(&path).unwrap();
  • replacement in src/lib.rs at line 72
    [3.2861][3.2861:2888]()
    save_path,
    [3.2861]
    [3.2888]
    path,
  • replacement in src/lib.rs at line 85
    [3.3143][3.3143:3198]()
    pub fn save_series_meta(series_id: &str, path: &str) {
    [3.3143]
    [3.2043]
    pub fn save_series_meta(series_id: &str, full_path: &str) {
  • replacement in src/lib.rs at line 95
    [3.3283][3.3283:3334]()
    "./data/{}/{}.meta",
    path,
    [3.3283]
    [3.3334]
    "{}/{}.meta",
    full_path,
  • replacement in src/lib.rs at line 103
    [3.3393][3.187:233](),[3.1795][3.187:233]()
    /// Return relevant CPI series for a country.
    [3.3393]
    [3.233]
    /// Returns relevant CPI series for a country, by pre-selecting series titles for each country.
    ///
  • replacement in src/lib.rs at line 106
    [3.241][3.241:294]()
    /// println!("{}", cpi_series(Country::NewZealand));
    [3.241]
    [3.294]
    /// println!("{}", cpi_series(&Country::NewZealand));
  • replacement in src/lib.rs at line 108
    [3.302][3.302:350]()
    pub fn cpi_series(country: Country) -> String {
    [3.302]
    [3.124]
    pub fn cpi_series(country: &Country) -> SeriesItems {
  • edit in src/lib.rs at line 461
    [3.2376][3.2376:2401]()
    .to_string()
  • replacement in src/lib.rs at line 985
    [3.12137][3.4567:4682]()
    /// Save csv data and meta data to file, for a given `Country`.
    pub fn save_unemployment_data(country: &Country) {
    [3.12137]
    [3.4682]
    /// Save csv data and meta data to file, for a given `Country` using full path.
    /// ```
    /// save_unemployment_data(&Country::NewZealand, "/fullpath/data/new_zealand");
    /// ```
    pub fn save_unemployment_data(country: &Country, path: &str) {
  • edit in src/lib.rs at line 991
    [3.4738][3.4738:4776]()
    let path = country.as_path();
  • replacement in src/lib.rs at line 997
    [3.4906][3.4906:4946]()
    pub fn update_all_unemployment_data() {
    [3.4906]
    [3.4946]
    /// Save csv data and meta data to file, for a given `Country` using full path.
    /// ```
    /// save_cpi_data(&Country::NewZealand, "/fullpath/data/cpi/new_zealand");
    /// ```
    pub fn save_cpi_data(country: &Country, path: &str) {
    for series in cpi_series(country).iter() {
    save_data_csv(&series.id, &path);
    save_series_meta(&series.id, &path);
    println!("{}", series.id)
    }
    }
    /// Save csv data and meta data to file, for a given `Country`, using full path.
    /// ```
    /// save_all_unemployment_data("/fullpath/data/u");
    /// ```
    pub fn save_all_unemployment_data(path: &str) {
  • replacement in src/lib.rs at line 1016
    [3.5043][3.5043:5085]()
    save_unemployment_data(&country);
    [3.5043]
    [3.5085]
    save_unemployment_data(&country, &format!("{}/{}", path, country.as_path()));
    }
    }
    /// Save csv data and meta data to file, for a given `Country`, using full path.
    /// ```
    /// save_all_cpi_data("/fullpath/data/cpi");
    /// ```
    pub fn save_all_cpi_data(path: &str) {
    for country in countries_with_data().iter() {
    println!("\n{}", country.to_string());
    save_cpi_data(&country, &format!("{}/{}", path, country.as_path()));
    }
    }
    /// Generate the base keytree spec for all countries, using full path.
    /// ```
    /// generate_keytree("/fullpath/data/generated.keytree");
    /// ```
    /// ```text
    /// source:
    /// html_page:
    /// data_type: u
    /// country: Australia
    /// graphic:
    /// height: 200
    /// data: AUSURAMS_a
    /// graphic:
    /// data: AUSURANAA_a
    /// graphic:
    /// ```
    // TODO: cpi, u
    pub fn generate_keytree(path: &str) {
    let mut s = String::from("source:\n");
    // Unemployment
    println!("u");
    for country in countries_with_data().iter() {
    s.push_str(" html_page:\n data_type: u\n");
    s.push_str(&format!(" country: {}\n", country));
    println!("{}", country.to_string());
    for series in unemployment_series(country).iter() {
    s.push_str(" graphic:\n data: ");
    s.push_str(&series.id);
    s.push('\n');
    }
    s.push('\n');
    };
    // CPI
    println!("cpi");
    for country in countries_with_data().iter() {
    s.push_str(" html_page:\n data_type: u\n");
    s.push_str(&format!(" country: {}\n", country));
    println!("{}", country.to_string());
    for series in cpi_series(country).iter() {
    s.push_str(" graphic:\n data: ");
    s.push_str(&series.id);
    s.push('\n');
    }
    s.push('\n');
    };
    fs::create_dir_all(&path).unwrap();
    fs::write(&path, s).unwrap();
    }
    /// Save csv data and meta data to file, for all countries after `Country` in the
    //'countries_with_data' list.
    pub fn save_all_cpi_data_after(after: &Country, path: &str) {
    for country in countries_with_data().iter().skip_while(|&country| country != after) {
    println!("\n{}", country.to_string());
    save_cpi_data(&country, &format!("{}/{}", path, country.as_path()));
  • edit in Cargo.toml at line 12
    [3.21840]
    [2.348]
    shellexpand = "2.1.0"