UCSU3QE4352YC4VOVI7GCSTNNA5FAHYURNJLJQEHY32BB6S3CZVAC
AIFRDCG2GLASIMF3WZYAQBHIGZZDGPMP2WBYH7HXIYORKAK2SUYAC
GUXZCEWWPBCHXO26JVWZ74CTSDFDDO775YR7FKY7UGVZCA7GCSYAC
CUADTSHQNPGMWHIJCWXKHNNIY4UJOYZ7XBZA5CJ2VVJJAMSNT4BAC
IKPVWWLKQZW7O23ZUSFFRE7IUUDFZR6UOCN6MVPNPMSTDSN7X4VAC
AT753JPOOWZCIYNKAG27LZSZZ72ZILWVENG42Y6U2S34JD3B6ZZQC
5POF332LJEBGWEJUGI34P33Q4BQP7CAQNV5ODQT3PWG7FI7VNLOQC
LURDUHBIQRLOMOMHK3OFOQ4N5S56C46JPAHRQ3PCXBJ4CDPE24HAC
4MG5JFXTKAE3SOVKGGNKEUTNCKOWEBHTGKVZHJWLWE3PTZTQKHPAC
use ui_data::{
cpi_series,
countries_with_data,
save_unemployment_data,
to_tag,
unemployment_series,
};
use ui_data::*;
// 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);
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));
/// Save csv data and meta data to file, for a given `Country`.
pub fn save_unemployment_data(country: &Country) {
/// 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) {
pub fn update_all_unemployment_data() {
/// 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) {
save_unemployment_data(&country);
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()));