Messed with metar stuff
This commit is contained in:
@@ -309,8 +309,7 @@ impl Airport {
|
||||
Self::push_condition_like(&mut builder, &mut has_where, "name", &query.name);
|
||||
Self::push_condition_bounds(&mut builder, &mut has_where, &query.bounds)?;
|
||||
|
||||
// Order by AircraftCategory
|
||||
builder.push(" ORDER BY (metar_observation_time IS NULL), ");
|
||||
builder.push(" ORDER BY (metar_observation_time IS NULL) ASC, ");
|
||||
builder.push(" CASE category ");
|
||||
builder.push(" WHEN 'large_airport' THEN 1 ");
|
||||
builder.push(" WHEN 'medium_airport' THEN 2 ");
|
||||
|
||||
@@ -888,6 +888,43 @@ impl Metar {
|
||||
// let estimated_density = ;
|
||||
// metar.density_altitude = Some(metar.density_altitude);
|
||||
|
||||
// Update the airport's metar observation time
|
||||
let icao = metar.icao.clone();
|
||||
let observation_time = metar.observation_time.clone();
|
||||
tokio::spawn(async move {
|
||||
match Airport::update(
|
||||
&icao,
|
||||
&UpdateAirport {
|
||||
icao: None,
|
||||
iata: None,
|
||||
local: None,
|
||||
name: None,
|
||||
category: None,
|
||||
iso_country: None,
|
||||
iso_region: None,
|
||||
municipality: None,
|
||||
elevation_ft: None,
|
||||
longitude: None,
|
||||
latitude: None,
|
||||
has_tower: None,
|
||||
has_beacon: None,
|
||||
runways: None,
|
||||
frequencies: None,
|
||||
public: None,
|
||||
latest_metar_observation: Some(observation_time),
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(err) => log::error!(
|
||||
"Unable to update airport {} with the latest observation time: {}",
|
||||
icao,
|
||||
err
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
Ok(metar)
|
||||
}
|
||||
|
||||
@@ -896,7 +933,7 @@ impl Metar {
|
||||
station_icaos: &Vec<String>,
|
||||
) -> Vec<String> {
|
||||
let mut missing_metar_icaos: Vec<String> = vec![];
|
||||
let current_time = chrono::Local::now().naive_local().and_utc().timestamp();
|
||||
let current_time = Utc::now().timestamp();
|
||||
let db_metars_set: HashSet<&str> = db_metars.iter().map(|icao| icao.icao.as_str()).collect();
|
||||
let station_icaos_set: HashSet<&str> = station_icaos.iter().map(|s| s.as_str()).collect();
|
||||
for difference in db_metars_set.symmetric_difference(&station_icaos_set) {
|
||||
@@ -987,7 +1024,6 @@ impl Metar {
|
||||
r#"
|
||||
SELECT DISTINCT ON (icao) * FROM {}
|
||||
WHERE icao = ANY($1)
|
||||
AND observation_time >= NOW() - INTERVAL '50 minutes'
|
||||
ORDER BY icao, observation_time DESC
|
||||
"#,
|
||||
TABLE_NAME
|
||||
@@ -995,53 +1031,10 @@ impl Metar {
|
||||
.bind(icao_list)
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
for metar_row in metar_rows {
|
||||
let metar = match Metar::from_db(metar_row) {
|
||||
Ok(m) => m,
|
||||
Err(err) => {
|
||||
log::error!("{}", err);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
let icao = metar.icao.clone();
|
||||
let observation_time = metar.observation_time.clone();
|
||||
tokio::spawn(async move {
|
||||
match Airport::update(
|
||||
&icao,
|
||||
&UpdateAirport {
|
||||
icao: None,
|
||||
iata: None,
|
||||
local: None,
|
||||
name: None,
|
||||
category: None,
|
||||
iso_country: None,
|
||||
iso_region: None,
|
||||
municipality: None,
|
||||
elevation_ft: None,
|
||||
longitude: None,
|
||||
latitude: None,
|
||||
has_tower: None,
|
||||
has_beacon: None,
|
||||
runways: None,
|
||||
frequencies: None,
|
||||
public: None,
|
||||
latest_metar_observation: Some(observation_time),
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {}
|
||||
Err(err) => log::error!(
|
||||
"Unable to update airport {} with the latest observation time: {}",
|
||||
icao,
|
||||
err
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
metars.push(metar);
|
||||
}
|
||||
metars = metar_rows
|
||||
.into_iter()
|
||||
.map(|m| Metar::from_db(m).unwrap())
|
||||
.collect();
|
||||
}
|
||||
|
||||
let mut conn = redis_async_connection().await?;
|
||||
@@ -1056,7 +1049,8 @@ impl Metar {
|
||||
let result: RedisResult<Option<bool>> = conn.get(icao).await;
|
||||
match result {
|
||||
Ok(Some(value)) => {
|
||||
if !value {
|
||||
log::info!("{}: {}", icao, value);
|
||||
if value {
|
||||
updated_missing_icao_list.push(icao);
|
||||
}
|
||||
}
|
||||
@@ -1068,7 +1062,6 @@ impl Metar {
|
||||
}
|
||||
}
|
||||
}
|
||||
dbg!(&updated_missing_icao_list);
|
||||
if !updated_missing_icao_list.is_empty() {
|
||||
log::trace!(
|
||||
"Retrieving missing METAR data for {:?}",
|
||||
@@ -1095,6 +1088,13 @@ impl Metar {
|
||||
Self::get_missing_metar_icaos(&missing_icao_list, icao_list).await;
|
||||
if !still_missing_icao_list.is_empty() {
|
||||
for icao in still_missing_icao_list {
|
||||
// Skip values if they've been set to true in the past
|
||||
let result: RedisResult<Option<bool>> = conn.get(&icao).await;
|
||||
if let Ok(Some(v)) = result {
|
||||
if v {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let _: RedisResult<()> = conn.set_ex(&icao, false, 3600).await;
|
||||
}
|
||||
}
|
||||
@@ -1125,7 +1125,7 @@ SLP125 P0003 60009 T00640036 10066 21012 58033 TSNO $".to_string();
|
||||
|
||||
metar_string = "KMIA 090053Z 33004KT 10SM FEW015 FEW024 SCT075 SCT250 25/22 A2990 RMK AO2 SLP126 T02500217 $".to_string();
|
||||
let metar = Metar::parse(&metar_string).unwrap();
|
||||
dbg!(&metar);
|
||||
// dbg!(&metar);
|
||||
|
||||
metar_string =
|
||||
"KMRB 082253Z 30014G23KT 10SM CLR 05/M12 A3002 RMK AO2 PK WND 30028/2157 SLP168 T00501117"
|
||||
|
||||
@@ -116,8 +116,6 @@ impl UpdateUser {
|
||||
query_builder.push_bind(email.to_string());
|
||||
query_builder.push(" RETURNING *");
|
||||
|
||||
dbg!(&query_builder.sql());
|
||||
|
||||
let query = query_builder.build_query_as::<User>();
|
||||
let user = query.fetch_one(pool).await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user