use chrono::NaiveDate;
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Frequency {
Hourly,
Daily,
Monthly,
Climate,
}
impl Frequency {
pub(crate) const fn path_segment(self) -> &'static str {
match self {
Self::Hourly => "hourly",
Self::Daily => "daily",
Self::Monthly => "monthly",
Self::Climate => "normals",
}
}
pub(crate) fn cache_file_prefix(self) -> String {
format!("{}-", self.path_segment())
}
pub(crate) fn get_schema_column_names(self) -> Vec<&'static str> {
match self {
Self::Hourly => vec![
"date", "hour", "temp", "dwpt", "rhum", "prcp", "snow", "wdir", "wspd", "wpgt",
"pres", "tsun", "coco",
],
Self::Daily => vec![
"date", "tavg", "tmin", "tmax", "prcp", "snow", "wdir", "wspd", "wpgt", "pres",
"tsun",
],
Self::Monthly => vec![
"year", "month", "tavg", "tmin", "tmax", "prcp", "wspd", "pres", "tsun",
],
Self::Climate => vec![
"start_year",
"end_year",
"month",
"tmin",
"tmax",
"prcp",
"wspd",
"pres",
"tsun",
],
}
}
}
impl fmt::Display for Frequency {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.path_segment())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum RequiredData {
Any,
SpecificDate(NaiveDate),
DateRange {
start: NaiveDate,
end: NaiveDate,
},
FullYear(i32),
}
impl RequiredData {
#[allow(dead_code)]
pub(crate) const fn get_end_date(&self) -> Option<NaiveDate> {
match self {
Self::Any => None,
Self::SpecificDate(date) => Some(*date),
Self::DateRange { start: _, end } => Some(*end),
Self::FullYear(year) => NaiveDate::from_ymd_opt(*year, 12, 31),
}
}
}