add comment to map plots

This commit is contained in:
KF7EEL 2021-03-02 12:41:03 -08:00
parent 888d8c19b7
commit d332604f26
3 changed files with 113 additions and 92 deletions

View File

@ -160,12 +160,12 @@ def aprs_send(packet):
AIS.close() AIS.close()
logger.info('Packet sent to APRS-IS.') logger.info('Packet sent to APRS-IS.')
def dashboard_loc_write(call, lat, lon, time): def dashboard_loc_write(call, lat, lon, time, comment):
#try: #try:
dash_entries = ast.literal_eval(os.popen('cat /tmp/gps_data_user_loc.txt').read()) dash_entries = ast.literal_eval(os.popen('cat /tmp/gps_data_user_loc.txt').read())
# except: # except:
# dash_entries = [] # dash_entries = []
dash_entries.insert(0, {'call': call, 'lat': lat, 'lon': lon, 'time':time}) dash_entries.insert(0, {'call': call, 'lat': lat, 'lon': lon, 'time':time, 'comment': comment})
with open("/tmp/gps_data_user_loc.txt", 'w') as user_loc_file: with open("/tmp/gps_data_user_loc.txt", 'w') as user_loc_file:
user_loc_file.write(str(dash_entries[:200])) user_loc_file.write(str(dash_entries[:200]))
user_loc_file.close() user_loc_file.close()
@ -366,7 +366,7 @@ def process_sms(_rf_src, sms):
try: try:
aprslib.parse(aprs_loc_packet) aprslib.parse(aprs_loc_packet)
aprs_send(aprs_loc_packet) aprs_send(aprs_loc_packet)
dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time()) dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time(), comment)
#logger.info('Sent manual position to APRS') #logger.info('Sent manual position to APRS')
except Exception as error_exception: except Exception as error_exception:
logger.info('Exception. Not uploaded') logger.info('Exception. Not uploaded')
@ -1550,7 +1550,7 @@ class routerHBP(HBSYSTEM):
float(lat_deg) < 91 float(lat_deg) < 91
float(lon_deg) < 121 float(lon_deg) < 121
aprs_send(aprs_loc_packet) aprs_send(aprs_loc_packet)
dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time()) dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time(), comment)
#logger.info('Sent APRS packet') #logger.info('Sent APRS packet')
except Exception as error_exception: except Exception as error_exception:
logger.info('Error. Failed to send packet. Packet may be malformed.') logger.info('Error. Failed to send packet. Packet may be malformed.')
@ -1652,7 +1652,7 @@ class routerHBP(HBSYSTEM):
float(loc.lat) float(loc.lat)
float(loc.lon) float(loc.lon)
aprs_send(aprs_loc_packet) aprs_send(aprs_loc_packet)
dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, str(loc.lat[0:7]) + str(loc.lat_dir), str(loc.lon[0:8]) + str(loc.lon_dir), time()) dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, str(loc.lat[0:7]) + str(loc.lat_dir), str(loc.lon[0:8]) + str(loc.lon_dir), time(), comment)
except Exception as error_exception: except Exception as error_exception:
logger.info('Failed to parse packet. Packet may be deformed. Not uploaded.') logger.info('Failed to parse packet. Packet may be deformed. Not uploaded.')
logger.info(error_exception) logger.info(error_exception)

View File

