Martin 6 жил өмнө
parent
commit
86087a00ee
5 өөрчлөгдсөн 112 нэмэгдсэн , 12 устгасан
  1. 1 1
      commute.py
  2. 9 8
      config.py
  3. 2 1
      properties.py
  4. 5 2
      visualize.py
  5. 95 0
      visualize_map.py

+ 1 - 1
commute.py

@@ -239,7 +239,7 @@ def analyze_locations(commutes, num_locations):
             target_loc = (lat, lon)
             closest_dist = geo_util.ggcd(target_loc, closest)
 
-            if (closest_dist > 300 and any(geo_util.inside(target_loc, bbox) for bbox in config.MONITORED_BBOXES)):
+            if (closest_dist > 300 and any(geo_util.inside(target_loc, bbox) for bbox in config.MONITORED_BBOXES.values())):
                 to_load.append(target_loc)
             elif closest_dist <= 300:
                 durations.append(commutes[closest]['duration'] + closest_dist)

+ 9 - 8
config.py

@@ -17,14 +17,15 @@ MONITORED_LOCALITIES = [
     2712, # Co Meath
 ]
 
-MONITORED_BBOXES = [
-    ((53, -6.9), (53.85, -5.9)), # Overall
-    ((53.358687,-6.219396), (53.371389,-6.168778)), # Clontarf
-    ((53.355553,-6.108301), (53.397744,-6.031430)), # Howth
-    ((53.459195,-6.173369), (53.588187,-6.060123)), # NE
-    ((53.450280,-6.190388), (53.456924,-6.158301)), # Malahide estuary
-    ((53.265768,-6.127407), (53.290505,-6.081422)), # Dalkey, Killiney
-]
+MONITORED_BBOXES = {
+    '1 Overall': ((53, -6.9), (53.85, -5.9)),
+    '2 Clontarf': ((53.360213,-6.209679), (53.386021,-6.138611)),
+    '3 Howth': ((53.355553,-6.108301), (53.397744,-6.031430)),
+    '4 Malahide estuary': ((53.450280,-6.190388), (53.456924,-6.158301)),
+    '5 Skerries': ((53.562193,-6.157150), (53.588490,-6.088829)),
+    '6 Dalkey, Killiney': ((53.265768,-6.127407), (53.290505,-6.081422)),
+}
+VISUALIZED_BBOXES = {k: v for k, v in MONITORED_BBOXES.items() if k != 'Overallx'}
 
 WORKPLACE = (53.353361,-6.247984)
 WORKPLACE_TARGET_TIME = 1540893600 # tue 10:00

+ 2 - 1
properties.py

@@ -13,7 +13,7 @@ def load_properties(require_active, require_update_since):
             if not price or not size or not lat or not lon:
                 continue
 
-            if not any(geo_util.inside((lat, lon), bbox) for bbox in config.MONITORED_BBOXES):
+            if not any(geo_util.inside((lat, lon), bbox) for bbox in config.MONITORED_BBOXES.values()):
                 continue
 
             price = price/1000
@@ -47,6 +47,7 @@ def load_properties(require_active, require_update_since):
                 res[pid]['price'] = price/1000
             
             res[pid]['price_history'].append(price)
+            res[pid]['ts'] = time
 
         if require_active:
             res = {k: v for k, v in res.items() if v['price_history'] and v['price_history'][-1] != 'GONE'}

+ 5 - 2
visualize.py

@@ -6,13 +6,14 @@ import properties
 import ranking
 import util
 import datetime
+import visualize_map
 
 def _write_bboxes(f):
     f.write('''
     <Folder>
         <visibility>0</visibility>
         <name>Monitored bboxes</name>\n''')
-    for (lat1, lon1), (lat2, lon2) in config.MONITORED_BBOXES:
+    for (lat1, lon1), (lat2, lon2) in config.VISUALIZED_BBOXES.values():
         f.write('<Placemark><LineString><coordinates>')
         f.write('%s,%s' % (lon1, lat1))
         f.write(' %s,%s' % (lon1, lat2))
@@ -127,7 +128,7 @@ def _set_tmp_ids(properties_dict):
     return res
 
 def run():
-    load_since = datetime.datetime.now() - datetime.timedelta(days=180)
+    load_since = datetime.datetime.now() - datetime.timedelta(days=365)
     properties_dict = properties.load_properties(True, load_since)
     print('Loaded %i properties' % len(properties_dict))
 
@@ -150,5 +151,7 @@ def run():
     tmp_ids = _set_tmp_ids(properties_dict)
     _write_kml(commutes, properties_dict, 'vis.kml', tmp_ids)
 
+    visualize_map.visualize(properties_dict)
+
 if __name__ == '__main__':
     run()

+ 95 - 0
visualize_map.py

@@ -0,0 +1,95 @@
+import datetime
+
+import geo_util
+import config
+import db
+
+# https://www.latlong.net/Show-Latitude-Longitude.html
+
+_BBOX = [
+    # (53.114059,-6.448975),
+    # (53.607418,-6.019135),
+    (53.244098,-6.394043),
+    (53.458048,-6.035614),
+]
+
+_POIS = [
+    ('H', (53.375669,-6.071320)), # Howth
+    ('D', (53.347949,-6.261520)), # Dublin city centre
+    ('D', (53.289498,-6.139984)), # Dun Laohaire
+    ('D', (53.278155,-6.107154)), # Dalkey
+    ('B', (53.200953,-6.112175)), # Bray
+    ('G', (53.143331,-6.072006)), # Graystones
+
+    ('S', (53.372233,-6.177664)), # St Annes Park
+    ('S', (53.369417,-6.193714)), # St Annes Park
+    ('S', (53.367266,-6.172686)), # St Annes Park
+    ('S', (53.374333,-6.166763)), # St Annes Park
+    ('S', (53.374896,-6.176205)), # St Annes Park
+    ('S', (53.372028,-6.185131)), # St Annes Park
+
+
+
+
+    ('M', (53.450095,-6.157150)), # Malahide
+
+    ('s', (53.585810,-6.142559)), # Skerries
+    ('s', (53.581734,-6.105652)), # Skerries
+    ('s', (53.566241,-6.098957)), # Skerries
+]
+
+# x, y resolution
+_RESOLUTION = 60
+
+def _get_pos(resolution, loc, corner_nw):
+    lat, lon = loc
+    lat_idx = int(resolution * geo_util.ggcd(loc, (corner_nw[0], lon)))
+    lon_idx = int(2 * resolution * geo_util.ggcd(loc, (lat, corner_nw[1])))
+    return lat_idx, lon_idx
+
+def _visualize(label, bbox, properties_dict):
+    ts_cutoff = db.datetime_to_str(datetime.datetime.now() - datetime.timedelta(days=14))
+    properties = [p for p in properties_dict.values()
+                  if geo_util.inside(p['loc'], bbox) and p['ts'] > ts_cutoff]
+    properties.sort(key=lambda p: p['score'])
+    if not properties:
+        return
+
+    corner_sw = bbox[0]
+    corner_ne = bbox[1]
+    corner_nw = (corner_ne[0], corner_sw[1])
+    corner_se = (corner_sw[0], corner_ne[1])
+    
+    width_m = geo_util.ggcd(corner_sw, corner_se)
+    height_m = geo_util.ggcd(corner_sw, corner_nw)
+    resolution = _RESOLUTION / max(width_m, height_m) # pixel per meter
+
+    symbols = [] # symbols[y][x]
+    for y in range(int(resolution * height_m) + 1):
+        symbols.append([])
+        for x in range(int(2 * resolution * width_m) + 1):
+            symbols[-1].append(' ')
+    
+    for symbol, loc in _POIS:
+        if geo_util.inside(loc, bbox):
+            lat_idx, lon_idx = _get_pos(resolution, loc, corner_nw)
+            symbols[lat_idx][lon_idx] = symbol
+    
+    for p in properties:
+        loc = p['loc']
+        lat_idx, lon_idx = _get_pos(resolution, loc, corner_nw)
+        symbols[lat_idx][lon_idx] = str(int(10*p['score']))
+
+    print()
+    print(label)
+    for line in symbols:
+        print(''.join(line))
+
+
+
+def visualize(properties_dict):
+    for label, bbox in sorted(config.VISUALIZED_BBOXES.items()):
+        _visualize(label, bbox, properties_dict)
+
+    
+