load aircraftDatabase
This commit is contained in:
parent
0bd99acd00
commit
fc61b04967
|
@ -41,6 +41,18 @@ version = "1.3.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.8.0"
|
||||
|
@ -87,6 +99,28 @@ version = "0.8.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
|
||||
|
||||
[[package]]
|
||||
name = "csv"
|
||||
version = "1.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"csv-core",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "csv-core"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.29"
|
||||
|
@ -290,6 +324,7 @@ dependencies = [
|
|||
name = "heliwatch"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"csv",
|
||||
"geo",
|
||||
"reqwest",
|
||||
"serde",
|
||||
|
@ -711,6 +746,12 @@ dependencies = [
|
|||
"bitflags",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
|
||||
|
||||
[[package]]
|
||||
name = "remove_dir_all"
|
||||
version = "0.5.3"
|
||||
|
|
|
@ -9,3 +9,4 @@ reqwest = { version = "0.11", features = ["json"] }
|
|||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
geo = "0.18"
|
||||
csv = "1.1"
|
||||
|
|
|
@ -11,3 +11,5 @@ for level in 7 8 9 10 11 ; do
|
|||
done
|
||||
|
||||
overpass "($Q); out body; >; out skel;" > locations.json
|
||||
|
||||
wget https://opensky-network.org/datasets/metadata/aircraftDatabase.csv
|
||||
|
|
|
@ -25,6 +25,14 @@ pub struct Info {
|
|||
}
|
||||
|
||||
impl Info {
|
||||
pub fn get_hex(&self) -> &str {
|
||||
let mut hex = &self.hex[..];
|
||||
while hex.len() > 0 && hex.chars().last().unwrap().is_whitespace() {
|
||||
hex = &hex[..hex.len() - 1];
|
||||
}
|
||||
hex
|
||||
}
|
||||
|
||||
pub fn get_flight(&self) -> Option<String> {
|
||||
let mut i = self.flight.len();
|
||||
while i > 0 && self.flight.chars().nth(i - 1).unwrap().is_whitespace() {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Aircraft {
|
||||
pub icao24: String,
|
||||
pub registration: String,
|
||||
pub manufacturername: String,
|
||||
pub model: String,
|
||||
pub owner: String,
|
||||
}
|
||||
|
||||
pub struct Aircrafts {
|
||||
data: HashMap<String, Aircraft>,
|
||||
}
|
||||
|
||||
impl Aircrafts {
|
||||
pub fn load(file: &str) -> Self {
|
||||
let mut rdr = csv::Reader::from_reader(File::open(file).unwrap());
|
||||
let mut data = HashMap::new();
|
||||
for result in rdr.deserialize() {
|
||||
let aircraft: Aircraft = result.unwrap();
|
||||
data.insert(aircraft.icao24.clone(), aircraft);
|
||||
}
|
||||
println!("Loaded aircraft database with {} entries", data.len());
|
||||
|
||||
Aircrafts {
|
||||
data,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find<'s>(&'s self, hex: &str) -> Option<&'s Aircraft> {
|
||||
self.data.get(hex)
|
||||
}
|
||||
}
|
|
@ -1,13 +1,18 @@
|
|||
mod adsb;
|
||||
mod location;
|
||||
mod aircrafts;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let aircrafts = aircrafts::Aircrafts::load("aircraftDatabase.csv");
|
||||
let locations = location::Locations::load("locations.json");
|
||||
let mut events = adsb::run("https://adsb.hq.c3d2.de/data.json", locations).await;
|
||||
|
||||
while let Some(event) = events.recv().await {
|
||||
println!("event: {:?}", event);
|
||||
if let Some(aircraft) = aircrafts.find(&event.info.get_hex()) {
|
||||
println!("aircraft: {:?}", aircraft);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue