BF:BFD[
3.6] → [
4.21250:21265]
BF:BFD[
4.21265] → [
4.21266:21266]
B:BD[
4.21266] → [
4.21267:21547]
∅:D[
2.17711] → [
4.21568:22545]
B:BD[
4.21568] → [
4.21568:22545]
∅:D[
2.17800] → [
4.22634:22642]
B:BD[
4.22634] → [
4.22634:22642]
∅:D[
2.17867] → [
4.22709:44897]
B:BD[
4.22709] → [
4.22709:44897]
∅:D[
2.17931] → [
4.44961:45264]
B:BD[
4.44961] → [
4.44961:45264]
∅:D[
2.17983] → [
4.45316:45408]
B:BD[
4.45316] → [
4.45316:45408]
∅:D[
2.27092] → [
4.45408:45479]
B:BD[
4.45408] → [
4.45408:45479]
∅:D[
2.27171] → [
4.45558:45566]
B:BD[
4.45558] → [
4.45558:45566]
∅:D[
2.27236] → [
4.45631:60080]
B:BD[
4.45631] → [
4.45631:60080]
∅:D[
2.28921] → [
4.60080:60177]
B:BD[
4.60080] → [
4.60080:60177]
∅:D[
2.28955] → [
4.60210:60219]
B:BD[
4.60210] → [
4.60210:60219]
∅:D[
2.29003] → [
4.60258:60302]
B:BD[
4.60258] → [
4.60258:60302]
B:BD[
4.60336] → [
4.60336:60379]
∅:D[
2.29339] → [
4.60696:60711]
B:BD[
4.60696] → [
4.60696:60711]
∅:D[
2.29406] → [
4.60711:61142]
B:BD[
4.60711] → [
4.60711:61142]
B:BD[
4.61151] → [
4.61151:61152]
∅:D[
2.29536] → [
4.61535:61674]
B:BD[
4.61535] → [
4.61535:61674]
∅:D[
5.5582] → [
4.61724:62006]
B:BD[
4.61724] → [
4.61724:62006]
∅:D[
6.12043] → [
4.62006:62032]
B:BD[
4.62006] → [
4.62006:62032]
∅:D[
2.29567] → [
6.12055:12063]
B:BD[
6.12055] → [
6.12055:12063]
∅:D[
2.29597] → [
6.12065:12073]
B:BD[
6.12065] → [
6.12065:12073]
∅:D[
2.29628] → [
4.62107:62402]
B:BD[
4.62107] → [
4.62107:62402]
∅:D[
2.29700] → [
4.62447:62617]
B:BD[
4.62447] → [
4.62447:62617]
B:BD[
4.62882] → [
4.62882:62920]
∅:D[
5.5761] → [
4.63017:63049]
∅:D[
2.29763] → [
4.63017:63049]
B:BD[
4.63017] → [
4.63017:63049]
B:BD[
4.62920] → [
5.5583:5706]
B:BD[
5.5706] → [
2.29701:29763]
B:BD[
4.62402] → [
2.29629:29700]
B:BD[
6.12073] → [
2.29598:29628]
B:BD[
6.12063] → [
2.29568:29597]
B:BD[
6.12045] → [
6.12045:12053]
B:BD[
6.12053] → [
2.29537:29567]
B:BD[
4.62006] → [
6.12038:12043]
B:BD[
4.61674] → [
5.5529:5582]
B:BD[
4.61152] → [
2.29407:29536]
B:BD[
4.60711] → [
2.29340:29406]
B:BD[
4.60379] → [
2.29004:29339]
B:BD[
4.60219] → [
2.28956:29003]
B:BD[
4.60177] → [
2.28922:28955]
B:BD[
4.60080] → [
2.27237:28921]
B:BD[
4.45566] → [
2.27172:27236]
B:BD[
4.45479] → [
2.27093:27171]
B:BD[
4.45408] → [
2.17984:27092]
B:BD[
4.45264] → [
2.17932:17983]
B:BD[
4.44897] → [
2.17868:17931]
B:BD[
4.22642] → [
2.17801:17867]
B:BD[
4.22545] → [
2.17712:17800]
B:BD[
4.21547] → [
2.17667:17711]
//! Builds generic specifications.
use std::convert::TryInto;
use std::fs;
use countries::Country;
use fred_api::{
Fred,
SeriesItems,
};
use keytree::{
KeyTree,
KeyTreeRef,
};
use keytree::Error;
use keytree::serialize::{
IntoKeyTree,
KeyTreeString,
};
/// Return all the countries with good data as a `Vec`.
pub fn countries_with_data() -> Vec<Country> {
vec!(
Country::Australia,
Country::Austria,
Country::Belgium,
Country::Canada,
Country::Chile,
Country::CzechRepublic,
Country::Denmark,
Country::Estonia,
Country::Finland,
Country::France,
Country::Germany,
Country::Greece,
Country::Ireland,
Country::Israel,
Country::Italy,
Country::Japan,
Country::Latvia,
Country::Netherlands,
Country::NewZealand,
Country::Norway,
Country::Poland,
Country::Serbia,
Country::SouthKorea,
Country::Spain,
Country::Sweden,
Country::Switzerland,
Country::UnitedKingdom,
Country::UnitedStates,
)
}
/// Returns relevant CPI series for a country, by pre-selecting series titles for each country.
///
/// ```
/// ```
let titles = match country {
Country::Australia => {
vec!(
"Consumer Price Index: All items: Total: Total for Australia",
"Consumer Price Index: All Items for Australia",
"Consumer Price Index in Australia (DISCONTINUED)",
"Consumer Price Index: Total All Items for Australia",
"Consumer Price Index for Australia",
"Inflation, consumer prices for Australia",
)
}
Country::Austria => {
vec!(
"Consumer Price Index for Austria",
"Consumer Price Index: All items: Total: Total for Austria",
"Consumer Price Index: All Items for Austria",
"Consumer Price Index in Austria (DISCONTINUED)",
"Consumer Price Index: Harmonized Prices: Total All Items for Austria",
"Consumer Price Index: Harmonized Prices: Total All Items for Austria // (DISCONTINUED)",
"Consumer Price Index: Total All Items for Austria",
"Harmonized Index of Consumer Prices: All Items for Austria",
"Harmonized Index of Consumer Prices in Austria (DISCONTINUED)",
"Inflation, consumer prices for Austria",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for // Austria",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Austria (DISCONTINUED)",
)
}
Country::Belgium => {
vec!(
"Consumer Price Index for Belgium",
"Consumer Price Index: Harmonized Prices: Total All Items for Belgium",
"Consumer Price Index: Harmonized Prices: Total All Items for Belgium (DISCONTINUED)",
"Consumer Price Index: Total All Items for Belgium",
"Harmonized Index of Consumer Prices: All Items for Belgium",
"Harmonized Index of Consumer Prices in Belgium (DISCONTINUED)",
"Consumer Price Index: All Items for Belgium",
"Consumer Price Index in Belgium (DISCONTINUED)",
"Consumer Price Index: All items: Total: Total for Belgium",
)
}
Country::Canada => {
vec!(
"Inflation, consumer prices for Canada",
"Consumer Price Index for Canada",
"Consumer Price Index: Total All Items for Canada",
"Consumer Price Index in Canada (DISCONTINUED)",
"Consumer Price Index of All Items in Canada",
"Consumer Price Index: All items: Total: Total for Canada",
)
}
Country::Chile => {
vec!(
"Consumer Price Index for Chile",
"Inflation, consumer prices for Chile",
"Consumer Price Index: Total All Items for Chile",
"Consumer Price Index: All Items for Chile",
"Consumer Price Index: All items: Total: Total for Chile",
)
}
Country::CzechRepublic => {
vec!(
"Consumer Price Index for Czech Republic",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Czech Republic",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Czech Republic (DISCONTINUED)",
"Consumer Price Index: All Items for Czech Republic",
"Consumer Price Index: All items: Total: Total for the Czech Republic",
"Consumer Price Index: Harmonized Prices: Total All Items for the Czech Republic",
"Consumer Price Index: Harmonized Prices: Total All Items for the Czech Republic (DISCONTINUED)",
"Consumer Price Index: Total All Items for the Czech Republic",
"Harmonized Index of Consumer Prices: All Items for Czech Republic",
)
}
Country::Denmark => {
vec!(
"Inflation, consumer prices for Denmark",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Denmark",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Denmark (DISCONTINUED)",
"Harmonized Index of Consumer Prices in Denmark (DISCONTINUED)",
"Consumer Price Index: All Items for Denmark",
"Consumer Price Index in Denmark (DISCONTINUED)",
"Consumer Price Index: All items: Total: Total for Denmark",
"Consumer Price Index for Denmark",
"Consumer Price Index: Total All Items for Denmark",
"Harmonized Index of Consumer Prices: All Items for Denmark",
)
}
Country::Estonia => {
vec!(
"Inflation, consumer prices for Estonia",
"Consumer Price Index: All items: Total: Total for Estonia",
"Consumer Price Index for Estonia",
"Consumer Price Index: Harmonized Prices: Total All Items for Estonia",
"Consumer Price Index: Harmonized Prices: Total All Items for Estonia (DISCONTINUED)",
"Consumer Price Index: Total All Items for Estonia",
"Harmonized Index of Consumer Prices: All Items for Estonia",
)
}
Country::Finland => {
vec!(
"Inflation, consumer prices for Finland",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Finland",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Finland (DISCONTINUED)",
"Consumer Price Index: All Items for Finland",
"Consumer Price Index: OECD Groups: Services: Total for Finland",
"Consumer Price Index: All items: Total: Total for Finland",
"Consumer Price Index: Harmonized Prices: Total All Items for Finland (DISCONTINUED)",
"Consumer Price Index for Finland",
"Consumer Price Index: Harmonized Prices: Total All Items for Finland",
"Consumer Price Index: Total All Items for Finland",
"Harmonized Index of Consumer Prices: All Items for Finland",
)
}
Country::France => {
vec!(
"Harmonized Index of Consumer Prices in France (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for France (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for France",
"Consumer Price Index in France (DISCONTINUED)",
"Consumer Price Index of All Items in France",
"Consumer Price Index: All items: Total: Total for France",
"Inflation, consumer prices for France",
"Consumer Price Index for France",
"Consumer Price Index: Harmonized Prices: Total All Items for France (DISCONTINUED)",
"Consumer Price Index: Harmonized Prices: Total All Items for France",
"Consumer Price Index: Total All Items for France",
)
}
Country::Germany => {
vec!(
"Inflation, consumer prices for Germany",
"Harmonized Index of Consumer Prices in Germany (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Germany (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Germany",
"Consumer Price Index in Germany (DISCONTINUED)",
"Consumer Price Index of All Items in Germany",
"Consumer Price Index: All items: Total: Total for Germany",
"Consumer Price Index for Germany",
"Consumer Price Index: Harmonized Prices: Total All Items for Germany (DISCONTINUED)",
"Consumer Price Index: Harmonized Prices: Total All Items for Germany",
"Consumer Price Index: Total All Items for Germany",
"Harmonized Index of Consumer Prices: All Items for Germany (including former GDR from 1991)",
)
}
Country::Greece => {
vec!(
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Greece",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Greece (DISCONTINUED)",
"Consumer Price Index: All Items for Greece",
"Consumer Price Index: All items: Total: Total for Greece",
"Inflation, consumer prices for Greece",
"Consumer Price Index for Greece",
"Consumer Price Index: Harmonized Prices: Total All Items for Greece",
"Consumer Price Index: Harmonized Prices: Total All Items for Greece (DISCONTINUED)",
"Consumer Price Index: Total All Items for Greece",
"Harmonized Index of Consumer Prices: All Items for Greece",
)
}
Country::Ireland => {
vec!(
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Ireland",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Ireland (DISCONTINUED)",
"Consumer Price Index: OECD Groups: Services: Total for Ireland",
// "Consumer Price Index: All Items for Ireland", // Does not parse
// "Consumer Price Index: All items: Total: Total for Ireland", // Does not parse
"Consumer Price Index: Harmonized Prices: Total All Items for Ireland (DISCONTINUED)",
"Consumer Price Index for Ireland",
"Consumer Price Index: Harmonized Prices: Total All Items for Ireland",
"Harmonized Index of Consumer Prices: All Items for Ireland",
)
}
Country::Israel => {
vec!(
"Consumer Price Index: All Items for Israel",
"Consumer Price Index: All items: Total: Total for Israel",
"Consumer Price Index for Israel",
"Inflation, consumer prices for Israel",
"Consumer Price Index: Total All Items for Israel",
)
}
Country::Italy => {
vec!(
"Harmonized Index of Consumer Prices in Italy (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Italy (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Italy",
"Consumer Price Index: Food for Italy",
"Consumer Price Index in Italy (DISCONTINUED)",
"Consumer Price Index of All Items in Italy",
"Consumer Price Index: All items: Total: Total for Italy",
"Inflation, consumer prices for Italy",
"Consumer Price Index for Italy",
"Consumer Price Index: Harmonized Prices: Total All Items for Italy (DISCONTINUED)",
"Consumer Price Index: Harmonized Prices: Total All Items for Italy",
"Consumer Price Index: Total All Items for Italy",
"Harmonized Index of Consumer Prices: All Items for Italy",
)
}
Country::Japan => {
vec!(
"Harmonized Index of Consumer Prices in Japan (DISCONTINUED)",
"Consumer Price Index in Japan (DISCONTINUED)",
"Consumer Price Index of All Items in Japan",
"Consumer Price Index: All items: Total: Total for Japan",
"Inflation, consumer prices for Japan",
"Not Seasonally Adjusted",
)
}
Country::Latvia => {
vec!(
"Consumer Price Index: All items: Total: Total for Latvia",
"Inflation, consumer prices for Latvia",
"Harmonized Index of Consumer Prices: Unprocessed Food for Latvia",
"Consumer Price Index for Latvia",
)
}
Country::Netherlands => {
vec!(
"Harmonized Index of Consumer Prices in Netherlands (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Netherlands (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Netherlands",
"Consumer Price Index in Netherlands (DISCONTINUED)",
"Consumer Price Index: All Items for Netherlands",
"Consumer Price Index: All items: Total: Total for the Netherlands",
"Consumer Price Index for Netherlands",
"Consumer Price Index: Harmonized Prices: Total All Items for the Netherlands",
"Consumer Price Index: Harmonized Prices: Total All Items for the Netherlands (DISCONTINUED)",
"Consumer Price Index: Total All Items for the Netherlands",
"Harmonized Index of Consumer Prices: All Items for Netherlands",
)
}
Country::NewZealand => {
vec!(
"Consumer Price Index: All Items for New Zealand",
"Consumer Price Index: All Items Excluding Food and Energy for New Zealand",
"Consumer Price Index: All items: Total: Total for New Zealand",
"Consumer Price Index for New Zealand",
"Inflation, consumer prices for New Zealand",
"Consumer Price Index: Total All Items for New Zealand",
)
}
Country::Norway => {
vec!(
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Norway",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Norway (DISCONTINUED)",
"Consumer Price Index: All Items for Norway",
"Consumer Price Index in Norway (DISCONTINUED)",
"Consumer Price Index: All items: Total: Total for Norway",
"Consumer Price Index: Harmonized Prices: Total All Items for Norway (DISCONTINUED)",
"Consumer Price Index for Norway",
"Consumer Price Index: Harmonized Prices: Total All Items for Norway",
"Consumer Price Index: Total All Items for Norway",
"Harmonized Index of Consumer Prices: All Items for Norway",
)
}
Country::Poland => {
vec!(
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Poland",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Poland (DISCONTINUED)",
"Consumer Price Index: Food for Poland",
"Consumer Price Index: All Items for Poland",
"Consumer Price Index: All items: Total: Total for Poland",
"Inflation, consumer prices for Poland",
"Consumer Price Index for Poland",
"Consumer Price Index: Total All Items for Poland",
"Harmonized Index of Consumer Prices: All Items for Poland",
)
}
Country::Serbia => {
vec!(
"Consumer Price Index for Serbia",
"Inflation, consumer prices for Serbia",
)
}
Country::SouthKorea => {
vec!(
"Consumer Price Index: All Items for Korea",
"Consumer Price Index: All items: Total: Total for the Republic of Korea",
"Inflation, consumer prices for the Republic of Korea",
"Consumer Price Index for Republic of Korea",
"Consumer Price Index: Total All Items for the Republic of Korea",
)
}
Country::Spain => {
vec!(
"Inflation, consumer prices for Spain",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Spain (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Spain",
"Consumer Price Index in Spain (DISCONTINUED)",
"Consumer Price Index: All Items for Spain",
"Consumer Price Index: All items: Total: Total for Spain",
"Consumer Price Index for Spain",
"Consumer Price Index: Harmonized Prices: Total All Items for Spain (DISCONTINUED)",
"Consumer Price Index: Harmonized Prices: Total All Items for Spain",
"Consumer Price Index: Total All Items for Spain",
"Harmonized Index of Consumer Prices: All Items for Spain",
)
}
Country::Sweden => {
vec!(
"Harmonized Index of Consumer Prices in Sweden (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Sweden",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Sweden (DISCONTINUED)",
"Consumer Price Index: All Items for Sweden",
"Consumer Price Index in Sweden (DISCONTINUED)",
"Consumer Price Index: All items: Total: Total for Sweden",
"Consumer Price Index: Harmonized Prices: Total All Items for Sweden",
"Consumer Price Index: Harmonized Prices: Total All Items for Sweden (DISCONTINUED)",
"Consumer Price Index for Sweden",
"Consumer Price Index: Total, Net All Items for Sweden (DISCONTINUED)",
"Consumer Price Index: Total All Items for Sweden",
"Harmonized Index of Consumer Prices: All Items for Sweden",
)
}
Country::Switzerland => {
vec!(
"Consumer Price Index: Harmonized Prices: Total All Items for Switzerland",
"Consumer Price Index: Harmonized Prices: Total All Items for Switzerland (DISCONTINUED)",
"Consumer Price Index for Switzerland",
"Consumer Price Index: Total All Items for Switzerland",
"Harmonized Index of Consumer Prices: All Items for Switzerland",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Switzerland",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for Switzerland (DISCONTINUED)",
)
}
Country::UnitedKingdom => {
vec!(
"Harmonized Index of Consumer Prices in the United Kingdom (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for United Kingdom (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for United Kingdom",
"Consumer Price Index in the United Kingdom (DISCONTINUED)",
"Consumer Price Index of All Items in the United Kingdom",
"Consumer Price Index: All Items for United Kingdom",
"Consumer Price Index: All items: Total: Total for the United Kingdom",
"Inflation, consumer prices for the United Kingdom",
"Consumer Price Index for United Kingdom",
"Consumer Price Index in the United Kingdom",
"Consumer Price Inflation in the United Kingdom",
"Consumer Price Index: Harmonized Prices: Total All Items for the United Kingdom (DISCONTINUED)",
"Consumer Price Index: Harmonized Prices: Total All Items for the United Kingdom",
"Consumer Price Index: Total All Items for the United Kingdom",
"Harmonized Index of Consumer Prices: All Items for United Kingdom",
)
}
Country::UnitedStates => {
vec!(
"Harmonized Index of Consumer Prices: All Items for United States",
"Consumer Price Index: Total All Items for the United States",
"Consumer Price Index: Harmonized Prices: Total All Items for the United States",
"Consumer Price Index: Harmonized Prices: Total All Items for the United States (DISCONTINUED)",
"Research Consumer Price Index: All Items",
"Consumer Price Index for United States",
"Flexible Price Consumer Price Index",
"Inflation, consumer prices for the United States",
"Consumer Price Index, All Items for United States",
"Rate of Change (6 Month Span at Annual Rate), Consumer Price Index, All Items (Centered) for United States",
"Median Consumer Price Index",
"Sticky Price Consumer Price Index",
"16% Trimmed-Mean Consumer Price Index",
"Consumer Price Index: All Items for the United States",
"Consumer Price Index of All Items in United States",
"Consumer Price Index in the United States (DISCONTINUED)",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for the United States",
"Consumer Price Index: All Items (Harmonized Index of Consumer Prices) for the United States (DISCONTINUED)",
"Harmonized Index of Consumer Prices in the United States (DISCONTINUED)",
)
}
_ => panic!(),
};
match country {
Country::UnitedStates => {
match Fred::tags_series("cpi;usa") {
Ok(tags_series) => {
tags_series.seriess
.equals_one_of(titles)
},
Err(json_error) => {
println!("{}", json_error);
panic!();
},
}
},
_ => {
Ok(tags_series) => {
tags_series.seriess
.equals_one_of(titles)
},
Err(json_error) => {
println!("{}", json_error);
panic!();
},
}
},
}
}
format!(
"{};{}",
tag,
country.to_string().to_lowercase()
)
}
/// Return relevant unemployment rate series for a country.
/// ```
/// ```
if let Country::UnitedStates = country {
// Need to use a different search technique for US data.
let exclude_phrase = vec!(
"Male",
"Female",
"Men",
"Women",
"Youth",
);
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("unemployment;rate;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!(
"Male",
"Female",
"55-64",
"25-54",
"15-24",
"20 to 24",
"Youth",
"Women",
"Teenagers",
),
vec!(
"Rate"
),
)
}
Country::Austria => {
(
vec!(
"Male",
"Female",
"55-64",
"25-54",
"15-24",
"15-64", // series includes 15-74
"20 to 24",
"Youth",
"Women",
"Teenagers",
),
vec!(
"Rate"
),
)
}
Country::Belgium => {
(
vec!(
"Male",
"Female",
"55-64",
"25-54",
"15-24",
"15-64", // series includes 15-74
"20 to 24",
"Youth",
"Women",
"Teenagers",
),
vec!(
"Rate"
),
)
}
Country::Canada => {
(
vec!(
"Male",
"Female",
"15-64",
"55-64",
"25-54",
"15-24",
"20 to 24",
"Youth",
"Women",
"Teenagers",
),
vec!(
"Rate"
),
)
}
Country::Chile => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate"
),
)
}
Country::CzechRepublic => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate"
),
)
}
Country::Denmark => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate"
),
)
}
Country::Estonia => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Finland => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::France => {
(
vec!(
"Male",
"Men",
"Female",
"Women",
"Youth",
"Teenagers",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Germany => {
(
vec!(
"Male",
"Men",
"Female",
"Youth",
"Women",
"Teenagers",
"20 to 24",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Greece => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Ireland => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Israel => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Italy => {
(
vec!(
"Male",
"Female",
"Youth",
"Men",
"Women",
"Teenagers",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Japan => {
(
vec!(
"Male",
"Female",
"Youth",
"Men",
"Women",
"Teenagers",
"20 to 24",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Latvia => {
(
vec!(
"Youth",
"Male",
"Female",
"25 and over",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"nemployment",
),
)
}
Country::Netherlands => {
(
vec!(
"Male",
"Female",
"Youth",
"Women",
"Teenagers",
"Men",
"20 to 24",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::NewZealand => {
(
vec!(
"Male",
"Female",
"55-64",
"25-54",
"15-24",
"Youth",
),
vec!(
"Rate",
),
)
}
Country::Norway => {
(
vec!(
"Male",
"Female",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Poland => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Serbia => {
(
vec!(
),
vec!(
"",
),
)
}
Country::SouthKorea => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Spain => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::Sweden => {
(
vec!(
"Male",
"Female",
"Youth",
"Men",
"Women",
"Teenagers",
"15-24",
"15-64",
"25-54",
"55-64",
"20 to 24",
),
vec!(
"Rate",
),
)
}
Country::Switzerland => {
(
vec!(
"Male",
"Female",
"Youth",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
Country::UnitedKingdom => {
(
vec!(
"Male",
"Female",
"Youth",
"Men",
"Women",
"Teenagers",
"20 to 24",
"15-24",
"15-64",
"25-54",
"55-64",
),
vec!(
"Rate",
),
)
}
_ => panic!(),
};
match Fred::tags_series(&to_tag("unemployment", country)) {
Ok(tags_series) => {
tags_series.seriess
.exclude_phrases(exclude_phrase)
.only_include(include_phrase)
},
Err(err) => {
println!("{}", err);
panic!();
},
}
}
}
/// ```
/// seriess:
/// series:
/// data_type: u
/// country: Australia
/// ```
let mut seriess = DataSpec(Vec::new());
for country in countries_with_data() {
seriess
}
/// ```
/// series:
/// data_type: u
/// country: United States
/// id: LRUNTTTTUSQ156S
/// ```
pub struct DataSpec(pub Vec<SourceSeries>);
impl DataSpec {
/// Read in keytree data from file.
pub fn from_file(path: &str) -> Self {
let source_spec = fs::read_to_string(path).unwrap();
let kt = KeyTree::parse(&source_spec).unwrap();
kt.to_ref().try_into().unwrap()
}
}
impl<'a> TryInto<DataSpec> for KeyTreeRef<'a> {
type Error = Error;
fn try_into(self) -> Result<DataSpec, Error> {
Ok(
)
}
}
impl IntoKeyTree for DataSpec {
fn keytree(&self) -> KeyTreeString {
let mut kt = KeyTreeString::new();
kt.push_key(0, "seriess");
for series in &self.0 {
kt.push_keytree(1, series.keytree());
}
kt
}
}
pub struct SourceSeries {
///
///
}
impl IntoKeyTree for SourceSeries {
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, "country", &self.country.to_string());
kt
}
}
impl<'a> TryInto<SourceSeries> for KeyTreeRef<'a> {
type Error = keytree::Error;
fn try_into(self) -> Result<SourceSeries, keytree::Error> {
Ok(
SourceSeries{
}
)
}
}
data_type: self.value("series::data_type")?,
country: self.value("series::country")?,
series_id: self.value("series::series_id")?,
kt.push_keyvalue(1, "series_id", &self.series_id.to_string());
pub series_id: SeriesId,
pub country: Country,
///
pub data_type: DataType,
///
DataSpec(self.vec_at("seriess:series")?)
/// Append `other` to `Self`.
pub fn append(&mut self, other: &mut DataSpec) {
self.0.append(&mut other.0)
}
/// A generic specification of all data series. Output looks like
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));
}
pub fn build_generic_data_spec() -> DataSpec {
/// series_id: AUSURAMS
/// 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
pub fn generic_u_series_spec(country: Country) -> SeriesItems {
/// println!("{}", unemployment_series(Country::Canada, "u_series.keytree"));
}
/// 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!();
},
}
}
fn to_tag(tag: &str, country: Country) -> String {
match Fred::tags_series(&to_tag("cpi", country)) {
pub fn generic_cpi_series_spec(country: Country) -> SeriesItems {
/// println!("{}", generic_cpi_series_spec(Country::NewZealand, "cpi_series.keytree"));
use crate::{
DataType,
SeriesId,
};