From 5b8b8d748f98c6c9b300a10f77e4b4783afe0538 Mon Sep 17 00:00:00 2001 From: eric bryant Date: Sat, 30 Mar 2019 14:19:04 -0400 Subject: [PATCH 1/2] traveled graphs: record only relevant travelers https://github.com/TravelMapping/DataProcessing/issues/199 --- siteupdate/python-teresco/siteupdate.py | 37 +++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/siteupdate/python-teresco/siteupdate.py b/siteupdate/python-teresco/siteupdate.py index daea5a2c..0d1c2cce 100755 --- a/siteupdate/python-teresco/siteupdate.py +++ b/siteupdate/python-teresco/siteupdate.py @@ -1800,6 +1800,7 @@ def matching_traveled_edges(self, mv, regions=None, systems=None, # return a set of edges for the traveled graph format, # optionally restricted by region or system or placeradius edge_set = set() + trav_set = set() for v in mv: if v.visibility < 1: continue @@ -1813,7 +1814,9 @@ def matching_traveled_edges(self, mv, regions=None, systems=None, system_match = True if system_match: edge_set.add(e) - return edge_set + for t in e.segment.clinched_by: + trav_set.add(t) + return (edge_set, sorted(trav_set, key=lambda TravelerList: TravelerList.traveler_name)) # write the entire set of highway data a format very similar to # the original .gra format. The first line is a header specifying @@ -1934,14 +1937,21 @@ def write_master_tmg_traveled(self, filename, traveler_lists): # restricted by regions in the list if given, # by systems in the list if given, # or to within a given area if placeradius is given - def write_subgraphs_tmg(self, graph_list, path, root, descr, category, regions, systems, placeradius, traveler_lists): + def write_subgraphs_tmg(self, graph_list, path, root, descr, category, regions, systems, placeradius): simplefile = open(path+root+"-simple.tmg","w",encoding='utf-8') collapfile = open(path+root+".tmg","w",encoding='utf-8') travelfile = open(path+root+"-traveled.tmg","w",encoding='utf-8') (mv, cv_count, tv_count) = self.matching_vertices(regions, systems, placeradius, self.rg_vset_hash) mse = self.matching_simple_edges(mv, regions, systems, placeradius) mce = self.matching_collapsed_edges(mv, regions, systems, placeradius) - mte = self.matching_traveled_edges(mv, regions, systems, placeradius) + (mte, traveler_lists) = self.matching_traveled_edges(mv, regions, systems, placeradius) + """if len(traveler_lists) == 0: + print("\n\nNo travelers in " + root + "\n", flush=True)#""" + # assign traveler numbers + travnum = 0 + for t in traveler_lists: + t.traveler_num = travnum + travnum += 1 print('(' + str(len(mv)) + ',' + str(len(mse)) + ") ", end="", flush=True) print('(' + str(cv_count) + ',' + str(len(mce)) + ") ", end="", flush=True) print('(' + str(tv_count) + ',' + str(len(mte)) + ") ", end="", flush=True) @@ -3044,8 +3054,7 @@ def run(self): for a in area_list: print(a.base + '(' + str(a.r) + ') ', end="", flush=True) graph_data.write_subgraphs_tmg(graph_list, args.graphfilepath + "/", a.base + str(a.r) + "-area", - a.place + " (" + str(a.r) + " mi radius)", "area", None, None, a, - traveler_lists) + a.place + " (" + str(a.r) + " mi radius)", "area", None, None, a) graph_types.append(['area', 'Routes Within a Given Radius of a Place', 'These graphs contain all routes currently plotted within the given distance radius of the given place.']) print("!") @@ -3063,8 +3072,7 @@ def run(self): region_type = r[4] print(region_code + ' ', end="",flush=True) graph_data.write_subgraphs_tmg(graph_list, args.graphfilepath + "/", region_code + "-region", - region_name + " (" + region_type + ")", "region", [ region_code ], None, None, - traveler_lists) + region_name + " (" + region_type + ")", "region", [ region_code ], None, None) graph_types.append(['region', 'Routes Within a Single Region', 'These graphs contain all routes currently plotted within the given region.']) print("!") @@ -3088,8 +3096,7 @@ def run(self): if h is not None: print(h.systemname + ' ', end="",flush=True) graph_data.write_subgraphs_tmg(graph_list, args.graphfilepath + "/", h.systemname+"-system", - h.systemname + " (" + h.fullname + ")", "system", None, [ h ], None, - traveler_lists) + h.systemname + " (" + h.fullname + ")", "system", None, [ h ], None) if h is not None: graph_types.append(['system', 'Routes Within a Single Highway System', 'These graphs contain the routes within a single highway system and are not restricted by region.']) @@ -3114,8 +3121,7 @@ def run(self): if h.systemname in selected_systems: systems.append(h) graph_data.write_subgraphs_tmg(graph_list, args.graphfilepath + "/", fields[1], - fields[0], "multisystem", None, systems, None, - traveler_lists) + fields[0], "multisystem", None, systems, None) graph_types.append(['multisystem', 'Routes Within Multiple Highway Systems', 'These graphs contain the routes within a set of highway systems.']) print("!") @@ -3139,8 +3145,7 @@ def run(self): if r[0] in selected_regions and r[0] in active_preview_mileage_by_region: region_list.append(r[0]) graph_data.write_subgraphs_tmg(graph_list, args.graphfilepath + "/", fields[1], - fields[0], "multiregion", region_list, None, None, - traveler_lists) + fields[0], "multiregion", region_list, None, None) graph_types.append(['multiregion', 'Routes Within Multiple Regions', 'These graphs contain the routes within a set of regions.']) print("!") @@ -3159,8 +3164,7 @@ def run(self): if len(region_list) >= 2: print(c[0] + " ", end="", flush=True) graph_data.write_subgraphs_tmg(graph_list, args.graphfilepath + "/", c[0] + "-country", - c[1] + " All Routes in Country", "country", region_list, None, None, - traveler_lists) + c[1] + " All Routes in Country", "country", region_list, None, None) graph_types.append(['country', 'Routes Within a Single Multi-Region Country', 'These graphs contain the routes within a single country that is composed of multiple regions that contain plotted routes. Countries consisting of a single region are represented by their regional graph.']) print("!") @@ -3177,8 +3181,7 @@ def run(self): if len(region_list) >= 1: print(c[0] + " ", end="", flush=True) graph_data.write_subgraphs_tmg(graph_list, args.graphfilepath + "/", c[0] + "-continent", - c[1] + " All Routes on Continent", "continent", region_list, None, None, - traveler_lists) + c[1] + " All Routes on Continent", "continent", region_list, None, None) graph_types.append(['continent', 'Routes Within a Continent', 'These graphs contain the routes on a continent.']) print("!") From e815c31e2ae767f9db71cb6b304cc2141a445a52 Mon Sep 17 00:00:00 2001 From: eric bryant Date: Tue, 23 Apr 2019 17:18:22 -0400 Subject: [PATCH 2/2] finalizing traveled graphs https://github.com/TravelMapping/DataProcessing/issues/199 https://github.com/TravelMapping/DataProcessing/pull/201 --- siteupdate/python-teresco/siteupdate.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/siteupdate/python-teresco/siteupdate.py b/siteupdate/python-teresco/siteupdate.py index a6fd6fb0..66c72001 100755 --- a/siteupdate/python-teresco/siteupdate.py +++ b/siteupdate/python-teresco/siteupdate.py @@ -727,6 +727,8 @@ def clinchedby_code(self, traveler_lists): # The 2nd character stores traveler 4 thru traveler 7, etc. # For each character, the low-order bit stores traveler n, and the high bit traveler n+3. + if len(traveler_lists) == 0: + return "0" code = "" clinch_array = [0]*( math.ceil(len(traveler_lists)/4) ) for t in self.clinched_by: @@ -1901,7 +1903,8 @@ def write_master_tmg_traveled(self, filename, traveler_lists): tmgfile = open(filename, 'w') tmgfile.write("TMG 2.0 traveled\n") tmgfile.write(str(self.num_traveled_vertices()) + " " + - str(self.traveled_edge_count()) + "\n") + str(self.traveled_edge_count()) + " " + + str(len(traveler_lists)) + "\n") # write visible vertices t_vertex_num = 0 @@ -1940,7 +1943,7 @@ def write_master_tmg_traveled(self, filename, traveler_lists): # or to within a given area if placeradius is given def write_subgraphs_tmg(self, graph_list, path, root, descr, category, regions, systems, placeradius): simplefile = open(path+root+"-simple.tmg","w",encoding='utf-8') - collapfile = open(path+root+".tmg","w",encoding='utf-8') + collapfile = open(path+root+"-collapsed.tmg","w",encoding='utf-8') travelfile = open(path+root+"-traveled.tmg","w",encoding='utf-8') (mv, cv_count, tv_count) = self.matching_vertices(regions, systems, placeradius, self.rg_vset_hash) mse = self.matching_simple_edges(mv, regions, systems, placeradius) @@ -1961,7 +1964,7 @@ def write_subgraphs_tmg(self, graph_list, path, root, descr, category, regions, travelfile.write("TMG 2.0 traveled\n") simplefile.write(str(len(mv)) + ' ' + str(len(mse)) + '\n') collapfile.write(str(cv_count) + ' ' + str(len(mce)) + '\n') - travelfile.write(str(tv_count) + ' ' + str(len(mte)) + '\n') + travelfile.write(str(tv_count) + ' ' + str(len(mte)) + ' ' + str(len(traveler_lists)) + '\n') # write vertices sv = 0 @@ -2000,9 +2003,9 @@ def write_subgraphs_tmg(self, graph_list, path, root, descr, category, regions, collapfile.close() travelfile.close() - graph_list.append(GraphListEntry(root+ "-simple.tmg", descr, len(mv), len(mse), "simple", category)) - graph_list.append(GraphListEntry(root+ ".tmg", descr, cv_count, len(mce), "collapsed", category)) - graph_list.append(GraphListEntry(root+"-traveled.tmg", descr, tv_count, len(mte), "traveled", category)) + graph_list.append(GraphListEntry(root+ "-simple.tmg", descr, len(mv), len(mse), "simple", category)) + graph_list.append(GraphListEntry(root+"-collapsed.tmg", descr, cv_count, len(mce), "collapsed", category)) + graph_list.append(GraphListEntry(root+ "-traveled.tmg", descr, tv_count, len(mte), "traveled", category)) def format_clinched_mi(clinched,total): """return a nicely-formatted string for a given number of miles @@ -3028,9 +3031,9 @@ def run(self): (sv, se) = graph_data.write_master_tmg_simple(args.graphfilepath+'/tm-master-simple.tmg') graph_list.append(GraphListEntry('tm-master-simple.tmg', 'All Travel Mapping Data', sv, se, 'simple', 'master')) - print(et.et() + "Writing master TM collapsed graph file, tm-master.tmg.", flush=True) - (cv, ce) = graph_data.write_master_tmg_collapsed(args.graphfilepath+'/tm-master.tmg') - graph_list.append(GraphListEntry('tm-master.tmg', 'All Travel Mapping Data', cv, ce, 'collapsed', 'master')) + print(et.et() + "Writing master TM collapsed graph file, tm-master-collapsed.tmg.", flush=True) + (cv, ce) = graph_data.write_master_tmg_collapsed(args.graphfilepath+'/tm-master-collapsed.tmg') + graph_list.append(GraphListEntry('tm-master-collapsed.tmg', 'All Travel Mapping Data', cv, ce, 'collapsed', 'master')) print(et.et() + "Writing master TM traveled graph file, tm-master-traveled.tmg.", flush=True) (tv, te) = graph_data.write_master_tmg_traveled(args.graphfilepath+'/tm-master-traveled.tmg', traveler_lists)