clean up code, refactor for efficiency
This commit is contained in:
parent
2c0bccd157
commit
9acab81e98
2 changed files with 7 additions and 75 deletions
|
@ -99,77 +99,14 @@ def main_page():
|
|||
|
||||
@app.route('/dsf673bh_past/<seconds>')
|
||||
def get_past_data(seconds):
|
||||
# for testing
|
||||
# test_marker = [
|
||||
# {
|
||||
# 'device_id': 'test',
|
||||
# 'datetime': '2019-02-11T13:51:04.336697974Z',
|
||||
# 'date': parser().parse('2019-03-08T16:43:54.720956321Z'),
|
||||
# 'latitude': '34.040066',
|
||||
# 'longitude': '-84.560319',
|
||||
# 'altitude': '200',
|
||||
# 'hdop': '3.2'
|
||||
# },
|
||||
# {
|
||||
# 'device_id': 'test2',
|
||||
# 'datetime': '2019-02-11T13:51:04.336697974Z',
|
||||
# 'date': parser().parse('2019-03-08T16:43:54.720956321Z'),
|
||||
# 'latitude': '34.045066',
|
||||
# 'longitude': '-84.556319',
|
||||
# 'altitude': '220',
|
||||
# 'hdop': '4'
|
||||
# }
|
||||
# ]
|
||||
# return jsonify(test_marker)
|
||||
|
||||
# now_utc = datetime.datetime.utcnow()
|
||||
#
|
||||
# new_location = Location(
|
||||
# device_id='test',
|
||||
# datetime_obj=now_utc,
|
||||
# datetime=now_utc.strftime("%Y-%m-%d %H:%M:%S.%f"),
|
||||
# latitude='34.040066',
|
||||
# longitude='-84.560319',
|
||||
# altitude='300',
|
||||
# hdop='4')
|
||||
# db.session.add(new_location)
|
||||
# db.session.commit()
|
||||
#
|
||||
# logger.error("TEST00: save {}".format(now_utc.strftime("%Y-%m-%d %H:%M:%S.%f")))
|
||||
#
|
||||
# now_utc = datetime.datetime.utcnow()
|
||||
#
|
||||
# new_location = Location(
|
||||
# device_id='test',
|
||||
# datetime_obj=now_utc,
|
||||
# datetime=now_utc.strftime("%Y-%m-%d %H:%M:%S.%f"),
|
||||
# latitude='34.045066',
|
||||
# longitude='-84.556319',
|
||||
# altitude='300',
|
||||
# hdop='4')
|
||||
# db.session.add(new_location)
|
||||
# db.session.commit()
|
||||
#
|
||||
# for each_loc in Location.query.all():
|
||||
# logger.error("TEST01: test {}".format(each_loc.added_at.strftime("%Y-%m-%d %H:%M:%S.%f")))
|
||||
#
|
||||
# logger.error("TEST01: save {}".format(now_utc.strftime("%Y-%m-%d %H:%M:%S.%f")))
|
||||
|
||||
past_dt_object = datetime.datetime.now() - datetime.timedelta(seconds=int(seconds))
|
||||
|
||||
# logger.error("TEST02: {}".format(past_dt_object.strftime("%Y-%m-%d %H:%M:%S.%f")))
|
||||
|
||||
if seconds_from_last() > 10:
|
||||
get_new_data()
|
||||
|
||||
markers = Location.query.filter(Location.added_at > past_dt_object).all()
|
||||
|
||||
# logger.error("TEST03: {} > {}: {}".format(now_utc.strftime("%Y-%m-%d %H:%M:%S.%f"),
|
||||
# past_dt_object.strftime("%Y-%m-%d %H:%M:%S.%f"),
|
||||
# now_utc > past_dt_object))
|
||||
#
|
||||
# logger.error("TEST04: {}".format(Location.query.filter(Location.added_at > past_dt_object).count()))
|
||||
|
||||
if seconds == '0':
|
||||
markers = Location.query.all()
|
||||
else:
|
||||
past_dt_object = datetime.datetime.now() - datetime.timedelta(seconds=int(seconds))
|
||||
markers = Location.query.filter(Location.added_at > past_dt_object).all()
|
||||
return jsonify([i.serialize for i in markers])
|
||||
|
||||
|
||||
|
|
|
@ -105,13 +105,6 @@
|
|||
console.log("Clicked: " + e.latlng.lat + ", " + e.latlng.lng);
|
||||
});
|
||||
|
||||
{% for each_location in location_data %}
|
||||
var node = L.circleMarker([{{each_location.latitude}}, {{each_location.longitude}}], {
|
||||
color: 'red',
|
||||
radius: 5
|
||||
}).bindPopup('Node: {{each_location.device_id}}<br />{{each_location.datetime}}<br />Lat/Lon: {{each_location.latitude|float|round(6)}}, {{each_location.longitude|float|round(6)}}<br />Altitude: {{each_location.altitude}} m, hdop: {{each_location.hdop}}').addTo(map);
|
||||
{% endfor %}
|
||||
|
||||
{% for each_gateway in gateway_locations %}
|
||||
var gateway = L.marker([{{each_gateway[1]}}, {{each_gateway[2]}}]).bindPopup('Gateway: {{each_gateway[0]}}<br />Lat/Lon: {{each_gateway[1]}}, {{each_gateway[2]}}').addTo(map);
|
||||
{% endfor %}
|
||||
|
@ -139,6 +132,8 @@
|
|||
}, Number(past_seconds) * 1000);
|
||||
}
|
||||
|
||||
add_new_markers('0');
|
||||
|
||||
window.onload = function() {
|
||||
repeat_add_new_markers('{{refresh_period_seconds}}');
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue