Delete the last traffic_signal_data example and remove the support for it.

Keeping this format up-to-date with importer pipeline changes has always
been annoying, and I previously removed all but one example. Now the
last example is getting in the way of progress. Per #995, this save file
format needs to be way more robust before we try something like this
again.
This commit is contained in:
Dustin Carlino 2022-11-28 14:06:33 +00:00
parent 40dcc27072
commit cf4cd37683
8 changed files with 11 additions and 506 deletions

2
Cargo.lock generated
View File

@ -4395,9 +4395,7 @@ dependencies = [
name = "traffic_signal_data"
version = "0.1.0"
dependencies = [
"include_dir",
"serde",
"serde_json",
]
[[package]]

View File

@ -290,8 +290,12 @@ impl Map {
error!("Traffic signal at {} downgraded to stop sign, because it has no movements -- probably roads under construction", i.orig_id);
stop_signs.insert(i.id, ControlStopSign::new(&map, i.id));
} else {
traffic_signals
.insert(i.id, ControlTrafficSignal::validating_new(&map, i.id));
traffic_signals.insert(
i.id,
ControlTrafficSignal::get_possible_policies(&map, i.id)
.remove(0)
.1,
);
}
}
IntersectionControl::Construction => {}

View File

@ -18,43 +18,10 @@ mod lagging_green;
/// Applies a bunch of heuristics to a single intersection, returning the valid results in
/// best-first order. The signal configuration is only based on the roads connected to the
/// intersection.
///
/// If `enforce_manual_signals` is true, then any data from the `traffic_signal_data` crate that
/// matches the map will be validated against the current map. If the config is out-of-date, this
/// method will panic, so that whoever is running the importer can immediately fix the config.
pub fn get_possible_policies(
map: &Map,
id: IntersectionID,
enforce_manual_signals: bool,
) -> Vec<(String, ControlTrafficSignal)> {
pub fn get_possible_policies(map: &Map, id: IntersectionID) -> Vec<(String, ControlTrafficSignal)> {
let mut results = Vec::new();
let i = map.get_i(id);
if let Some(raw) = traffic_signal_data::load_all_data()
.unwrap()
.remove(&i.orig_id.0)
{
match ControlTrafficSignal::import(raw, id, map).and_then(|ts| ts.validate(i).map(|_| ts)) {
Ok(ts) => {
results.push(("manually specified settings".to_string(), ts));
}
Err(err) => {
if enforce_manual_signals {
panic!(
"traffic_signal_data data for {} ({}) out of date, go update it: {}",
i.orig_id,
i.name(None, map),
err
);
} else {
warn!(
"traffic_signal_data data for {} no longer valid with map edits: {}",
i.orig_id, err
);
}
}
}
}
// As long as we're using silly heuristics for these by default, prefer shorter cycle
// length.
@ -456,9 +423,8 @@ fn make_stages(
pub fn synchronize(map: &mut Map) {
let mut seen = HashSet::new();
let mut pairs = Vec::new();
let handmapped = traffic_signal_data::load_all_data().unwrap();
for i in map.all_intersections() {
if !i.is_traffic_signal() || seen.contains(&i.id) || handmapped.contains_key(&i.orig_id.0) {
if !i.is_traffic_signal() || seen.contains(&i.id) {
continue;
}
if let Some(list) = IntersectionCluster::autodetect(i.id, map) {

View File

@ -61,23 +61,11 @@ impl ControlTrafficSignal {
policies.remove(0).1
}
/// Only call this variant while importing the map, to enforce that baked-in signal config is
/// valid.
pub(crate) fn validating_new(map: &Map, id: IntersectionID) -> ControlTrafficSignal {
let mut policies = get_possible_policies(map, id, true);
if policies.len() == 1 {
warn!("Falling back to greedy_assignment for {}", id);
}
policies.remove(0).1
}
pub fn get_possible_policies(
map: &Map,
id: IntersectionID,
) -> Vec<(String, ControlTrafficSignal)> {
// This method is called publicly while editing the map, so don't enforce valid baked-in
// signal config.
get_possible_policies(map, id, false)
get_possible_policies(map, id)
}
pub fn get_min_crossing_time(&self, idx: usize, i: &Intersection) -> Duration {

View File

@ -5,6 +5,4 @@ authors = ["Dustin Carlino <dabreegster@gmail.com>"]
edition = "2021"
[dependencies]
include_dir = { git = "https://github.com/dabreegster/include_dir", branch = "union" }
serde = { workspace = true }
serde_json = { workspace = true }

View File

@ -1,409 +0,0 @@
{
"intersection_osm_node_id": 53223864,
"plans": [
{
"start_time_seconds": 0,
"stages": [
{
"protected_turns": [
{
"from": {
"osm_way_id": 337818332,
"osm_node1": 53223864,
"osm_node2": 53086809,
"is_forwards": false
},
"to": {
"osm_way_id": 337818332,
"osm_node1": 53223864,
"osm_node2": 53086809,
"is_forwards": true
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": true
},
{
"from": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": true
},
{
"from": {
"osm_way_id": 739678024,
"osm_node1": 1818407082,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 912599281,
"osm_node1": 3857577565,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 912599281,
"osm_node1": 3857577565,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 6488417,
"osm_node1": 53223864,
"osm_node2": 3857577561,
"is_forwards": true
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
}
],
"permitted_turns": [
{
"from": {
"osm_way_id": 337818332,
"osm_node1": 53223864,
"osm_node2": 53086809,
"is_forwards": false
},
"to": {
"osm_way_id": 6488417,
"osm_node1": 53223864,
"osm_node2": 3857577561,
"is_forwards": true
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 912599281,
"osm_node1": 3857577565,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 739678024,
"osm_node1": 1818407082,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 337818332,
"osm_node1": 53223864,
"osm_node2": 53086809,
"is_forwards": true
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 739678024,
"osm_node1": 1818407082,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 912599281,
"osm_node1": 3857577565,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 337818332,
"osm_node1": 53223864,
"osm_node2": 53086809,
"is_forwards": true
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 912599281,
"osm_node1": 3857577565,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
}
],
"stage_type": {
"Fixed": 30
}
},
{
"protected_turns": [
{
"from": {
"osm_way_id": 337818332,
"osm_node1": 53223864,
"osm_node2": 53086809,
"is_forwards": false
},
"to": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 337818332,
"osm_node1": 53223864,
"osm_node2": 53086809,
"is_forwards": true
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 739678024,
"osm_node1": 1818407082,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 6488417,
"osm_node1": 53223864,
"osm_node2": 3857577561,
"is_forwards": true
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": true
},
{
"from": {
"osm_way_id": 912599281,
"osm_node1": 3857577565,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 912599281,
"osm_node1": 3857577565,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": true
}
],
"permitted_turns": [
{
"from": {
"osm_way_id": 337818332,
"osm_node1": 53223864,
"osm_node2": 53086809,
"is_forwards": false
},
"to": {
"osm_way_id": 6488417,
"osm_node1": 53223864,
"osm_node2": 3857577561,
"is_forwards": true
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 337818332,
"osm_node1": 53223864,
"osm_node2": 53086809,
"is_forwards": false
},
"to": {
"osm_way_id": 912599281,
"osm_node1": 3857577565,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 6488417,
"osm_node1": 53223864,
"osm_node2": 3857577561,
"is_forwards": true
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 912599281,
"osm_node1": 3857577565,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 739678024,
"osm_node1": 1818407082,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 912599281,
"osm_node1": 3857577565,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 337818332,
"osm_node1": 53223864,
"osm_node2": 53086809,
"is_forwards": true
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
}
],
"stage_type": {
"Fixed": 30
}
},
{
"protected_turns": [
{
"from": {
"osm_way_id": 337818332,
"osm_node1": 53223864,
"osm_node2": 53086809,
"is_forwards": false
},
"to": {
"osm_way_id": 912599281,
"osm_node1": 3857577565,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 6488417,
"osm_node1": 53223864,
"osm_node2": 3857577561,
"is_forwards": true
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
},
{
"from": {
"osm_way_id": 739678024,
"osm_node1": 1818407082,
"osm_node2": 53223864,
"is_forwards": true
},
"to": {
"osm_way_id": 428315591,
"osm_node1": 53096142,
"osm_node2": 53223864,
"is_forwards": false
},
"intersection_osm_node_id": 53223864,
"is_crosswalk": false
}
],
"permitted_turns": [],
"stage_type": {
"Variable": [
5,
1,
10
]
}
}
],
"offset_seconds": 0
}
]
}

View File

@ -1,26 +0,0 @@
#!/usr/bin/python3
# 790e13e9278e54cd7e1f5a2969a00057e33f778c changed the JSON schema. This script
# updates all of the data/ files. Keeping it around as an example for the next
# transition.
#
# The Rust code also implements this transformation (in
# map_model/src/edits/compat.rs), but it's less convenient to run it over all
# the data files, since it operates on entire map edits.
import json
import sys
for path in sys.argv[1:]:
with open(path) as f:
data = json.load(f)
data['plans'] = [{
'start_time_seconds': 0,
'stages': data['stages'],
'offset_seconds': data['offset_seconds'],
}]
del data['stages']
del data['offset_seconds']
with open(path, 'w') as f:
f.write(json.dumps(data, indent=2))
f.close()

View File

@ -1,8 +1,9 @@
//! A representation of traffic signal configuration that references OpenStreetMap IDs and is
//! hopefully robust to minor edits over time.
use std::collections::BTreeSet;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct TrafficSignal {
@ -93,18 +94,3 @@ pub struct DirectedRoad {
/// https://wiki.openstreetmap.org/wiki/Forward_%26_backward,_left_%26_right for details.
pub is_forwards: bool,
}
// "" means include all files within data. My hacks to the include_dir crate need a better API.
static DATA: include_dir::Dir = include_dir::include_dir!("data", "");
/// Returns all traffic signal data compiled into this build, keyed by OSM node ID. If any single
/// file is broken, returns an error for the entire load.
// TODO Use a build script to do this. But have to generate Rust code to populate the struct?
pub fn load_all_data() -> Result<BTreeMap<i64, TrafficSignal>, std::io::Error> {
let mut results = BTreeMap::new();
for f in DATA.files() {
let ts: TrafficSignal = serde_json::from_slice(f.contents())?;
results.insert(ts.intersection_osm_node_id, ts);
}
Ok(results)
}