aboutsummaryrefslogtreecommitdiff
path: root/dedup.py
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2020-11-05 15:40:21 -0500
committerGalen Guyer <galen@galenguyer.com>2020-11-05 15:40:21 -0500
commitf8628ca4473f655e05d031e312dd5e7f92ff148c (patch)
tree9ddded40552f2a6b535af6a55c136d7cdc051ae2 /dedup.py
parent4bad72d853e05da08126ae24d353bfbed2c42d94 (diff)
move dedup into poller to run on insert
Diffstat (limited to 'dedup.py')
-rw-r--r--dedup.py70
1 files changed, 0 insertions, 70 deletions
diff --git a/dedup.py b/dedup.py
deleted file mode 100644
index cff72bb..0000000
--- a/dedup.py
+++ /dev/null
@@ -1,70 +0,0 @@
-import sqlite3
-
-def get_all_from_db():
- 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 drop_by_date(date):
- db_conn = sqlite3.connect('data/data.sqlite3')
- c = db_conn.cursor()
- sql = f'DELETE FROM `alertlevel` WHERE time=\'{date}\';'
- c.execute(sql)
- sql = f'DELETE FROM `total` WHERE time=\'{date}\';'
- c.execute(sql)
- sql = f'DELETE FROM `new` WHERE time=\'{date}\';'
- c.execute(sql)
- sql = f'DELETE FROM `quarantine` WHERE time=\'{date}\';'
- c.execute(sql)
- sql = f'DELETE FROM `isolation` WHERE time=\'{date}\';'
- c.execute(sql)
- sql = f'DELETE FROM `beds` WHERE time=\'{date}\';'
- c.execute(sql)
- sql = f'DELETE FROM `tests` WHERE time=\'{date}\';'
- c.execute(sql)
- db_conn.commit()
- db_conn.close()
-
-
-data = get_all_from_db()
-# get first date
-starting_date = data[-1]['last_updated'].split(' ')[0]
-for i in range(len(data)-2, 0, -1):
- if data[i]['last_updated'].split(' ')[0] != starting_date:
- starting_date = data[i]['last_updated'].split(' ')[0]
- else:
- drop_by_date(data[i]['last_updated'])
- print('dropped ' + data[i]['last_updated'])