basic graph and input data

This commit is contained in:
Zynh0722 2024-04-23 22:35:43 -07:00
parent bfaaa46bdd
commit 36c58bb9e1
4 changed files with 2212 additions and 7 deletions

2
input.csv Normal file
View 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
1 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
2 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

File diff suppressed because it is too large Load diff

View file

@ -1,15 +1,39 @@
mod distance;
mod parse;
use std::collections::HashMap;
use parse::Record;
#[derive(Debug)]
struct Node {
destinations: Vec<Record>,
}
fn main() {
// 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()
.flatten()
.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!(
"{}",
distance::haversine((19.10317, -165.54224), (73.85371, 55.85692))

View file

@ -2,16 +2,16 @@
pub struct Record {
pub origin_airport_code: String,
pub origin_airport: String,
pub origin_airport_id: String,
pub origin_airport_latitude: String,
pub origin_airport_longitude: String,
pub origin_airport_id: usize,
pub origin_airport_latitude: f64,
pub origin_airport_longitude: f64,
pub origin_city: String,
pub origin_country: String,
pub destination_airport_code: String,
pub destination_airport: String,
pub destination_airport_id: String,
pub destination_airport_latitude: String,
pub destination_airport_longitude: String,
pub destination_airport_id: usize,
pub destination_airport_latitude: f64,
pub destination_airport_longitude: f64,
pub destination_city: String,
pub destination_country: String,
}