Spaces:
Runtime error
Runtime error
go2sujeet
commited on
Commit
•
13d902e
1
Parent(s):
682ed0f
- src/main.py +3 -2
- src/utils.py +16 -4
src/main.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from datetime import datetime
|
2 |
import json
|
3 |
from data_classes import Event, TimeWindow
|
4 |
-
from utils import filter_event_by_date_facility_id, find_max_continuous_sequence, loadDataFromJson, twenty_four_hours_bucket_time_series_by_minute
|
5 |
import gradio as gr
|
6 |
from gradio_calendar import Calendar
|
7 |
|
@@ -28,10 +28,11 @@ def process1(target_date, target_facility_id):
|
|
28 |
result = find_most_occupied_window(target_date, target_facility_id)
|
29 |
return "Most occupied window is between {} and {} with {} occupied spots".format(result[0][0],result[0][1],result[1])
|
30 |
|
|
|
31 |
with gr.Blocks() as app:
|
32 |
with gr.Group():
|
33 |
target_date = Calendar(label="Target Date",value=target_date)
|
34 |
-
target_facility_id = gr.
|
35 |
btn_1 = gr.Button(value="Find Most Occupied Window")
|
36 |
output1 = gr.Text(label="Most Occupied Window",show_copy_button = True)
|
37 |
btn_1.click(process1, [target_date, target_facility_id], outputs=output1)
|
|
|
1 |
from datetime import datetime
|
2 |
import json
|
3 |
from data_classes import Event, TimeWindow
|
4 |
+
from utils import filter_event_by_date_facility_id, find_max_continuous_sequence, get_all_facility_ids, loadDataFromJson, twenty_four_hours_bucket_time_series_by_minute
|
5 |
import gradio as gr
|
6 |
from gradio_calendar import Calendar
|
7 |
|
|
|
28 |
result = find_most_occupied_window(target_date, target_facility_id)
|
29 |
return "Most occupied window is between {} and {} with {} occupied spots".format(result[0][0],result[0][1],result[1])
|
30 |
|
31 |
+
all_facility_ids = get_all_facility_ids()
|
32 |
with gr.Blocks() as app:
|
33 |
with gr.Group():
|
34 |
target_date = Calendar(label="Target Date",value=target_date)
|
35 |
+
target_facility_id = gr.Dropdown(label="Facility ID",choices=all_facility_ids,value=all_facility_ids[0])
|
36 |
btn_1 = gr.Button(value="Find Most Occupied Window")
|
37 |
output1 = gr.Text(label="Most Occupied Window",show_copy_button = True)
|
38 |
btn_1.click(process1, [target_date, target_facility_id], outputs=output1)
|
src/utils.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import time
|
2 |
from data_classes import Event, TimeWindow
|
3 |
-
import datetime
|
4 |
import json
|
|
|
|
|
5 |
|
6 |
def twenty_four_hours_bucket_time_series_by_minute(valid_events:list[Event],target_date:datetime)->(list[int],list[list[Event]]): # type: ignore
|
7 |
#create a pre defined time window for 24 hours by minute precision
|
@@ -56,13 +57,24 @@ def find_max_continuous_sequence(x):
|
|
56 |
return (max_element, start, end)
|
57 |
|
58 |
def loadDataFromJson():
|
59 |
-
|
60 |
-
|
|
|
|
|
61 |
return data
|
62 |
|
|
|
63 |
def filter_event_by_date_facility_id(event:Event,target_date:datetime, facility_id:int):
|
64 |
if event.facility_id == facility_id:
|
65 |
if event.entrance_time.date() <= target_date.date() and event.exit_time.date() >= target_date.date():
|
66 |
return True
|
67 |
else:
|
68 |
-
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import time
|
2 |
from data_classes import Event, TimeWindow
|
|
|
3 |
import json
|
4 |
+
from datetime import datetime
|
5 |
+
data = None
|
6 |
|
7 |
def twenty_four_hours_bucket_time_series_by_minute(valid_events:list[Event],target_date:datetime)->(list[int],list[list[Event]]): # type: ignore
|
8 |
#create a pre defined time window for 24 hours by minute precision
|
|
|
57 |
return (max_element, start, end)
|
58 |
|
59 |
def loadDataFromJson():
|
60 |
+
global data
|
61 |
+
if data is None:
|
62 |
+
with open('data/events.json') as f:
|
63 |
+
data = json.load(f)
|
64 |
return data
|
65 |
|
66 |
+
|
67 |
def filter_event_by_date_facility_id(event:Event,target_date:datetime, facility_id:int):
|
68 |
if event.facility_id == facility_id:
|
69 |
if event.entrance_time.date() <= target_date.date() and event.exit_time.date() >= target_date.date():
|
70 |
return True
|
71 |
else:
|
72 |
+
return False
|
73 |
+
|
74 |
+
def get_all_entrance_dates()->list[datetime]:
|
75 |
+
data = loadDataFromJson()
|
76 |
+
return [datetime.fromisoformat(event['entrance_time']) for event in data]
|
77 |
+
|
78 |
+
def get_all_facility_ids()->list[int]:
|
79 |
+
data = loadDataFromJson()
|
80 |
+
return list(set([event['facility_id'] for event in data]))
|