Skip to content

Commit

Permalink
Added ICAO code <> country
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecardleitao committed Feb 10, 2024
1 parent 50cb605 commit f0d32c6
Show file tree
Hide file tree
Showing 6 changed files with 1,355 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/export_private_jets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ It contains 3 columns:
* `tail_number`: The tail number of the aircraft
* `model`: The icao number of the aircraft type. It is only one of the ones
identified as private jet according to the methodology.
* `country`: The country (ISO 3166) of registration
Both `icao_number` and `tail_number` are unique keys (independently).
"#;
Expand Down
5 changes: 5 additions & 0 deletions methodology.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,8 @@ It also consisted in extracting statements or slogans from these owners from the
to illustrate the incompatibility between owning a private jet and their sustainability goals.

This is stored in [`./src/owners.json`](./src/owners.json).

### M-9: Identification of country of registration

This was performed automatically and consisted in mapping the ICAO number to its
corresponding country, as per Appendix A of [ICAO working paper NACC/DCA/3 – WP/05](https://www.icao.int/Meetings/AMC/MA/NACC_DCA03_2008/naccdca3wp05.pdf).
9 changes: 8 additions & 1 deletion src/aircraft_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use reqwest;
use serde::{Deserialize, Serialize};
use serde_json;

use crate::{fs, fs_s3};
use crate::{fs, fs_s3, CountryIcaoRanges};

/// [`HashMap`] between tail number (e.g. "OY-TWM") and an [`Aircraft`]
pub type Aircrafts = HashMap<String, Aircraft>;
Expand All @@ -23,6 +23,8 @@ pub struct Aircraft {
pub type_designator: String,
/// The model
pub model: String,
/// The country in ISO 3166 of the aircraft
pub country: Option<Arc<str>>,
}

static DATABASE: &'static str = "db-20231106";
Expand Down Expand Up @@ -110,6 +112,8 @@ async fn children<'a: 'async_recursion>(
pub async fn load_aircrafts(
client: Option<&fs_s3::ContainerClient>,
) -> Result<Aircrafts, Box<dyn Error>> {
let country_ranges = CountryIcaoRanges::new();

let prefixes = (b'A'..=b'F').chain(b'0'..b'9');
let prefixes = prefixes.map(|x| std::str::from_utf8(&[x]).unwrap().to_string());

Expand All @@ -135,13 +139,16 @@ pub async fn load_aircrafts(
let tail_number = std::mem::take(&mut data[0])?;
let type_designator = std::mem::take(&mut data[1])?;
let model = std::mem::take(&mut data[3])?;
let country = country_ranges.country(&icao_number).unwrap();

Some((
tail_number.clone(),
Aircraft {
icao_number: icao_number.to_ascii_lowercase().into(),
tail_number,
type_designator,
model,
country: country.cloned(),
},
))
});
Expand Down
Loading

0 comments on commit f0d32c6

Please sign in to comment.