From 38da77b80d7d12487da4f89e10cbfcb67f54272a Mon Sep 17 00:00:00 2001 From: eric bryant Date: Wed, 9 Jun 2021 02:13:06 -0400 Subject: [PATCH] check chop/con .csv Route+Banner parity closes #423 interactive rebase bcf0ac114c0cc9bf5f633ade9eec70ca5e0f717c --- siteupdate/cplusplus/Makefile | 2 +- .../classes/ConnectedRoute/ConnectedRoute.cpp | 2 +- .../cplusplus/classes/Datacheck/Datacheck.cpp | 5 +- .../cplusplus/classes/Datacheck/Datacheck.h | 5 +- .../classes/HighwaySystem/HighwaySystem.cpp | 7 ++ .../classes/HighwaySystem/HighwaySystem.h | 4 +- .../classes/HighwaySystem/route_integrity.cpp | 80 +++++++++++++++++ siteupdate/cplusplus/classes/Route/Route.cpp | 15 ++++ siteupdate/cplusplus/classes/Route/Route.h | 2 +- .../classes/Route/compute_stats_r.cpp | 3 +- .../classes/Route/label_and_connect.cpp | 79 ----------------- siteupdate/cplusplus/siteupdate.cpp | 7 +- .../{LabelConThread.cpp => RteIntThread.cpp} | 4 +- siteupdate/cplusplus/threads/threads.cpp | 2 +- siteupdate/cplusplus/threads/threads.h | 2 +- siteupdate/python-teresco/siteupdate.py | 85 +++++++++++++------ 16 files changed, 184 insertions(+), 120 deletions(-) create mode 100644 siteupdate/cplusplus/classes/HighwaySystem/route_integrity.cpp delete mode 100644 siteupdate/cplusplus/classes/Route/label_and_connect.cpp rename siteupdate/cplusplus/threads/{LabelConThread.cpp => RteIntThread.cpp} (78%) diff --git a/siteupdate/cplusplus/Makefile b/siteupdate/cplusplus/Makefile index 58a632a4..7d48fad7 100644 --- a/siteupdate/cplusplus/Makefile +++ b/siteupdate/cplusplus/Makefile @@ -20,9 +20,9 @@ CommonObjects = \ classes/GraphGeneration/PlaceRadius.o \ classes/HighwaySegment/HighwaySegment.o \ classes/HighwaySystem/HighwaySystem.o \ + classes/HighwaySystem/route_integrity.o \ classes/Region/Region.o \ classes/Route/Route.o \ - classes/Route/label_and_connect.o \ classes/Route/read_wpt.o \ classes/TravelerList/TravelerList.o \ classes/TravelerList/userlog.o \ diff --git a/siteupdate/cplusplus/classes/ConnectedRoute/ConnectedRoute.cpp b/siteupdate/cplusplus/classes/ConnectedRoute/ConnectedRoute.cpp index 7dcf931c..746cbf02 100644 --- a/siteupdate/cplusplus/classes/ConnectedRoute/ConnectedRoute.cpp +++ b/siteupdate/cplusplus/classes/ConnectedRoute/ConnectedRoute.cpp @@ -61,7 +61,7 @@ ConnectedRoute::ConnectedRoute(std::string &line, HighwaySystem *sys, ErrorList " in system " + system->systemname + '.'); } } - if (roots.size() < 1) el.add_error("No roots in " + system->systemname + "_con.csv line: " + line); + if (roots.size() < 1) el.add_error("No valid roots in " + system->systemname + "_con.csv line: " + line); } std::string ConnectedRoute::connected_rtes_line() diff --git a/siteupdate/cplusplus/classes/Datacheck/Datacheck.cpp b/siteupdate/cplusplus/classes/Datacheck/Datacheck.cpp index 7e310769..7089feb6 100644 --- a/siteupdate/cplusplus/classes/Datacheck/Datacheck.cpp +++ b/siteupdate/cplusplus/classes/Datacheck/Datacheck.cpp @@ -133,8 +133,11 @@ bool operator < (const Datacheck &a, const Datacheck &b) std::list Datacheck::fps; std::unordered_set Datacheck::always_error -{ "ABBREV_AS_BANNER", +{ "ABBREV_AS_CHOP_BANNER", + "ABBREV_AS_CON_BANNER", "BAD_ANGLE", + "CON_BANNER_MISMATCH", + "CON_ROUTE_MISMATCH", "DISCONNECTED_ROUTE", "DUPLICATE_LABEL", "HIDDEN_TERMINUS", diff --git a/siteupdate/cplusplus/classes/Datacheck/Datacheck.h b/siteupdate/cplusplus/classes/Datacheck/Datacheck.h index 36313c45..e0f5685c 100644 --- a/siteupdate/cplusplus/classes/Datacheck/Datacheck.h +++ b/siteupdate/cplusplus/classes/Datacheck/Datacheck.h @@ -18,9 +18,12 @@ class Datacheck code is the error code | info is additional string, one of: | information, if used: -----------------------+-------------------------------------------- - ABBREV_AS_BANNER | offending line # in chopped route CSV + ABBREV_AS_CHOP_BANNER | offending line # in chopped route CSV + ABBREV_AS_CON_BANNER | offending line # in connected route CSV BAD_ANGLE | BUS_WITH_I | + CON_BANNER_MISMATCH | Banner field in chopped & connected CSVs + CON_ROUTE_MISMATCH | Route field in chopped & connected CSVs DISCONNECTED_ROUTE | adjacent root's expected connection point DUPLICATE_COORDS | coordinate pair DUPLICATE_LABEL | diff --git a/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp b/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp index 0ca0a050..a90fef2b 100644 --- a/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp +++ b/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp @@ -133,6 +133,13 @@ size_t HighwaySystem::route_index(Route* r) return -1; // error, Route not found } +/* Return index of a specified ConnectedRoute within con_route_list */ +size_t HighwaySystem::con_route_index(ConnectedRoute* cr) +{ for (size_t i = 0; i < con_route_list.size(); i++) + if (con_route_list[i] == cr) return i; + return -1; // error, ConnectedRoute not found +} + void HighwaySystem::insert_vertex(HGVertex* v) { lniu_mtx.lock(); // re-use an existing mutex... vertices.insert(v); diff --git a/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.h b/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.h index 01390866..d51d61e5 100644 --- a/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.h +++ b/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.h @@ -35,7 +35,7 @@ class HighwaySystem char level; // 'a' for active, 'p' for preview, 'd' for devel std::vector route_list; - std::list con_route_list; + std::vector con_route_list; std::unordered_map mileage_by_region; std::unordered_set vertices; std::unordered_setlistnamesinuse, unusedaltroutenames; @@ -54,5 +54,7 @@ class HighwaySystem double total_mileage(); // Return total system mileage across all regions std::string level_name(); // Return full "active" / "preview" / "devel" string" size_t route_index(Route*); // Return index of a specified Route* within route_list + size_t con_route_index(ConnectedRoute*); // same thing for ConnectedRoutes + void route_integrity(ErrorList& el); void insert_vertex(HGVertex*); }; diff --git a/siteupdate/cplusplus/classes/HighwaySystem/route_integrity.cpp b/siteupdate/cplusplus/classes/HighwaySystem/route_integrity.cpp new file mode 100644 index 00000000..a75c932e --- /dev/null +++ b/siteupdate/cplusplus/classes/HighwaySystem/route_integrity.cpp @@ -0,0 +1,80 @@ +#include "HighwaySystem.h" +#include "../ConnectedRoute/ConnectedRoute.h" +#include "../Datacheck/Datacheck.h" +#include "../ErrorList/ErrorList.h" +#include "../Route/Route.h" +#include "../Waypoint/Waypoint.h" +#include "../../functions/upper.h" + +void HighwaySystem::route_integrity(ErrorList& el) +{ for (Route* r : route_list) + { // check for unconnected chopped routes + if (!r->con_route) + el.add_error(systemname + ".csv: root " + r->root + " not matched by any connected route root."); + + // create label hashes and check for duplicates + for (unsigned int index = 0; index < r->point_list.size(); index++) + { // ignore case and leading '+' or '*' + const char* lbegin = r->point_list[index]->label.data(); + while (*lbegin == '+' || *lbegin == '*') lbegin++; + std::string upper_label(lbegin); + upper(upper_label.data()); + // if primary label not duplicated, add to pri_label_hash + if (r->alt_label_hash.find(upper_label) != r->alt_label_hash.end()) + { Datacheck::add(r, r->point_list[index]->label, "", "", "DUPLICATE_LABEL", ""); + r->duplicate_labels.insert(upper_label); + } + else if (!r->pri_label_hash.insert(std::pair(upper_label, index)).second) + { Datacheck::add(r, r->point_list[index]->label, "", "", "DUPLICATE_LABEL", ""); + r->duplicate_labels.insert(upper_label); + } + for (std::string& a : r->point_list[index]->alt_labels) + { // create canonical AltLabels + while (a[0] == '+' || a[0] == '*') a = a.data()+1; + upper(a.data()); + // populate unused set + r->unused_alt_labels.insert(a); + // create label->index hashes and check if AltLabels duplicated + std::unordered_map::iterator A = r->pri_label_hash.find(a); + if (A != r->pri_label_hash.end()) + { Datacheck::add(r, r->point_list[A->second]->label, "", "", "DUPLICATE_LABEL", ""); + r->duplicate_labels.insert(a); + } + else if (!r->alt_label_hash.insert(std::pair(a, index)).second) + { Datacheck::add(r, a, "", "", "DUPLICATE_LABEL", ""); + r->duplicate_labels.insert(a); + } + } + } + } + + for (ConnectedRoute* cr : con_route_list) + { if (cr->roots.empty()) continue; // because there could be an invalid _con.csv entry + // check cr->roots[0] by itself outside of loop + cr->roots[0]->con_mismatch(); + for (size_t i = 1; i < cr->roots.size(); i++) + { // check for mismatched route endpoints within connected routes + #define q cr->roots[i-1] + #define r cr->roots[i] + r->con_mismatch(); + if ( q->point_list.size() > 1 && r->point_list.size() > 1 && !r->con_beg()->same_coords(q->con_end()) ) + { if ( q->con_beg()->same_coords(r->con_beg()) ) + q->is_reversed = 1; + else if ( q->con_end()->same_coords(r->con_end()) ) + r->is_reversed = 1; + else if ( q->con_beg()->same_coords(r->con_end()) ) + { q->is_reversed = 1; + r->is_reversed = 1; + } + else + { Datacheck::add(r, r->con_beg()->label, "", "", + "DISCONNECTED_ROUTE", q->con_end()->root_at_label()); + Datacheck::add(q, q->con_end()->label, "", "", + "DISCONNECTED_ROUTE", r->con_beg()->root_at_label()); + } + } + #undef q + #undef r + } + } +} diff --git a/siteupdate/cplusplus/classes/Route/Route.cpp b/siteupdate/cplusplus/classes/Route/Route.cpp index d5bdc9db..9327122c 100644 --- a/siteupdate/cplusplus/classes/Route/Route.cpp +++ b/siteupdate/cplusplus/classes/Route/Route.cpp @@ -1,5 +1,6 @@ #include "Route.h" #include "../Args/Args.h" +#include "../ConnectedRoute/ConnectedRoute.h" #include "../Datacheck/Datacheck.h" #include "../DBFieldLength/DBFieldLength.h" #include "../ErrorList/ErrorList.h" @@ -248,6 +249,20 @@ Waypoint* Route::con_end() { return is_reversed ? point_list.front() : point_list.back(); } +// datacheck +void Route::con_mismatch() +{ if (route != con_route->route) + Datacheck::add(this, "", "", "", "CON_ROUTE_MISMATCH", + route+" <-> "+con_route->route); + if (banner != con_route->banner) + if (abbrev.size() && abbrev == con_route->banner) + Datacheck::add(this, "", "", "", "ABBREV_AS_CON_BANNER", system->systemname + "_con.csv#L" + + std::to_string(system->con_route_index(con_route)+2)); + else Datacheck::add(this, "", "", "", "CON_BANNER_MISMATCH", + (banner.size() ? banner : "(blank)") + " <-> " + + (con_route->banner.size() ? con_route->banner : "(blank)")); +} + // sort routes by most recent update for use at end of user logs // all should have a valid updates entry pointer before being passed here bool sort_route_updates_oldest(const Route *r1, const Route *r2) diff --git a/siteupdate/cplusplus/classes/Route/Route.h b/siteupdate/cplusplus/classes/Route/Route.h index 88d03a22..1e9699cb 100644 --- a/siteupdate/cplusplus/classes/Route/Route.h +++ b/siteupdate/cplusplus/classes/Route/Route.h @@ -95,7 +95,7 @@ class Route void write_nmp_merged(); void store_traveled_segments(TravelerList*, std::ofstream &, unsigned int, unsigned int); void compute_stats_r(); - void label_and_connect(ErrorList&); + void con_mismatch(); Waypoint* con_beg(); Waypoint* con_end(); }; diff --git a/siteupdate/cplusplus/classes/Route/compute_stats_r.cpp b/siteupdate/cplusplus/classes/Route/compute_stats_r.cpp index 950b4b10..291411e6 100644 --- a/siteupdate/cplusplus/classes/Route/compute_stats_r.cpp +++ b/siteupdate/cplusplus/classes/Route/compute_stats_r.cpp @@ -59,7 +59,8 @@ void Route::compute_stats_r() // datachecks if (abbrev.empty()) { if ( banner.size() && !strncmp(banner.data(), city.data(), banner.size()) ) - Datacheck::add(this, "", "", "", "ABBREV_AS_BANNER", + Datacheck::add(this, "", "", "", "ABBREV_AS_CHOP_BANNER", + system->systemname + ".csv#L" + std::to_string(system->route_index(this)+2)); } } diff --git a/siteupdate/cplusplus/classes/Route/label_and_connect.cpp b/siteupdate/cplusplus/classes/Route/label_and_connect.cpp deleted file mode 100644 index d155bbd8..00000000 --- a/siteupdate/cplusplus/classes/Route/label_and_connect.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "Route.h" -#include "../ConnectedRoute/ConnectedRoute.h" -#include "../Datacheck/Datacheck.h" -#include "../ErrorList/ErrorList.h" -#include "../HighwaySystem/HighwaySystem.h" -#include "../Waypoint/Waypoint.h" -#include "../../functions/upper.h" - -void Route::label_and_connect(ErrorList& el) -{ // check for unconnected chopped routes - if (!con_route) - { el.add_error(system->systemname + ".csv: root " + root + " not matched by any connected route root."); - return; - } - - // check for mismatched route endpoints within connected routes - #define q con_route->roots[rootOrder-1] - if ( rootOrder > 0 && q->point_list.size() > 1 && point_list.size() > 1 && !con_beg()->same_coords(q->con_end()) ) - { if ( q->con_beg()->same_coords(con_beg()) ) - { //std::cout << "DEBUG: marking only " << q->str() << " reversed" << std::endl; - //if (q->is_reversed) std::cout << "DEBUG: " << q->str() << " already reversed!" << std::endl; - q->is_reversed = 1; - } - else if ( q->con_end()->same_coords(con_end()) ) - { //std::cout << "DEBUG: marking only " << str() << " reversed" << std::endl; - //if ( is_reversed) std::cout << "DEBUG: " << str() << " already reversed!" << std::endl; - is_reversed = 1; - } - else if ( q->con_beg()->same_coords(con_end()) ) - { //std::cout << "DEBUG: marking both " << q->str() << " and " << str() << " reversed" << std::endl; - //if (q->is_reversed) std::cout << "DEBUG: " << q->str() << " already reversed!" << std::endl; - //if ( is_reversed) std::cout << "DEBUG: " << str() << " already reversed!" << std::endl; - q->is_reversed = 1; - is_reversed = 1; - } - else - { Datacheck::add(this, con_beg()->label, "", "", - "DISCONNECTED_ROUTE", q->con_end()->root_at_label()); - Datacheck::add(q, q->con_end()->label, "", "", - "DISCONNECTED_ROUTE", con_beg()->root_at_label()); - } - } - #undef q - - // create label hashes and check for duplicates - for (unsigned int index = 0; index < point_list.size(); index++) - { // ignore case and leading '+' or '*' - const char* lbegin = point_list[index]->label.data(); - while (*lbegin == '+' || *lbegin == '*') lbegin++; - std::string upper_label(lbegin); - upper(upper_label.data()); - // if primary label not duplicated, add to pri_label_hash - if (alt_label_hash.find(upper_label) != alt_label_hash.end()) - { Datacheck::add(this, point_list[index]->label, "", "", "DUPLICATE_LABEL", ""); - duplicate_labels.insert(upper_label); - } - else if (!pri_label_hash.insert(std::pair(upper_label, index)).second) - { Datacheck::add(this, point_list[index]->label, "", "", "DUPLICATE_LABEL", ""); - duplicate_labels.insert(upper_label); - } - for (std::string& a : point_list[index]->alt_labels) - { // create canonical AltLabels - while (a[0] == '+' || a[0] == '*') a = a.data()+1; - upper(a.data()); - // populate unused set - unused_alt_labels.insert(a); - // create label->index hashes and check if AltLabels duplicated - std::unordered_map::iterator A = pri_label_hash.find(a); - if (A != pri_label_hash.end()) - { Datacheck::add(this, point_list[A->second]->label, "", "", "DUPLICATE_LABEL", ""); - duplicate_labels.insert(a); - } - else if (!alt_label_hash.insert(std::pair(a, index)).second) - { Datacheck::add(this, a, "", "", "DUPLICATE_LABEL", ""); - duplicate_labels.insert(a); - } - } - } -} diff --git a/siteupdate/cplusplus/siteupdate.cpp b/siteupdate/cplusplus/siteupdate.cpp index 45f8897d..7c1f148c 100644 --- a/siteupdate/cplusplus/siteupdate.cpp +++ b/siteupdate/cplusplus/siteupdate.cpp @@ -315,15 +315,14 @@ int main(int argc, char *argv[]) #include "tasks/concurrency_detection.cpp" - cout << et.et() << "Processing waypoint labels and checking for unconnected chopped routes." << endl; + cout << et.et() << "Creating label hashes and checking route integrity." << endl; #ifdef threading_enabled HighwaySystem::it = HighwaySystem::syslist.begin(); - THREADLOOP thr[t] = thread(LabelConThread, t, &list_mtx, &el); + THREADLOOP thr[t] = thread(RteIntThread, t, &list_mtx, &el); THREADLOOP thr[t].join(); #else for (HighwaySystem *h : HighwaySystem::syslist) - for (Route* r : h->route_list) - r->label_and_connect(el); + h->route_integrity(el); #endif #include "tasks/read_updates.cpp" diff --git a/siteupdate/cplusplus/threads/LabelConThread.cpp b/siteupdate/cplusplus/threads/RteIntThread.cpp similarity index 78% rename from siteupdate/cplusplus/threads/LabelConThread.cpp rename to siteupdate/cplusplus/threads/RteIntThread.cpp index d19ed452..9b2af069 100644 --- a/siteupdate/cplusplus/threads/LabelConThread.cpp +++ b/siteupdate/cplusplus/threads/RteIntThread.cpp @@ -1,4 +1,4 @@ -void LabelConThread(unsigned int id, std::mutex* hs_mtx, ErrorList* el) +void RteIntThread(unsigned int id, std::mutex* hs_mtx, ErrorList* el) { //printf("Starting LabelConThread %02i\n", id); fflush(stdout); while (HighwaySystem::it != HighwaySystem::syslist.end()) { hs_mtx->lock(); @@ -11,6 +11,6 @@ void LabelConThread(unsigned int id, std::mutex* hs_mtx, ErrorList* el) HighwaySystem::it++; //printf("LabelConThread %02i HighwaySystem::it++\n", id); fflush(stdout); hs_mtx->unlock(); - for (Route* r : h->route_list) r->label_and_connect(*el); + h->route_integrity(*el); } } diff --git a/siteupdate/cplusplus/threads/threads.cpp b/siteupdate/cplusplus/threads/threads.cpp index 4efa4138..35ad2615 100644 --- a/siteupdate/cplusplus/threads/threads.cpp +++ b/siteupdate/cplusplus/threads/threads.cpp @@ -12,11 +12,11 @@ #include "CompStatsRThread.cpp" #include "CompStatsTThread.cpp" #include "ConcAugThread.cpp" -#include "LabelConThread.cpp" #include "MasterTmgThread.cpp" #include "NmpMergedThread.cpp" #include "NmpSearchThread.cpp" #include "ReadListThread.cpp" #include "ReadWptThread.cpp" +#include "RteIntThread.cpp" #include "SubgraphThread.cpp" #include "UserLogThread.cpp" diff --git a/siteupdate/cplusplus/threads/threads.h b/siteupdate/cplusplus/threads/threads.h index 871bac1d..9c5714a4 100644 --- a/siteupdate/cplusplus/threads/threads.h +++ b/siteupdate/cplusplus/threads/threads.h @@ -9,11 +9,11 @@ class WaypointQuadtree; void CompStatsRThread(unsigned int, std::mutex*); void CompStatsTThread(unsigned int, std::mutex*); void ConcAugThread (unsigned int, std::mutex*, std::list*); -void LabelConThread (unsigned int, std::mutex*, ErrorList*); void MasterTmgThread(HighwayGraph*, std::mutex*, std::mutex*, WaypointQuadtree*, ElapsedTime*); void NmpMergedThread (unsigned int, std::mutex*); void NmpSearchThread (unsigned int, std::mutex*, WaypointQuadtree*); void ReadListThread (unsigned int, std::mutex*, ErrorList*); void ReadWptThread (unsigned int, std::mutex*, ErrorList*, WaypointQuadtree*); +void RteIntThread (unsigned int, std::mutex*, ErrorList*); void SubgraphThread (unsigned int, std::mutex*, std::mutex*, HighwayGraph*, WaypointQuadtree*, ElapsedTime*); void UserLogThread (unsigned int, std::mutex*, ClinchedDBValues*, const double, const double); diff --git a/siteupdate/python-teresco/siteupdate.py b/siteupdate/python-teresco/siteupdate.py index 712e5f35..4abeaa23 100755 --- a/siteupdate/python-teresco/siteupdate.py +++ b/siteupdate/python-teresco/siteupdate.py @@ -1103,6 +1103,21 @@ def con_beg(self): def con_end(self): return self.point_list[0] if self.is_reversed else self.point_list[-1] + # datacheck + def con_mismatch(self): + if self.route != self.con_route.route: + datacheckerrors.append(DatacheckEntry(self, [], "CON_ROUTE_MISMATCH", + self.route+" <-> "+self.con_route.route)) + if self.banner != self.con_route.banner: + if len(self.abbrev) and self.abbrev == self.con_route.banner: + datacheckerrors.append(DatacheckEntry(self, [], "ABBREV_AS_CON_BANNER", + self.system.systemname + "_con.csv#L" + + str(self.system.con_route_index(self.con_route)+2))) + else: + datacheckerrors.append(DatacheckEntry(self, [], "CON_BANNER_MISMATCH", + (self.banner if len(self.banner) else "(blank)") + " <-> " + + (self.con_route.banner if len(self.con_route.banner) else "(blank)"))) + class ConnectedRoute: """This class encapsulates a single 'connected route' as given by a single line of a _con.csv file @@ -1160,7 +1175,7 @@ def __init__(self,line,system,el): el.add_error("Could not find Route matching ConnectedRoute root " + root + " in system " + system.systemname + '.') if len(self.roots) < 1: - el.add_error("No roots in " + system.systemname + "_con.csv line: " + line) + el.add_error("No valid roots in " + system.systemname + "_con.csv line: " + line) # will be computed for routes in active & preview systems later def csv_line(self): @@ -1263,6 +1278,13 @@ def route_index(self, r): return i return None # error, Route not found + """Return index of a specified ConnectedRoute within con_route_list""" + def con_route_index(self, cr): + for i in range(len(self.con_route_list)): + if self.con_route_list[i] == cr: + return i + return None # error, ConnectedRoute not found + """String representation""" def __str__(self): return self.systemname @@ -1612,9 +1634,12 @@ class DatacheckEntry: code is the error code | info is additional string, one of: | information, if used: -----------------------+-------------------------------------------- - ABBREV_AS_BANNER | chopped route CSV filename + ABBREV_AS_CHOP_BANNER | offending line # in chopped route CSV + ABBREV_AS_CON_BANNER | offending line # in connected route CSV BAD_ANGLE | BUS_WITH_I | + CON_BANNER_MISMATCH | Banner field in chopped & connected CSVs + CON_ROUTE_MISMATCH | Route field in chopped & connected CSVs DISCONNECTED_ROUTE | adjacent root's expected connection point DUPLICATE_COORDS | coordinate pair DUPLICATE_LABEL | @@ -2927,33 +2952,15 @@ def run(self): print(".", end="", flush=True) print() -print(et.et() + "Processing waypoint labels and checking for unconnected chopped routes.",flush=True) +print(et.et() + "Creating label hashes and checking route integrity.",flush=True) for h in highway_systems: for r in h.route_list: # check for unconnected chopped routes if r.con_route is None: el.add_error(r.system.systemname + ".csv: root " + r.root + " not matched by any connected route root.") - continue - - # check for mismatched route endpoints within connected routes - q = r.con_route.roots[r.rootOrder-1] - if r.rootOrder > 0 and len(q.point_list) > 1 and len(r.point_list) > 1 and not r.con_beg().same_coords(q.con_end()): - if q.con_beg().same_coords(r.con_beg()): - q.is_reversed = True - elif q.con_end().same_coords(r.con_end()): - r.is_reversed = True - elif q.con_beg().same_coords(r.con_end()): - q.is_reversed = True - r.is_reversed = True - else: - datacheckerrors.append(DatacheckEntry(r, [r.con_beg().label], - "DISCONNECTED_ROUTE", q.root + '@' + q.con_end().label)) - datacheckerrors.append(DatacheckEntry(q, [q.con_end().label], - "DISCONNECTED_ROUTE", r.root + '@' + r.con_beg().label)) # create label hashes and check for duplicates - index = 0 - for w in r.point_list: + for index, w in enumerate(r.point_list): # ignore case and leading '+' or '*' upper_label = w.label.lstrip('+*').upper() # if primary label not duplicated, add to r.pri_label_hash @@ -2979,7 +2986,30 @@ def run(self): r.duplicate_labels.add(w.alt_labels[a]) else: r.alt_label_hash[w.alt_labels[a]] = index - index += 1 + + for cr in h.con_route_list: + if len(cr.roots) == 0: + continue # because there could be an invalid _con.csv entry + # check cr.roots[0] by itself outside of loop + cr.roots[0].con_mismatch() + for i in range(1,len(cr.roots)): + # check for mismatched route endpoints within connected routes + q = cr.roots[i-1] + r = cr.roots[i] + r.con_mismatch() + if r.rootOrder > 0 and len(q.point_list) > 1 and len(r.point_list) > 1 and not r.con_beg().same_coords(q.con_end()): + if q.con_beg().same_coords(r.con_beg()): + q.is_reversed = True + elif q.con_end().same_coords(r.con_end()): + r.is_reversed = True + elif q.con_beg().same_coords(r.con_end()): + q.is_reversed = True + r.is_reversed = True + else: + datacheckerrors.append(DatacheckEntry(r, [r.con_beg().label], + "DISCONNECTED_ROUTE", q.root + '@' + q.con_end().label)) + datacheckerrors.append(DatacheckEntry(q, [q.con_end().label], + "DISCONNECTED_ROUTE", r.root + '@' + r.con_beg().label)) # Read updates.csv file, just keep in the fields array for now since we're # just going to drop this into the DB later anyway @@ -3332,8 +3362,8 @@ def run(self): # datachecks if r.abbrev == "": if len(r.banner) and r.city.startswith(r.banner): - datacheckerrors.append(DatacheckEntry(r, [], "ABBREV_AS_BANNER", - str(r.system.route_index(r)+2))) + datacheckerrors.append(DatacheckEntry(r, [], "ABBREV_AS_CHOP_BANNER", + h.systemname + ".csv#L" + str(r.system.route_index(r)+2))) print("!", flush=True) print(et.et() + "Writing highway data stats log file (highwaydatastats.log).",flush=True) @@ -3625,8 +3655,11 @@ def run(self): lines.pop(0) # ignore header line datacheckfps = [] datacheck_always_error = [ \ - 'ABBREV_AS_BANNER', + 'ABBREV_AS_CHOP_BANNER', + 'ABBREV_AS_CON_BANNER', 'BAD_ANGLE', + 'CON_BANNER_MISMATCH', + 'CON_ROUTE_MISMATCH', 'DISCONNECTED_ROUTE', 'DUPLICATE_LABEL', 'HIDDEN_TERMINUS',