1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
//! Cumulative data

use serde::{Deserialize, Serialize};

use crate::{build_request, impl_into_iter, impl_iter_and_mut};

// HTTP GET /total
/// Latest total cummulative data in Greece
#[derive(Debug, Deserialize, Serialize)]
pub struct Total {
    pub cases: TotalSlice,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct TotalSlice {
    pub confirmed: u32,
    pub date: String,
    pub deaths: u32,
}

// HTTP GET /regions
/// Latest cumulative number of confirmed cases per region in Greece
#[derive(Debug, Serialize, Deserialize)]
pub struct Regions {
    pub regions: Vec<Region>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Region {
    pub area_gr: String,
    pub area_en: String,
    pub region_gr: String,
    pub region_en: String,
    pub geo_department_gr: String,
    pub geo_department_en: String,
    pub last_updated_at: String,
    pub longtitude: f64,
    pub latitude: f64,
    pub population: u32,
    pub total_cases: u32,
    pub cases_per_100000_people: f32,
}

impl_into_iter!(Regions, Region, regions);
impl_iter_and_mut!(Regions, Region, regions);

// HTTP GET /age-distribution
/// Age distribution of patients
#[derive(Debug, Serialize, Deserialize)]
pub struct AgeDistribution {
    pub age_distribution: AgeDistItem,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AgeDistItem {
    pub age_average: f32,
    pub average_death_age: f32,
    pub total_age_groups: TotalAgeRes,
    pub updated: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct TotalAgeRes {
    pub cases: AgeSlice,
    pub critical: AgeSlice,
    pub deaths: AgeSlice,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AgeSlice {
    /// Age :[0-17]
    #[serde(rename = "0-17")]
    pub age_group1: u32,
    /// Age :[18-39]
    #[serde(rename = "18-39")]
    pub age_group2: u32,
    /// Age :[40-64]
    #[serde(rename = "40-64")]
    pub age_group3: u32,
    /// Age :[65+]
    #[serde(rename = "65+")]
    pub age_group4: u32,
}

// HTTP GET /gender-distribution
/// Gender distribution of patients
#[derive(Debug, Serialize, Deserialize)]
pub struct GenderDistribution {
    pub gender_percentages: GenderDistItem,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct GenderDistItem {
    pub total_females_percentage: f32,
    pub total_males_percentage: f32,
    pub updated: String,
}

// HTTP /total-vaccinations
/// Total vaccinations
#[derive(Debug, Serialize, Deserialize)]
pub struct TotalVaccinations {
    #[serde(rename = "total-vaccinations")]
    total_vaccinations: TotalVaccineSlice,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct TotalVaccineSlice {
    totaldistinctpersons: u32,
    totalvaccinations: u32,
    updated: String,
}

// TODO : /total-vaccinations-per-region
// TODO : /gender-age-distribution
// TODO : /measures-timeline
// TODO : /risk-levels
// TODO : /measures-by-risk-level

/// Get the latest cumulative data in Greece
pub fn get_total_data() -> Total {
    let json_resp = build_request("total");
    let total_ser = serde_json::from_str(&json_resp).unwrap();
    total_ser
}

/// Get the latest cumulative number of confirmed cases per region in Greece
pub fn get_regions_data() -> Regions {
    let json_resp = build_request("regions");
    let regions_ser = serde_json::from_str(&json_resp).unwrap();
    regions_ser
}

/// Get the age distribution of the patients reported in Greece
pub fn get_age_dist_data() -> AgeDistribution {
    let json_resp = build_request("age-distribution");
    let age_dist_ser = serde_json::from_str(&json_resp).unwrap();
    age_dist_ser
}

/// Get the gender ratio of the patients reported in Greece as a percentage (%)
pub fn get_gender_dist_data() -> GenderDistribution {
    let json_resp = build_request("gender-distribution");
    let gender_dist_ser = serde_json::from_str(&json_resp).unwrap();
    gender_dist_ser
}

/// Get the total vaccinations in Greece
pub fn get_total_vaccin_data() -> TotalVaccinations {
    let json_resp = build_request("total-vaccinations");
    let total_vaccin_ser = serde_json::from_str(&json_resp).unwrap();
    total_vaccin_ser
}

mod tests {
    use super::*;

    #[test]
    fn test_des_total() {
        const STR_JSON: &str = r#"
        {
          "cases": {
                "confirmed": 0,
                "deaths": 0,
                "date": "2021-04-29"
           }
        }
        "#;
        let total: Result<Total, _> = serde_json::from_str(STR_JSON);
        println!("{:?}", total);
        assert!(total.is_ok());
    }

    #[test]
    fn test_get_total_data() {
        let total_series = get_total_data();
    }

    #[test]
    fn test_des_regions() {
        const STR_JSON: &str = r#"
        {
            "regions": [
              {
                "area_gr": "string",
                "area_en": "string",
                "region_gr": "string",
                "region_en": "string",
                "geo_department_gr": "string",
                "geo_department_en": "string",
                "last_updated_at": "2021-04-29",
                "longtitude": 0,
                "latitude": 0,
                "population": 0,
                "total_cases": 0,
                "cases_per_100000_people": 0
              }
            ]
          }
        "#;
        let regions: Result<Regions, _> = serde_json::from_str(STR_JSON);
        println!("{:?}", regions);
        assert!(regions.is_ok());
    }

    #[test]
    fn test_get_region_data() {
        let region_series = get_regions_data();
    }

    #[test]
    fn test_des_age_distribution() {
        const STR_JSON: &str = r#"
            {
                "age_distribution": {
                    "age_average": 0,
                    "average_death_age": 0,
                    "total_age_groups": {
                    "cases": {
                        "0-17": 0,
                        "18-39": 0,
                        "40-64": 0,
                        "65+": 0
                    },
                    "critical": {
                        "0-17": 0,
                        "18-39": 0,
                        "40-64": 0,
                        "65+": 0
                    },
                    "deaths": {
                        "0-17": 0,
                        "18-39": 0,
                        "40-64": 0,
                        "65+": 0
                    }
                },
                    "updated": "2021-04-29"
                    
                }
            }
        "#;

        let age_dist: Result<AgeDistribution, _> = serde_json::from_str(STR_JSON);
        println!("{:?}", age_dist);
        assert!(age_dist.is_ok());
    }

    #[test]
    fn test_get_age_dist_data() {
        let age_dist_series = get_age_dist_data();
    }

    #[test]
    fn test_des_gender_distribution() {
        const STR_JSON: &str = r#"
         {
            "gender_percentages" : {
                "total_females_percentage" : 0,
                "total_males_percentage": 0,
                "updated": "2021-04-29"
            }
         }
        "#;
        let gender_dist: Result<GenderDistribution, _> = serde_json::from_str(STR_JSON);
        println!("{:?}", gender_dist);
        assert!(gender_dist.is_ok());
    }

    #[test]
    fn test_get_gender_dist_data() {
        let gender_dist_series = get_gender_dist_data();
    }

    #[test]
    fn test_des_total_vaccinations() {
        const STR_JSON: &str = r#"
                {
                    "total-vaccinations": {
                        
                            "totaldistinctpersons" : 0,
                            "totalvaccinations": 0,
                            "updated": "2021-04-29"
                        
                    }
                } 
        "#;
        let total_vacc: Result<TotalVaccinations, _> = serde_json::from_str(STR_JSON);
        println!("{:?}", total_vacc);
        assert!(total_vacc.is_ok());
    }

    #[test]
    fn test_get_total_vaccin_data() {
        let total_vaccin_series = get_total_vaccin_data();
    }
}