XPXYFEZMZJSF2GOFG5HTCMLVHINNVRYIVWV7KJ6A7A3PG3CM2TGAC
BB2T6X3XK3Y4JFOMBGKTFVL6BZ5NOGBTPSCK4ADRSZQLQKQHESLAC
5B2HBV3JTNBNJYEJ4BXFQDEP2D552SBJFPY6STKSK7SPFZYSTCFAC
GQVS55HIQLU7KPJNRMF57QUM4EATSWFQRCS7ZEJMJPUXFX2NHSYAC
2CCG6KUP6VL2Q7WQKLVNIPPGZWHSWIOWETRCS3APZTV4WSF5GLWAC
SPSFTMLRZE2R4EBAAQKWBUZDRYZ36S2VFTBIJRE6XS7JMKELV4AQC
TSY4YBBZ4AEW2JTEI4AS5FGTTUZR5WE3TENDHVIOWWY6V2DRT7ZQC
GUXZCEWWPBCHXO26JVWZ74CTSDFDDO775YR7FKY7UGVZCA7GCSYAC
77SIQZ3EGGV6KSECMLPDKQFGEC7CCFAPWGER7ZARQ5STDKJNU6GQC
XI5ALEH6NPTQWB6O62QV62EP4H3K7WSNTHCOGT3LZIIU6I2YDGIQC
4MG5JFXTKAE3SOVKGGNKEUTNCKOWEBHTGKVZHJWLWE3PTZTQKHPAC
SAHJYVNBUBBIUBI4ZMAXK4QJFOT54M5UA3W2HQMTNDSP3GGCRX7QC
TTR5IFSG25VNBQ2F2FNOLUMTEIHVBHFOEXYB2ZWEHWOURUV4GJMQC
UUD3CJZLSTAVLMIXIWE4CHN5HQSFM6K3DCPWECJMKGXDOROK4G4AC
UKQAGL5F5LWZZR7RWFJI3H2MW6LXPRGPXAIGNBZI5IVJLWUFHLGAC
K4CH53V4MO5KCCJOOQUQKI3LEFSUSCNAJS24VUWOZISXTCQD4FZQC
// Iterate over series_ids and build series_json first. There is a one-to-one
// correspondence between SeriesSpec and SeriesJson so we can use the indices in
// SeriesSpec to build GraphicJson.
// Push SeriesJson Vec<SeriesJson>
for (i, series_id) in series_ids.iter().enumerate() {
m_series.insert(
series_id.clone(),
(
i,
page_spec.into_series_json(series_id, *country, root_path)?,
)
);
}
graphic_json.graphics.push(page_spec.into_series_json(series_id, *country, root_path)?);
let series_ref = match m_series.get(series_id) {
Some((series_ref, _)) => series_ref,
None => {
return Err(failed_to_reference_series(
file!(),
line!(),
&series_id.to_string(),
))
},
};
graphic_json.series_ref.push(*series_ref);
// We pass country because `series_spec.country` is None.
/// Return the meta data for a `SeriesSpec`.
pub fn meta(&self, country: Country, root_path: &str) -> SeriesMetaData
/// Read metadata from file.
pub fn read_meta_from_file(&self, country: Country, root_path: &str) -> SeriesMetaData
/// Return `Self` given a `series_id`.
pub fn from_series_id(series_id: &str, root_path: &str) -> Result<Self, Error> {
let sid = SeriesId::from_str(series_id).unwrap();
let data_spec = DataSpec::from_file(root_path)?;
// /// Return `Self` given a `series_id`.
// pub fn from_series_id(series_id: &str, root_path: &str) -> Result<Self, Error> {
// let sid = SeriesId::from_str(series_id).unwrap();
// let data_spec = DataSpec::from_file(root_path)?;
let key = match data_spec.reverse.get(&sid) {
Some(key) => key,
None => { return Err(
series_id_not_in_dataspec(
file!(),
line!(),
&series_id.to_string()
)
)},
};
// let key = match data_spec.reverse.get(&sid) {
// Some(key) => key,
// None => { return Err(
// series_id_not_in_dataspec(
// file!(),
// line!(),
// &series_id.to_string()
// )
// )},
// };
match data_spec.map.get(&key) {
Some(series_specs) => {
Ok(
series_specs.iter()
.find(|series_spec| series_spec.series_id == sid)
.unwrap()
.clone()
)
},
None => unreachable!(),
}
}
pub fn data_with_transforms(&self) -> Result<RegularTimeSeries<1>, Error> {
// match data_spec.map.get(&key) {
// Some(series_specs) => {
// Ok(
// series_specs.iter()
// .find(|series_spec| series_spec.series_id == sid)
// .unwrap()
// .clone()
// )
// },
// None => unreachable!(),
// }
// }
/// Use `Self` to make a Fred request for series data, and return a `RegularTimeSeries`.
pub fn data_without_transform(&self) -> Result<RegularTimeSeries<1>, Error> {
let csv_path = data_path(
root_path,
self.data_type,
country,
series_id_stem,
"csv",
);
let ts = TimeSeries::<1>::from_csv(&csv_path)
.map_err(|err| {
external(file!(), line!(), &err.to_string())
})?;
let rts = ts.try_into()
.map_err(|err: time_series::error::Error| {
external(file!(), line!(), &err.to_string())
})?;
Ok(rts)
}
pub fn data_from_fred(
&self,
country: Country) -> Result<RegularTimeSeries<1>, Error>
{
// pub fn data_without_transform(
// &self,
// country: Country,
// root_path: &str) -> Result<RegularTimeSeries<1>, Error>
// {
// // Select the observation data from the FRED data.
//
// let observations = match Fred::series_observations(&self.series_id.to_string()) {
// Ok(series_obs) => series_obs.observations,
// Err(err) => { return Err(fred_error(file!(), line!(), &err.to_string())) },
// };
// // We need to build a RegularTimeSeries here, and then use RegularTimeSeries here
// // to build csv file.
// // Data is parsed into a RegularTimeSeries
// // Want power to drop_first
// let mut v = Vec::new();
// // Drop the first n items
// let skip = match self.drop_first {
// None => 0,
// Some(n) => n,
// };
// for (i, obs) in observations.iter().enumerate().skip(skip) {
// let date = MonthlyDate::from_str(&obs.date)?;
// let value: f32 = match obs.value.parse() {
// Ok(n) => n,
// Err(_) => {
// let err = parse_fred_value_failed(
// file!(),
// line!(),
// &self.data_type.to_string(),
// // Expect country to be Some while building source.
// &country.to_string(),
// &self.series_id.to_string(),
// &format!(
// "{}, {}",
// obs.date,
// obs.value,
// ),
// i + 1,
// );
// self.soft_parse(observations, err);
// unreachable!();
// },
// };
// let date_point = DatePoint::<1>::new(date.0, [value]);
// v.push(date_point)
// }
// let ts = TimeSeries::new(v);
// let rts = match ts.try_into() {
// Ok(rts) => {
// rts
// },
// Err(_) => {
// let err = expected_regular_time_series(
// file!(),
// line!(),
// &country.to_string(),
// &self.data_type.to_string(),
// &self.series_id.to_string(),
// );
// self.soft_parse(observations, err);
// unreachable!();
// },
// };
// Ok(rts)
// }
pub fn write_data(&self, root_path: &str) -> Result<(), Error> {
pub fn write_data_to_file(&self, root_path: &str) -> Result<(), Error> {
// When this function is used, Self.country should be Some.
let rts = self.data_from_fred(self.country.unwrap())?;