-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_interaction.py
174 lines (140 loc) · 5.24 KB
/
user_interaction.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
"""
UofT Speedrunner
Module Description
==================
This module implements a simplified text-based interaction with program using Python input/output.
Copyright and Usage Information
===============================
This file is provided solely for the personal and private use of the students
mentioned below and all CSC111 course staff at the University of Toronto.
Any other parties not mentioned may not use or possess copies of
this code, whether modified or otherwise.
This file is Copyright (c) 2023
Jason Barahan, Vibhas Raizada, Benjamin Sandoval, Eleonora Scognamiglio.
"""
import load_all_data
import map_generation as mg
def run_path_generation(start: str, end: str, amenities: list[str] = None) -> None:
"""
Generate a path using the SpeedRunner.
Preconditions:
- start is a valid building code
- end is a valid building code
- all elements in amenities are valid amenity strings
"""
if amenities is None or len(amenities) == 0:
mg.visualize_djikstra(start, end)
else:
mg.visualize_djikstra_with_stopovers(start, end, amenities)
# IO functions
def io_main_menu() -> None:
"""
Manage the main in input/output interface, by asking the user which feature of
UofT Speedrunner they would like to use.
"""
string = 0
print('Welcome to UofT Speedrunner!')
print('We get you to where you want to go!')
print('')
print('[A] Show me buildings at the University of Toronto')
print('[B] Show me all the intersections at the University of Toronto')
print('[C] Get me somewhere')
while string not in {'A', 'B', 'C'}:
string = input()
# user chooses option A
if string == 'A':
io_show_buildings()
# user chooses option B
elif string == 'B':
mg.generate_all_intersection_points_with_edges()
# user chooses option C
elif string == 'C':
io_get_path()
# non recognizable input
else:
print("Invalid entry.")
string = 0
def io_get_path() -> None:
"""
CLI IO handling for getting a desired shortest path.
Asks te user for their starting point and final destination,
as well as any potential stopovers.
"""
# get building data
a = load_all_data.load_data('data/building_data.csv', 'data/intersections_data.csv')
building_codes = list(a.buildings)
code, code2, code3 = 'a', 'a', 'a'
amenities = [] # List of amenity strings. For example: ['gym', 'library']
# initial menu
print('For reference, here are the building codes:')
# print out all building codes
for key in a.buildings:
print(key + ': ' + a.buildings[key].name)
print('Lost? Use [ctrl] + [f]')
# 1: input start building
print('\n')
print('Input your start building code')
while code not in building_codes:
code = input('')
# destination in building codes
if code in building_codes:
pass
# non recognizable input
else:
print('Invalid entry.')
# 2: input end building
print('\n')
print('Print your destination')
while code2 not in building_codes:
code2 = input('')
# destination in building codes
if code2 in building_codes:
pass
# non recognizable input
else:
print('Invalid entry.')
# 3: input stopovers
print('\n')
print('Input an amenity you would like your route to include (no quotation marks): ')
print(str(load_all_data.AMENITIES))
print('Or press enter if you have none to add')
while code3 not in building_codes and code3 != '':
code3 = input('')
# no more stopovers
if code3 == '':
# print final info / generate path
print('Directions from ' + code + ' to ' + code2 + ' including ' + str(amenities))
print('Now processing...')
run_path_generation(code, code2, amenities)
# stopover is an amenity
elif code3 in load_all_data.AMENITIES:
amenities.append(code3)
print('The ' + code3 + ' amenity has been added to your request.')
print('Type another amenity or press enter if you are finished.')
code3 = 'a'
# non recognizable input
else:
print('Invalid entry.')
def io_show_buildings() -> None:
"""
CLI IO handling for showing all buildings, or showing buildings with a certain amenity.
"""
io = 'a'
print('Are you looking for a building with a certain amenity in mind?')
print('We have:' + str(list(load_all_data.AMENITIES)))
print('Type one of the above options, or press enter to show all buildings:')
print('No quotation marks please')
while (io != '') and (io not in load_all_data.AMENITIES):
io = input()
if io == '':
mg.generate_all_building_points()
elif io in load_all_data.AMENITIES:
mg.generate_all_building_points(io)
else:
print('Invalid entry. Try again')
if __name__ == '__main__':
# for reference, these are the amenities:
# 'study', 'dining', 'coffee', 'microwave', 'gym', 'library', 'atm',
# 'math learning centre', 'writing centre', 'transportation'
import doctest
doctest.testmod()