Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update notification bugfixes (#500) / speedup #502

Merged
merged 1 commit into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/classes/Route/Route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void Route::store_traveled_segments(TravelerList* t, std::ofstream& log, unsigne
hs->add_clinched_by(t);
t->clinched_segments.insert(hs);
}
if (t->routes.insert(this).second && last_update && t->update && last_update[0] >= *t->update)
if (last_update && t->updated_routes.insert(this).second && t->update && last_update[0] >= *t->update)
log << "Route updated " << last_update[0] << ": " << readable_name() << '\n';
}

Expand Down
5 changes: 5 additions & 0 deletions siteupdate/cplusplus/classes/TravelerList/TravelerList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ TravelerList::TravelerList(std::string travname, std::string* updarr[], ErrorLis
if (*c == '#') break;
else fields.push_back(c);
}
#define UPDATE_NOTE(R) if (R->last_update) \
{ updated_routes.insert(R); \
log << " Route updated " << R->last_update[0] << ": " << R->readable_name() << '\n'; \
}
if (fields.size() == 4)
{
#include "mark_chopped_route_segments.cpp"
Expand All @@ -129,6 +133,7 @@ TravelerList::TravelerList(std::string travname, std::string* updarr[], ErrorLis
<< fields.size() << "): " << trim_line << '\n';
splist << orig_line << endlines[l];
}
#undef UPDATE_NOTE
}
delete[] listdata;
log << "Processed " << list_entries << " good lines marking " << clinched_segments.size() << " segments traveled.\n";
Expand Down
2 changes: 1 addition & 1 deletion siteupdate/cplusplus/classes/TravelerList/TravelerList.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TravelerList
std::unordered_map<Region*, double> active_preview_mileage_by_region; // total mileage per region, active+preview only
std::unordered_map<Region*, double> active_only_mileage_by_region; // total mileage per region, active only
std::unordered_map<HighwaySystem*, std::unordered_map<Region*, double>> system_region_mileages; // mileage per region per system
std::unordered_set<Route*> routes;
std::unordered_set<Route*> updated_routes;
bool* in_subgraph;
unsigned int *traveler_num;
unsigned int active_systems_traveled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ if (lit1 == r->alt_label_hash.end() || lit2 == r->alt_label_hash.end())
if (invalid_char) log << " [contains invalid character(s)]";
log << '\n';
splist << orig_line << endlines[l];
if (routes.insert(r).second && r->last_update)
log << " Route updated " << r->last_update[0] << ": " << r->readable_name() << '\n';
UPDATE_NOTE(r)
continue;
}
// are either of the labels used duplicates?
Expand All @@ -85,8 +84,7 @@ if (duplicate)
if (lit1->second == lit2->second)
{ log << "Equivalent waypoint labels mark zero distance traveled in line: " << trim_line << '\n';
splist << orig_line << endlines[l];
if (routes.insert(r).second && r->last_update)
log << " Route updated " << r->last_update[0] << ": " << r->readable_name() << '\n';
UPDATE_NOTE(r)
}
// otherwise both labels are valid; mark in use & proceed
else { r->system->lniu_mtx.lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,8 @@ Route* r2 = rit2->second;
if (r1->con_route != r2->con_route)
{ log << lookup1 << " and " << lookup2 << " not in same connected route in line: " << trim_line << '\n';
splist << orig_line << endlines[l];
// log updates for routes beginning/ending r1's ConnectedRoute
Route* cr = r1->con_route->roots.front();
if (routes.insert(cr).second && cr->last_update)
log << " Route updated " << cr->last_update[0] << ": " << cr->readable_name() << '\n';
if (r1->con_route->roots.size() > 1)
{ Route* cr = r1->con_route->roots.back();
if (routes.insert(cr).second && cr->last_update)
log << " Route updated " << cr->last_update[0] << ": " << cr->readable_name() << '\n';
}
// log updates for routes beginning/ending r2's ConnectedRoute
cr = r2->con_route->roots.front();
if (routes.insert(cr).second && cr->last_update)
log << " Route updated " << cr->last_update[0] << ": " << cr->readable_name() << '\n';
if (r2->con_route->roots.size() > 1)
{ Route* cr = r2->con_route->roots.back();
if (routes.insert(cr).second && cr->last_update)
log << " Route updated " << cr->last_update[0] << ": " << cr->readable_name() << '\n';
}
UPDATE_NOTE(r1->con_route->roots.front()) if (r1->con_route->roots.size() > 1) UPDATE_NOTE(r1->con_route->roots.back())
UPDATE_NOTE(r2->con_route->roots.front()) if (r2->con_route->roots.size() > 1) UPDATE_NOTE(r2->con_route->roots.back())
continue;
}
if (r1->system->devel())
Expand Down Expand Up @@ -102,10 +86,8 @@ if (lit1 == r1->alt_label_hash.end() || lit2 == r2->alt_label_hash.end())
if (invalid_char) log << " [contains invalid character(s)]";
log << '\n';
splist << orig_line << endlines[l];
if (lit1 == r1->alt_label_hash.end() && routes.insert(r1).second && r1->last_update)
log << " Route updated " << r1->last_update[0] << ": " << r1->readable_name() << '\n';
if (lit2 == r2->alt_label_hash.end() && routes.insert(r2).second && r2->last_update)
log << " Route updated " << r2->last_update[0] << ": " << r2->readable_name() << '\n';
if (lit1 == r1->alt_label_hash.end() && lit1 != lit2) UPDATE_NOTE(r1)
if (lit2 == r2->alt_label_hash.end()) /*^diff rtes^*/ UPDATE_NOTE(r2)
continue;
}
// are either of the labels used duplicates?
Expand Down Expand Up @@ -133,8 +115,7 @@ if (r1 == r2)
if (index1 == index2)
{ log << "Equivalent waypoint labels mark zero distance traveled in line: " << trim_line << '\n';
splist << orig_line << endlines[l];
if (routes.insert(r1).second && r1->last_update)
log << " Route updated " << r1->last_update[0] << ": " << r1->readable_name() << '\n';
UPDATE_NOTE(r1)
continue;
}
if (index1 <= index2)
Expand Down
4 changes: 2 additions & 2 deletions siteupdate/cplusplus/classes/TravelerList/userlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ void TravelerList::userlog(ClinchedDBValues *clin_db_val, const double total_act
// updated routes, sorted by date
log << "\nMost recent updates for listed routes:\n";
std::list<Route*> route_list;
for (Route* r : routes) if (r->last_update) route_list.push_back(r);
routes.clear();
for (Route* r : updated_routes) if (r->last_update) route_list.push_back(r);
updated_routes.clear();
route_list.sort(sort_route_updates_oldest);
for (Route* r : route_list)
log << r->last_update[0] << " | " << r->last_update[1] << " | " << r->last_update[2] << " | "
Expand Down
70 changes: 32 additions & 38 deletions siteupdate/python-teresco/siteupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,9 +1188,9 @@ def store_traveled_segments(self, t, beg, end):
hs = self.segment_list[pos]
hs.add_clinched_by(t)
t.clinched_segments.add(hs)
if self not in t.routes:
t.routes.add(self)
if self.last_update and t.update and self.last_update[0] >= t.update:
if self.last_update and self not in t.updated_routes:
t.updated_routes.add(self)
if t.update and self.last_update[0] >= t.update:
t.log_entries.append("Route updated " + self.last_update[0] + ": " + self.readable_name())

def con_beg(self):
Expand Down Expand Up @@ -1434,7 +1434,7 @@ def __init__(self,travelername,update,el,path="../../../UserData/list_files"):
except TypeError:
self.log_entries = []
self.update = None
self.routes = set()
self.updated_routes = set()

for line in lines:
line = line.strip(" \t\r\n\x00")
Expand Down Expand Up @@ -1510,10 +1510,9 @@ def __init__(self,travelername,update,el,path="../../../UserData/list_files"):
self.log_entries.append(log_entry)
if invchar:
self.log_entries[-1] += " [contains invalid character(s)]"
if r not in self.routes:
self.routes.add(r)
if r.last_update:
self.log_entries.append(" Route updated " + r.last_update[0] + ": " + r.readable_name())
if r.last_update:
self.updated_routes.add(r)
self.log_entries.append(" Route updated " + r.last_update[0] + ": " + r.readable_name())
continue
# are either of the labels used duplicates?
duplicate = False
Expand All @@ -1529,10 +1528,9 @@ def __init__(self,travelername,update,el,path="../../../UserData/list_files"):
# if both labels reference the same waypoint...
if index1 == index2:
self.log_entries.append("Equivalent waypoint labels mark zero distance traveled in line: " + line)
if r not in self.routes:
self.routes.add(r)
if r.last_update:
self.log_entries.append(" Route updated " + r.last_update[0] + ": " + r.readable_name())
if r.last_update:
self.updated_routes.add(r)
self.log_entries.append(" Route updated " + r.last_update[0] + ": " + r.readable_name())
# otherwise both labels are valid; mark in use & proceed
else:
r.system.listnamesinuse.add(lookup)
Expand Down Expand Up @@ -1594,28 +1592,24 @@ def __init__(self,travelername,update,el,path="../../../UserData/list_files"):
self.log_entries.append(lookup1 + " and " + lookup2 + " not in same connected route in line: " + line)
# log updates for routes beginning/ending r1's ConnectedRoute
cr = r1.con_route.roots[0]
if cr not in self.routes:
self.routes.add(cr)
if cr.last_update:
self.updated_routes.add(cr)
self.log_entries.append(" Route updated " + cr.last_update[0] + ": " + cr.readable_name())
if len(r1.con_route.roots) > 1:
cr = r1.con_route.roots[-1]
if cr.last_update:
self.updated_routes.add(cr)
self.log_entries.append(" Route updated " + cr.last_update[0] + ": " + cr.readable_name())
if len(r1.con_route.roots) > 1:
cr = r1.con_route.roots[-1]
if cr not in self.routes:
self.routes.add(cr)
if cr.last_update:
self.log_entries.append(" Route updated " + cr.last_update[0] + ": " + cr.readable_name())
# log updates for routes beginning/ending r2's ConnectedRoute
cr = r2.con_route.roots[0]
if cr not in self.routes:
self.routes.add(cr)
if cr.last_update:
self.updated_routes.add(cr)
self.log_entries.append(" Route updated " + cr.last_update[0] + ": " + cr.readable_name())
if len(r2.con_route.roots) > 1:
cr = r2.con_route.roots[-1]
if cr.last_update:
self.updated_routes.add(cr)
self.log_entries.append(" Route updated " + cr.last_update[0] + ": " + cr.readable_name())
if len(r2.con_route.roots) > 1:
cr = r2.con_route.roots[-1]
if cr not in self.routes:
self.routes.add(cr)
if cr.last_update:
self.log_entries.append(" Route updated " + cr.last_update[0] + ": " + cr.readable_name())
continue
if r1.system.devel():
self.log_entries.append("Ignoring line matching highway in system in development: " + line)
Expand Down Expand Up @@ -1658,12 +1652,13 @@ def __init__(self,travelername,update,el,path="../../../UserData/list_files"):
self.log_entries.append(log_entry)
if invchar:
self.log_entries[-1] += " [contains invalid character(s)]"
if index1 is None and r1 not in self.routes and r1.last_update:
if index1 is None and r1.last_update:
self.log_entries.append(" Route updated " + r1.last_update[0] + ": " + r1.readable_name())
self.routes.add(r1)
if index2 is None and r2 not in self.routes and r2.last_update:
self.updated_routes.add(r1)
if index2 is None and r2.last_update \
and (index1 is not None or r1 != r2):
self.log_entries.append(" Route updated " + r2.last_update[0] + ": " + r2.readable_name())
self.routes.add(r2)
self.updated_routes.add(r2)
continue
# are either of the labels used duplicates?
duplicate = False
Expand All @@ -1681,10 +1676,9 @@ def __init__(self,travelername,update,el,path="../../../UserData/list_files"):
# if both labels reference the same waypoint...
if index1 == index2:
self.log_entries.append("Equivalent waypoint labels mark zero distance traveled in line: " + line)
if r1 not in self.routes:
self.routes.add(r1)
if r1.last_update:
self.log_entries.append(" Route updated " + r1.last_update[0] + ": " + r1.readable_name())
if r1.last_update:
self.updated_routes.add(r1)
self.log_entries.append(" Route updated " + r1.last_update[0] + ": " + r1.readable_name())
continue
if index1 <= index2:
r1.store_traveled_segments(self, index1, index2)
Expand Down Expand Up @@ -3677,10 +3671,10 @@ def run(self):
# updated routes, sorted by date
t.log_entries.append("\nMost recent updates for listed routes:")
route_list = []
for r in t.routes:
for r in t.updated_routes:
if r.last_update:
route_list.append(r)
del t.routes
del t.updated_routes
route_list.sort(key=lambda r: r.last_update[0]+r.last_update[3])
for r in route_list:
t.log_entries.append(r.last_update[0] + " | " + r.last_update[1] + " | " + \
Expand Down