mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
WIP detecting problems applying fixes
This commit is contained in:
parent
fc62d96fb4
commit
7800ac046e
@ -35,13 +35,20 @@ pub fn read_json<T: DeserializeOwned>(path: &str, timer: &mut Timer) -> Result<T
|
||||
}
|
||||
|
||||
timer.start(&format!("parse {}", path));
|
||||
// TODO timer.read_file isn't working here. :(
|
||||
let mut file = File::open(path)?;
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)?;
|
||||
let obj: T = serde_json::from_str(&contents)?;
|
||||
timer.stop(&format!("parse {}", path));
|
||||
Ok(obj)
|
||||
// TODO timer.read_file isn't working here. And we need to call stop() if there's no file.
|
||||
match File::open(path) {
|
||||
Ok(mut file) => {
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)?;
|
||||
let obj: T = serde_json::from_str(&contents)?;
|
||||
timer.stop(&format!("parse {}", path));
|
||||
Ok(obj)
|
||||
}
|
||||
Err(e) => {
|
||||
timer.stop(&format!("parse {}", path));
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_binary<T: Serialize>(path: &str, obj: &T) -> Result<(), Error> {
|
||||
|
@ -360,12 +360,19 @@ impl<'a> std::ops::Drop for Timer<'a> {
|
||||
match self.stack.last() {
|
||||
Some(StackEntry::TimerSpan(ref s)) => {
|
||||
if s.name != stop_name {
|
||||
println!("dropping Timer because of panic");
|
||||
println!("dropping Timer during {}, due to panic?", s.name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Some(_) => {
|
||||
println!("dropping Timer because of panic");
|
||||
Some(StackEntry::File(ref r)) => {
|
||||
println!("dropping Timer while reading {}, due to panic?", r.path);
|
||||
return;
|
||||
}
|
||||
Some(StackEntry::Progress(ref p)) => {
|
||||
println!(
|
||||
"dropping Timer while doing progress {}, due to panic?",
|
||||
p.label
|
||||
);
|
||||
return;
|
||||
}
|
||||
None => unreachable!(),
|
||||
|
@ -36,6 +36,7 @@
|
||||
- tweeting small problems -> bug tracker
|
||||
- https://www.the74million.org/article/building-a-smarter-and-cheaper-school-bus-system-how-a-boston-mit-partnership-led-to-new-routes-that-are-20-more-efficient-use-400-fewer-buses-save-5-million/
|
||||
- https://www.citylab.com/perspective/2019/10/micromobility-urban-design-car-free-infrastruture-futurama/600163/
|
||||
- https://www.sanjorn.com/
|
||||
|
||||
## Similar projects
|
||||
|
||||
|
@ -1081,14 +1081,9 @@ fn make_half_map(
|
||||
}
|
||||
if i.is_border() {
|
||||
if i.roads.len() != 1 {
|
||||
let mut roads = Vec::new();
|
||||
let id = i.id;
|
||||
for r in i.roads.clone() {
|
||||
roads.push(map.get_r(r).orig_id);
|
||||
}
|
||||
panic!(
|
||||
"{} is a border, but is connected to >1 road: {:?}",
|
||||
id, roads
|
||||
i.id, i.roads
|
||||
);
|
||||
}
|
||||
continue;
|
||||
|
@ -7,6 +7,19 @@ use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct RawMap {
|
||||
pub name: String,
|
||||
pub roads: BTreeMap<OriginalRoad, RawRoad>,
|
||||
pub intersections: BTreeMap<OriginalIntersection, RawIntersection>,
|
||||
pub buildings: BTreeMap<OriginalBuilding, RawBuilding>,
|
||||
pub bus_routes: Vec<Route>,
|
||||
pub areas: Vec<RawArea>,
|
||||
|
||||
pub boundary_polygon: Polygon,
|
||||
pub gps_bounds: GPSBounds,
|
||||
}
|
||||
|
||||
// A way to refer to roads across many maps.
|
||||
//
|
||||
// Previously, OriginalRoad and OriginalIntersection used LonLat to reference objects across maps.
|
||||
@ -58,19 +71,6 @@ impl fmt::Display for OriginalBuilding {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct RawMap {
|
||||
pub name: String,
|
||||
pub roads: BTreeMap<OriginalRoad, RawRoad>,
|
||||
pub intersections: BTreeMap<OriginalIntersection, RawIntersection>,
|
||||
pub buildings: BTreeMap<OriginalBuilding, RawBuilding>,
|
||||
pub bus_routes: Vec<Route>,
|
||||
pub areas: Vec<RawArea>,
|
||||
|
||||
pub boundary_polygon: Polygon,
|
||||
pub gps_bounds: GPSBounds,
|
||||
}
|
||||
|
||||
impl RawMap {
|
||||
pub fn blank(name: String) -> RawMap {
|
||||
RawMap {
|
||||
@ -107,6 +107,15 @@ impl RawMap {
|
||||
self.apply_fixes("huge_seattle", &master_fixes, timer);
|
||||
self.apply_fixes(&self.name.clone(), &local_fixes, timer);
|
||||
}
|
||||
|
||||
// Validation round afterwards
|
||||
for (id, r) in &self.roads {
|
||||
if r.center_points[0] != self.intersections[&id.i1].point
|
||||
|| *r.center_points.last().unwrap() != self.intersections[&id.i2].point
|
||||
{
|
||||
timer.warn(format!("{} geomtry doesn't match intersections", id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_fixes(&mut self, name: &str, fixes: &MapFixes, timer: &mut Timer) {
|
||||
|
Loading…
Reference in New Issue
Block a user