From 310e296ef9ec393c6abf309a5b60234dfefd7c1d Mon Sep 17 00:00:00 2001 From: Ryan Chen Date: Sat, 12 Aug 2023 08:24:58 -0700 Subject: [PATCH] Added filtering for midnight --- main.py | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index fb864fd..93d5e41 100644 --- a/main.py +++ b/main.py @@ -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,10 +13,46 @@ 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) ax.set_ylabel("moments of weakness") 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) + + + +