Added NOSIG to metar parsing, changed default metar timeout to 50 min
This commit is contained in:
1
.env
1
.env
@@ -28,6 +28,7 @@ MINIO_BROWSER_REDIRECT_URL=${NGINX_PROTOCOL}://${NGINX_HOST}:${NGINX_HTTP_PORT}/
|
|||||||
|
|
||||||
UI_PORT=3000
|
UI_PORT=3000
|
||||||
API_PORT=5000
|
API_PORT=5000
|
||||||
|
API_METAR_TIME_OFFSET=3000
|
||||||
|
|
||||||
SSL_CA_NAME=ca
|
SSL_CA_NAME=ca
|
||||||
SSL_CA_PATH=../ssl/${SSL_CA_NAME}.pem
|
SSL_CA_PATH=../ssl/${SSL_CA_NAME}.pem
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use crate::error::Error;
|
|||||||
use crate::{error::ApiResult, db};
|
use crate::{error::ApiResult, db};
|
||||||
use chrono::{DateTime, Datelike, Utc};
|
use chrono::{DateTime, Datelike, Utc};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use std::env;
|
||||||
use redis::{AsyncCommands, RedisResult};
|
use redis::{AsyncCommands, RedisResult};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -49,6 +50,8 @@ pub struct Metar {
|
|||||||
pub humidity: Option<f64>,
|
pub humidity: Option<f64>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub density_altitude: Option<f64>,
|
pub density_altitude: Option<f64>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub no_significant_changes: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@@ -193,6 +196,7 @@ impl Default for Metar {
|
|||||||
precip_in: None,
|
precip_in: None,
|
||||||
humidity: None,
|
humidity: None,
|
||||||
density_altitude: None,
|
density_altitude: None,
|
||||||
|
no_significant_changes: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,6 +659,12 @@ impl Metar {
|
|||||||
metar_parts.remove(0);
|
metar_parts.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No significant changes
|
||||||
|
if !metar_parts.is_empty() && metar_parts[0] == "NOSIG" {
|
||||||
|
metar.no_significant_changes = Some(true);
|
||||||
|
metar_parts.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
// Remarks
|
// Remarks
|
||||||
if !metar_parts.is_empty() && metar_parts[0] == "RMK" {
|
if !metar_parts.is_empty() && metar_parts[0] == "RMK" {
|
||||||
metar_parts.remove(0);
|
metar_parts.remove(0);
|
||||||
@@ -837,8 +847,12 @@ impl Metar {
|
|||||||
for difference in db_metars_set.symmetric_difference(&station_icaos_set) {
|
for difference in db_metars_set.symmetric_difference(&station_icaos_set) {
|
||||||
missing_metar_icaos.push(difference.to_string());
|
missing_metar_icaos.push(difference.to_string());
|
||||||
}
|
}
|
||||||
|
let time_offset = env::var("API_METAR_TIME_OFFSET")
|
||||||
|
.unwrap_or("3000".to_string())
|
||||||
|
.parse::<i64>()
|
||||||
|
.unwrap_or(3000);
|
||||||
for metar in db_metars {
|
for metar in db_metars {
|
||||||
if current_time > (metar.observation_time.timestamp() + 3600) {
|
if current_time > (metar.observation_time.timestamp() + time_offset) {
|
||||||
log::trace!("{} METAR data is outdated", metar.station_id);
|
log::trace!("{} METAR data is outdated", metar.station_id);
|
||||||
missing_metar_icaos.push(metar.station_id.to_string());
|
missing_metar_icaos.push(metar.station_id.to_string());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user