From 06c4c179b64f86c879b792b195db26b561d94cfc Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Sun, 31 Jan 2021 09:35:52 -0500 Subject: Do math to get the new over two weeks data --- poller/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/poller/__init__.py b/poller/__init__.py index f6e5259..caf629c 100644 --- a/poller/__init__.py +++ b/poller/__init__.py @@ -24,6 +24,7 @@ if not os.path.exists('./data'): os.mkdir('./data') def update_db(): + print('updating db') with db_lock: db_conn = sqlite3.connect('data/data.sqlite3') c = db_conn.cursor() @@ -64,6 +65,7 @@ def db_is_same(current_data): return True def get_data(): + print('fetching data') global data_thread data_thread = threading.Timer(POOL_TIME, get_data, ()) data_thread.start() @@ -96,13 +98,13 @@ def get_data(): fall_data = None with open('history/fall-2020.json', 'r') as fd: fall_data = json.loads(fd.read()) - + two_weeks_ago = get_all_from_db()[-11] current_data = { 'alert_level': color, 'total_students': total_students + fall_data['total_students'], 'total_staff': total_staff + fall_data['total_staff'], - 'new_students': -1, - 'new_staff': -1, + 'new_students': total_students + fall_data['total_students'] - two_weeks_ago['total_students'], + 'new_staff': total_staff + fall_data['total_staff'] - two_weeks_ago['total_staff'], 'quarantine_on_campus': quarantine_on_campus, 'quarantine_off_campus': quarantine_off_campus, 'isolation_on_campus': isolation_on_campus, @@ -116,6 +118,8 @@ def get_data(): update_db() return current_data +get_data() + APP = Flask(__name__) # Load file based configuration overrides if present -- cgit v1.2.3