Fixed scheduler, updated parsing metar to check each value instead of skipping on bad data
This commit is contained in:
@@ -91,7 +91,6 @@ pub struct Metar {
|
|||||||
pub max_t_c: Option<f64>,
|
pub max_t_c: Option<f64>,
|
||||||
pub min_t_c: Option<f64>,
|
pub min_t_c: Option<f64>,
|
||||||
pub precip_in: Option<f64>,
|
pub precip_in: Option<f64>,
|
||||||
pub elevation_m: i32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Metar {
|
impl Default for Metar {
|
||||||
@@ -118,7 +117,6 @@ impl Default for Metar {
|
|||||||
max_t_c: None,
|
max_t_c: None,
|
||||||
min_t_c: None,
|
min_t_c: None,
|
||||||
precip_in: None,
|
precip_in: None,
|
||||||
elevation_m: 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,6 +167,10 @@ impl Metar {
|
|||||||
let observation_time = format!("{}-{}-{}T{}:{}:00Z", observation_time_year, observation_time_month, observation_time_day, observation_time_hour, observation_time_minute);
|
let observation_time = format!("{}-{}-{}T{}:{}:00Z", observation_time_year, observation_time_month, observation_time_day, observation_time_hour, observation_time_minute);
|
||||||
metar.observation_time = chrono::NaiveDateTime::parse_from_str(&observation_time, "%Y-%m-%dT%H:%M:%SZ").unwrap();
|
metar.observation_time = chrono::NaiveDateTime::parse_from_str(&observation_time, "%Y-%m-%dT%H:%M:%SZ").unwrap();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
if metar_parts.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
// Report Modifiers
|
// Report Modifiers
|
||||||
if metar_parts[0] == "AUTO" {
|
if metar_parts[0] == "AUTO" {
|
||||||
metar.quality_control_flags.auto = Some(true);
|
metar.quality_control_flags.auto = Some(true);
|
||||||
@@ -245,8 +247,8 @@ impl Metar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Runway Visual Range
|
// Runway Visual Range
|
||||||
let rvr_re = regex::Regex::new(r"^R[0-9]{1,3}(?:L|R)?/[PM]?[0-9]{4}FT$").unwrap();
|
let rvr_re = regex::Regex::new(r"^R[0-9]{1,3}(?:L|R|C)?/[PM]?[0-9]{4}FT$").unwrap();
|
||||||
let variable_rvr_re = regex::Regex::new(r"^R[0-9]{1,3}(?:L|R)?/[PM]?[0-9]{4}V[PM]?[0-9]{4}FT$").unwrap();
|
let variable_rvr_re = regex::Regex::new(r"^R[0-9]{1,3}(?:L|R|C)?/[PM]?[0-9]{4}V[PM]?[0-9]{4}FT$").unwrap();
|
||||||
while rvr_re.is_match(metar_parts[0]) || variable_rvr_re.is_match(metar_parts[0]) {
|
while rvr_re.is_match(metar_parts[0]) || variable_rvr_re.is_match(metar_parts[0]) {
|
||||||
let rvr_string = metar_parts[0];
|
let rvr_string = metar_parts[0];
|
||||||
metar_parts.remove(0);
|
metar_parts.remove(0);
|
||||||
@@ -267,7 +269,7 @@ impl Metar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Weather Phenomena
|
// Weather Phenomena
|
||||||
let wx_re = regex::Regex::new(r"^[+-]?(?:RA|SN|UP|FG|FZFG|BR|HZ|SQ|FC|TS|GR|GS|FZRA|VA|DZ)$").unwrap();
|
let wx_re = regex::Regex::new(r"^(?:[+-]|VC|MI|PR|BC|DR|BL|SH|TS|FZ)?(?:DZ|RA|SN|SG|IC|PL|GR|GS|UP|BR|FG|FU|VA|DU|SA|HZ|PY|PO|SQ|FC|SS|DS)$").unwrap();
|
||||||
while wx_re.is_match(metar_parts[0]) {
|
while wx_re.is_match(metar_parts[0]) {
|
||||||
metar.weather_phenomena.push(metar_parts[0].to_string());
|
metar.weather_phenomena.push(metar_parts[0].to_string());
|
||||||
metar_parts.remove(0);
|
metar_parts.remove(0);
|
||||||
@@ -338,31 +340,34 @@ impl Metar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remarks
|
// Remarks
|
||||||
if !metar_parts.is_empty() {
|
if !metar_parts.is_empty() && metar_parts[0] == "RMK" {
|
||||||
if metar_parts[0] == "RMK" {
|
|
||||||
metar_parts.remove(0);
|
metar_parts.remove(0);
|
||||||
} else {
|
|
||||||
warn!("Unexpected field found, skipping METAR: '{}' ({})", metar_parts[0], metar_string);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loop {
|
loop {
|
||||||
if metar_parts.is_empty() {
|
if metar_parts.is_empty() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
let slp_re = regex::Regex::new(r"^SLP([0-9]{3})$").unwrap();
|
||||||
let remark = metar_parts[0];
|
let remark = metar_parts[0];
|
||||||
metar_parts.remove(0);
|
metar_parts.remove(0);
|
||||||
if remark == "AO2" {
|
if remark == "AO2" {
|
||||||
metar.quality_control_flags.auto_station = Some(true);
|
metar.quality_control_flags.auto_station = Some(true);
|
||||||
|
} else if remark == "$" {
|
||||||
|
metar.quality_control_flags.maintenance_indicator_on = Some(true);
|
||||||
|
} else if slp_re.is_match(remark) {
|
||||||
|
let slp = slp_re.captures(remark).unwrap();
|
||||||
|
metar.sea_level_pressure_mb = Some(slp[1].parse::<f64>().unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip unexpected fields
|
||||||
|
if !metar_parts.is_empty() {
|
||||||
|
warn!("Skipping unexpected field: '{}' ({})", metar_parts[0], metar_string);
|
||||||
|
metar_parts.remove(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flight Category
|
// Flight Category
|
||||||
// VFR: Visibility >= 5 miles, Ceiling >= 3000 ft
|
|
||||||
// MVFR: Visibility >= 3 miles, Ceiling >= 1000 ft
|
|
||||||
// IFR: Visibility >= 1 mile, Ceiling >= 500 ft
|
|
||||||
// LIFR: Visibility < 1 mile, Ceiling < 500 ft
|
|
||||||
// UNKN: Visibility or Ceiling is missing
|
|
||||||
if metar.visibility_statute_mi.is_none() || metar.sky_condition.is_empty() {
|
if metar.visibility_statute_mi.is_none() || metar.sky_condition.is_empty() {
|
||||||
metar.flight_category = FlightCategory::UNKN;
|
metar.flight_category = FlightCategory::UNKN;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ pub fn update_airports() {
|
|||||||
|
|
||||||
let airport_icaos: Vec<String> = airports.iter().map(|a| a.icao.to_string()).collect();
|
let airport_icaos: Vec<String> = airports.iter().map(|a| a.icao.to_string()).collect();
|
||||||
let mut peekable = airport_icaos.into_iter().peekable();
|
let mut peekable = airport_icaos.into_iter().peekable();
|
||||||
let mut observation_time = 0;
|
let mut observation_time = chrono::Utc::now().timestamp();
|
||||||
|
|
||||||
while peekable.peek().is_some() {
|
while peekable.peek().is_some() {
|
||||||
let chunk: Vec<String> = peekable.by_ref().take(limit as usize).collect();
|
let chunk: Vec<String> = peekable.by_ref().take(limit as usize).collect();
|
||||||
@@ -57,7 +57,7 @@ pub fn update_airports() {
|
|||||||
debug!("METAR update complete");
|
debug!("METAR update complete");
|
||||||
// Sleep until the observation time is 1 hour old
|
// Sleep until the observation time is 1 hour old
|
||||||
let now = chrono::Utc::now().timestamp();
|
let now = chrono::Utc::now().timestamp();
|
||||||
let sleep_time = (observation_time + (60 * 60)) - now;
|
let sleep_time = now - (observation_time + (3600));
|
||||||
debug!("Next update in {} seconds", sleep_time);
|
debug!("Next update in {} seconds", sleep_time);
|
||||||
sleep(Duration::from_secs(sleep_time as u64)).await;
|
sleep(Duration::from_secs(sleep_time as u64)).await;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user