Skip to content

Commit

Permalink
Improved computation of the leg (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecardleitao authored Jan 28, 2024
1 parent d9c18db commit 937e7ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
16 changes: 8 additions & 8 deletions methodology.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ Source code is available at [src/icao_to_trace.rs](./src/icao_to_trace.rs).

### M-4: Identify legs of a route

This is performed automatically by the computer program. A leg is defined in this methodology has:
This is performed automatically by the computer program. A leg is defined in this methodology
has a continuous sequence of ADS-B positions in time where the aircraft is flying.

> a continuous sequence of ADS-B positions split by landings whose distance is higher than 3km and duration longer than 5 minutes
The aircraft at a given segment between two ADS-B positions is considered grounded (not flying) when either:
* both positions are on the ground
* the time between these positions is > 5m and the aircraft is below 10.000 feet

where a landing is identified by either:
* The previous ADS-B position was flying, and the current is grounded
* Both the previous and current position is flying, and are separated by more than 5 minutes apart.

The latter condition is used to mitigate the risk that ADS-B radars do not always pick up signals
too close from the ground, resulting the leg to not be identified.
The latter condition is used to mitigate the risk that ADS-B receivers sometimes
do not receive an aircraft's signal when the aircraft is at low altitude.
When this happens for more than 5m, we consider that the aircraft approached and landed.

Source code is available at [src/legs.rs](./src/legs.rs).

Expand Down
24 changes: 16 additions & 8 deletions src/legs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,19 @@ fn landed(prev_position: &Position, position: &Position) -> bool {
) || (matches!(
(&prev_position, &position),
(Position::Flying { .. }, Position::Flying { .. })
) && position.datetime() - prev_position.datetime() > time::Duration::minutes(5))
) && position.datetime() - prev_position.datetime() > time::Duration::minutes(5)
&& position.altitude() < 10000.0)
}

fn is_grounded(prev_position: &Position, position: &Position) -> bool {
matches!(
(&prev_position, &position),
(Position::Grounded { .. }, Position::Grounded { .. })
) || (matches!(
(&prev_position, &position),
(Position::Flying { .. }, Position::Flying { .. })
) && position.datetime() - prev_position.datetime() > time::Duration::minutes(5)
&& position.altitude() < 10000.0)
}

/// Returns a set of [`Leg`]s from a sequence of [`Position`]s.
Expand All @@ -62,13 +74,9 @@ pub fn all_legs(mut positions: impl Iterator<Item = Position>) -> Vec<Leg> {
let mut sequence: Vec<Position> = vec![];
let mut legs: Vec<Leg> = vec![];
positions.for_each(|position| {
if let (Position::Grounded { .. }, Position::Grounded { .. }) = (&prev_position, &position)
{
// legs are by definition the minimum length on ground
prev_position = position;
return;
};
sequence.push(position.clone());
if !is_grounded(&prev_position, &position) {
sequence.push(position.clone());
}
if landed(&prev_position, &position) {
legs.push(Leg {
positions: std::mem::take(&mut sequence),
Expand Down

0 comments on commit 937e7ac

Please sign in to comment.