Skip to content

Commit

Permalink
Improved leg calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Jan 28, 2024
1 parent 1b04d62 commit 7f3e3a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/legs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn landed(prev_position: &Position, position: &Position) -> bool {
(&prev_position, &position),
(Position::Flying { .. }, Position::Flying { .. })
) && position.datetime() - prev_position.datetime() > time::Duration::minutes(5)
&& position.altitude() < 10000.0)
&& (position.altitude() < 10000.0 || prev_position.altitude() < 10000.0))
}

fn is_grounded(prev_position: &Position, position: &Position) -> bool {
Expand All @@ -62,7 +62,7 @@ fn is_grounded(prev_position: &Position, position: &Position) -> bool {
(&prev_position, &position),
(Position::Flying { .. }, Position::Flying { .. })
) && position.datetime() - prev_position.datetime() > time::Duration::minutes(5)
&& position.altitude() < 10000.0)
&& (position.altitude() < 10000.0 || prev_position.altitude() < 10000.0))
}

/// Returns a set of [`Leg`]s from a sequence of [`Position`]s.
Expand Down
7 changes: 7 additions & 0 deletions tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,10 @@ async fn multi_day_legs() -> Result<(), Box<dyn Error>> {
assert_eq!(legs.len(), 6);
Ok(())
}

#[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?;
assert_eq!(legs.len(), 4);
Ok(())
}

0 comments on commit 7f3e3a7

Please sign in to comment.