Compare commits

...

2 Commits

Author SHA1 Message Date
Astro 9172dc5abd heliwatch: don't Arc unique data 2024-04-14 22:16:57 +02:00
Astro e1d6c0ecb2 heliwatch: narrow bbox in fetch_data for less ram usage 2024-04-14 22:16:19 +02:00
2 changed files with 17 additions and 14 deletions

View File

@ -6,10 +6,10 @@ overpass() {
curl -X POST -d "data=[out:json];$1" -o $2 http://overpass-api.de/api/interpreter
}
bbox="50,12,52,15.5"
bbox="51,13,52,15"
Q=""
for level in 6 7 8 9 10 11 ; do
Q=$Q'way["admin_level"="'$level'"]('$bbox'); relation["admin_level"="'$level'"]('$bbox');'
Q=$Q'way["boundary"="administrative"]["admin_level"="'$level'"]('$bbox'); relation["boundary"="administrative"]["admin_level"="'$level'"]('$bbox');'
done
if [ ! -e locations.json ]; then

View File

@ -7,7 +7,7 @@ use serde::Deserialize;
#[derive(Debug)]
pub struct Aircraft {
pub owner: Option<Arc<String>>,
pub registration: Option<Arc<String>>,
pub registration: Option<String>,
pub model: Option<Arc<String>>,
}
@ -26,35 +26,38 @@ pub struct Aircrafts {
impl Aircrafts {
pub fn load(file: &str) -> Self {
let mut strings = HashMap::new();
let mut nullable = move |s: String| {
if s.len() > 0 {
let e = strings.entry(s.clone())
.or_insert_with(|| Arc::new(s));
Some(e.clone())
} else {
let nullable = |s: String| {
if s == "" {
None
} else {
Some(s)
}
};
let mut stringtable = HashMap::new();
let mut stringtabled = |s: String| {
let e = stringtable.entry(s.clone())
.or_insert_with(|| Arc::new(s));
e.clone()
};
let mut data = HashMap::new();
let mut rdr = csv::Reader::from_reader(BufReader::new(File::open(file).unwrap()));
for result in rdr.deserialize() {
let rec: Record = result.unwrap();
if rec.registration != "" {
data.insert(rec.icao24, Aircraft {
owner: nullable(rec.owner),
owner: nullable(rec.owner).map(&mut stringtabled),
registration: nullable(rec.registration),
model: if rec.manufacturername == "" && rec.model == "" {
None
} else if rec.model.starts_with(&rec.manufacturername) {
nullable(rec.model)
nullable(rec.model).map(&mut stringtabled)
} else {
nullable(format!("{} {}", rec.manufacturername, rec.model))
Some(stringtabled(format!("{} {}", rec.manufacturername, rec.model)))
},
});
}
}
println!("Loaded aircraft database with {} entries", data.len());
println!("Loaded {} aircrafts ({} entries, {} strings)", data.len(), data.len(), stringtable.len());
Aircrafts {
data,