-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (67 loc) · 3.59 KB
/
main.py
File metadata and controls
76 lines (67 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from mock_data import *
from default_scenarios import *
from utilities import *
from tabulate import tabulate
from pymongo import MongoClient
from predictions import *
import warnings
warnings.filterwarnings("ignore")
warnings.simplefilter(action='ignore', category=FutureWarning)
def main_script():
print("\nWelcome to the Sight++ Footfall Predictor !\n")
# Retrieve all default scenarios
options_dict = {"Option": [], "Yearly Seasonality": [], "Weekly Seasonality": [], "Daily Seasonality": []}
while True:
for option in scenarios:
# Retrieve seasonality parameters
yearly_seasonality = scenario_seasonality[option]["Yearly Seasonality"]
weekly_seasonality = scenario_seasonality[option]["Weekly Seasonality"]
daily_seasonality = scenario_seasonality[option]["Daily Seasonality"]
# Append to dictionary
options_dict["Option"].append(option)
options_dict["Yearly Seasonality"].append(yearly_seasonality)
options_dict["Weekly Seasonality"].append(weekly_seasonality)
options_dict["Daily Seasonality"].append(daily_seasonality)
options_df = pd.DataFrame(options_dict)
print("\nThe table below lists several mock data sets including information about "
"seasonality.\n")
print(tabulate(options_df, tablefmt='pretty', headers='keys'))
print("")
input_number = input("Please select an option that matches the specifics of your venue using the index number "
"(e.g. '0'): ")
user_choice = exception_handler_id(input_number, options_df)
if user_choice == "Invalid":
print("\n")
return True
else:
selected_option = options_df.loc[user_choice][0]
print(f"\nThe Sight++ Footfall Predictor is currently creating the data set for {selected_option}.\n"
f"This may take a few moments..\n")
scenario = scenarios[selected_option]
total_df = synthesise_data(scenario, use_cases, start_ts, end_ts)
devices = device_info[selected_option]
# Insert data and selected scenario settings to database
insert_to_mongodb(total_df, collection_ff, db)
cum_visitor_count(collection_ff)
print(f"\nHistorical data has been synthesised and is now used by machine learning algorithms to predict"
f" footfall 2 months ahead from now. Please, do not terminate the program.\nIn the meantime, you can"
f" analyse your data in the 'Historical Footfall' and 'Real-Time Footfall' sections of your MongoDB"
f" dashboard.\n")
insert_to_mongodb(scenario, collection_scenario, db)
insert_to_mongodb(devices, collection_devices, db)
historical_data = retrieve_from_mongo(collection_ff, db)
predictions = create_future_data(historical_data)
insert_to_mongodb(predictions, collection_preds, db)
print(f"\nTime series forecasting has now been completed and is ready for analysis in the 'Predictive"
f" Footfall' section of your MongoDB dashboard.\n")
break
return True
if __name__ == "__main__":
cluster = MongoClient("mongodb+srv://sightpp:UCLSightPP2021@sightcluster.ea126.mongodb.net/myFirstDatabase"
"?retryWrites=true&w=majority")
db = cluster["sight"]
collection_ff = db["footfall"]
collection_preds = db["predictions"]
collection_scenario = db["scenario"]
collection_devices = db["devices"]
main_script()