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