mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-27 16:36:02 +03:00
importing basic info from PSRC trips
This commit is contained in:
parent
0569dd4abd
commit
a069380439
@ -4,7 +4,11 @@ fn main() {
|
||||
"/home/dabreegster/Downloads/psrc/2014/landuse/parcels_urbansim.txt",
|
||||
)
|
||||
.unwrap();
|
||||
println!("{} matches", parcels.len());
|
||||
println!("{} parcels", parcels.len());
|
||||
let trips =
|
||||
popdat::psrc::import_trips("/home/dabreegster/Downloads/psrc/trips_2014.csv", parcels)
|
||||
.unwrap();
|
||||
println!("{} trips", trips.len());
|
||||
|
||||
let popdat = popdat::PopDat::import_all(&mut abstutil::Timer::new("importing popdat"));
|
||||
abstutil::write_binary("../data/shapes/popdat", &popdat).unwrap();
|
||||
|
@ -1,8 +1,54 @@
|
||||
use geom::{GPSBounds, LonLat};
|
||||
use geom::{Duration, GPSBounds, LonLat};
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, BufWriter, Write};
|
||||
|
||||
pub struct Trip {
|
||||
pub from: LonLat,
|
||||
pub to: LonLat,
|
||||
// Relative to midnight
|
||||
pub depart_at: Duration,
|
||||
// TODO Also scrape mode, maybe interesting extra stuff like purpose of the trip
|
||||
}
|
||||
|
||||
pub fn import_trips(
|
||||
path: &str,
|
||||
parcels: HashMap<String, LonLat>,
|
||||
) -> Result<Vec<Trip>, failure::Error> {
|
||||
let mut trips = Vec::new();
|
||||
for rec in csv::Reader::from_reader(BufReader::new(File::open(path)?)).records() {
|
||||
let rec = rec?;
|
||||
|
||||
// opcl
|
||||
let from = if let Some(pt) = parcels.get(rec[15].trim_end_matches(".0")) {
|
||||
*pt
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
// dpcl
|
||||
let to = if let Some(pt) = parcels.get(rec[6].trim_end_matches(".0")) {
|
||||
*pt
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
|
||||
// deptm
|
||||
let mins: usize = rec[4].trim_end_matches(".0").parse()?;
|
||||
let depart_at = Duration::minutes(mins);
|
||||
|
||||
trips.push(Trip {
|
||||
from,
|
||||
to,
|
||||
depart_at,
|
||||
});
|
||||
// TODO Read all trips
|
||||
if trips.len() == 10 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(trips)
|
||||
}
|
||||
|
||||
pub fn import_parcels(path: &str) -> Result<HashMap<String, LonLat>, failure::Error> {
|
||||
let mut coords = BufWriter::new(File::create("/tmp/parcels")?);
|
||||
let mut parcel_ids = Vec::new();
|
||||
@ -16,7 +62,7 @@ pub fn import_parcels(path: &str) -> Result<HashMap<String, LonLat>, failure::Er
|
||||
parcel_ids.push(rec[15].to_string());
|
||||
coords.write_fmt(format_args!("{} {}\n", &rec[25], &rec[26]))?;
|
||||
// TODO convert it all
|
||||
if parcel_ids.len() == 100 {
|
||||
if parcel_ids.len() == 10000 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -48,7 +94,6 @@ pub fn import_parcels(path: &str) -> Result<HashMap<String, LonLat>, failure::Er
|
||||
let lat: f64 = pieces[1].parse()?;
|
||||
let pt = LonLat::new(lon, lat);
|
||||
if bounds.contains(pt) {
|
||||
println!("parcel {} is at {}", id, pt);
|
||||
result.insert(id, pt);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user