Add bear_correction as response parameter

The paramater bear_correction is now added to the
request response. It determines whether the dynamic
azimuth correction based on the clients orientation
is applied on the device or not.

Also a bug for retrieving the correct row was fixed.

Debug output removed.
This commit is contained in:
Tim Staat 2025-09-05 11:37:38 +02:00
parent 488ad08e38
commit 7547640597

View File

@ -8,6 +8,8 @@ from datetime import timezone as dttz
app = Flask(__name__)
bear_correction = False
with sqlite3.connect('location.db', check_same_thread=False) as conn:
cur = conn.cursor()
@ -21,10 +23,6 @@ with sqlite3.connect('location.db', check_same_thread=False) as conn:
);"""
)
with sqlite3.connect('location.db', check_same_thread=False) as conn:
cur = conn.cursor()
res = cur.execute("SELECT * FROM location_data;")
print(res.fetchall())
ureg = pint.UnitRegistry()
@ -43,6 +41,8 @@ def getGpsDistance():
lat = dm(lat) if lat and len(lat) > 1 else 0.0
long = dm(long) if long and len(long) > 1 else 0.0
print(request.args)
try:
gpsDateTime = datetime.strptime(request.args.get('gpsDateTime')[:11], '%d%m%y%H%M%S')
@ -50,7 +50,7 @@ def getGpsDistance():
except ValueError:
print("No gpsDateTime")
gpsDateTime = datetime.now()
print(request.args)
with sqlite3.connect('location.db', check_same_thread=False) as conn:
@ -86,7 +86,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}"
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)
@ -103,11 +103,7 @@ def getGpsDistance():
fwd_azimuth = 0.0
rTime = datetime.utcnow()
return jsonify({'distance': prettyDistance, 'azimuth': fwd_azimuth, 'lastUpdateTZ': rTime.strftime("%H:%M:%S")})
return jsonify({'distance': prettyDistance, 'azimuth': fwd_azimuth, 'lastUpdateTZ': rTime.strftime("%m/%d %H:%M:%S"), 'bear_correction': bear_correction})
def dm(ddmm: str):