basic graph and input data
This commit is contained in:
parent
bfaaa46bdd
commit
36c58bb9e1
4 changed files with 2212 additions and 7 deletions
2
input.csv
Normal file
2
input.csv
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
origin_airport_code,origin_airport,origin_airport_id,origin_airport_latitude,origin_airport_longitude,origin_city,origin_country,destination_airport_code,destination_airport,destination_airport_id,destination_airport_latitude,destination_airport_longitude,destination_city,destination_country
|
||||||
|
PDX,Portland International Airport,3720,45.58869934,-122.5979996,Portland,United States,SFO,San Francisco International Airport,3469,37.61899948120117,-122.375,San Francisco,United States
|
|
2179
routes.csv
Normal file
2179
routes.csv
Normal file
File diff suppressed because it is too large
Load diff
26
src/main.rs
26
src/main.rs
|
@ -1,15 +1,39 @@
|
||||||
mod distance;
|
mod distance;
|
||||||
mod parse;
|
mod parse;
|
||||||
|
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use parse::Record;
|
use parse::Record;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Node {
|
||||||
|
destinations: Vec<Record>,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Read all data lines in, ignoring errors
|
// Read all data lines in, ignoring errors
|
||||||
let _data: Vec<Record> = csv::Reader::from_reader(std::io::stdin())
|
let data: Vec<Record> = csv::Reader::from_reader(std::io::stdin())
|
||||||
.deserialize()
|
.deserialize()
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let mut graph: HashMap<String, Node> = HashMap::new();
|
||||||
|
|
||||||
|
for record in data.into_iter() {
|
||||||
|
use std::collections::hash_map::Entry;
|
||||||
|
|
||||||
|
match graph.entry(record.origin_airport_code.clone()) {
|
||||||
|
Entry::Occupied(mut entry) => entry.get_mut().destinations.push(record),
|
||||||
|
Entry::Vacant(entry) => {
|
||||||
|
entry.insert(Node {
|
||||||
|
destinations: vec![record],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{graph:#?}");
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
distance::haversine((19.10317, -165.54224), (73.85371, 55.85692))
|
distance::haversine((19.10317, -165.54224), (73.85371, 55.85692))
|
||||||
|
|
12
src/parse.rs
12
src/parse.rs
|
@ -2,16 +2,16 @@
|
||||||
pub struct Record {
|
pub struct Record {
|
||||||
pub origin_airport_code: String,
|
pub origin_airport_code: String,
|
||||||
pub origin_airport: String,
|
pub origin_airport: String,
|
||||||
pub origin_airport_id: String,
|
pub origin_airport_id: usize,
|
||||||
pub origin_airport_latitude: String,
|
pub origin_airport_latitude: f64,
|
||||||
pub origin_airport_longitude: String,
|
pub origin_airport_longitude: f64,
|
||||||
pub origin_city: String,
|
pub origin_city: String,
|
||||||
pub origin_country: String,
|
pub origin_country: String,
|
||||||
pub destination_airport_code: String,
|
pub destination_airport_code: String,
|
||||||
pub destination_airport: String,
|
pub destination_airport: String,
|
||||||
pub destination_airport_id: String,
|
pub destination_airport_id: usize,
|
||||||
pub destination_airport_latitude: String,
|
pub destination_airport_latitude: f64,
|
||||||
pub destination_airport_longitude: String,
|
pub destination_airport_longitude: f64,
|
||||||
pub destination_city: String,
|
pub destination_city: String,
|
||||||
pub destination_country: String,
|
pub destination_country: String,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue