use std::fmt;
#[derive(Debug, Clone, PartialEq, Copy)]
pub enum SpaceWeatherExtrapolation {
Zero,
Hold,
Error,
}
impl fmt::Display for SpaceWeatherExtrapolation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
SpaceWeatherExtrapolation::Zero => write!(f, "SpaceWeatherExtrapolation::Zero"),
SpaceWeatherExtrapolation::Hold => write!(f, "SpaceWeatherExtrapolation::Hold"),
SpaceWeatherExtrapolation::Error => write!(f, "SpaceWeatherExtrapolation::Error"),
}
}
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub enum SpaceWeatherType {
Unknown,
CssiSpaceWeather,
Static,
}
#[derive(Debug, Clone, PartialEq, Copy)]
pub enum SpaceWeatherSection {
Observed,
DailyPredicted,
MonthlyPredicted,
}
impl fmt::Display for SpaceWeatherSection {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
SpaceWeatherSection::Observed => write!(f, "Observed"),
SpaceWeatherSection::DailyPredicted => write!(f, "DailyPredicted"),
SpaceWeatherSection::MonthlyPredicted => write!(f, "MonthlyPredicted"),
}
}
}
impl fmt::Display for SpaceWeatherType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
SpaceWeatherType::Unknown => write!(f, "Unknown"),
SpaceWeatherType::CssiSpaceWeather => write!(f, "CSSI Space Weather"),
SpaceWeatherType::Static => write!(f, "Static"),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct SpaceWeatherData {
pub year: u32,
pub month: u8,
pub day: u8,
pub bsrn: u32,
pub nd: u32,
pub kp: [f64; 8],
pub kp_sum: f64,
pub ap: [f64; 8],
pub ap_avg: f64,
pub cp: f64,
pub c9: u8,
pub isn: u32,
pub f107_obs: f64,
pub qualifier: u8,
pub f107_adj_ctr81: f64,
pub f107_adj_lst81: f64,
pub f107_obs_ctr81: f64,
pub f107_obs_lst81: f64,
pub section: SpaceWeatherSection,
}
impl Default for SpaceWeatherData {
fn default() -> Self {
SpaceWeatherData {
year: 0,
month: 0,
day: 0,
bsrn: 0,
nd: 0,
kp: [0.0; 8],
kp_sum: 0.0,
ap: [0.0; 8],
ap_avg: 0.0,
cp: 0.0,
c9: 0,
isn: 0,
f107_obs: 0.0,
qualifier: 0,
f107_adj_ctr81: 0.0,
f107_adj_lst81: 0.0,
f107_obs_ctr81: 0.0,
f107_obs_lst81: 0.0,
section: SpaceWeatherSection::Observed,
}
}
}
impl fmt::Display for SpaceWeatherData {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"SpaceWeatherData({:04}-{:02}-{:02}, Ap_avg={}, F10.7={})",
self.year, self.month, self.day, self.ap_avg, self.f107_obs
)
}
}
#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests {
use super::*;
#[test]
fn test_space_weather_extrapolation_display() {
assert_eq!(
format!("{}", SpaceWeatherExtrapolation::Zero),
"SpaceWeatherExtrapolation::Zero"
);
assert_eq!(
format!("{}", SpaceWeatherExtrapolation::Hold),
"SpaceWeatherExtrapolation::Hold"
);
assert_eq!(
format!("{}", SpaceWeatherExtrapolation::Error),
"SpaceWeatherExtrapolation::Error"
);
}
#[test]
fn test_space_weather_type_display() {
assert_eq!(format!("{}", SpaceWeatherType::Unknown), "Unknown");
assert_eq!(
format!("{}", SpaceWeatherType::CssiSpaceWeather),
"CSSI Space Weather"
);
assert_eq!(format!("{}", SpaceWeatherType::Static), "Static");
}
#[test]
fn test_space_weather_data_default() {
let data = SpaceWeatherData::default();
assert_eq!(data.year, 0);
assert_eq!(data.month, 0);
assert_eq!(data.day, 0);
assert_eq!(data.kp, [0.0; 8]);
assert_eq!(data.ap, [0.0; 8]);
assert_eq!(data.f107_obs, 0.0);
}
#[test]
fn test_space_weather_data_display() {
let data = SpaceWeatherData {
year: 2024,
month: 1,
day: 15,
bsrn: 2600,
nd: 5,
kp: [2.0, 3.0, 2.3, 1.7, 2.0, 2.3, 3.0, 2.7],
kp_sum: 19.0,
ap: [7.0, 15.0, 9.0, 6.0, 7.0, 9.0, 15.0, 12.0],
ap_avg: 10.0,
cp: 0.5,
c9: 2,
isn: 120,
f107_obs: 150.5,
qualifier: 0,
f107_adj_ctr81: 148.0,
f107_adj_lst81: 147.0,
f107_obs_ctr81: 149.0,
f107_obs_lst81: 148.0,
section: SpaceWeatherSection::Observed,
};
let display = format!("{}", data);
assert!(display.contains("2024-01-15"));
assert!(display.contains("Ap_avg=10"));
assert!(display.contains("F10.7=150.5"));
}
#[test]
fn test_space_weather_section_display() {
assert_eq!(format!("{}", SpaceWeatherSection::Observed), "Observed");
assert_eq!(
format!("{}", SpaceWeatherSection::DailyPredicted),
"DailyPredicted"
);
assert_eq!(
format!("{}", SpaceWeatherSection::MonthlyPredicted),
"MonthlyPredicted"
);
}
#[test]
fn test_space_weather_section_clone_eq() {
let s1 = SpaceWeatherSection::DailyPredicted;
let s2 = s1; assert_eq!(s1, s2);
}
#[test]
fn test_space_weather_extrapolation_clone_eq() {
let ext1 = SpaceWeatherExtrapolation::Hold;
let ext2 = ext1; assert_eq!(ext1, ext2);
}
#[test]
fn test_space_weather_type_clone_eq() {
let t1 = SpaceWeatherType::CssiSpaceWeather;
let t2 = t1; assert_eq!(t1, t2);
}
#[test]
fn test_space_weather_data_clone_eq() {
let data1 = SpaceWeatherData::default();
let data2 = data1.clone();
assert_eq!(data1, data2);
}
}