From 8b7c8bf1e8ecbd6b9fa79a057752535d024e940c Mon Sep 17 00:00:00 2001 From: Matt Kohls Date: Tue, 17 Oct 2023 17:10:13 -0400 Subject: Hotfixes Minor tweaks based on things I noticed with real data --- snag/data.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'snag/data.py') diff --git a/snag/data.py b/snag/data.py index 3bf8df3..69f9849 100644 --- a/snag/data.py +++ b/snag/data.py @@ -6,11 +6,19 @@ from flask import ( Blueprint, flash, g, redirect, render_template, request, url_for, json ) from werkzeug.exceptions import abort -from datetime import datetime +from datetime import datetime, timedelta from snag.db import get_db +import time bp = Blueprint('data', __name__, url_prefix='/data') +# Temp dst function, should add this to database to track instead +def is_dst_aware(deviceId): + if (deviceId in [2]): + return False + else: + return True + # Process json data # # Expects something like this: @@ -43,6 +51,10 @@ def unpack_json_scheme_1(req): if 'status' in req: if 'timeStamp' in req['status'][0]: now = req['status'][0]['timeStamp'] + now = datetime.strptime(now, "%Y-%m-%dT%H:%M:%SZ") + if not is_dst_aware(deviceId) and time.daylight: + now = now + timedelta(hours=1) + now = now.strftime("%Y-%m-%d %H:%M:%S") else: now = datetime.now() battery = req['status'][0]['battery'] @@ -55,6 +67,10 @@ def unpack_json_scheme_1(req): humidity = environment['humidity'] pressure = environment['pressure'] now = environment['timeStamp'] + now = datetime.strptime(now, "%Y-%m-%dT%H:%M:%SZ") + if not is_dst_aware(deviceId) and time.daylight: + now = now + timedelta(hours=1) + now = now.strftime("%Y-%m-%d %H:%M:%S") if env == 'outdoor': lux = environment['lux'] uv = environment['uv'] @@ -102,7 +118,7 @@ def get_devices(): for env in envs: envDict = { "environment" : env["environment"], - # "environmentDesc" : env["environmentDescription"] + "environmentDesc" : env["environmentDescription"] } envList.append(envDict) deviceLine = { -- cgit v1.2.3