From ab7a1b31a991742e7b471ebec117d530b78903d3 Mon Sep 17 00:00:00 2001 From: muhesh Date: Mon, 21 Mar 2022 19:41:23 +0530 Subject: [PATCH 1/4] feat(dashboard):route for dashboard --- scripts/main_constants.py | 552 ++++++++++++++++---------------- scripts/seeder/seed_details.py | 5 +- scripts/seeder/seed_tests.py | 1 + server/controllers/dashboard.py | 65 ++++ server/main.py | 3 +- server/models/dashboard.py | 38 +++ server/routers/dashboard.py | 79 +++++ server/routers/seeds.py | 1 - server/schemas/department.py | 3 +- tests/dashboard_test.py | 26 ++ tests/main_test.py | 9 + 11 files changed, 501 insertions(+), 281 deletions(-) create mode 100644 server/controllers/dashboard.py create mode 100644 server/models/dashboard.py create mode 100644 server/routers/dashboard.py create mode 100644 tests/dashboard_test.py diff --git a/scripts/main_constants.py b/scripts/main_constants.py index 8d44029..4af4ab7 100644 --- a/scripts/main_constants.py +++ b/scripts/main_constants.py @@ -72,7 +72,7 @@ "rules": "", "event_link": "http://genericlink.com/route", "image_link": "http://genericlink.com/route", - "start_time": datetime(2012, 3, 3, 10, 10, 10), + "start_time": datetime(2022, 3, 27, 10, 10, 10), "end_time": datetime(2012, 3, 3, 10, 10, 10), "date": "date", "is_reg_completed": False, @@ -87,7 +87,7 @@ "rules": "", "event_link": "http://genericlink.com/route", "image_link": "http://genericlink.com/route", - "start_time": datetime(2012, 3, 3, 10, 10, 10), + "start_time": datetime(2022, 3, 28, 10, 10, 10), "end_time": datetime(2012, 3, 3, 10, 10, 10), "date": "date", "is_reg_completed": False, @@ -1379,1644 +1379,1644 @@ "point": 5, "position": 1, "event_id": 1, - "department_id": "", + "department_id": 1, }, { "point": 3, "position": 2, "event_id": 1, - "department_id": "", + "department_id": 1, }, { "point": 2, "position": 3, "event_id": 1, - "department_id": "", + "department_id": 2, }, { "point": 5, "position": 1, "event_id": 2, - "department_id": "", + "department_id": 2, }, { "point": 3, "position": 2, "event_id": 2, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 2, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 3, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 3, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 3, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 4, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 4, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 4, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 5, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 5, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 5, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 1, "event_id": 6, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 2, "event_id": 6, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 3, "event_id": 6, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 7, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 7, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 7, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 8, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 8, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 8, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 1, "event_id": 9, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 2, "event_id": 9, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 3, "event_id": 9, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 10, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 10, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 10, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 11, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 11, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 11, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 12, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 12, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 12, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 13, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 13, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 13, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 14, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 14, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 14, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 15, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 15, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 15, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 16, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 16, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 16, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 17, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 17, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 17, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 1, "event_id": 18, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 2, "event_id": 18, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 3, "event_id": 18, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 19, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 19, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 19, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 20, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 20, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 20, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 1, "event_id": 20, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 2, "event_id": 21, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 3, "event_id": 21, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 22, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 22, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 22, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 23, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 23, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 23, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 1, "event_id": 24, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 2, "event_id": 24, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 3, "event_id": 24, - "department_id": "", + "department_id": None, }, { "point": 12, "position": 1, "event_id": 25, - "department_id": "", + "department_id": None, }, { "point": 10, "position": 2, "event_id": 25, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 3, "event_id": 25, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 4, "event_id": 25, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 26, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 26, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 26, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 27, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 27, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 27, - "department_id": "", + "department_id": None, }, { "point": 12, "position": 1, "event_id": 28, - "department_id": "", + "department_id": None, }, { "point": 10, "position": 2, "event_id": 28, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 3, "event_id": 28, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 4, "event_id": 28, - "department_id": "", + "department_id": None, }, { "point": 12, "position": 1, "event_id": 29, - "department_id": "", + "department_id": None, }, { "point": 10, "position": 2, "event_id": 29, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 3, "event_id": 29, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 4, "event_id": 29, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 30, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 30, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 30, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 31, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 31, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 31, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 32, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 32, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 32, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 33, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 33, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 33, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 34, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 34, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 34, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 35, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 35, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 35, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 36, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 36, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 36, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 37, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 37, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 37, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 38, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 38, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 38, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 39, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 39, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 39, - "department_id": "", + "department_id": None, }, { "point": 10, "position": 1, "event_id": 40, - "department_id": "", + "department_id": None, }, { "point": 7, "position": 2, "event_id": 40, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 3, "event_id": 40, - "department_id": "", + "department_id": None, }, { "point": 12, "position": 1, "event_id": 41, - "department_id": "", + "department_id": None, }, { "point": 10, "position": 2, "event_id": 41, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 3, "event_id": 41, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 4, "event_id": 41, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 43, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 43, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 43, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 45, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 45, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 45, - "department_id": "", + "department_id": None, }, { "point": 10, "position": 1, "event_id": 42, - "department_id": "", + "department_id": None, }, { "point": 7, "position": 2, "event_id": 42, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 3, "event_id": 42, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 44, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 44, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 44, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 46, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 46, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 46, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 47, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 47, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 47, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 1, "event_id": 48, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 2, "event_id": 48, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 3, "event_id": 48, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 49, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 49, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 49, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 50, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 50, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 50, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 1, "event_id": 51, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 2, "event_id": 51, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 3, "event_id": 51, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 1, "event_id": 52, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 2, "event_id": 52, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 3, "event_id": 52, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 53, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 53, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 53, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 54, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 54, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 54, - "department_id": "", + "department_id": None, }, { "point": 10, "position": 1, "event_id": 55, - "department_id": "", + "department_id": None, }, { "point": 7, "position": 2, "event_id": 55, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 3, "event_id": 55, - "department_id": "", + "department_id": None, }, { "point": 10, "position": 1, "event_id": 56, - "department_id": "", + "department_id": None, }, { "point": 7, "position": 2, "event_id": 56, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 3, "event_id": 56, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 57, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 57, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 57, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 58, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 58, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 58, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 61, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 61, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 61, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 63, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 63, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 63, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 59, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 59, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 59, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 62, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 62, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 62, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 60, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 60, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 60, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 64, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 64, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 64, - "department_id": "", + "department_id": None, }, { "point": 9, "position": 1, "event_id": 66, - "department_id": "", + "department_id": None, }, { "point": 7, "position": 2, "event_id": 66, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 3, "event_id": 66, - "department_id": "", + "department_id": None, }, { "point": 10, "position": 1, "event_id": 65, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 2, "event_id": 65, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 3, "event_id": 65, - "department_id": "", + "department_id": None, }, { "point": 8, "position": 1, "event_id": 67, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 2, "event_id": 67, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 3, "event_id": 67, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 68, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 68, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 68, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 69, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 69, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 69, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 70, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 70, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 70, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 71, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 71, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 71, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 72, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 72, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 72, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 73, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 73, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 73, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 1, "event_id": 74, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 2, "event_id": 74, - "department_id": "", + "department_id": None, }, { "point": 1, "position": 3, "event_id": 74, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 76, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 76, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 76, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 79, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 79, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 79, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 80, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 80, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 80, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 81, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 81, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 81, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 82, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 82, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 82, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 75, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 75, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 75, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 77, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 77, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 77, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 78, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 78, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 78, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 77, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 77, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 77, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 83, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 83, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 83, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 77, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 77, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 77, - "department_id": "", + "department_id": None, }, { "point": 6, "position": 1, "event_id": 85, - "department_id": "", + "department_id": None, }, { "point": 4, "position": 2, "event_id": 85, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 85, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 84, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 84, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 84, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 86, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 86, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 86, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 87, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 87, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 87, - "department_id": "", + "department_id": None, }, { "point": 5, "position": 1, "event_id": 88, - "department_id": "", + "department_id": None, }, { "point": 3, "position": 2, "event_id": 88, - "department_id": "", + "department_id": None, }, { "point": 2, "position": 3, "event_id": 88, - "department_id": "", + "department_id": None, }, ] diff --git a/scripts/seeder/seed_details.py b/scripts/seeder/seed_details.py index 9e435a7..fa7cf85 100644 --- a/scripts/seeder/seed_details.py +++ b/scripts/seeder/seed_details.py @@ -25,6 +25,7 @@ async def seed_maindb(database: Session): for department in test_departments: database.add( Department( + id=department["id"], name=department["name"], description=department["description"], ) @@ -37,7 +38,7 @@ async def seed_maindb(database: Session): email=test_user["email"], mobile_number=test_user["mobile_number"], gender=test_user["gender"], - department_id=None, + department_id=test_user["department_id"], fcm_token=None, ) ) @@ -78,7 +79,7 @@ async def seed_maindb(database: Session): point=point["point"], position=point["position"], event_id=point["event_id"], - department_id=None, + department_id=point["department_id"], ) ) database.commit() diff --git a/scripts/seeder/seed_tests.py b/scripts/seeder/seed_tests.py index 795cc4d..6fcf3be 100644 --- a/scripts/seeder/seed_tests.py +++ b/scripts/seeder/seed_tests.py @@ -36,6 +36,7 @@ def seed_testdb(database: Session): for department in test_departments: database.add( Department( + key=department["id"], name=department["name"], description=department["description"], ) diff --git a/server/controllers/dashboard.py b/server/controllers/dashboard.py new file mode 100644 index 0000000..6560e98 --- /dev/null +++ b/server/controllers/dashboard.py @@ -0,0 +1,65 @@ +""" +Dashboard controller +""" + +from datetime import datetime + +from server.models.event import EventModel +from server.schemas.event import Event + + +def get_upcoming_events(events: tuple[Event]) -> list[EventModel]: + """ + Util function to get upcoming events + """ + upcoming_events: list[EventModel] = [] + current_time = datetime.now() + for event in events: + if event.start_time > current_time: + upcoming_events.append( + EventModel( + image_link=event.image_link, + rules=event.rules, + description=event.description, + start_time=event.start_time, + end_time=event.end_time, + is_reg_completed=event.is_reg_completed, + name=event.name, + points=[], + form_link=event.form_link, + is_event_completed=event.is_event_completed, + event_link=event.event_link, + ) + ) + return upcoming_events + + +def get_points(points: list[tuple], department: int) -> int: + """ + Util function to get points of the department + """ + point_list: dict = {} + for point in points: + point_list.update({point[0]: point[1]}) + print(point_list) + return point_list.get(department, 0) + + +def get_position(points: list[tuple], department: int) -> int: + """ + Util function to get position of the department + """ + point_list: dict = {} + for point in points: + point_list.update({point[0]: point[1]}) + sorted_list = sorted(point_list.items(), key=lambda item: item[1]) + sorted_list.reverse() + pos = 0 + current_value = -1 + for point in sorted_list: + if current_value != point[1]: + current_value = point[1] + pos += 1 + if point[0] == department: + break + return pos diff --git a/server/main.py b/server/main.py index d019fe8..4c7c31e 100644 --- a/server/main.py +++ b/server/main.py @@ -9,7 +9,7 @@ from config.database import Base, engine from config.settings import settings -from server.routers import department, event +from server.routers import dashboard, department, event if "pytest" in sys.modules: from server.routers import auth, preferences, questions, scores, tshirt @@ -33,6 +33,7 @@ app.include_router(event.router) app.include_router(tshirt.router) app.include_router(scores.router) +app.include_router(dashboard.router) origins = [] if "pytest" not in sys.modules: diff --git a/server/models/dashboard.py b/server/models/dashboard.py new file mode 100644 index 0000000..2ef907c --- /dev/null +++ b/server/models/dashboard.py @@ -0,0 +1,38 @@ +""" +Dasnboard Model +""" + +from pydantic import BaseModel +from pydantic.fields import Field + +from server.models.event import EventModel + + +class DashboardResponseModel(BaseModel): + """ + model for dashboard + """ + + department: str = Field( + ..., + title="department", + description="department of the current User", + ) + + point: float = Field( + ..., + title="point", + description="Total score of department in the event", + ) + + position: int = Field( + ..., + title="description", + description="current positon of the department in the event", + ) + + upcoming_events: list[EventModel] = Field( + ..., + title="Upcomind Events", + description="List of all upcoming Events", + ) diff --git a/server/routers/dashboard.py b/server/routers/dashboard.py new file mode 100644 index 0000000..4e29045 --- /dev/null +++ b/server/routers/dashboard.py @@ -0,0 +1,79 @@ +""" +Dashboard route +""" + +from fastapi import APIRouter, HTTPException +from fastapi.param_functions import Depends +from sqlalchemy import func +from sqlalchemy.orm import Session + +from config.database import get_database +from config.logger import logger +from server.controllers.auth import JWTBearer, decode_jwt +from server.controllers.dashboard import ( + get_points, + get_position, + get_upcoming_events, +) +from server.models.dashboard import DashboardResponseModel +from server.models.errors import GenericError +from server.schemas.department import Department +from server.schemas.event import Event +from server.schemas.point import Point +from server.schemas.users import Users + +router = APIRouter( + prefix="/dashboard", +) + + +@router.get( + "/", + response_model=DashboardResponseModel, + dependencies=[Depends(get_database)], +) +async def get_dashboard( + token: str = Depends(JWTBearer()), + database: Session = Depends(get_database), +) -> DashboardResponseModel: + """ + GET route for Dashboard + """ + try: + user_email = decode_jwt(token)["user_email"] + user = database.query(Users).filter_by(email=user_email).first() + if not user: + raise GenericError("User not found") + + department = ( + database.query(Department) + .filter_by(id=user.department_id) + .first() + ) + if not department: + raise GenericError("Department not found for the current user") + + points = ( + database.query(Point.department_id, func.sum(Point.point)) + .group_by(Point.department_id) + .all() + ) + print(points) + events = tuple(database.query(Event).all()) + + return DashboardResponseModel( + department=department.name, + point=get_points(points=points, department=1), + upcoming_events=get_upcoming_events(events=events), + position=get_position(points=points, department=1), + ) + + except GenericError as exception: + logger.error(f"") + raise HTTPException( + status_code=500, + detail="An unexpected error occurred while retrieving dashboard details ", + headers={ + "X-Error": "An unexpected error occurred while retrieving dashboard" + }, + ) from exception diff --git a/server/routers/seeds.py b/server/routers/seeds.py index 824bcfc..d4695c7 100644 --- a/server/routers/seeds.py +++ b/server/routers/seeds.py @@ -8,7 +8,6 @@ from scripts.seeder.seed_details import seed_maindb from config.database import SessionLocal - router = APIRouter() diff --git a/server/schemas/department.py b/server/schemas/department.py index 107de29..9b91475 100644 --- a/server/schemas/department.py +++ b/server/schemas/department.py @@ -15,7 +15,8 @@ class Department(Base): name = Column(String(100)) description = Column(String(3000)) - def __init__(self, name, description): + def __init__(self, key, name, description): + self.id = key self.name = name self.description = description diff --git a/tests/dashboard_test.py b/tests/dashboard_test.py new file mode 100644 index 0000000..a420f4b --- /dev/null +++ b/tests/dashboard_test.py @@ -0,0 +1,26 @@ +""" +Test for dashboard route +""" + +from fastapi.testclient import TestClient + +from config.settings import settings + +jwt_test = settings.test_jwt +header = {"Authorization": f"Bearer {jwt_test}"} +ROUTE = "/dashboard/" +res = { + "department": "EEE", + "point": 34.0, + "position": 2, + "upcoming_events": [], +} + + +def get_dashboard(client: TestClient): + """ + get list of dashboard + """ + get_response = client.get(url=ROUTE, headers=header) + assert get_response.status_code == 200 + assert get_response.json() == res diff --git a/tests/main_test.py b/tests/main_test.py index b7eda20..c32dc96 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -13,6 +13,7 @@ from scripts.seeder.seed_tests import seed_testdb from server.main import app from tests.answers_test import post_answers +from tests.dashboard_test import get_dashboard from tests.department_test import get_departments from tests.event_test import get_events from tests.preferences_test import ( @@ -76,6 +77,13 @@ def scores_test(): get_scores(client) +def dashboard_test(): + """ + method to execute tests on dashboard route + """ + get_dashboard(client) + + app.dependency_overrides[get_database] = get_test_database client = test() @@ -86,3 +94,4 @@ def scores_test(): departments_test() events_test() scores_test() +dashboard_test() From 04517c4a7b765e56404658baa90f5e12ac576639 Mon Sep 17 00:00:00 2001 From: sarvesh-03 Date: Mon, 28 Mar 2022 23:18:16 +0530 Subject: [PATCH 2/4] fix(scripts):fix in seeding department --- scripts/main_constants.py | 4 ++-- scripts/seeder/seed_details.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/main_constants.py b/scripts/main_constants.py index 4af4ab7..da0561f 100644 --- a/scripts/main_constants.py +++ b/scripts/main_constants.py @@ -492,7 +492,7 @@ "rules": "", "event_link": "http://genericlink.com/route", "image_link": "http://genericlink.com/route", - "start_time": datetime(2012, 3, 3, 10, 10, 10), + "start_time": datetime(2022, 4, 4, 10, 10, 10), "end_time": datetime(2012, 3, 3, 10, 10, 10), "date": "date", "is_reg_completed": False, @@ -507,7 +507,7 @@ "rules": "", "event_link": "http://genericlink.com/route", "image_link": "http://genericlink.com/route", - "start_time": datetime(2012, 3, 3, 10, 10, 10), + "start_time": datetime(2022, 4, 4, 10, 10, 10), "end_time": datetime(2012, 3, 3, 10, 10, 10), "date": "date", "is_reg_completed": False, diff --git a/scripts/seeder/seed_details.py b/scripts/seeder/seed_details.py index fa7cf85..93aebae 100644 --- a/scripts/seeder/seed_details.py +++ b/scripts/seeder/seed_details.py @@ -25,7 +25,7 @@ async def seed_maindb(database: Session): for department in test_departments: database.add( Department( - id=department["id"], + key=department["id"], name=department["name"], description=department["description"], ) From 9944cdcefe33aaaf875c64e1da86d62b8d5a466d Mon Sep 17 00:00:00 2001 From: sarvesh-03 Date: Tue, 29 Mar 2022 14:25:13 +0530 Subject: [PATCH 3/4] fix(dept):seed departments --- scripts/main_constants.py | 20 ++++++++++++++ scripts/seeder/seed_details.py | 50 +++++++++++++++++----------------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/scripts/main_constants.py b/scripts/main_constants.py index da0561f..e4fe9b2 100644 --- a/scripts/main_constants.py +++ b/scripts/main_constants.py @@ -3020,3 +3020,23 @@ "department_id": None, }, ] + +departments = [ + {"id": 1, "name": "AR", "description": "some generic description"}, + {"id": 2, "name": "CL", "description": "some generic description"}, + {"id": 3, "name": "CV", "description": "some generic description"}, + {"id": 4, "name": "CY", "description": "some generic description"}, + {"id": 5, "name": "CA", "description": "some generic description"}, + {"id": 6, "name": "CS", "description": "some generic description"}, + {"id": 7, "name": "EE", "description": "some generic description"}, + {"id": 8, "name": "EC", "description": "some generic description"}, + {"id": 9, "name": "HS", "description": "some generic description"}, + {"id": 10, "name": "IC", "description": "some generic description"}, + {"id": 11, "name": "ME", "description": "some generic description"}, + {"id": 12, "name": "MT", "description": "some generic description"}, + {"id": 13, "name": "PH", "description": "some generic description"}, + {"id": 14, "name": "PR", "description": "some generic description"}, + {"id": 15, "name": "MG", "description": "some generic description"}, + {"id": 16, "name": "MA", "description": "some generic description"}, + {"id": 17, "name": "EN", "description": "some generic description"}, +] diff --git a/scripts/seeder/seed_details.py b/scripts/seeder/seed_details.py index 93aebae..e1e419e 100644 --- a/scripts/seeder/seed_details.py +++ b/scripts/seeder/seed_details.py @@ -5,7 +5,7 @@ from requests.sessions import Session from config.logger import logger -from scripts.main_constants import clusters, events, points +from scripts.main_constants import clusters, events, points, departments from scripts.test_constants import test_departments, test_user from server.schemas.cluster import Cluster from server.schemas.department import Department @@ -22,7 +22,7 @@ async def seed_maindb(database: Session): logger.info("Seeding main database") if database.query(Department).count() == 0: logger.info("Seeding database with test departments") - for department in test_departments: + for department in departments: database.add( Department( key=department["id"], @@ -31,18 +31,18 @@ async def seed_maindb(database: Session): ) ) database.commit() - if database.query(Users).count() == 0: - database.add( - Users( - name=test_user["name"], - email=test_user["email"], - mobile_number=test_user["mobile_number"], - gender=test_user["gender"], - department_id=test_user["department_id"], - fcm_token=None, - ) - ) - database.commit() + # if database.query(Users).count() == 0: + # database.add( + # Users( + # name=test_user["name"], + # email=test_user["email"], + # mobile_number=test_user["mobile_number"], + # gender=test_user["gender"], + # department_id=test_user["department_id"], + # fcm_token=None, + # ) + # ) + # database.commit() if database.query(Cluster).count() == 0: for cluster in clusters: database.add( @@ -72,17 +72,17 @@ async def seed_maindb(database: Session): ) ) database.commit() - if database.query(Point).count() == 0: - for point in points: - database.add( - Point( - point=point["point"], - position=point["position"], - event_id=point["event_id"], - department_id=point["department_id"], - ) - ) - database.commit() + # if database.query(Point).count() == 0: + # for point in points: + # database.add( + # Point( + # point=point["point"], + # position=point["position"], + # event_id=point["event_id"], + # department_id=point["department_id"], + # ) + # ) + # database.commit() logger.info("Successfully seeded database") database.commit() database.close() From b63c957eec29281ff5db1de3403b8412f2b7481d Mon Sep 17 00:00:00 2001 From: sarvesh-03 Date: Fri, 1 Apr 2022 19:57:06 +0530 Subject: [PATCH 4/4] fix(department):change logic for get department id --- server/controllers/auth.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/controllers/auth.py b/server/controllers/auth.py index cb37798..a92e857 100644 --- a/server/controllers/auth.py +++ b/server/controllers/auth.py @@ -77,7 +77,14 @@ def get_department_id(email: str) -> int: """ get the department id of the current User """ - return int(email[1:3]) + if int(email[0] == 1): + return int(email[1:3]) + if int(email[0] == 2): + return 15 + if int(email[0] == 3 or email[0] == 4): + return 16 + + return 1 class JWTBearer(HTTPBearer):