diff options
author | Galen Guyer <galen@galenguyer.com> | 2021-01-31 09:35:52 -0500 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2021-01-31 09:35:52 -0500 |
commit | 06c4c179b64f86c879b792b195db26b561d94cfc (patch) | |
tree | 06ea0b0a0e3997c4899e5bf0feab379bf576968d | |
parent | b2117092b11f3f08215c95454d9f067e0dfe44c8 (diff) |
Do math to get the new over two weeks data
-rw-r--r-- | poller/__init__.py | 10 |
1 files 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 |