From f3d7adb57e0b3f1b897c8a497d4665e7849df91a Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Tue, 2 Feb 2021 23:24:40 -0800 Subject: [PATCH] add reverse --- gmap.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/gmap.py b/gmap.py index f3d7605..9d2065b 100644 --- a/gmap.py +++ b/gmap.py @@ -18,10 +18,11 @@ matrix_retrieve_url = "https://matrix.router.hereapi.com/v8/matrix/{0}" granularity = 0.0050 commute_range = 75 work_group_size = 100 -color_scale_width = 50 +color_scale_width = 60 # this is equal to minutes until full red saturation, 60 == 60 minutes alpha = "70" blot_size = 13 map_scale = 11 +reverse = True def get_bearer_token(): data = {"grant_type": "client_credentials"} @@ -57,9 +58,16 @@ class Worker(threading.Thread): if tup is not None: start_points.append({'lat': tup[0], 'lng': tup[1]}) + if self.backwards is True: + origins = [self.destination] + destinations = start_points + else: + origins = start_points + destinations = [self.destination] + request_payload = { - "origins": start_points, - "destinations": [self.destination], + "origins": origins, + "destinations": destinations, "regionDefinition": { "type": "world", # "type": "circle", @@ -118,7 +126,8 @@ class Worker(threading.Thread): pass tup = (tup[1], tup[0]) - col_val = int((timelen / 60)) + col_val = int((timelen / 60)) # set the color bucket to the number of minutes + # so this means that full saturation will == the number of minutes when setting color_scale_width if error is True: marker = CircleMarker(tup, "blue", 6) @@ -126,9 +135,15 @@ class Worker(threading.Thread): # the + 70 here is just setting the aplha value marker = CircleMarker(tup, Color("red").get_hex_l() + alpha, blot_size) else: - marker = CircleMarker(tup, colors[col_val].get_hex_l() + alpha, blot_size) + if col_val == color_scale_width / 2: + marker = CircleMarker(tup, colors[col_val].get_hex_l() + "FF", blot_size) + else: + marker = CircleMarker(tup, colors[col_val].get_hex_l() + alpha, blot_size) + self.graphical_map.add_marker(marker) + print("Done with this one") + def entry(): @@ -139,7 +154,7 @@ def entry(): graphical_map = StaticMap(3000, 3000, url_template=url) # Since we are testing commute-to, we set the destination of "work" - destination_point = {'lat': 47.7599606, "lng": -122.1858287} + destination_point = {'lat': 47.5121104, "lng": -121.8852897} # Populate this list with an complete xy grid of points centered on destination_point coord_grid = [] @@ -155,7 +170,7 @@ def entry(): # dispatch the workers to the pool worker_pool = [] for coord_batch in group_elements(coord_grid, work_group_size): - w = Worker(destination_point, coord_batch, graphical_map, access_token) + w = Worker(destination_point, coord_batch, graphical_map, access_token, backwards=reverse) w.start() worker_pool.append(w)