Added filtering for midnight

This commit is contained in:
Ryan Chen
2023-08-12 08:24:58 -07:00
parent 012b8127dc
commit 310e296ef9

50
main.py
View File

@@ -4,19 +4,7 @@ import matplotlib.pyplot as plt
from datetime import datetime
from collections import defaultdict
with sqlite3.connect("doordash.db") as connection:
c = connection.cursor()
results = c.execute("select STORE_NAME, DELIVERY_TIME, sum(cast(SUBTOTAL as decimal)) from doordash group by DELIVERY_TIME, STORE_NAME;")
hours = defaultdict(lambda: [])
for result in results:
try:
time = datetime.fromisoformat(result[1])
hours[time.hour] = hours[time.hour] + [time]
except:
pass
def weakness_by_hours(hours):
keys = list(hours.keys())
keys.sort()
@@ -25,6 +13,7 @@ with sqlite3.connect("doordash.db") as connection:
fig, ax = plt.subplots()
ax.tick_params(axis='x', labelrotation=45)
hour_list = keys
counts = [len(hours.get(key)) for key in hours]
ax.bar(hour_list, counts)
@@ -32,3 +21,38 @@ with sqlite3.connect("doordash.db") as connection:
ax.set_title("akshay's moments of weakness")
plt.show()
class Weakness:
def __init__(self, row):
self.name = row[0]
try:
self.time = datetime.fromisoformat(row[1])
except:
self.time = datetime.today()
self.total = row[2]
def weaknessInAnHour(results):
weaknesses = [Weakness(row) for row in results]
restaurants = defaultdict(lambda: 0)
for weakness in weaknesses:
if weakness.time.hour == 0:
restaurants[weakness.name] += 1
print(restaurants)
fig, ax = plt.subplots()
plt.xticks(rotation=45, ha='right')
ax.bar(restaurants.keys(), restaurants.values())
plt.show()
with sqlite3.connect("doordash.db") as connection:
c = connection.cursor()
results = c.execute("select STORE_NAME, DELIVERY_TIME, sum(cast(SUBTOTAL as decimal)) from doordash group by DELIVERY_TIME, STORE_NAME;")
weaknessInAnHour(results)