From 4a7b4084f7850f9e7a01300059f03834b56a8028 Mon Sep 17 00:00:00 2001 From: Eric Bryant Date: Wed, 27 Apr 2022 12:52:21 -0400 Subject: [PATCH 1/4] 523: remove redundant active/preview mileage allbyregionactiveonly.csv allbyregionactivepreview.csv --- .../functions/allbyregionactiveonly.cpp | 10 +++------- .../functions/allbyregionactivepreview.cpp | 10 +++------- siteupdate/cplusplus/siteupdate.cpp | 16 ++++++++-------- siteupdate/python-teresco/siteupdate.py | 4 ++-- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/siteupdate/cplusplus/functions/allbyregionactiveonly.cpp b/siteupdate/cplusplus/functions/allbyregionactiveonly.cpp index 573d1da3..3cc543da 100644 --- a/siteupdate/cplusplus/functions/allbyregionactiveonly.cpp +++ b/siteupdate/cplusplus/functions/allbyregionactiveonly.cpp @@ -4,18 +4,14 @@ #include "../threads/threads.h" #include -void allbyregionactiveonly(std::mutex* mtx) -{ double total_mi; - char fstr[112]; +void allbyregionactiveonly(std::mutex* mtx, double total_mi) +{ char fstr[112]; std::ofstream allfile(Args::csvstatfilepath + "/allbyregionactiveonly.csv"); allfile << "Traveler,Total"; std::list regions; - total_mi = 0; for (Region* r : Region::allregions) if (r->active_only_mileage) - { regions.push_back(r); - total_mi += r->active_only_mileage; - } + regions.push_back(r); regions.sort(sort_regions_by_code); for (Region *region : regions) allfile << ',' << region->code; diff --git a/siteupdate/cplusplus/functions/allbyregionactivepreview.cpp b/siteupdate/cplusplus/functions/allbyregionactivepreview.cpp index 22fbba39..8320ff19 100644 --- a/siteupdate/cplusplus/functions/allbyregionactivepreview.cpp +++ b/siteupdate/cplusplus/functions/allbyregionactivepreview.cpp @@ -4,18 +4,14 @@ #include "../threads/threads.h" #include -void allbyregionactivepreview(std::mutex* mtx) -{ double total_mi; - char fstr[112]; +void allbyregionactivepreview(std::mutex* mtx, double total_mi) +{ char fstr[112]; std::ofstream allfile(Args::csvstatfilepath + "/allbyregionactivepreview.csv"); allfile << "Traveler,Total"; std::list regions; - total_mi = 0; for (Region* r : Region::allregions) if (r->active_preview_mileage) - { regions.push_back(r); - total_mi += r->active_preview_mileage; - } + regions.push_back(r); regions.sort(sort_regions_by_code); for (Region *region : regions) allfile << ',' << region->code; diff --git a/siteupdate/cplusplus/siteupdate.cpp b/siteupdate/cplusplus/siteupdate.cpp index 7170d41e..679c1822 100644 --- a/siteupdate/cplusplus/siteupdate.cpp +++ b/siteupdate/cplusplus/siteupdate.cpp @@ -41,8 +41,8 @@ This module defines classes to represent the contents of a #include #include "threads/threads.h" #endif -void allbyregionactiveonly(std::mutex*); -void allbyregionactivepreview(std::mutex*); +void allbyregionactiveonly(std::mutex*, double); +void allbyregionactivepreview(std::mutex*, double); using namespace std; int main(int argc, char *argv[]) @@ -579,22 +579,22 @@ int main(int argc, char *argv[]) { case 1: #endif cout << et.et() << "Writing allbyregionactiveonly.csv." << endl; - allbyregionactiveonly(0); + allbyregionactiveonly(0, active_only_miles); cout << et.et() << "Writing allbyregionactivepreview.csv." << endl; - allbyregionactivepreview(0); + allbyregionactivepreview(0, active_preview_miles); cout << et.et() << "Writing per-system stats csv files." << endl; for (HighwaySystem* h : HighwaySystem::syslist) h->stats_csv(); #ifdef threading_enabled break; case 2: - thr[0] = thread(allbyregionactiveonly, &list_mtx); - thr[1] = thread(allbyregionactivepreview, &list_mtx); + thr[0] = thread(allbyregionactiveonly, &list_mtx, active_only_miles); + thr[1] = thread(allbyregionactivepreview, &list_mtx, active_preview_miles); thr[0].join(); thr[1].join(); break; default: - thr[0] = thread(allbyregionactiveonly, (std::mutex*)0); - thr[1] = thread(allbyregionactivepreview, (std::mutex*)0); + thr[0] = thread(allbyregionactiveonly, nullptr, active_only_miles); + thr[1] = thread(allbyregionactivepreview, nullptr, active_preview_miles); thr[2] = thread(StatsCsvThread, 2, &list_mtx); thr[0].join(); thr[1].join(); diff --git a/siteupdate/python-teresco/siteupdate.py b/siteupdate/python-teresco/siteupdate.py index bd5b6547..63e06f6c 100755 --- a/siteupdate/python-teresco/siteupdate.py +++ b/siteupdate/python-teresco/siteupdate.py @@ -3668,7 +3668,7 @@ def run(self): else: allfile.write(',0') allfile.write('\n') -allfile.write('TOTAL,{0:.2f}'.format(math.fsum(active_only_mileage_by_region.values()))) +allfile.write('TOTAL,{0:.2f}'.format(active_only_miles)) for region in regions: allfile.write(',{0:.2f}'.format(active_only_mileage_by_region[region])) allfile.write('\n') @@ -3689,7 +3689,7 @@ def run(self): else: allfile.write(',0') allfile.write('\n') -allfile.write('TOTAL,{0:.2f}'.format(math.fsum(active_preview_mileage_by_region.values()))) +allfile.write('TOTAL,{0:.2f}'.format(active_preview_miles)) for region in regions: allfile.write(',{0:.2f}'.format(active_preview_mileage_by_region[region])) allfile.write('\n') From 124f24b855c39f9aedeb840534aeee68833e2257 Mon Sep 17 00:00:00 2001 From: Eric Bryant Date: Wed, 27 Apr 2022 12:55:31 -0400 Subject: [PATCH 2/4] 522B: redundant active/preview system counts user logs --- .../classes/HighwaySystem/HighwaySystem.cpp | 7 +++- .../classes/HighwaySystem/HighwaySystem.h | 2 ++ .../classes/TravelerList/userlog.cpp | 19 ++++------- siteupdate/python-teresco/siteupdate.py | 33 +++++++++---------- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp b/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp index 0ee45329..13ad8abc 100644 --- a/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp +++ b/siteupdate/cplusplus/classes/HighwaySystem/HighwaySystem.cpp @@ -12,6 +12,8 @@ std::list HighwaySystem::syslist; std::list::iterator HighwaySystem::it; +unsigned int HighwaySystem::num_active = 0; +unsigned int HighwaySystem::num_preview = 0; HighwaySystem::HighwaySystem(std::string &line, ErrorList &el, std::vector> &countries) { std::ifstream file; @@ -54,7 +56,10 @@ HighwaySystem::HighwaySystem(std::string &line, ErrorList &el, std::vector syslist; static std::list::iterator it; + static unsigned int num_active; + static unsigned int num_preview; HighwaySystem(std::string &, ErrorList &, std::vector> &); diff --git a/siteupdate/cplusplus/classes/TravelerList/userlog.cpp b/siteupdate/cplusplus/classes/TravelerList/userlog.cpp index 2afbf4b9..4d7b45e5 100644 --- a/siteupdate/cplusplus/classes/TravelerList/userlog.cpp +++ b/siteupdate/cplusplus/classes/TravelerList/userlog.cpp @@ -29,17 +29,10 @@ void TravelerList::userlog(const double total_active_only_miles, const double to << format_clinched_mi(active_preview_mileage_by_region.at(region), region->active_preview_mileage) << '\n'; } - unsigned int active_systems = 0; - unsigned int preview_systems = 0; - - // present stats by system here, also generate entries for - // DB table clinchedSystemMileageByRegion as we compute and - // have the data handy + // stats by system for (HighwaySystem *h : HighwaySystem::syslist) if (h->active_or_preview()) - { if (h->active()) active_systems++; - else preview_systems++; - double t_system_overall = 0; + { double t_system_overall = 0; if (system_region_mileages.count(h)) t_system_overall = system_region_miles(h); if (t_system_overall) @@ -110,13 +103,13 @@ void TravelerList::userlog(const double total_active_only_miles, const double to // grand summary, active only sprintf(fstr,"\nTraveled %i of %i (%.1f%%), Clinched %i of %i (%.1f%%) active systems", - active_systems_traveled, active_systems, 100*(double)active_systems_traveled/active_systems, - active_systems_clinched, active_systems, 100*(double)active_systems_clinched/active_systems); + active_systems_traveled, HighwaySystem::num_active, 100*(double)active_systems_traveled/HighwaySystem::num_active, + active_systems_clinched, HighwaySystem::num_active, 100*(double)active_systems_clinched/HighwaySystem::num_active); log << fstr << '\n'; // grand summary, active+preview sprintf(fstr,"Traveled %i of %i (%.1f%%), Clinched %i of %i (%.1f%%) preview systems", - preview_systems_traveled, preview_systems, 100*(double)preview_systems_traveled/preview_systems, - preview_systems_clinched, preview_systems, 100*(double)preview_systems_clinched/preview_systems); + preview_systems_traveled, HighwaySystem::num_preview, 100*(double)preview_systems_traveled/HighwaySystem::num_preview, + preview_systems_clinched, HighwaySystem::num_preview, 100*(double)preview_systems_clinched/HighwaySystem::num_preview); log << fstr << '\n'; // updated routes, sorted by date diff --git a/siteupdate/python-teresco/siteupdate.py b/siteupdate/python-teresco/siteupdate.py index 63e06f6c..47a4f1b0 100755 --- a/siteupdate/python-teresco/siteupdate.py +++ b/siteupdate/python-teresco/siteupdate.py @@ -1307,6 +1307,9 @@ class HighwaySystem: a designation within the same system crosses region boundaries, a connected route defines the entirety of the route. """ + num_active = 0 + num_preview = 0 + def __init__(self,systemname,country,fullname,color,tier,level,el, path="../../../HighwayData/hwy_data/_systems"): self.route_list = [] @@ -2812,6 +2815,10 @@ def __init__(self,filename,descr,vertices,edges,travelers,format,category): # verify Level if fields[5] != "active" and fields[5] != "preview" and fields[5] != "devel": el.add_error("Unrecognized level in " + args.systemsfile + " line: " + line) + elif fields[5] == "preview": + HighwaySystem.num_preview += 1 + elif fields[5] == "active": + HighwaySystem.num_active += 1 print(fields[0] + ".",end="",flush=True) hs = HighwaySystem(fields[0], fields[1], fields[2], @@ -3540,18 +3547,10 @@ def run(self): t.active_systems_clinched = 0 t.preview_systems_traveled = 0 t.preview_systems_clinched = 0 - active_systems = 0 - preview_systems = 0 - # present stats by system here, also generate entries for - # DB table clinchedSystemMileageByRegion as we compute and - # have the data handy + # stats by system for h in highway_systems: if h.active_or_preview(): - if h.active(): - active_systems += 1 - else: - preview_systems += 1 t_system_overall = 0.0 if h.systemname in t.system_region_mileages: t_system_overall = math.fsum(t.system_region_mileages[h.systemname].values()) @@ -3620,16 +3619,16 @@ def run(self): # grand summary, active only - t.log_entries.append("\nTraveled " + str(t.active_systems_traveled) + " of " + str(active_systems) + - " ({0:.1f}%)".format(100*t.active_systems_traveled/active_systems) + - ", Clinched " + str(t.active_systems_clinched) + " of " + str(active_systems) + - " ({0:.1f}%)".format(100*t.active_systems_clinched/active_systems) + + t.log_entries.append("\nTraveled " + str(t.active_systems_traveled) + " of " + str(HighwaySystem.num_active) + + " ({0:.1f}%)".format(100*t.active_systems_traveled/HighwaySystem.num_active) + + ", Clinched " + str(t.active_systems_clinched) + " of " + str(HighwaySystem.num_active) + + " ({0:.1f}%)".format(100*t.active_systems_clinched/HighwaySystem.num_active) + " active systems") # grand summary, active+preview - t.log_entries.append("Traveled " + str(t.preview_systems_traveled) + " of " + str(preview_systems) + - " ({0:.1f}%)".format(100*t.preview_systems_traveled/preview_systems) + - ", Clinched " + str(t.preview_systems_clinched) + " of " + str(preview_systems) + - " ({0:.1f}%)".format(100*t.preview_systems_clinched/preview_systems) + + t.log_entries.append("Traveled " + str(t.preview_systems_traveled) + " of " + str(HighwaySystem.num_preview) + + " ({0:.1f}%)".format(100*t.preview_systems_traveled/HighwaySystem.num_preview) + + ", Clinched " + str(t.preview_systems_clinched) + " of " + str(HighwaySystem.num_preview) + + " ({0:.1f}%)".format(100*t.preview_systems_clinched/HighwaySystem.num_preview) + " preview systems") # updated routes, sorted by date t.log_entries.append("\nMost recent updates for listed routes:") From dd4231d13dae5a82f1329816335543b5e93d31ab Mon Sep 17 00:00:00 2001 From: Eric Bryant Date: Wed, 27 Apr 2022 12:58:07 -0400 Subject: [PATCH 3/4] y220: snip vestigial variable --- siteupdate/cplusplus/threads/ReadListThread.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/siteupdate/cplusplus/threads/ReadListThread.cpp b/siteupdate/cplusplus/threads/ReadListThread.cpp index d5a07daf..2e8e42e7 100644 --- a/siteupdate/cplusplus/threads/ReadListThread.cpp +++ b/siteupdate/cplusplus/threads/ReadListThread.cpp @@ -12,7 +12,6 @@ void ReadListThread(unsigned int id, std::mutex* tl_mtx, ErrorList* el) //printf("ReadListThread %02i (*it)++\n", id); fflush(stdout); std::cout << tl << ' ' << std::flush; tl_mtx->unlock(); - std::string** update; TravelerList *t = new TravelerList(tl, el); // deleted on termination of program TravelerList::mtx.lock(); From 29a6edfddc1132bfac95e0bbc59157f27fade551 Mon Sep 17 00:00:00 2001 From: Eric Bryant Date: Tue, 26 Apr 2022 16:37:37 -0400 Subject: [PATCH 4/4] userlog speedup: chopped routes display interactive rebase 04eb795 --- .../classes/TravelerList/userlog.cpp | 24 +++++++++++-------- .../functions/format_clinched_mi.cpp | 13 ++++------ .../cplusplus/functions/format_clinched_mi.h | 3 +-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/siteupdate/cplusplus/classes/TravelerList/userlog.cpp b/siteupdate/cplusplus/classes/TravelerList/userlog.cpp index 4d7b45e5..112be699 100644 --- a/siteupdate/cplusplus/classes/TravelerList/userlog.cpp +++ b/siteupdate/cplusplus/classes/TravelerList/userlog.cpp @@ -13,8 +13,8 @@ void TravelerList::userlog(const double total_active_only_miles, const double to std::cout << "." << std::flush; std::ofstream log(Args::logfilepath+"/users/"+traveler_name+".log", std::ios::app); log << "Clinched Highway Statistics\n"; - log << "Overall in active systems: " << format_clinched_mi(active_only_miles(), total_active_only_miles) << '\n'; - log << "Overall in active+preview systems: " << format_clinched_mi(active_preview_miles(), total_active_preview_miles) << '\n'; + log << "Overall in active systems: " << format_clinched_mi(fstr, active_only_miles(), total_active_only_miles) << '\n'; + log << "Overall in active+preview systems: " << format_clinched_mi(fstr, active_preview_miles(), total_active_preview_miles) << '\n'; log << "Overall by region: (each line reports active only then active+preview)\n"; std::list travregions; @@ -25,8 +25,8 @@ void TravelerList::userlog(const double total_active_only_miles, const double to { double t_active_miles = 0; if (active_only_mileage_by_region.count(region)) t_active_miles = active_only_mileage_by_region.at(region); - log << region->code << ": " << format_clinched_mi(t_active_miles, region->active_only_mileage) << ", " - << format_clinched_mi(active_preview_mileage_by_region.at(region), region->active_preview_mileage) << '\n'; + log << region->code << ": " << format_clinched_mi(fstr, t_active_miles, region->active_only_mileage) << ", " + << format_clinched_mi(fstr, active_preview_mileage_by_region.at(region), region->active_preview_mileage) << '\n'; } // stats by system @@ -50,7 +50,7 @@ void TravelerList::userlog(const double total_active_only_miles, const double to auto& systemname = h->systemname; auto& sysmbr = h->mileage_by_region; log << "System " << systemname << " (" << h->level_name() << ") overall: " - << format_clinched_mi(t_system_overall, h->total_mileage()) << '\n'; + << format_clinched_mi(fstr, t_system_overall, h->total_mileage()) << '\n'; if (sysmbr.size() > 1) { log << "System " << systemname << " by region:\n"; std::list sysregions; @@ -62,7 +62,7 @@ void TravelerList::userlog(const double total_active_only_miles, const double to auto it = system_region_mileages.at(h).find(region); if (it != system_region_mileages.at(h).end()) system_region_mileage = it->second; - log << " " << region->code << ": " << format_clinched_mi(system_region_mileage, sysmbr.at(region)) << '\n'; + log << " " << region->code << ": " << format_clinched_mi(fstr, system_region_mileage, sysmbr.at(region)) << '\n'; } } @@ -73,7 +73,7 @@ void TravelerList::userlog(const double total_active_only_miles, const double to log << "System " << systemname << " by route (traveled routes only):\n"; for (ConnectedRoute *cr : h->con_route_list) { double con_clinched_miles = 0; - std::string to_write = ""; + std::vector> chop_mi; auto& roots = cr->roots; for (Route *r : roots) { // find traveled mileage on this by this user @@ -81,17 +81,21 @@ void TravelerList::userlog(const double total_active_only_miles, const double to if (miles) { cr_values.emplace_back(r, miles); con_clinched_miles += miles; - to_write += " " + r->readable_name() + ": " + format_clinched_mi(miles,r->mileage) + "\n"; + chop_mi.emplace_back(r, miles); } } if (con_clinched_miles) { num_con_rtes_traveled += 1; num_con_rtes_clinched += (con_clinched_miles == cr->mileage); ccr_values.emplace_back(cr, con_clinched_miles); - log << cr->readable_name() << ": " << format_clinched_mi(con_clinched_miles, cr->mileage) << '\n'; + log << cr->readable_name() << ": " << format_clinched_mi(fstr, con_clinched_miles, cr->mileage) << '\n'; if (roots.size() == 1) log << " (" << roots[0]->readable_name() << " only)\n"; - else log << to_write << '\n'; + else { for (auto& rm : chop_mi) + log << " " << rm.first->readable_name() << ": " + << format_clinched_mi(fstr, rm.second,rm.first->mileage) << "\n"; + log << '\n'; + } } } sprintf(fstr, " connected routes traveled: %i of %i (%.1f%%), clinched: %i of %i (%.1f%%).", diff --git a/siteupdate/cplusplus/functions/format_clinched_mi.cpp b/siteupdate/cplusplus/functions/format_clinched_mi.cpp index d94f771b..dc2a9414 100644 --- a/siteupdate/cplusplus/functions/format_clinched_mi.cpp +++ b/siteupdate/cplusplus/functions/format_clinched_mi.cpp @@ -1,14 +1,11 @@ #include "format_clinched_mi.h" +#include -std::string format_clinched_mi(double clinched, double total) +char* format_clinched_mi(char* str, double clinched, double total) { /* return a nicely-formatted string for a given number of miles clinched and total miles, including percentage */ - char str[37]; - std::string percentage = "-.--%"; if (total) - { sprintf(str, "(%0.2f%%)", 100*clinched/total); - percentage = str; - } - sprintf(str, "%0.2f of %0.2f mi ", clinched, total); - return str + percentage; + sprintf(str, "%0.2f of %0.2f mi (%0.2f%%)", clinched, total, 100*clinched/total); + else sprintf(str, "%0.2f of %0.2f mi -.--%%", clinched, total); + return str; } diff --git a/siteupdate/cplusplus/functions/format_clinched_mi.h b/siteupdate/cplusplus/functions/format_clinched_mi.h index 3c135a17..9344ebdc 100644 --- a/siteupdate/cplusplus/functions/format_clinched_mi.h +++ b/siteupdate/cplusplus/functions/format_clinched_mi.h @@ -1,2 +1 @@ -#include -std::string format_clinched_mi(double, double); +char* format_clinched_mi(char*, double, double);