Resolving further gps time issues
This commit is contained in:
parent
85f216b869
commit
c976809c1e
|
|
@ -27,9 +27,7 @@ with sqlite3.connect('location.db', check_same_thread=False) as conn:
|
|||
ureg = pint.UnitRegistry()
|
||||
geodesic = Geod(ellps='WGS84')
|
||||
|
||||
current_datetime = datetime.now(dttz.utc)
|
||||
date_yesterday = current_datetime - timedelta(days=1)
|
||||
date_tomorrow = current_datetime + timedelta(days=1)
|
||||
|
||||
|
||||
|
||||
@app.route('/')
|
||||
|
|
@ -38,6 +36,10 @@ def hello():
|
|||
|
||||
@app.route('/updateGPS')
|
||||
def getGpsDistance():
|
||||
|
||||
current_datetime = datetime.now(dttz.utc)
|
||||
date_yesterday = current_datetime - timedelta(days=1)
|
||||
date_tomorrow = current_datetime + timedelta(days=1)
|
||||
own_id = request.args.get('id')
|
||||
req_id = request.args.get('req_id')
|
||||
lat = request.args.get('lat').translate(str.maketrans('', '', ':'))
|
||||
|
|
@ -51,10 +53,10 @@ def getGpsDistance():
|
|||
print(request.args)
|
||||
|
||||
try:
|
||||
gpsDateTime = datetime.strptime(request.args.get('gpsDateTime')[:11], '%d%m%y%H%M%S')
|
||||
gpsDateTime = datetime.strptime(request.args.get('gpsDateTime')[:11], '%d%m%y%H%M%S').replace(tzinfo=dttz.utc)
|
||||
if gpsDateTime > date_tomorrow or current_datetime < date_yesterday:
|
||||
gpsDateTime = datetime.now(dttz.utc)
|
||||
print(gpsDateTime)
|
||||
print(f'GPS datetime out of boundaries - replacing with system time: {gpsDateTime}')
|
||||
except ValueError:
|
||||
print("No gpsDateTime")
|
||||
gpsDateTime = datetime.now(dttz.utc)
|
||||
|
|
@ -103,11 +105,8 @@ def getGpsDistance():
|
|||
if timezone_str is None:
|
||||
print("Could not determine the time zone")
|
||||
else:
|
||||
print(timezone_str)
|
||||
print(pytz.timezone(timezone_str))
|
||||
rTime = rTime.replace(tzinfo=dttz.utc).astimezone(pytz.timezone(timezone_str))
|
||||
|
||||
print(rTime)
|
||||
print(f'GPS datetime of requested database entry: {rTime}')
|
||||
else:
|
||||
|
||||
try:
|
||||
|
|
@ -118,7 +117,8 @@ def getGpsDistance():
|
|||
if row:
|
||||
lat, long, lastOwnDateTime, lastOwnInsertDateTime = row
|
||||
print(f'lat: {lat}, long: {long}, req_lat: {req_lat}, req_long: {req_long}, req_dateTime: {req_dateTime}')
|
||||
|
||||
rTime = datetime.fromisoformat(req_dateTime)
|
||||
if rTime < date_tomorrow and current_datetime > date_yesterday:
|
||||
fwd_azimuth, back_azimuth, distance = geodesic.inv(long, lat, req_long, req_lat)
|
||||
|
||||
distance = distance * ureg.meter
|
||||
|
|
@ -129,15 +129,17 @@ def getGpsDistance():
|
|||
if timezone_str is None:
|
||||
print("Could not determine the time zone")
|
||||
else:
|
||||
print(rTime)
|
||||
|
||||
|
||||
|
||||
rTime = rTime.replace(tzinfo=dttz.utc).astimezone(pytz.timezone(timezone_str))
|
||||
else:
|
||||
prettyDistance = "Invalid GPS Signal"
|
||||
fwd_azimuth = 0.0
|
||||
rTime = datetime.utcnow()
|
||||
else:
|
||||
|
||||
print(timezone_str)
|
||||
print(pytz.timezone(timezone_str))
|
||||
rTime = rTime.replace(tzinfo=dttz.utc).astimezone(pytz.timezone(timezone_str))
|
||||
prettyDistance = "Invalid GPS Signal"
|
||||
fwd_azimuth = 0.0
|
||||
rTime = datetime.utcnow()
|
||||
|
||||
except sqlite3.Error as error:
|
||||
print("Failed to read data for last own entry from table -- ignore", error)
|
||||
prettyDistance = "Invalid GPS Signal"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user