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)