Skip to content

Commit

Permalink
Improved position representation (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecardleitao authored Feb 18, 2024
1 parent e96b48b commit 74c99d2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ reqwest-middleware = "*"
rand = {version="*", default_features = false, features = ["std", "std_rng", "getrandom"]}

# to perform time-based calculations
time = {version="*", default_features = false, features = ["formatting", "parsing", "macros", "serde"]}
time = {version="*", default_features = false, features = ["formatting", "parsing", "macros", "serde", "serde-well-known"]}

# compute distances between geo-points
geoutils = {version="*", default_features = false}
Expand Down
4 changes: 2 additions & 2 deletions src/icao_to_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use reqwest::{self, StatusCode};
use reqwest_middleware::ClientBuilder;
use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware};
use time::Date;
use time::PrimitiveDateTime;
use time::OffsetDateTime;

use super::Position;
use crate::{fs, fs_s3};
Expand Down Expand Up @@ -174,7 +174,7 @@ pub async fn positions(
trace.into_iter().filter_map(move |entry| {
let time_seconds = entry[0].as_f64().unwrap();
let time = time::Time::MIDNIGHT + time_seconds.seconds();
let datetime = PrimitiveDateTime::new(date.clone(), time);
let datetime = OffsetDateTime::new_utc(date.clone(), time);
let latitude = entry[1].as_f64().unwrap();
let longitude = entry[2].as_f64().unwrap();
entry[3]
Expand Down
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ pub use private_emissions::*;
/// A position of an aircraft
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct Position {
datetime: time::PrimitiveDateTime,
#[serde(with = "time::serde::rfc3339")]
datetime: time::OffsetDateTime,
latitude: f64,
longitude: f64,
/// None means on the ground
Expand Down Expand Up @@ -65,7 +66,7 @@ impl Position {
self.altitude.unwrap_or(0.0)
}

pub fn datetime(&self) -> time::PrimitiveDateTime {
pub fn datetime(&self) -> time::OffsetDateTime {
self.datetime
}

Expand Down
2 changes: 2 additions & 0 deletions tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ async fn ads_b_lost_on_ground() -> Result<(), Box<dyn Error>> {
Ok(())
}

/// Verifies that condition 2. of `M-4` is correctly applied.
/// https://globe.adsbexchange.com/?icao=459257&showTrace=2023-12-17
#[tokio::test]
async fn case_459257_2023_12_17() -> Result<(), Box<dyn Error>> {
let legs = legs(date!(2023 - 12 - 17), date!(2023 - 12 - 20), "459257", None).await?;
Expand Down

0 comments on commit 74c99d2

Please sign in to comment.