-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch.py
145 lines (109 loc) · 4.25 KB
/
launch.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File: launch.py
# Authors: Bhavyai Gupta, Brandon Attai
# Description: Source Code to control the execution flow for the Project
from ansi_colors import Color as color
from custom_errors import ValueOutOfRange
import data_analysis as da
import time
import os
def clear_console():
"""Function to clear the console
Parameters:
none
Returns:
None
"""
print("\033\143")
def splash_message():
"""
Function to display the welcome message to the program, and opens up the VT mode
by bug (https://bugs.python.org/issue30075) for windows default console for ANSI
sequence to work. This function intends to be run only once at program startup.
Parameters:
none
Returns:
None
"""
os.system("")
clear_console()
print(color.magenta)
print("----------------------------------------------")
print(" Welcome to ENSF-592 project on UN Statistics")
print("----------------------------------------------")
print(color.reset, end="")
# show the splash screen for 1.5 seconds and then clear again
time.sleep(1.5)
clear_console()
def program_menu():
"""
Function to control the flow the whole program by displaying the menu
and navigation throughtout according to the user input
Parameters:
none
Returns:
None
"""
# creating object of class DataAnalysis
analysis = da.DataAnalysis()
# loop to keep printing the menu until Exit
while(True):
# clear the console everytime menu is printed
clear_console()
print("\n" + color.yellow + "Program menu" + color.reset)
# generic options
print("\n[1] Print the imported dataframes")
print("\n[2] Re-export the entire merged hierarchical dataset into Excel")
print("\n[3] Print aggregate stats for the entire dataset")
# data specific options
print(
"\n[4] Print aggregation stats grouped by UN Region/UN Sub-Region and available years")
print(
"\n[5] Print the list of countries that have higher GDP per capita than USA, and the year")
print(
"\n[6] Compare four different countries on various statistical data and plot graphs")
print("\n[0] Exit")
# loop to get valid choice from the user
while(True):
try:
choice = int(input("\nPlease enter the menu option number: "))
if choice < 0 or choice > 6:
raise ValueOutOfRange(
"This option is not supported. Please choose a valid menu option")
elif choice == 0:
print("\nBye!\n")
return
else:
break
except ValueError as e:
print("\n" + color.red +
"Please enter a valid menu option" + color.reset)
except ValueOutOfRange as e:
print("\n" + color.red + str(e) + color.reset)
# after getting a valid option from the user, perform the requested option
if choice == 1:
analysis.print_imported_dataframes(choice)
input("\n" + color.cyan +
"Press enter to return to the menu " + color.reset)
elif choice == 2:
analysis.export_dataset(choice)
input("\n" + color.cyan +
"Press enter to return to the menu " + color.reset)
elif choice == 3:
analysis.print_aggregate_stats(choice)
input("\n" + color.cyan +
"Press enter to return to the menu " + color.reset)
elif choice == 4:
analysis.group_by_stats(choice)
input("\n" + color.cyan +
"Press enter to return to the menu " + color.reset)
elif choice == 5:
analysis.higher_gdp_than_usa(choice)
input("\n" + color.cyan +
"Press enter to return to the menu " + color.reset)
else: # choice == 6:
analysis.pivot_plot(choice)
input("\n" + color.cyan +
"Press enter to return to the menu " + color.reset)
if __name__ == '__main__':
splash_message()
program_menu()