EHEK63WARL6PGYZMCSOH53JXOYPHNGWZO4QP5RKODPIQJ53IWDDQC XPXYFEZMZJSF2GOFG5HTCMLVHINNVRYIVWV7KJ6A7A3PG3CM2TGAC 5B2HBV3JTNBNJYEJ4BXFQDEP2D552SBJFPY6STKSK7SPFZYSTCFAC GQVS55HIQLU7KPJNRMF57QUM4EATSWFQRCS7ZEJMJPUXFX2NHSYAC TSY4YBBZ4AEW2JTEI4AS5FGTTUZR5WE3TENDHVIOWWY6V2DRT7ZQC SPSFTMLRZE2R4EBAAQKWBUZDRYZ36S2VFTBIJRE6XS7JMKELV4AQC GUXZCEWWPBCHXO26JVWZ74CTSDFDDO775YR7FKY7UGVZCA7GCSYAC XI5ALEH6NPTQWB6O62QV62EP4H3K7WSNTHCOGT3LZIIU6I2YDGIQC 2CCG6KUP6VL2Q7WQKLVNIPPGZWHSWIOWETRCS3APZTV4WSF5GLWAC 4MG5JFXTKAE3SOVKGGNKEUTNCKOWEBHTGKVZHJWLWE3PTZTQKHPAC K4CH53V4MO5KCCJOOQUQKI3LEFSUSCNAJS24VUWOZISXTCQD4FZQC pub struct Json(BTreeMap<(Country, DataType, usize), (Vec<SeriesJson>, Vec<GraphicJson>)>);
pub struct Json(BTreeMap<(Country, DataType, usize), PageValue>);impl Json {pub fn into_ts_data(&self) -> Result<TSData, Error> {let mut map: BTreeMap<(Country, DataType, usize), String> = BTreeMap::new();for (key, value) in self.0.iter() {let json = serde_json::to_string(&value).map_err(|_| {failed_to_serialize_to_json(file!(),line!(),)})?;map.insert(*key, json);}Ok(TSData(map))}}pub struct TSData(pub BTreeMap<(Country, DataType, usize), String>);// The JSON that is served for a given page.#[derive(Debug, Serialize)]pub struct PageValue {country: Country,data_type: DataType,index: usize,seriess: Vec<SeriesJson>,graphics: Vec<GraphicJson>,first_date: MonthlyDate,last_date: MonthlyDate,max: f32,min: f32,height: f32,}
// Iterate over graphics on one page
// Build series data from series specification.// We want to build a BTreeMap<SeriesId, SeriesJson> from a BTreeMap<SeriesId, SeriesSpec>for (i, (series_id, series_spec)) in seriess.iter().enumerate() {m_series.insert(series_id.clone(),(i,page_spec.into_series_json(series_id, *country, root_path)?,));}//Build graphics from graphics specification.
// 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)?,));}
json.insert((*country, *data_type, *index), (v_series, v_graphics));
let first_date = v_series.iter().map(|series_json| series_json.rts.first_date()).min().unwrap();let last_date = v_series.iter().map(|series_json| series_json.rts.last_date()).max().unwrap();let max = v_series.iter().map(|series_json| series_json.rts.max(0)).fold(f32::NEG_INFINITY, |a, b| a.max(b));let min = v_series.iter().map(|series_json| series_json.rts.min(0)).fold(f32::INFINITY, |a, b| a.min(b));let height = match height_opt {Some(h) => *h,None => GRAPHIC_HEIGHT,};let page_value = PageValue {country: *country,data_type: *data_type,index: *index,seriess: v_series,graphics: v_graphics,first_date: MonthlyDate(first_date),last_date: MonthlyDate(last_date),max: max,min: min,height: height,};json.insert((*country, *data_type, *index), page_value);