Exclude invaid gps datetimes
This commit is contained in:
parent
7547640597
commit
bda17d8ec9
|
|
@ -1,11 +1,10 @@
|
|||
from flask import Flask, request, jsonify
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
import pint
|
||||
import sqlite3
|
||||
from pyproj import Geod
|
||||
import timezonefinder, pytz
|
||||
from datetime import timezone as dttz
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
bear_correction = False
|
||||
|
|
@ -28,6 +27,11 @@ with sqlite3.connect('location.db', check_same_thread=False) as conn:
|
|||
ureg = pint.UnitRegistry()
|
||||
geodesic = Geod(ellps='WGS84')
|
||||
|
||||
current_datetime = datetime.utcnow()
|
||||
date_yesterday = current_datetime - timedelta(days=1)
|
||||
date_tomorrow = current_datetime + timedelta(days=1)
|
||||
valid_date = True
|
||||
|
||||
@app.route('/')
|
||||
def hello():
|
||||
return 'Hello!'
|
||||
|
|
@ -46,10 +50,14 @@ def getGpsDistance():
|
|||
|
||||
try:
|
||||
gpsDateTime = datetime.strptime(request.args.get('gpsDateTime')[:11], '%d%m%y%H%M%S')
|
||||
if gpsDateTime > date_tomorrow or current_datetime < date_yesterday:
|
||||
valid_date = False
|
||||
print(gpsDateTime)
|
||||
except ValueError:
|
||||
print("No gpsDateTime")
|
||||
gpsDateTime = datetime.now()
|
||||
valid_date = False
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -77,7 +85,7 @@ def getGpsDistance():
|
|||
req_long = 0.0
|
||||
req_dateTime = datetime.now()
|
||||
|
||||
if (lat != 0.0 and long != 0.0):
|
||||
if (lat != 0.0 and long != 0.0 and valid_date):
|
||||
cur.execute(f'INSERT INTO location_data(sender_id, lat, long, gpsDateTime) VALUES({own_id}, {lat}, {long}, "{gpsDateTime.isoformat()}");')
|
||||
conn.commit()
|
||||
|
||||
|
|
@ -86,7 +94,7 @@ def getGpsDistance():
|
|||
fwd_azimuth, back_azimuth, distance = geodesic.inv(long, lat, req_long, req_lat)
|
||||
|
||||
distance = distance * ureg.meter
|
||||
prettyDistance = f"{distance:.1f~#P}" + ' (N)' if not bear_correction else ''
|
||||
prettyDistance = f"{distance:.1f~#P}" + ' (N)' if not bear_correction else ''
|
||||
print(f'fwd: {fwd_azimuth}, bwd: {back_azimuth}, dist: {prettyDistance}')
|
||||
tf = timezonefinder.TimezoneFinder()
|
||||
timezone_str = tf.certain_timezone_at(lat=lat, lng=long)
|
||||
|
|
@ -99,7 +107,7 @@ def getGpsDistance():
|
|||
|
||||
print(rTime)
|
||||
else:
|
||||
prettyDistance = "No GPS Signal"
|
||||
prettyDistance = "Invalid GPS Signal"
|
||||
fwd_azimuth = 0.0
|
||||
rTime = datetime.utcnow()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user