@ -153,12 +153,12 @@ def aprs_send(packet):
AIS.close() AIS.close()
logger.info('Packet sent to APRS-IS.') logger.info('Packet sent to APRS-IS.')
def dashboard_loc_write(call, lat, lon, time): def dashboard_loc_write(call, lat, lon, time, comment):
#try: #try:
dash_entries = ast.literal_eval(os.popen('cat /tmp/gps_data_user_loc.txt').read()) dash_entries = ast.literal_eval(os.popen('cat /tmp/gps_data_user_loc.txt').read())
# except: # except:
# dash_entries = [] # dash_entries = []
dash_entries.insert(0, {'call': call, 'lat': lat, 'lon': lon, 'time':time}) dash_entries.insert(0, {'call': call, 'lat': lat, 'lon': lon, 'time':time, 'comment': comment})
with open("/tmp/gps_data_user_loc.txt", 'w') as user_loc_file: with open("/tmp/gps_data_user_loc.txt", 'w') as user_loc_file:
user_loc_file.write(str(dash_entries[:200])) user_loc_file.write(str(dash_entries[:200]))
user_loc_file.close() user_loc_file.close()
@ -357,7 +357,7 @@ def process_sms(_rf_src, sms):
try: try:
aprslib.parse(aprs_loc_packet) aprslib.parse(aprs_loc_packet)
aprs_send(aprs_loc_packet) aprs_send(aprs_loc_packet)
dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time.time()) dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time.time(), comment)
#logger.info('Sent manual position to APRS') #logger.info('Sent manual position to APRS')
except Exception as error_exception: except Exception as error_exception:
logger.info('Exception. Not uploaded') logger.info('Exception. Not uploaded')
@ -496,7 +496,7 @@ class DATA_SYSTEM(HBSYSTEM):
float(lat_deg) < 91 float(lat_deg) < 91
float(lon_deg) < 121 float(lon_deg) < 121
aprs_send(aprs_loc_packet) aprs_send(aprs_loc_packet)
dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time.time()) dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, aprs_lat, aprs_lon, time.time(), comment)
#logger.info('Sent APRS packet') #logger.info('Sent APRS packet')
except Exception as error_exception: except Exception as error_exception:
logger.info('Error. Failed to send packet. Packet may be malformed.') logger.info('Error. Failed to send packet. Packet may be malformed.')
@ -598,7 +598,7 @@ class DATA_SYSTEM(HBSYSTEM):
float(loc.lat) float(loc.lat)
float(loc.lon) float(loc.lon)
aprs_send(aprs_loc_packet) aprs_send(aprs_loc_packet)
dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, str(loc.lat[0:7]) + str(loc.lat_dir), str(loc.lon[0:8]) + str(loc.lon_dir), time.time()) dashboard_loc_write(str(get_alias(int_id(_rf_src), subscriber_ids)) + '-' + ssid, str(loc.lat[0:7]) + str(loc.lat_dir), str(loc.lon[0:8]) + str(loc.lon_dir), time.time(), comment)
except Exception as error_exception: except Exception as error_exception:
logger.info('Failed to parse packet. Packet may be deformed. Not uploaded.') logger.info('Failed to parse packet. Packet may be deformed. Not uploaded.')
logger.info(error_exception) logger.info(error_exception)

View File

@ -202,94 +202,105 @@ def view_map():
map_size = request.args.get('map_size') map_size = request.args.get('map_size')
user_loc = ast.literal_eval(os.popen('cat /tmp/gps_data_user_loc.txt').read()) user_loc = ast.literal_eval(os.popen('cat /tmp/gps_data_user_loc.txt').read())
last_known_list = [] last_known_list = []
try: #try:
if track_call: if track_call:
#folium_map = folium.Map(location=map_center, zoom_start=int(zoom_level)) #folium_map = folium.Map(location=map_center, zoom_start=int(zoom_level))
#marker_cluster = MarkerCluster().add_to(folium_map) #marker_cluster = MarkerCluster().add_to(folium_map)
for user_coord in user_loc: for user_coord in user_loc:
user_lat = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lat']))) user_lat = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lat'])))
user_lon = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lon']))) user_lon = aprs_to_latlon(float(re.sub('[A-Za-z]','', user_coord['lon'])))
if type(user_coord['time']) == str: if type(user_coord['time']) == str:
loc_time = str(user_coord['time']) loc_time = str(user_coord['time'])
if type(user_coord['time']) == int or type(user_coord['time']) == float: if type(user_coord['time']) == int or type(user_coord['time']) == float:
loc_time = datetime.fromtimestamp(user_coord['time']).strftime(time_format) loc_time = datetime.fromtimestamp(user_coord['time']).strftime(time_format)
if 'S' in user_coord['lat']: if 'S' in user_coord['lat']:
user_lat = -user_lat user_lat = -user_lat
if 'W' in user_coord['lon']: if 'W' in user_coord['lon']:
user_lon = -user_lon user_lon = -user_lon
if user_coord['call'] not in last_known_list and user_coord['call'] == track_call: loc_comment = ''
folium_map = folium.Map(location=[user_lat, user_lon], tiles=map_theme, zoom_start=15) if 'comment' in user_coord:
marker_cluster = MarkerCluster().add_to(folium_map) loc_comment = """
folium.Marker([user_lat, user_lon], popup="""<i> <tr>
<table style="width: 150px;"> <td style="text-align: center;">Comment:</td>
</tr>
<tr>
<td style="text-align: center;"><strong>"""+ str(user_coord['comment']) +"""</strong></td>
</tr>"""
if user_coord['call'] not in last_known_list and user_coord['call'] == track_call:
folium_map = folium.Map(location=[user_lat, user_lon], tiles=map_theme, zoom_start=15)
marker_cluster = MarkerCluster().add_to(folium_map)
folium.Marker([user_lat, user_lon], popup="""<i>
<table style="width: 150px;">
<tbody>
<tr>
<td style="text-align: center;">Last Location:</td>
</tr>
<tr>
<td style="text-align: center;"><strong>"""+ str(user_coord['call']) +"""</strong></td>
</tr>
<tr>
<td style="text-align: center;"><em>"""+ loc_time +"""</em></td>
""" + loc_comment + """
</tr>
</tbody>
</table>
</i>
""", icon=folium.Icon(color="red", icon="record"), tooltip=str(user_coord['call'])).add_to(folium_map)
last_known_list.append(user_coord['call'])
if user_coord['call'] in last_known_list and user_coord['call'] == track_call:
folium.CircleMarker([user_lat, user_lon], popup="""
<table style="width: 150px;">
<tbody>
<tr>
<td style="text-align: center;"><strong>""" + user_coord['call'] + """</strong></td>
</tr>
<tr>
<td style="text-align: center;"><em>""" + loc_time + """</em></td>
</tr>
</tbody>
</table>
""", tooltip=str(user_coord['call']), fill=True, fill_color="#3186cc", radius=4).add_to(marker_cluster)
#return folium_map._repr_html_()
if not reload_time:
reload_time = 120
if not map_size:
map_view = '''<table style="width: 1000px; height: 600px; margin-left: auto; margin-right: auto;" border="1">
<tbody> <tbody>
<tr> <tr>
<td style="text-align: center;">Last Location:</td> <td>
</tr> ''' + folium_map._repr_html_() + '''</td>
<tr>
<td style="text-align: center;"><strong>"""+ str(user_coord['call']) +"""</strong></td>
</tr>
<tr>
<td style="text-align: center;"><em>"""+ loc_time +"""</em></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>'''
</i> if map_size == 'full':
""", icon=folium.Icon(color="red", icon="record"), tooltip=str(user_coord['call'])).add_to(folium_map) map_view = folium_map._repr_html_()
last_known_list.append(user_coord['call'])
if user_coord['call'] in last_known_list and user_coord['call'] == track_call:
folium.CircleMarker([user_lat, user_lon], popup="""
<table style="width: 150px;">
<tbody>
<tr>
<td style="text-align: center;"><strong>""" + user_coord['call'] + """</strong></td>
</tr>
<tr>
<td style="text-align: center;"><em>""" + loc_time + """</em></td>
</tr>
</tbody>
</table>
""", tooltip=str(user_coord['call']), fill=True, fill_color="#3186cc", radius=4).add_to(marker_cluster)
#return folium_map._repr_html_()
if not reload_time:
reload_time = 120
if not map_size:
map_view = '''<table style="width: 1000px; height: 600px; margin-left: auto; margin-right: auto;" border="1">
<tbody>
<tr>
<td>
''' + folium_map._repr_html_() + '''</td>
</tr>
</tbody>
</table>'''
if map_size == 'full':
map_view = folium_map._repr_html_()
content = ''' content = '''
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="refresh" content="''' + str(reload_time) + """" > <meta http-equiv="refresh" content="''' + str(reload_time) + """" >
<title>""" + dashboard_title + """ - Tracking """+ track_call + """</title> <title>""" + dashboard_title + """ - Tracking """+ track_call + """</title>
</head> </head>
<p style="text-align: center;"><strong>""" + dashboard_title + """ - Tracking """ + track_call + """</strong></p> <p style="text-align: center;"><strong>""" + dashboard_title + """ - Tracking """ + track_call + """</strong></p>
<p style="text-align: center;"><em>Page automatically reloads every """ + str(reload_time) + """ seconds.</em></p> <p style="text-align: center;"><em>Page automatically reloads every """ + str(reload_time) + """ seconds.</em></p>
<p style="text-align: center;"> <p style="text-align: center;">
<select name="sample" onchange="location = this.value;"> <select name="sample" onchange="location = this.value;">
<option value="view_map?track=""" + track_call + """&reload=120">2 Minutes</option> <option value="view_map?track=""" + track_call + """&reload=120">2 Minutes</option>
<option value="view_map?track=""" + track_call + """&reload=">Don't Reload</option> <option value="view_map?track=""" + track_call + """&reload=">Don't Reload</option>
<option value="view_map?track=""" + track_call + """&reload=30">30 Seconds</option> <option value="view_map?track=""" + track_call + """&reload=30">30 Seconds</option>
<option value="view_map?track=""" + track_call + """&reload=5">5 Minutes</option> <option value="view_map?track=""" + track_call + """&reload=5">5 Minutes</option>
<option value="view_map?track=""" + track_call + """&reload=600">10 Minutes</option> <option value="view_map?track=""" + track_call + """&reload=600">10 Minutes</option>
</select> </select>
<p style="text-align: center;"><button onclick="self.close()">Close</button><!--<button onclick="history.back()">Back</button>--> <p style="text-align: center;"><button onclick="self.close()">Close</button><!--<button onclick="history.back()">Back</button>-->
</p> </p>
""" + map_view """ + map_view
return render_template('generic.html', title = dashboard_title, logo = logo, content = Markup(content))
except:
content = """<h1 style="text-align: center;">Station not found.</h1>
<p style="text-align: center;"><button onclick="self.close()">Close Window</button>
</p>"""
return render_template('generic.html', title = dashboard_title, logo = logo, content = Markup(content)) return render_template('generic.html', title = dashboard_title, logo = logo, content = Markup(content))
#except Exception as e:
#content = """<h1 style="text-align: center;">Station not found.</h1>
#<p style="text-align: center;"><button onclick="self.close()">Close Window</button>
#</p>"""
#content = str(e)
#return render_template('generic.html', title = dashboard_title, logo = logo, content = Markup(content))
if not track_call: if not track_call:
folium_map = folium.Map(location=map_center, tiles=map_theme, zoom_start=int(zoom_level)) folium_map = folium.Map(location=map_center, tiles=map_theme, zoom_start=int(zoom_level))
@ -305,6 +316,15 @@ def view_map():
user_lat = -user_lat user_lat = -user_lat
if 'W' in user_coord['lon']: if 'W' in user_coord['lon']:
user_lon = -user_lon user_lon = -user_lon
loc_comment = ''
if 'comment' in user_coord:
loc_comment = """
<tr>
<td style="text-align: center;">Comment:</td>
</tr>
<tr>
<td style="text-align: center;"><strong>"""+ str(user_coord['comment']) +"""</strong></td>
</tr>"""
if user_coord['call'] not in last_known_list: if user_coord['call'] not in last_known_list:
folium.Marker([user_lat, user_lon], popup="""<i> folium.Marker([user_lat, user_lon], popup="""<i>
<table style="width: 150px;"> <table style="width: 150px;">
@ -318,6 +338,7 @@ def view_map():
<tr> <tr>
<td style="text-align: center;"><em>""" + loc_time + """</em></td> <td style="text-align: center;"><em>""" + loc_time + """</em></td>
</tr> </tr>
""" + loc_comment + """
<tr> <tr>
<td style="text-align: center;"><strong><A href="view_map?track=""" + user_coord['call'] + """" target="_blank">Track Station</A></strong></td> <td style="text-align: center;"><strong><A href="view_map?track=""" + user_coord['call'] + """" target="_blank">Track Station</A></strong></td>
</tr> </tr>