aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--history/history.json1360
-rw-r--r--migrations.py101
-rw-r--r--poller/__init__.py72
-rw-r--r--poller/db.py67
-rw-r--r--poller/dedup.py2
5 files changed, 1448 insertions, 154 deletions
diff --git a/history/history.json b/history/history.json
new file mode 100644
index 0000000..fd5603b
--- /dev/null
+++ b/history/history.json
@@ -0,0 +1,1360 @@
+[
+ {
+ "alert_level": "green",
+ "beds_available": 95,
+ "isolation_off_campus": 4,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-08-27 16:00:00",
+ "new_staff": 1,
+ "new_students": 2,
+ "quarantine_off_campus": 4,
+ "quarantine_on_campus": 3,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 3
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 96,
+ "isolation_off_campus": 3,
+ "isolation_on_campus": 0,
+ "last_updated": "2020-08-28 16:00:00",
+ "new_staff": 1,
+ "new_students": 2,
+ "quarantine_off_campus": 7,
+ "quarantine_on_campus": 3,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 3
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 95,
+ "isolation_off_campus": 1,
+ "isolation_on_campus": 0,
+ "last_updated": "2020-08-31 16:00:00",
+ "new_staff": 0,
+ "new_students": 1,
+ "quarantine_off_campus": 3,
+ "quarantine_on_campus": 4,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 3
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 92,
+ "isolation_off_campus": 0,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-09-01 16:00:00",
+ "new_staff": 0,
+ "new_students": 0,
+ "quarantine_off_campus": 2,
+ "quarantine_on_campus": 7,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 3
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 93,
+ "isolation_off_campus": 0,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-09-02 16:00:00",
+ "new_staff": 0,
+ "new_students": 0,
+ "quarantine_off_campus": 2,
+ "quarantine_on_campus": 6,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 3
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 92,
+ "isolation_off_campus": 0,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-09-03 16:00:00",
+ "new_staff": 0,
+ "new_students": 0,
+ "quarantine_off_campus": 3,
+ "quarantine_on_campus": 11,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 3
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 96,
+ "isolation_off_campus": 1,
+ "isolation_on_campus": 0,
+ "last_updated": "2020-09-04 16:00:00",
+ "new_staff": 1,
+ "new_students": 3,
+ "quarantine_off_campus": 5,
+ "quarantine_on_campus": 1,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 4
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 97,
+ "isolation_off_campus": 1,
+ "isolation_on_campus": 0,
+ "last_updated": "2020-09-06 16:00:00",
+ "new_staff": 0,
+ "new_students": 2,
+ "quarantine_off_campus": 5,
+ "quarantine_on_campus": 3,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 5
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 95,
+ "isolation_off_campus": 6,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-09-07 16:00:00",
+ "new_staff": 0,
+ "new_students": 3,
+ "quarantine_off_campus": 17,
+ "quarantine_on_campus": 5,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 6
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 98,
+ "isolation_off_campus": 3,
+ "isolation_on_campus": 0,
+ "last_updated": "2020-09-10 16:00:00",
+ "new_staff": 0,
+ "new_students": 3,
+ "quarantine_off_campus": 17,
+ "quarantine_on_campus": 1,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 6
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 96,
+ "isolation_off_campus": 4,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-09-11 16:00:00",
+ "new_staff": 0,
+ "new_students": 3,
+ "quarantine_off_campus": 17,
+ "quarantine_on_campus": 1,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 6
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 95,
+ "isolation_off_campus": 1,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-09-14 16:00:00",
+ "new_staff": 0,
+ "new_students": 4,
+ "quarantine_off_campus": 16,
+ "quarantine_on_campus": 4,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 6
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 92,
+ "isolation_off_campus": 2,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-09-15 16:00:00",
+ "new_staff": 0,
+ "new_students": 4,
+ "quarantine_off_campus": 19,
+ "quarantine_on_campus": 9,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 7
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 90,
+ "isolation_off_campus": 2,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-09-16 16:00:00",
+ "new_staff": 0,
+ "new_students": 5,
+ "quarantine_off_campus": 19,
+ "quarantine_on_campus": 12,
+ "tests_administered": 0,
+ "total_staff": 1,
+ "total_students": 8
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 88,
+ "isolation_off_campus": 1,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-09-17 16:00:00",
+ "new_staff": 1,
+ "new_students": 4,
+ "quarantine_off_campus": 18,
+ "quarantine_on_campus": 16,
+ "tests_administered": 0,
+ "total_staff": 2,
+ "total_students": 8
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 89,
+ "isolation_off_campus": 1,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-09-18 16:00:00",
+ "new_staff": 1,
+ "new_students": 4,
+ "quarantine_off_campus": 16,
+ "quarantine_on_campus": 14,
+ "tests_administered": 0,
+ "total_staff": 2,
+ "total_students": 9
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 94,
+ "isolation_off_campus": 1,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-09-21 16:00:00",
+ "new_staff": 1,
+ "new_students": 4,
+ "quarantine_off_campus": 14,
+ "quarantine_on_campus": 8,
+ "tests_administered": 0,
+ "total_staff": 2,
+ "total_students": 10
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 91,
+ "isolation_off_campus": 1,
+ "isolation_on_campus": 4,
+ "last_updated": "2020-09-22 16:00:00",
+ "new_staff": 1,
+ "new_students": 4,
+ "quarantine_off_campus": 9,
+ "quarantine_on_campus": 10,
+ "tests_administered": 0,
+ "total_staff": 2,
+ "total_students": 10
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 88,
+ "isolation_off_campus": 1,
+ "isolation_on_campus": 5,
+ "last_updated": "2020-09-24 16:00:00",
+ "new_staff": 1,
+ "new_students": 4,
+ "quarantine_off_campus": 8,
+ "quarantine_on_campus": 15,
+ "tests_administered": 0,
+ "total_staff": 2,
+ "total_students": 10
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 92,
+ "isolation_off_campus": 0,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-09-25 16:00:00",
+ "new_staff": 1,
+ "new_students": 4,
+ "quarantine_off_campus": 12,
+ "quarantine_on_campus": 10,
+ "tests_administered": 3747,
+ "total_staff": 2,
+ "total_students": 10
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 98,
+ "isolation_off_campus": 0,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-09-28 16:00:00",
+ "new_staff": 1,
+ "new_students": 2,
+ "quarantine_off_campus": 8,
+ "quarantine_on_campus": 1,
+ "tests_administered": 3751,
+ "total_staff": 2,
+ "total_students": 10
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 98,
+ "isolation_off_campus": 0,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-09-29 16:00:00",
+ "new_staff": 1,
+ "new_students": 2,
+ "quarantine_off_campus": 9,
+ "quarantine_on_campus": 0,
+ "tests_administered": 3753,
+ "total_staff": 2,
+ "total_students": 10
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 99,
+ "isolation_off_campus": 2,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-10-01 16:00:00",
+ "new_staff": 0,
+ "new_students": 0,
+ "quarantine_off_campus": 8,
+ "quarantine_on_campus": 0,
+ "tests_administered": 4038,
+ "total_staff": 2,
+ "total_students": 10
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 98,
+ "isolation_off_campus": 0,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-10-02 16:00:00",
+ "new_staff": 0,
+ "new_students": 0,
+ "quarantine_off_campus": 6,
+ "quarantine_on_campus": 1,
+ "tests_administered": 4135,
+ "total_staff": 2,
+ "total_students": 10
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 97,
+ "isolation_off_campus": 0,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-10-05 16:00:00",
+ "new_staff": 0,
+ "new_students": 1,
+ "quarantine_off_campus": 1,
+ "quarantine_on_campus": 3,
+ "tests_administered": 4136,
+ "total_staff": 2,
+ "total_students": 10
+ },
+ {
+ "alert_level": "green",
+ "beds_available": 90,
+ "isolation_off_campus": 0,
+ "isolation_on_campus": 5,
+ "last_updated": "2020-10-06 16:00:00",
+ "new_staff": 0,
+ "new_students": 1,
+ "quarantine_off_campus": 5,
+ "quarantine_on_campus": 11,
+ "tests_administered": 4139,
+ "total_staff": 2,
+ "total_students": 10
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 93,
+ "isolation_off_campus": 1,
+ "isolation_on_campus": 4,
+ "last_updated": "2020-10-08 16:00:00",
+ "new_staff": 0,
+ "new_students": 3,
+ "quarantine_off_campus": 10,
+ "quarantine_on_campus": 7,
+ "tests_administered": 4482,
+ "total_staff": 2,
+ "total_students": 12
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 92,
+ "isolation_off_campus": 0,
+ "isolation_on_campus": 4,
+ "last_updated": "2020-10-09 16:00:00",
+ "new_staff": 0,
+ "new_students": 3,
+ "quarantine_off_campus": 14,
+ "quarantine_on_campus": 8,
+ "tests_administered": 4625,
+ "total_staff": 2,
+ "total_students": 12
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 93,
+ "isolation_off_campus": 4,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-10-12 16:00:00",
+ "new_staff": 0,
+ "new_students": 4,
+ "quarantine_off_campus": 20,
+ "quarantine_on_campus": 8,
+ "tests_administered": 5053,
+ "total_staff": 2,
+ "total_students": 13
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 92,
+ "isolation_off_campus": 2,
+ "isolation_on_campus": 4,
+ "last_updated": "2020-10-13 16:00:00",
+ "new_staff": 0,
+ "new_students": 4,
+ "quarantine_off_campus": 24,
+ "quarantine_on_campus": 9,
+ "tests_administered": 5055,
+ "total_staff": 2,
+ "total_students": 13
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 93,
+ "isolation_off_campus": 4,
+ "isolation_on_campus": 4,
+ "last_updated": "2020-10-15 16:00:00",
+ "new_staff": 0,
+ "new_students": 5,
+ "quarantine_off_campus": 27,
+ "quarantine_on_campus": 8,
+ "tests_administered": 5471,
+ "total_staff": 2,
+ "total_students": 14
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 96,
+ "isolation_off_campus": 5,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-10-16 16:00:00",
+ "new_staff": 0,
+ "new_students": 6,
+ "quarantine_off_campus": 25,
+ "quarantine_on_campus": 5,
+ "tests_administered": 5590,
+ "total_staff": 2,
+ "total_students": 15
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 95,
+ "isolation_off_campus": 4,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-10-19 16:00:00",
+ "new_staff": 0,
+ "new_students": 6,
+ "quarantine_off_campus": 23,
+ "quarantine_on_campus": 6,
+ "tests_administered": 5591,
+ "total_staff": 2,
+ "total_students": 16
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 92,
+ "isolation_off_campus": 6,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-10-20 16:00:00",
+ "new_staff": 0,
+ "new_students": 7,
+ "quarantine_off_campus": 29,
+ "quarantine_on_campus": 11,
+ "tests_administered": 5598,
+ "total_staff": 2,
+ "total_students": 17
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 92,
+ "isolation_off_campus": 5,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-10-21 16:00:00",
+ "new_staff": 0,
+ "new_students": 6,
+ "quarantine_off_campus": 32,
+ "quarantine_on_campus": 11,
+ "tests_administered": 5887,
+ "total_staff": 2,
+ "total_students": 17
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 95,
+ "isolation_off_campus": 5,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-10-23 16:00:00",
+ "new_staff": 0,
+ "new_students": 7,
+ "quarantine_off_campus": 33,
+ "quarantine_on_campus": 8,
+ "tests_administered": 6141,
+ "total_staff": 2,
+ "total_students": 19
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 90,
+ "isolation_off_campus": 4,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-10-26 16:00:00",
+ "new_staff": 0,
+ "new_students": 8,
+ "quarantine_off_campus": 35,
+ "quarantine_on_campus": 16,
+ "tests_administered": 6146,
+ "total_staff": 2,
+ "total_students": 21
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 91,
+ "isolation_off_campus": 4,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-10-27 16:00:00",
+ "new_staff": 0,
+ "new_students": 9,
+ "quarantine_off_campus": 36,
+ "quarantine_on_campus": 14,
+ "tests_administered": 6150,
+ "total_staff": 2,
+ "total_students": 22
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 92,
+ "isolation_off_campus": 4,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-10-28 16:00:00",
+ "new_staff": 1,
+ "new_students": 10,
+ "quarantine_off_campus": 34,
+ "quarantine_on_campus": 12,
+ "tests_administered": 6392,
+ "total_staff": 3,
+ "total_students": 23
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 91,
+ "isolation_off_campus": 9,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-10-29 16:00:00",
+ "new_staff": 2,
+ "new_students": 10,
+ "quarantine_off_campus": 31,
+ "quarantine_on_campus": 13,
+ "tests_administered": 6490,
+ "total_staff": 4,
+ "total_students": 24
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 86,
+ "isolation_off_campus": 9,
+ "isolation_on_campus": 6,
+ "last_updated": "2020-10-30 16:00:00",
+ "new_staff": 2,
+ "new_students": 17,
+ "quarantine_off_campus": 27,
+ "quarantine_on_campus": 18,
+ "tests_administered": 6638,
+ "total_staff": 4,
+ "total_students": 32
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 87,
+ "isolation_off_campus": 10,
+ "isolation_on_campus": 5,
+ "last_updated": "2020-11-02 19:27:39",
+ "new_staff": 3,
+ "new_students": 19,
+ "quarantine_off_campus": 30,
+ "quarantine_on_campus": 17,
+ "tests_administered": 7318,
+ "total_staff": 5,
+ "total_students": 36
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 83,
+ "isolation_off_campus": 8,
+ "isolation_on_campus": 7,
+ "last_updated": "2020-11-03 19:47:40",
+ "new_staff": 3,
+ "new_students": 20,
+ "quarantine_off_campus": 34,
+ "quarantine_on_campus": 23,
+ "tests_administered": 7391,
+ "total_staff": 5,
+ "total_students": 37
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 78,
+ "isolation_off_campus": 8,
+ "isolation_on_campus": 10,
+ "last_updated": "2020-11-04 20:05:45",
+ "new_staff": 5,
+ "new_students": 20,
+ "quarantine_off_campus": 35,
+ "quarantine_on_campus": 27,
+ "tests_administered": 7514,
+ "total_staff": 7,
+ "total_students": 38
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 81,
+ "isolation_off_campus": 14,
+ "isolation_on_campus": 8,
+ "last_updated": "2020-11-05 19:36:46",
+ "new_staff": 5,
+ "new_students": 21,
+ "quarantine_off_campus": 41,
+ "quarantine_on_campus": 25,
+ "tests_administered": 7794,
+ "total_staff": 7,
+ "total_students": 40
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 80,
+ "isolation_off_campus": 12,
+ "isolation_on_campus": 7,
+ "last_updated": "2020-11-06 20:30:25",
+ "new_staff": 5,
+ "new_students": 24,
+ "quarantine_off_campus": 42,
+ "quarantine_on_campus": 26,
+ "tests_administered": 8278,
+ "total_staff": 7,
+ "total_students": 43
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 57,
+ "isolation_off_campus": 11,
+ "isolation_on_campus": 10,
+ "last_updated": "2020-11-09 14:40:26",
+ "new_staff": 5,
+ "new_students": 29,
+ "quarantine_off_campus": 59,
+ "quarantine_on_campus": 63,
+ "tests_administered": 8622,
+ "total_staff": 7,
+ "total_students": 51
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 61,
+ "isolation_off_campus": 11,
+ "isolation_on_campus": 8,
+ "last_updated": "2020-11-10 21:02:02",
+ "new_staff": 3,
+ "new_students": 33,
+ "quarantine_off_campus": 66,
+ "quarantine_on_campus": 57,
+ "tests_administered": 8712,
+ "total_staff": 7,
+ "total_students": 55
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 56,
+ "isolation_off_campus": 17,
+ "isolation_on_campus": 11,
+ "last_updated": "2020-11-11 18:38:08",
+ "new_staff": 4,
+ "new_students": 34,
+ "quarantine_off_campus": 66,
+ "quarantine_on_campus": 63,
+ "tests_administered": 8732,
+ "total_staff": 8,
+ "total_students": 57
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 55,
+ "isolation_off_campus": 20,
+ "isolation_on_campus": 11,
+ "last_updated": "2020-11-12 19:43:09",
+ "new_staff": 5,
+ "new_students": 33,
+ "quarantine_off_campus": 67,
+ "quarantine_on_campus": 63,
+ "tests_administered": 8819,
+ "total_staff": 9,
+ "total_students": 60
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 57,
+ "isolation_off_campus": 15,
+ "isolation_on_campus": 12,
+ "last_updated": "2020-11-13 20:28:09",
+ "new_staff": 5,
+ "new_students": 30,
+ "quarantine_off_campus": 72,
+ "quarantine_on_campus": 60,
+ "tests_administered": 8969,
+ "total_staff": 9,
+ "total_students": 63
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 77,
+ "isolation_off_campus": 8,
+ "isolation_on_campus": 9,
+ "last_updated": "2020-11-16 19:35:59",
+ "new_staff": 5,
+ "new_students": 29,
+ "quarantine_off_campus": 67,
+ "quarantine_on_campus": 30,
+ "tests_administered": 9009,
+ "total_staff": 9,
+ "total_students": 65
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 81,
+ "isolation_off_campus": 9,
+ "isolation_on_campus": 6,
+ "last_updated": "2020-11-17 18:55:59",
+ "new_staff": 7,
+ "new_students": 27,
+ "quarantine_off_campus": 63,
+ "quarantine_on_campus": 27,
+ "tests_administered": 9383,
+ "total_staff": 13,
+ "total_students": 65
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 83,
+ "isolation_off_campus": 16,
+ "isolation_on_campus": 7,
+ "last_updated": "2020-11-18 19:00:59",
+ "new_staff": 6,
+ "new_students": 31,
+ "quarantine_off_campus": 63,
+ "quarantine_on_campus": 23,
+ "tests_administered": 9959,
+ "total_staff": 13,
+ "total_students": 69
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 83,
+ "isolation_off_campus": 22,
+ "isolation_on_campus": 9,
+ "last_updated": "2020-11-19 21:05:59",
+ "new_staff": 8,
+ "new_students": 35,
+ "quarantine_off_campus": 70,
+ "quarantine_on_campus": 33,
+ "tests_administered": 9959,
+ "total_staff": 15,
+ "total_students": 77
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 75,
+ "isolation_off_campus": 22,
+ "isolation_on_campus": 6,
+ "last_updated": "2020-11-20 22:20:05",
+ "new_staff": 8,
+ "new_students": 35,
+ "quarantine_off_campus": 70,
+ "quarantine_on_campus": 36,
+ "tests_administered": 11963,
+ "total_staff": 15,
+ "total_students": 79
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 81,
+ "isolation_off_campus": 21,
+ "isolation_on_campus": 6,
+ "last_updated": "2020-11-23 18:09:50",
+ "new_staff": 10,
+ "new_students": 36,
+ "quarantine_off_campus": 68,
+ "quarantine_on_campus": 28,
+ "tests_administered": 12041,
+ "total_staff": 18,
+ "total_students": 89
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 85,
+ "isolation_off_campus": 22,
+ "isolation_on_campus": 4,
+ "last_updated": "2020-11-24 19:54:50",
+ "new_staff": 12,
+ "new_students": 34,
+ "quarantine_off_campus": 61,
+ "quarantine_on_campus": 21,
+ "tests_administered": 12147,
+ "total_staff": 20,
+ "total_students": 90
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 88,
+ "isolation_off_campus": 24,
+ "isolation_on_campus": 4,
+ "last_updated": "2020-11-25 18:59:50",
+ "new_staff": 11,
+ "new_students": 35,
+ "quarantine_off_campus": 65,
+ "quarantine_on_campus": 16,
+ "tests_administered": 12218,
+ "total_staff": 20,
+ "total_students": 93
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 96,
+ "isolation_off_campus": 11,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-11-30 19:29:52",
+ "new_staff": 12,
+ "new_students": 31,
+ "quarantine_off_campus": 64,
+ "quarantine_on_campus": 4,
+ "tests_administered": 12219,
+ "total_staff": 24,
+ "total_students": 96
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 96,
+ "isolation_off_campus": 8,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-12-01 19:14:51",
+ "new_staff": 11,
+ "new_students": 29,
+ "quarantine_off_campus": 61,
+ "quarantine_on_campus": 4,
+ "tests_administered": 12289,
+ "total_staff": 26,
+ "total_students": 97
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 98,
+ "isolation_off_campus": 12,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-12-02 20:04:51",
+ "new_staff": 11,
+ "new_students": 28,
+ "quarantine_off_campus": 41,
+ "quarantine_on_campus": 2,
+ "tests_administered": 12290,
+ "total_staff": 28,
+ "total_students": 99
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 98,
+ "isolation_off_campus": 16,
+ "isolation_on_campus": 2,
+ "last_updated": "2020-12-03 17:59:51",
+ "new_staff": 11,
+ "new_students": 23,
+ "quarantine_off_campus": 40,
+ "quarantine_on_campus": 2,
+ "tests_administered": 12364,
+ "total_staff": 28,
+ "total_students": 103
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 99,
+ "isolation_off_campus": 19,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-12-04 19:24:52",
+ "new_staff": 11,
+ "new_students": 22,
+ "quarantine_off_campus": 45,
+ "quarantine_on_campus": 1,
+ "tests_administered": 12364,
+ "total_staff": 30,
+ "total_students": 105
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 99,
+ "isolation_off_campus": 17,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-12-07 20:04:52",
+ "new_staff": 12,
+ "new_students": 19,
+ "quarantine_off_campus": 46,
+ "quarantine_on_campus": 0,
+ "tests_administered": 12364,
+ "total_staff": 30,
+ "total_students": 109
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 99,
+ "isolation_off_campus": 20,
+ "isolation_on_campus": 0,
+ "last_updated": "2020-12-08 19:09:52",
+ "new_staff": 13,
+ "new_students": 20,
+ "quarantine_off_campus": 48,
+ "quarantine_on_campus": 1,
+ "tests_administered": 12428,
+ "total_staff": 35,
+ "total_students": 110
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 99,
+ "isolation_off_campus": 23,
+ "isolation_on_campus": 0,
+ "last_updated": "2020-12-09 21:24:52",
+ "new_staff": 15,
+ "new_students": 16,
+ "quarantine_off_campus": 46,
+ "quarantine_on_campus": 1,
+ "tests_administered": 12432,
+ "total_staff": 37,
+ "total_students": 110
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 99,
+ "isolation_off_campus": 24,
+ "isolation_on_campus": 0,
+ "last_updated": "2020-12-10 18:19:52",
+ "new_staff": 13,
+ "new_students": 17,
+ "quarantine_off_campus": 44,
+ "quarantine_on_campus": 1,
+ "tests_administered": 12500,
+ "total_staff": 37,
+ "total_students": 111
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 99,
+ "isolation_off_campus": 19,
+ "isolation_on_campus": 0,
+ "last_updated": "2020-12-11 19:29:52",
+ "new_staff": 14,
+ "new_students": 19,
+ "quarantine_off_campus": 43,
+ "quarantine_on_campus": 1,
+ "tests_administered": 12500,
+ "total_staff": 39,
+ "total_students": 113
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 99,
+ "isolation_off_campus": 13,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-12-14 20:44:53",
+ "new_staff": 13,
+ "new_students": 20,
+ "quarantine_off_campus": 30,
+ "quarantine_on_campus": 0,
+ "tests_administered": 12553,
+ "total_staff": 43,
+ "total_students": 117
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 99,
+ "isolation_off_campus": 12,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-12-15 19:34:56",
+ "new_staff": 14,
+ "new_students": 21,
+ "quarantine_off_campus": 30,
+ "quarantine_on_campus": 0,
+ "tests_administered": 12593,
+ "total_staff": 45,
+ "total_students": 119
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 99,
+ "isolation_off_campus": 16,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-12-16 20:34:53",
+ "new_staff": 16,
+ "new_students": 24,
+ "quarantine_off_campus": 28,
+ "quarantine_on_campus": 0,
+ "tests_administered": 12629,
+ "total_staff": 49,
+ "total_students": 124
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 100,
+ "isolation_off_campus": 13,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-12-17 18:34:53",
+ "new_staff": 18,
+ "new_students": 22,
+ "quarantine_off_campus": 25,
+ "quarantine_on_campus": 0,
+ "tests_administered": 12630,
+ "total_staff": 52,
+ "total_students": 126
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 98,
+ "isolation_off_campus": 12,
+ "isolation_on_campus": 3,
+ "last_updated": "2020-12-18 20:09:53",
+ "new_staff": 18,
+ "new_students": 22,
+ "quarantine_off_campus": 23,
+ "quarantine_on_campus": 1,
+ "tests_administered": 12670,
+ "total_staff": 54,
+ "total_students": 127
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 100,
+ "isolation_off_campus": 9,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-12-21 21:00:25",
+ "new_staff": 17,
+ "new_students": 17,
+ "quarantine_off_campus": 12,
+ "quarantine_on_campus": 1,
+ "tests_administered": 12706,
+ "total_staff": 54,
+ "total_students": 127
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 100,
+ "isolation_off_campus": 7,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-12-22 19:20:26",
+ "new_staff": 14,
+ "new_students": 16,
+ "quarantine_off_campus": 9,
+ "quarantine_on_campus": 1,
+ "tests_administered": 12706,
+ "total_staff": 52,
+ "total_students": 126
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 100,
+ "isolation_off_campus": 6,
+ "isolation_on_campus": 1,
+ "last_updated": "2020-12-23 21:10:25",
+ "new_staff": 17,
+ "new_students": 18,
+ "quarantine_off_campus": 7,
+ "quarantine_on_campus": 1,
+ "tests_administered": 12746,
+ "total_staff": 55,
+ "total_students": 128
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 100,
+ "isolation_off_campus": 2,
+ "isolation_on_campus": 0,
+ "last_updated": "2021-01-04 21:30:27",
+ "new_staff": 11,
+ "new_students": 6,
+ "quarantine_off_campus": 4,
+ "quarantine_on_campus": 0,
+ "tests_administered": 12939,
+ "total_staff": 64,
+ "total_students": 132
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 96,
+ "isolation_off_campus": 4,
+ "isolation_on_campus": 0,
+ "last_updated": "2021-01-05 20:56:42",
+ "new_staff": 13,
+ "new_students": 5,
+ "quarantine_off_campus": 6,
+ "quarantine_on_campus": 0,
+ "tests_administered": 13002,
+ "total_staff": 70,
+ "total_students": 133
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 96,
+ "isolation_off_campus": 5,
+ "isolation_on_campus": 0,
+ "last_updated": "2021-01-06 20:51:42",
+ "new_staff": 15,
+ "new_students": 5,
+ "quarantine_off_campus": 7,
+ "quarantine_on_campus": 0,
+ "tests_administered": 13002,
+ "total_staff": 73,
+ "total_students": 134
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 96,
+ "isolation_off_campus": 5,
+ "isolation_on_campus": 0,
+ "last_updated": "2021-01-07 20:41:49",
+ "new_staff": 18,
+ "new_students": 4,
+ "quarantine_off_campus": 9,
+ "quarantine_on_campus": 0,
+ "tests_administered": 13064,
+ "total_staff": 77,
+ "total_students": 134
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 99,
+ "isolation_off_campus": 5,
+ "isolation_on_campus": 0,
+ "last_updated": "2021-01-08 20:41:42",
+ "new_staff": 19,
+ "new_students": 4,
+ "quarantine_off_campus": 10,
+ "quarantine_on_campus": 1,
+ "tests_administered": 13064,
+ "total_staff": 80,
+ "total_students": 134
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 95,
+ "isolation_off_campus": 6,
+ "isolation_on_campus": 1,
+ "last_updated": "2021-01-11 20:40:10",
+ "new_staff": 29,
+ "new_students": 6,
+ "quarantine_off_campus": 10,
+ "quarantine_on_campus": 1,
+ "tests_administered": 13129,
+ "total_staff": 94,
+ "total_students": 136
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 96,
+ "isolation_off_campus": 9,
+ "isolation_on_campus": 1,
+ "last_updated": "2021-01-12 20:50:10",
+ "new_staff": 33,
+ "new_students": 9,
+ "quarantine_off_campus": 15,
+ "quarantine_on_campus": 1,
+ "tests_administered": 13193,
+ "total_staff": 100,
+ "total_students": 139
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 96,
+ "isolation_off_campus": 10,
+ "isolation_on_campus": 1,
+ "last_updated": "2021-01-13 20:35:11",
+ "new_staff": 39,
+ "new_students": 8,
+ "quarantine_off_campus": 31,
+ "quarantine_on_campus": 5,
+ "tests_administered": 13193,
+ "total_staff": 110,
+ "total_students": 139
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 95,
+ "isolation_off_campus": 14,
+ "isolation_on_campus": 3,
+ "last_updated": "2021-01-14 21:35:10",
+ "new_staff": 40,
+ "new_students": 9,
+ "quarantine_off_campus": 28,
+ "quarantine_on_campus": 6,
+ "tests_administered": 13257,
+ "total_staff": 115,
+ "total_students": 141
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 95,
+ "isolation_off_campus": 19,
+ "isolation_on_campus": 3,
+ "last_updated": "2021-01-15 20:35:10",
+ "new_staff": 40,
+ "new_students": 11,
+ "quarantine_off_campus": 31,
+ "quarantine_on_campus": 6,
+ "tests_administered": 13257,
+ "total_staff": 118,
+ "total_students": 143
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 95,
+ "isolation_off_campus": 17,
+ "isolation_on_campus": 3,
+ "last_updated": "2021-01-18 20:59:05",
+ "new_staff": 42,
+ "new_students": 17,
+ "quarantine_off_campus": 24,
+ "quarantine_on_campus": 6,
+ "tests_administered": 13401,
+ "total_staff": 125,
+ "total_students": 150
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 95,
+ "isolation_off_campus": 24,
+ "isolation_on_campus": 3,
+ "last_updated": "2021-01-19 20:49:05",
+ "new_staff": 48,
+ "new_students": 17,
+ "quarantine_off_campus": 35,
+ "quarantine_on_campus": 6,
+ "tests_administered": 13456,
+ "total_staff": 133,
+ "total_students": 150
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 92,
+ "isolation_off_campus": 23,
+ "isolation_on_campus": 3,
+ "last_updated": "2021-01-20 20:39:07",
+ "new_staff": 50,
+ "new_students": 17,
+ "quarantine_off_campus": 48,
+ "quarantine_on_campus": 11,
+ "tests_administered": 13457,
+ "total_staff": 136,
+ "total_students": 151
+ },
+ {
+ "alert_level": "orange",
+ "beds_available": 92,
+ "isolation_off_campus": 22,
+ "isolation_on_campus": 5,
+ "last_updated": "2021-01-21 20:44:06",
+ "new_staff": 55,
+ "new_students": 21,
+ "quarantine_off_campus": 44,
+ "quarantine_on_campus": 6,
+ "tests_administered": 13531,
+ "total_staff": 143,
+ "total_students": 156
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 90,
+ "isolation_off_campus": 28,
+ "isolation_on_campus": 5,
+ "last_updated": "2021-01-22 21:04:06",
+ "new_staff": 56,
+ "new_students": 22,
+ "quarantine_off_campus": 47,
+ "quarantine_on_campus": 10,
+ "tests_administered": 13782,
+ "total_staff": 147,
+ "total_students": 158
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 93,
+ "isolation_off_campus": 33,
+ "isolation_on_campus": 10,
+ "last_updated": "2021-01-25 16:00:00",
+ "new_staff": -1,
+ "new_students": -1,
+ "quarantine_off_campus": 54,
+ "quarantine_on_campus": 9,
+ "tests_administered": 13843,
+ "total_staff": 149,
+ "total_students": 166
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 92,
+ "isolation_off_campus": 35,
+ "isolation_on_campus": 10,
+ "last_updated": "2021-01-26 16:00:00",
+ "new_staff": -1,
+ "new_students": -1,
+ "quarantine_off_campus": 64,
+ "quarantine_on_campus": 13,
+ "tests_administered": 13902,
+ "total_staff": 151,
+ "total_students": 171
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 91,
+ "isolation_off_campus": 35,
+ "isolation_on_campus": 13,
+ "last_updated": "2021-01-27 21:11:47",
+ "new_staff": -1,
+ "new_students": -1,
+ "quarantine_off_campus": 66,
+ "quarantine_on_campus": 16,
+ "tests_administered": 13842,
+ "total_staff": 149,
+ "total_students": 166
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 89,
+ "isolation_off_campus": 30,
+ "isolation_on_campus": 17,
+ "last_updated": "2021-01-28 20:46:47",
+ "new_staff": -1,
+ "new_students": -1,
+ "quarantine_off_campus": 64,
+ "quarantine_on_campus": 18,
+ "tests_administered": 15303,
+ "total_staff": 152,
+ "total_students": 170
+ },
+ {
+ "alert_level": "yellow",
+ "beds_available": 89,
+ "isolation_off_campus": 28,
+ "isolation_on_campus": 16,
+ "last_updated": "2021-01-29 20:46:47",
+ "new_staff": -1,
+ "new_students": -1,
+ "quarantine_off_campus": 56,
+ "quarantine_on_campus": 21,
+ "tests_administered": 17121,
+ "total_staff": 152,
+ "total_students": 177
+ }
+] \ No newline at end of file
diff --git a/migrations.py b/migrations.py
index b87a82a..5f692cb 100644
--- a/migrations.py
+++ b/migrations.py
@@ -1,29 +1,10 @@
import os
-import csv
+import json
import sqlite3
-LATEST_DATA={}
+from poller.db import create_tables, get_latest_from_db
-def create_tables():
- print('creating tables')
- db_conn = sqlite3.connect('./data/data.sqlite3')
- c = db_conn.cursor()
- sql = f'CREATE TABLE IF NOT EXISTS `alertlevel` (time DATETIME PRIMARY KEY NOT NULL, color CHAR(50) NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `total` (time DATETIME PRIMARY KEY NOT NULL, total_students INT NOT NULL, total_staff INT NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `new` (time DATETIME PRIMARY KEY NOT NULL, new_students INT NOT NULL, new_staff INT NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `quarantine` (time DATETIME PRIMARY KEY NOT NULL, quarantine_on_campus INT NOT NULL, quarantine_off_campus INT NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `isolation` (time DATETIME PRIMARY KEY NOT NULL, isolation_on_campus INT NOT NULL, isolation_off_campus INT NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `beds` (time DATETIME PRIMARY KEY NOT NULL, beds_available INT NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `tests` (time DATETIME PRIMARY KEY NOT NULL, tests_administered INT NOT NULL);'
- c.execute(sql)
- db_conn.commit()
- db_conn.close()
+LATEST_DATA={}
def update_db():
db_conn = sqlite3.connect('./data/data.sqlite3')
@@ -45,44 +26,6 @@ def update_db():
db_conn.commit()
db_conn.close()
-def get_latest_from_db():
-
- db_conn = sqlite3.connect('./data/data.sqlite3')
- c = db_conn.cursor()
- sql = 'SELECT max(alertlevel.time), alertlevel.color, total.total_students, total.total_staff, new.new_students, new.new_staff, ' + \
- 'quarantine.quarantine_on_campus, quarantine.quarantine_off_campus, isolation.isolation_on_campus, isolation.isolation_off_campus, ' + \
- 'beds.beds_available, tests.tests_administered ' + \
- 'FROM `alertlevel` ' + \
- 'INNER JOIN `total` ' + \
- 'ON alertlevel.time = total.time ' + \
- 'INNER JOIN `new` ' + \
- 'ON alertlevel.time = new.time ' + \
- 'INNER JOIN `quarantine` ' + \
- 'ON alertlevel.time = quarantine.time ' + \
- 'INNER JOIN `isolation` ' + \
- 'ON alertlevel.time = isolation.time ' + \
- 'INNER JOIN `beds` ' + \
- 'ON alertlevel.time = beds.time ' + \
- 'INNER JOIN `tests` ' + \
- 'ON alertlevel.time = tests.time'
- c.execute(sql)
- d = c.fetchone()
- data = {
- 'alert_level': d[1],
- 'total_students': d[2],
- 'total_staff': d[3],
- 'new_students': d[4],
- 'new_staff': d[5],
- 'quarantine_on_campus': d[6],
- 'quarantine_off_campus': d[7],
- 'isolation_on_campus': d[8],
- 'isolation_off_campus': d[9],
- 'beds_available': d[10],
- 'tests_administered': d[11],
- 'last_updated': d[0]
- }
- return data
-
def db_is_same():
global LATEST_DATA
latest_data = get_latest_from_db()
@@ -98,29 +41,25 @@ if not os.path.exists('./data'):
create_tables()
-with open('historical_data.csv', 'r') as csvfile:
+with open('history/history.json', 'r') as fd:
print('importing data...')
- csvreader = csv.reader(csvfile)
- firstRow = True
- for row in csvreader:
- if firstRow:
- firstRow = False
- continue
+ data = json.loads(fd.read())
+ for day in data:
+ print(day)
LATEST_DATA = {
- 'alert_level': str(row[1]),
- 'total_students': int(row[4]),
- 'total_staff': int(row[5]),
- 'new_students': int(row[2]),
- 'new_staff': int(row[3]),
- 'quarantine_on_campus': int(row[6]),
- 'quarantine_off_campus': int(row[7]),
- 'isolation_on_campus': int(row[8]),
- 'isolation_off_campus': int(row[9]),
- 'beds_available': int(row[11]),
- 'tests_administered': int(row[10]),
- 'last_updated': f'{row[0]} 16:00:00'
+ 'alert_level': str(day['alert_level']),
+ 'total_students': int(day['total_students']),
+ 'total_staff': int(day['total_staff']),
+ 'new_students': int(day['new_students']),
+ 'new_staff': int(day['new_staff']),
+ 'quarantine_on_campus': int(day['quarantine_on_campus']),
+ 'quarantine_off_campus': int(day['quarantine_off_campus']),
+ 'isolation_on_campus': int(day['isolation_on_campus']),
+ 'isolation_off_campus': int(day['isolation_off_campus']),
+ 'beds_available': int(day['beds_available']),
+ 'tests_administered': int(day['tests_administered']),
+ 'last_updated': day['last_updated']
}
- if not db_is_same():
- update_db()
+ update_db()
print('data imported!')
diff --git a/poller/__init__.py b/poller/__init__.py
index 29852ba..f6e5259 100644
--- a/poller/__init__.py
+++ b/poller/__init__.py
@@ -12,6 +12,7 @@ import requests
from bs4 import BeautifulSoup
from .dedup import dedup
+from .db import create_tables, get_all_from_db, get_latest_from_db
POOL_TIME = 5 * 60 # Seconds
DASHBOARD_URL = 'https://rit.edu/ready/spring-dashboard'
@@ -22,31 +23,6 @@ db_lock = threading.Lock()
if not os.path.exists('./data'):
os.mkdir('./data')
-def interrupt():
- global data_thread
- data_thread.cancel()
-
-def create_tables():
- with db_lock:
- db_conn = sqlite3.connect('data/data.sqlite3')
- c = db_conn.cursor()
- sql = f'CREATE TABLE IF NOT EXISTS `alertlevel` (time DATETIME PRIMARY KEY NOT NULL, color CHAR(50) NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `total` (time DATETIME PRIMARY KEY NOT NULL, total_students INT NOT NULL, total_staff INT NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `new` (time DATETIME PRIMARY KEY NOT NULL, new_students INT NOT NULL, new_staff INT NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `quarantine` (time DATETIME PRIMARY KEY NOT NULL, quarantine_on_campus INT NOT NULL, quarantine_off_campus INT NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `isolation` (time DATETIME PRIMARY KEY NOT NULL, isolation_on_campus INT NOT NULL, isolation_off_campus INT NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `beds` (time DATETIME PRIMARY KEY NOT NULL, beds_available INT NOT NULL);'
- c.execute(sql)
- sql = f'CREATE TABLE IF NOT EXISTS `tests` (time DATETIME PRIMARY KEY NOT NULL, tests_administered INT NOT NULL);'
- c.execute(sql)
- db_conn.commit()
- db_conn.close()
-
def update_db():
with db_lock:
db_conn = sqlite3.connect('data/data.sqlite3')
@@ -69,47 +45,6 @@ def update_db():
db_conn.close()
dedup()
-def get_latest_from_db():
- return get_all_from_db()[-1]
-
-def get_all_from_db():
- with db_lock:
- db_conn = sqlite3.connect('data/data.sqlite3')
- c = db_conn.cursor()
- sql = 'SELECT alertlevel.time, alertlevel.color, total.total_students, total.total_staff, new.new_students, new.new_staff, ' + \
- 'quarantine.quarantine_on_campus, quarantine.quarantine_off_campus, isolation.isolation_on_campus, isolation.isolation_off_campus, ' + \
- 'beds.beds_available, tests.tests_administered ' + \
- 'FROM `alertlevel` ' + \
- 'INNER JOIN `total` ' + \
- 'ON alertlevel.time = total.time ' + \
- 'INNER JOIN `new` ' + \
- 'ON alertlevel.time = new.time ' + \
- 'INNER JOIN `quarantine` ' + \
- 'ON alertlevel.time = quarantine.time ' + \
- 'INNER JOIN `isolation` ' + \
- 'ON alertlevel.time = isolation.time ' + \
- 'INNER JOIN `beds` ' + \
- 'ON alertlevel.time = beds.time ' + \
- 'INNER JOIN `tests` ' + \
- 'ON alertlevel.time = tests.time'
- c.execute(sql)
-
- data = [{
- 'alert_level': d[1],
- 'total_students': d[2],
- 'total_staff': d[3],
- 'new_students': d[4],
- 'new_staff': d[5],
- 'quarantine_on_campus': d[6],
- 'quarantine_off_campus': d[7],
- 'isolation_on_campus': d[8],
- 'isolation_off_campus': d[9],
- 'beds_available': d[10],
- 'tests_administered': d[11],
- 'last_updated': d[0]
- } for d in c.fetchall()]
- return data
-
def data_is_same(current_data):
global LATEST_DATA
if LATEST_DATA is None or current_data is None:
@@ -181,11 +116,6 @@ def get_data():
update_db()
return current_data
-
-get_data()
-# When you kill Flask (SIGTERM), clear the trigger for the next thread
-atexit.register(interrupt)
-
APP = Flask(__name__)
# Load file based configuration overrides if present
diff --git a/poller/db.py b/poller/db.py
new file mode 100644
index 0000000..d3836a7
--- /dev/null
+++ b/poller/db.py
@@ -0,0 +1,67 @@
+import threading
+import sqlite3
+
+db_lock = threading.Lock()
+
+def create_tables():
+ with db_lock:
+ db_conn = sqlite3.connect('data/data.sqlite3')
+ c = db_conn.cursor()
+ sql = f'CREATE TABLE IF NOT EXISTS `alertlevel` (time DATETIME PRIMARY KEY NOT NULL, color CHAR(50) NOT NULL);'
+ c.execute(sql)
+ sql = f'CREATE TABLE IF NOT EXISTS `total` (time DATETIME PRIMARY KEY NOT NULL, total_students INT NOT NULL, total_staff INT NOT NULL);'
+ c.execute(sql)
+ sql = f'CREATE TABLE IF NOT EXISTS `new` (time DATETIME PRIMARY KEY NOT NULL, new_students INT NOT NULL, new_staff INT NOT NULL);'
+ c.execute(sql)
+ sql = f'CREATE TABLE IF NOT EXISTS `quarantine` (time DATETIME PRIMARY KEY NOT NULL, quarantine_on_campus INT NOT NULL, quarantine_off_campus INT NOT NULL);'
+ c.execute(sql)
+ sql = f'CREATE TABLE IF NOT EXISTS `isolation` (time DATETIME PRIMARY KEY NOT NULL, isolation_on_campus INT NOT NULL, isolation_off_campus INT NOT NULL);'
+ c.execute(sql)
+ sql = f'CREATE TABLE IF NOT EXISTS `beds` (time DATETIME PRIMARY KEY NOT NULL, beds_available INT NOT NULL);'
+ c.execute(sql)
+ sql = f'CREATE TABLE IF NOT EXISTS `tests` (time DATETIME PRIMARY KEY NOT NULL, tests_administered INT NOT NULL);'
+ c.execute(sql)
+ db_conn.commit()
+ db_conn.close()
+
+
+def get_latest_from_db():
+ return get_all_from_db()[-1]
+
+def get_all_from_db():
+ with db_lock:
+ db_conn = sqlite3.connect('data/data.sqlite3')
+ c = db_conn.cursor()
+ sql = 'SELECT alertlevel.time, alertlevel.color, total.total_students, total.total_staff, new.new_students, new.new_staff, ' + \
+ 'quarantine.quarantine_on_campus, quarantine.quarantine_off_campus, isolation.isolation_on_campus, isolation.isolation_off_campus, ' + \
+ 'beds.beds_available, tests.tests_administered ' + \
+ 'FROM `alertlevel` ' + \
+ 'INNER JOIN `total` ' + \
+ 'ON alertlevel.time = total.time ' + \
+ 'INNER JOIN `new` ' + \
+ 'ON alertlevel.time = new.time ' + \
+ 'INNER JOIN `quarantine` ' + \
+ 'ON alertlevel.time = quarantine.time ' + \
+ 'INNER JOIN `isolation` ' + \
+ 'ON alertlevel.time = isolation.time ' + \
+ 'INNER JOIN `beds` ' + \
+ 'ON alertlevel.time = beds.time ' + \
+ 'INNER JOIN `tests` ' + \
+ 'ON alertlevel.time = tests.time'
+ c.execute(sql)
+
+ data = [{
+ 'alert_level': d[1],
+ 'total_students': d[2],
+ 'total_staff': d[3],
+ 'new_students': d[4],
+ 'new_staff': d[5],
+ 'quarantine_on_campus': d[6],
+ 'quarantine_off_campus': d[7],
+ 'isolation_on_campus': d[8],
+ 'isolation_off_campus': d[9],
+ 'beds_available': d[10],
+ 'tests_administered': d[11],
+ 'last_updated': d[0]
+ } for d in c.fetchall()]
+ return data
diff --git a/poller/dedup.py b/poller/dedup.py
index 9db5886..ba68be8 100644
--- a/poller/dedup.py
+++ b/poller/dedup.py
@@ -69,5 +69,3 @@ def dedup():
else:
drop_by_date(data[i]['last_updated'])
print('dropped ' + data[i]['last_updated'])
-
-dedup() \ No newline at end of file