use crate::dateutil::*;
use chrono::NaiveDate;
use julianday::JulianDay;
use sqlx::Query;
#[derive(PartialEq, Clone, Debug, sqlx::FromRow)]
pub struct CDataSet {
pub dataset: String,
pub locid: i64,
pub location_lat: Option<f64>,
pub location_long: Option<f64>,
pub date_julian: i32,
pub day_index_0: i32,
pub day_index_1: i32,
pub day_index_10: Option<i32>,
pub day_index_100: Option<i32>,
pub day_index_1k: Option<i32>,
pub day_index_10k: Option<i32>,
pub day_index_peak: Option<i32>,
pub day_index_peak_confirmed: Option<i32>,
pub day_index_peak_deaths: Option<i32>,
pub absolute_confirmed: i64,
pub absolute_deaths: i64,
pub absolute_recovered: i64,
pub absolute_infected: i64,
pub absolute_pop100k_confirmed: Option<f64>,
pub absolute_pop100k_deaths: Option<f64>,
pub absolute_pop100k_recovered: Option<f64>,
pub absolute_pop100k_infected: Option<f64>,
pub relative_deaths: Option<f64>,
pub relative_recovered: Option<f64>,
pub relative_infected: Option<f64>,
pub delta_confirmed: i64,
pub delta_deaths: i64,
pub delta_recovered: i64,
pub delta_infected: i64,
pub delta_pct_confirmed: Option<f64>,
pub delta_pct_deaths: Option<f64>,
pub delta_pct_recovered: Option<f64>,
pub delta_pct_infected: Option<f64>,
pub delta_pop100k_confirmed: Option<f64>,
pub delta_pop100k_deaths: Option<f64>,
pub delta_pop100k_recovered: Option<f64>,
pub delta_pop100k_infected: Option<f64>,
pub peak_pct_confirmed: Option<f64>,
pub peak_pct_deaths: Option<f64>,
pub peak_pct_recovered: Option<f64>,
pub peak_pct_infected: Option<f64>,
pub factbook_area: Option<f64>,
pub factbook_population: Option<i64>,
pub factbook_death_rate: Option<f64>,
pub factbook_median_age: Option<f64>,
}
impl CDataSet {
pub fn bind_query<'q>(self, query: Query<'q, sqlx::Sqlite>) -> Query<'q, sqlx::Sqlite> {
query
.bind(self.dataset)
.bind(self.locid)
.bind(self.location_lat)
.bind(self.location_long)
.bind(self.date_julian)
.bind(self.day_index_0)
.bind(self.day_index_1)
.bind(self.day_index_10)
.bind(self.day_index_100)
.bind(self.day_index_1k)
.bind(self.day_index_10k)
.bind(self.day_index_peak)
.bind(self.day_index_peak_confirmed)
.bind(self.day_index_peak_deaths)
.bind(self.absolute_confirmed)
.bind(self.absolute_deaths)
.bind(self.absolute_recovered)
.bind(self.absolute_infected)
.bind(self.absolute_pop100k_confirmed)
.bind(self.absolute_pop100k_deaths)
.bind(self.absolute_pop100k_recovered)
.bind(self.absolute_pop100k_infected)
.bind(self.relative_deaths)
.bind(self.relative_recovered)
.bind(self.relative_infected)
.bind(self.delta_confirmed)
.bind(self.delta_deaths)
.bind(self.delta_recovered)
.bind(self.delta_infected)
.bind(self.delta_pct_confirmed)
.bind(self.delta_pct_deaths)
.bind(self.delta_pct_recovered)
.bind(self.delta_pct_infected)
.bind(self.delta_pop100k_confirmed)
.bind(self.delta_pop100k_deaths)
.bind(self.delta_pop100k_recovered)
.bind(self.delta_pop100k_infected)
.bind(self.peak_pct_confirmed)
.bind(self.peak_pct_deaths)
.bind(self.peak_pct_recovered)
.bind(self.peak_pct_infected)
.bind(self.factbook_area)
.bind(self.factbook_population)
.bind(self.factbook_death_rate)
.bind(self.factbook_median_age)
}
pub fn insert_str() -> &'static str {
"INSERT INTO cdataset_raw VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
}
pub fn dup_day(self) -> Self {
CDataSet {
delta_confirmed: 0,
delta_deaths: 0,
delta_recovered: 0,
delta_infected: 0,
delta_pct_confirmed: None,
delta_pct_deaths: None,
delta_pct_recovered: None,
delta_pct_infected: None,
delta_pop100k_confirmed: None,
delta_pop100k_deaths: None,
delta_pop100k_recovered: None,
delta_pop100k_infected: None,
..self
}
}
pub fn set_date(&mut self, julian: i32) {
self.date_julian = julian;
}
#[allow(dead_code)]
pub fn set_date_julianday(&mut self, jd: &JulianDay) {
self.set_date(jd_to_day(jd));
}
#[allow(dead_code)]
pub fn set_date_naivedate(&mut self, nd: &NaiveDate) {
self.set_date(nd_to_day(nd));
}
}