forked from paulsgh/CityRanker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
city_ranker.pl
640 lines (595 loc) · 26.6 KB
/
city_ranker.pl
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
:- use_module(library(http/json)).
:- use_module(library(http/http_open)).
:- use_module(library(lists)).
%%
% the different category constants on which a user can query
%%
category("housing", 0).
category("cost", 1).
category("startups", 2).
category("travel", 4).
category("commute", 5).
category("business", 6).
category("safety", 7).
category("healthcare", 8).
category("education", 9).
category("environment", 10).
category("economy", 11).
category("tolerance", 12).
category("taxation", 13).
category("internet", 14).
category("culture", 15).
category("tolerance", 16).
category("outdoors",17).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% **** MAIN PROGRAM **** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
% entry point to start the program - "main menu"
% write 'main.' to start the program
%%
main() :-
nl,
write("Welcome to CityRanker 2019™!"),
nl,
write("Enter 'intro' if you've never used CityRanker 2019™ before."),
nl,
write("Enter 'list' if you'd like to see which cities are available to query."),
nl,
write("Enter 'skip' if you'd like to access the main program."),
nl,
nl,
write("▶▶▶ INPUT FORMAT: wrap with double-quotes ◀◀◀"),
nl,
nl,
read(Ans),
main_input(Ans).
% when given 'input', gives user an introduction to the program
% when given 'list', lists the cities when prompted in the main menu
% when given 'skip', directs the user to the main querying options
% when given erroneous input, directs the user back to the main menu
main_input("intro") :-
nl,
write("CityRanker 2019™ is your tool for comparing different cities around the world the based on certain quality of life indices."),
nl,
write("The scores are out of 10 (10 being the highest) and were gathered from sources such as: World Bank, World Health Organization, United Nations, and more."),
nl,
nl,
write("The following categories can be compared among cities:"),
nl,
nl,
Categories = [housing,cost,startups,travel,commute,business,safety,healthcare,education,environment,economy,tolerance,taxation,internet,culture,outdoors],
print_categories(Categories),
nl,
write("Would you like to view the list of cities that are available to query? ['yes'/'no']."),
nl,
nl,
write("▶▶▶ INPUT FORMAT: wrap with double-quotes ◀◀◀"),
nl,
nl,
read(Ans),
list_cities_input(Ans).
main_input("list") :-
list_cities(),
nl,
main_options().
main_input("skip") :-
main_options().
main_input(_) :-
nl,
write("✖✖✖ ERROR: bad input. Redirecting to main - please try again. ✖✖✖"),
nl,
nl,
main().
%%
% refered to as 'main querying options'
%%
main_options() :-
nl,
write("Enter 1 to learn about a particular city."),
nl,
write("Enter 2 to compare two different cities."),
nl,
read(Answer),
nl,
main_options_input(Answer).
% when given the input '1', allows the user to retrieve the score of one city only
% when given the input '2', allows the user to compare two cities' scores
% when given errnoeous input, redirects user to main_options
main_options_input(1):-
write("Enter the name of the city you would like to learn about."),
nl,
nl,
write("▶▶▶ INPUT FORMAT: lower case, no periods, no commas, spaces replaced with hyphens, wrapped with double-quotes ◀◀◀"),
nl,
nl,
read(Location),
validate_location(Location),
nl,
write("Would you like to view the available categories again? ['yes'/'no']."),
nl,
nl,
write("▶▶▶ INPUT FORMAT: wrap with double-quotes ◀◀◀"),
nl,
nl,
read(Ans),
print_cat(Ans),
nl,
string_concat("Enter the quality you would like to know about in ", Location, String2),
string_concat(String2, ".", String3),
write(String3),
nl,
nl,
write("▶▶▶ INPUT FORMAT: lower case, wrapped with double-quotes ◀◀◀"),
nl,
nl,
read(Category),
validate_category(Category, Location).
main_options_input(2):-
write("Enter the name of the first city to compare."),
nl,
nl,
write("▶▶▶ INPUT FORMAT: lower case, no periods, no commas, spaces replaced with hyphens, wrapped with double-quotes ◀◀◀"),
nl,
nl,
read(City1),
validate_location_two(City1),
nl,
write("Enter the name of the second city to compare."),
nl,
nl,
nl,
write("▶▶▶ INPUT FORMAT: lower case, no periods, no commas, spaces replaced with hyphens, wrapped with double-quotes ◀◀◀"),
nl,
nl,
read(City2),
validate_location_two(City2),
nl,
write("Would you like to view the available categories again? ['yes'/'no']."),
nl,
nl,
write("▶▶▶ INPUT FORMAT: wrap with double-quotes ◀◀◀"),
nl,
nl,
read(Ans),
print_cat_two(Ans),
nl,
write("Enter the category which you would like to compare among the cities chosen."),
nl,
nl,
write("▶▶▶ INPUT FORMAT: lower case, wrapped with double-quotes ◀◀◀"),
nl,
nl,
read(Category),
validate_category_two(Category, City1, City2).
main_options_input(_):-
nl,
write("✖✖✖ ERROR: bad input. Redirecting to options - please try again. ✖✖✖"),
nl,
nl,
main_options().
%%
% prints the scores of two cities in one category and declares which is higher
% if the score is the same, it declares them to be the same
%%
compare_two_cities(C1, S1, C2, S2):-
S1 > S2,
string_concat(C1, " has a higher score of ", Str2),
string_concat(Str2, S1, Str1Res),
string_concat(Str1Res, " as compared to ", Compare),
string_concat(Compare, S2, S2Res),
string_concat(S2Res, " in ", Almost),
string_concat(Almost, C2, FinalRes),
nl,
write("⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇"),
nl,
nl,
write(FinalRes),
nl,
visualize_two_cities(C1, S1, C2, S2),
nl,
nl,
write("⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆"),
nl,
continue().
compare_two_cities(C1, S1, C2, S2):-
S1 < S2,
string_concat(C2, " has a higher score of ", Str2),
string_concat(Str2, S2, Str2Res),
string_concat(Str2Res, " as compared to ", Compare),
string_concat(Compare, S1, S1Res),
string_concat(S1Res, " in ", Almost),
string_concat(Almost, C1, FinalRes),
nl,
write("⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇"),
nl,
nl,
write(FinalRes),
nl,
visualize_two_cities(C1, S1, C2, S2),
nl,
nl,
write("⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆"),
nl,
continue().
compare_two_cities(C1, S1, C2, S2):-
S1=S2,
string_concat("Both cities have the same score of ", S1, Str),
nl,
write("⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇"),
nl,
nl,
write(Str),
nl,
visualize_two_cities(C1, S2, C2,S2),
nl,
nl,
write("⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆"),
nl,
continue().
% asks the user whether they'd like to continue the program by entering another query
continue() :-
nl,
nl,
write("Would you like to try another query with CityRanker 2019™? ['yes'/'no']."),
nl,
write("Or, would you like to go back to the main menu? ['main']."),
nl,
nl,
write("▶▶▶ INPUT FORMAT: wrap with double-quotes ◀◀◀"),
nl,
nl,
read(Ans),
continue_input(Ans).
% directs the user to main_options, the main menu, or ends the program
% if given erroneous input, redirects to continuation options once again
continue_input("Yes") :-
nl,
nl,
main_options().
continue_input("yes") :-
nl,
nl,
main_options().
continue_input("y") :-
nl,
nl,
main_options().
continue_input("main") :-
nl,
nl,
main().
continue_input("no") :-
write("Thank you for using CityRanker 2019™. Goodbye.").
continue_input("No") :-
write("Thank you for using CityRanker 2019™. Goodbye.").
continue_input("n") :-
write("Thank you for using CityRanker 2019™. Goodbye.").
continue_input("N") :-
write("Thank you for using CityRanker 2019™. Goodbye.").
continue_input(_) :-
nl,
write("✖✖✖ ERROR: bad input. Redirecting to continuation options - please try again. ✖✖✖"),
nl,
nl,
continue().
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *** ALL HELPERS *** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *** API HELPERS *** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% true if Score is the rating for City based on Feature, and V is the visualization of Score
city_score(City,Feature,Score, V) :-
open_url_query(Data, City),
Categories = Data.get('categories'),
string_concat("", Feature, F1),
category(F1, X),
nth0(X, Categories, FirstView),
Score = FirstView.get('score_out_of_10'),
visualize_score(City, Score, V).
% querying results from the API at https://developers.teleport.org/api/reference/#!/urban_areas/getUrbanAreaScores
open_url_query(Data, Location) :-
Url_Start = "https://api.teleport.org/api/urban_areas/slug%3A",
Url_End = "/scores/",
string_concat(Url_Start, Location, Url_Mid),
string_concat(Url_Mid, Url_End, URL),
setup_call_cleanup(
http_open(URL, In, [request_header('Accept'='application/json')]),
json_read_dict(In, Data),
close(In)
).
% calls helpers to print the list of all valid cities from an API
list_cities() :-
get_city_list_obj(ListObj),
get_names_cities(ListObj,1),
nl,
nl,
write("▶▶▶ NOTE: When querying city names that contain commas, periods, or spaces, the user must omit all punctuation and replace spaces with hyphens ◀◀◀"),
nl,
write("▶▶▶ NOTE: For example, to query 'Washington, D.C.', the user must enter 'washington-dc' [wrapped in double-quotes] ◀◀◀"),
nl.
% gets list object of all valid cities that are available to query.
get_city_list_obj(ListObj) :-
open_url_list(Response),
Links = Response.get('_links'),
ListObj = Links.get('ua:item').
% Reference: https://stackoverflow.com/questions/29167342/prolog-http-get-request-with-request-headers
open_url_list(Response):-
setup_call_cleanup(
http_open('https://api.teleport.org/api/urban_areas', In, [request_header('Accept'='application/json')]),
json_read_dict(In, Response),
close(In)
).
% organizes the cities to be outputted in three columns when printed
% gets result from API at https://developers.teleport.org/api/reference/#!/urban_areas/listUrbanAreas
get_names_cities([], _).
get_names_cities([H|T], N) :-
nth0(0, [H|T], FirstName),
Name = FirstName.get('name'),
(mod(N,3) =:= 0 ->
write(Name),
nl,
N1 is N+1,
get_names_cities(T, N1);
write(Name),
string_length(Name, NameLen),
tab(30 - NameLen),
N1 is N+1,
get_names_cities(T, N1)).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *** CITIES HELPERS *** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% lists the cities available to query if the user gives yes/Yes/y/Y
% if given no/No/n/N, the user is redirected to the main querying options
% if given any other input, the user is redirected to the introduction
list_cities_input("yes") :-
nl,
list_cities,
nl,
nl,
write("Now let's try it out!"),
nl,
main_options().
list_cities_input("Yes") :-
nl,
list_cities,
nl,
nl,
write("Now let's try it out!"),
nl,
main_options().
list_cities_input("y") :-
nl,
list_cities,
nl,
nl,
write("Now let's try it out!"),
nl,
main_options().
list_cities_input("Y") :-
nl,
list_cities,
nl,
nl,
write("Now let's try it out!"),
nl,
main_options().
list_cities_input("no") :-
nl,
nl,
write("Now let's try it out!"),
nl,
main_options().
list_cities_input("No") :-
nl,
nl,
write("Now let's try it out!"),
nl,
main_options().
list_cities_input("n") :-
nl,
nl,
write("Now let's try it out!"),
nl,
main_options().
list_cities_input("N") :-
nl,
nl,
write("Now let's try it out!"),
nl,
main_options().
list_cities_input(_) :-
nl,
write("✖✖✖ ERROR: bad input. Redirecting to intro - please try again. ✖✖✖"),
nl,
main_input("intro").
%% check that input city is a valid city (when querying 1 city).
%% if so, continue program. otherwise, return to 1 city query options.
validate_location(Location) :-
Cities = ["aarhus", "adelaide", "albuquerque", "almaty", "amsterdam", "anchorage", "andorra", "ankara", "asheville", "asuncion", "athens", "atlanta", "auckland", "austin", "baku", "bali", "baltimore", "bangkok", "barcelona", "beijing", "beirut", "belfast", "belgrade", "belize-city", "bengaluru", "bergen", "berlin", "bern", "bilbao", "birmingham", "birmingham-al", "bogota", "boise", "bologna", "bordeaux", "boston", "boulder", "bozeman", "bratislava", "brighton", "brisbane", "bristol", "brno", "brussels", "bucharest", "budapest", "buenos-aires", "buffalo", "cairo", "calgary", "cambridge", "cape-town", "caracas", "cardiff", "casablanca", "charleston", "charlotte", "chattanooga", "chennai", "chiang-mai", "chicago", "chisinau", "christchurch", "cincinnati", "cleveland", "cluj-napoca", "cologne", "colorado-springs", "columbus", "copenhagen", "cork", "curitiba", "dallas", "dar-es-salaam", "delhi", "denver", "des-moines", "detroit", "doha", "dresden", "dubai", "dublin", "dusseldorf", "edinburgh", "edmonton", "eindhoven", "eugene", "florence", "florianopolis", "fort-collins", "frankfurt", "fukuoka", "galway", "gdansk", "geneva", "gibraltar", "glasgow", "gothenburg", "grenoble", "guadalajara", "guatemala-city", "halifax", "hamburg", "hannover", "havana", "helsinki", "ho-chi-minh-city", "hong-kong", "honolulu", "houston", "hyderabad", "indianapolis", "innsbruck", "istanbul", "jacksonville", "jakarta", "johannesburg", "kansas-city", "karlsruhe", "kathmandu", "kiev", "kingston", "knoxville", "krakow", "kuala-lumpur", "kyoto", "lagos", "la-paz", "las-palmas-de-gran-canaria", "las-vegas", "lausanne", "leeds", "leipzig", "lille", "lima", "lisbon", "liverpool", "ljubljana", "london", "los-angeles", "louisville", "luxembourg", "lviv", "lyon", "madison", "madrid", "malaga", "malmo", "managua", "manchester", "manila", "marseille", "medellin", "melbourne", "memphis", "mexico-city", "miami", "milan", "milwaukee", "minneapolis-saint-paul", "minsk", "montevideo", "montreal", "moscow", "mumbai", "munich", "nairobi", "nantes", "naples", "nashville", "new-orleans", "new-york", "nice", "nicosia", "oklahoma-city", "omaha", "orlando", "osaka", "oslo", "ottawa", "oulu", "oxford", "palo-alto", "panama", "paris", "perth", "philadelphia", "phnom-penh", "phoenix", "phuket", "pittsburgh", "portland-me", "portland-or", "porto", "porto-alegre", "prague", "providence", "quebec", "quito", "raleigh", "reykjavik", "richmond", "riga", "rio-de-janeiro", "riyadh", "rochester", "rome", "rotterdam", "saint-petersburg", "salt-lake-city", "san-antonio", "san-diego", "san-francisco-bay-area", "san-jose", "san-juan", "san-luis-obispo", "san-salvador", "santiago", "santo-domingo", "sao-paulo", "sarajevo", "saskatoon", "seattle", "seoul", "seville", "shanghai", "singapore", "skopje", "sofia", "st-louis", "stockholm", "stuttgart", "sydney", "taipei", "tallinn", "tampa-bay-area", "tampere", "tartu", "tashkent", "tbilisi", "tehran", "tel-aviv", "the-hague", "thessaloniki", "tokyo", "toronto", "toulouse", "tunis", "turin", "turku", "uppsala", "utrecht", "valencia", "valletta", "vancouver", "victoria", "vienna", "vilnius", "warsaw", "washington-dc", "wellington", "winnipeg", "wroclaw", "yerevan", "zagreb", "zurich"],
member(Location, Cities).
validate_location(Location) :-
nl,
write("✖✖✖ ERROR: bad input. Redirecting to 1 city query options - please try again. ✖✖✖"),
nl,
nl,
main_options_input(1).
%% check that input city is a valid city (when querying 2 cities).
%% if so, continue program. otherwise, return to 2 city query options.
validate_location_two(Location) :-
Cities = ["aarhus", "adelaide", "albuquerque", "almaty", "amsterdam", "anchorage", "andorra", "ankara", "asheville", "asuncion", "athens", "atlanta", "auckland", "austin", "baku", "bali", "baltimore", "bangkok", "barcelona", "beijing", "beirut", "belfast", "belgrade", "belize-city", "bengaluru", "bergen", "berlin", "bern", "bilbao", "birmingham", "birmingham-al", "bogota", "boise", "bologna", "bordeaux", "boston", "boulder", "bozeman", "bratislava", "brighton", "brisbane", "bristol", "brno", "brussels", "bucharest", "budapest", "buenos-aires", "buffalo", "cairo", "calgary", "cambridge", "cape-town", "caracas", "cardiff", "casablanca", "charleston", "charlotte", "chattanooga", "chennai", "chiang-mai", "chicago", "chisinau", "christchurch", "cincinnati", "cleveland", "cluj-napoca", "cologne", "colorado-springs", "columbus", "copenhagen", "cork", "curitiba", "dallas", "dar-es-salaam", "delhi", "denver", "des-moines", "detroit", "doha", "dresden", "dubai", "dublin", "dusseldorf", "edinburgh", "edmonton", "eindhoven", "eugene", "florence", "florianopolis", "fort-collins", "frankfurt", "fukuoka", "galway", "gdansk", "geneva", "gibraltar", "glasgow", "gothenburg", "grenoble", "guadalajara", "guatemala-city", "halifax", "hamburg", "hannover", "havana", "helsinki", "ho-chi-minh-city", "hong-kong", "honolulu", "houston", "hyderabad", "indianapolis", "innsbruck", "istanbul", "jacksonville", "jakarta", "johannesburg", "kansas-city", "karlsruhe", "kathmandu", "kiev", "kingston", "knoxville", "krakow", "kuala-lumpur", "kyoto", "lagos", "la-paz", "las-palmas-de-gran-canaria", "las-vegas", "lausanne", "leeds", "leipzig", "lille", "lima", "lisbon", "liverpool", "ljubljana", "london", "los-angeles", "louisville", "luxembourg", "lviv", "lyon", "madison", "madrid", "malaga", "malmo", "managua", "manchester", "manila", "marseille", "medellin", "melbourne", "memphis", "mexico-city", "miami", "milan", "milwaukee", "minneapolis-saint-paul", "minsk", "montevideo", "montreal", "moscow", "mumbai", "munich", "nairobi", "nantes", "naples", "nashville", "new-orleans", "new-york", "nice", "nicosia", "oklahoma-city", "omaha", "orlando", "osaka", "oslo", "ottawa", "oulu", "oxford", "palo-alto", "panama", "paris", "perth", "philadelphia", "phnom-penh", "phoenix", "phuket", "pittsburgh", "portland-me", "portland-or", "porto", "porto-alegre", "prague", "providence", "quebec", "quito", "raleigh", "reykjavik", "richmond", "riga", "rio-de-janeiro", "riyadh", "rochester", "rome", "rotterdam", "saint-petersburg", "salt-lake-city", "san-antonio", "san-diego", "san-francisco-bay-area", "san-jose", "san-juan", "san-luis-obispo", "san-salvador", "santiago", "santo-domingo", "sao-paulo", "sarajevo", "saskatoon", "seattle", "seoul", "seville", "shanghai", "singapore", "skopje", "sofia", "st-louis", "stockholm", "stuttgart", "sydney", "taipei", "tallinn", "tampa-bay-area", "tampere", "tartu", "tashkent", "tbilisi", "tehran", "tel-aviv", "the-hague", "thessaloniki", "tokyo", "toronto", "toulouse", "tunis", "turin", "turku", "uppsala", "utrecht", "valencia", "valletta", "vancouver", "victoria", "vienna", "vilnius", "warsaw", "washington-dc", "wellington", "winnipeg", "wroclaw", "yerevan", "zagreb", "zurich"],
member(Location, Cities).
validate_location_two(Location) :-
nl,
write("✖✖✖ ERROR: bad input. Redirecting to 2 city query options - please try again. ✖✖✖"),
nl,
nl,
main_options_input(2).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *** CATEGORIES HELPERS *** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% lists the available categories to query
print_categories([]).
print_categories([Cat|T]) :-
write(Cat),
nl,
print_categories(T).
%% prints the categories if the user inputs Yes/yes/y/Y (when querying 1 city)
%% continues program if the user inputs No/no/n/No
%% otherwise, returns to 1 city query options
print_cat("Yes") :-
nl,
Categories = [housing,cost,startups,travel,commute,business,safety,healthcare,education,environment,economy,tolerance,taxation,internet,culture,outdoors],
print_categories(Categories).
print_cat("yes") :-
nl,
Categories = [housing,cost,startups,travel,commute,business,safety,healthcare,education,environment,economy,tolerance,taxation,internet,culture,outdoors],
print_categories(Categories).
print_cat("y") :-
nl,
Categories = [housing,cost,startups,travel,commute,business,safety,healthcare,education,environment,economy,tolerance,taxation,internet,culture,outdoors],
print_categories(Categories).
print_cat("Y") :-
nl,
Categories = [housing,cost,startups,travel,commute,business,safety,healthcare,education,environment,economy,tolerance,taxation,internet,culture,outdoors],
print_categories(Categories).
print_cat("no").
print_cat("No").
print_cat("n").
print_cat("N").
print_cat(_) :-
nl,
write("✖✖✖ ERROR: bad input. Redirecting to 1 city query options - please try again. ✖✖✖"),
nl,
nl,
main_options_input(1).
%% prints the categories if the user inputs Yes/yes/y/Y (when querying 2 cities)
%% continues program if the user inputs No/no/n/No
%% otherwise, returns to 2 city query options
print_cat_two("Yes") :-
nl,
Categories = [housing,cost,startups,travel,commute,business,safety,healthcare,education,environment,economy,tolerance,taxation,internet,culture,outdoors],
print_categories(Categories).
print_cat_two("yes") :-
nl,
Categories = [housing,cost,startups,travel,commute,business,safety,healthcare,education,environment,economy,tolerance,taxation,internet,culture,outdoors],
print_categories(Categories).
print_cat_two("y") :-
nl,
Categories = [housing,cost,startups,travel,commute,business,safety,healthcare,education,environment,economy,tolerance,taxation,internet,culture,outdoors],
print_categories(Categories).
print_cat_two("Y") :-
nl,
Categories = [housing,cost,startups,travel,commute,business,safety,healthcare,education,environment,economy,tolerance,taxation,internet,culture,outdoors],
print_categories(Categories).
print_cat_two("no").
print_cat_two("No").
print_cat_two("n").
print_cat_two("N").
print_cat_two(_) :-
nl,
write("✖✖✖ ERROR: bad input. Redirecting to 2 city query options - please try again. ✖✖✖"),
nl,
nl,
main_options_input(2).
%% checks that input category is a valid category (when querying 1 city)
%% if so, continue program. otherwise, return to 1 city query options
validate_category(Category, Location) :-
Categories = ["housing", "cost", "startups", "travel", "commute", "business", "safety", "healthcare", "education",
"environment", "economy", "tolerance", "taxation", "internet", "culture", "outdoors"],
member(Category, Categories),
nl,
city_score(Location, Category, Score, V),
string_concat(Location, " has a score of ", Res1),
string_concat(Res1, Score, Res2),
string_concat(Res2, " in the category: ", Res3),
string_concat(Res3, Category, Res4),
string_concat(Res4, ".", Result),
write("⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇ ⬇"),
nl,
nl,
write(Result),
nl,
string_concat(Location, "=", P1),
write(P1),
write(V),
nl,
nl,
write("⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆ ⬆"),
nl,
continue().
validate_category(Category, _) :-
nl,
write("✖✖✖ ERROR: bad input. Redirecting to 1 city query options - please try again. ✖✖✖"),
nl,
nl,
main_options_input(1).
%% checks that input category is a valid category (when comparing 2 cities)
%% if so, continue program. otherwise, return to 2 city query options
validate_category_two(Category, City1, City2) :-
Categories = ["housing", "cost", "startups", "travel", "commute", "business", "safety", "healthcare", "education",
"environment", "economy", "tolerance", "taxation", "internet", "culture", "outdoors"],
member(Category, Categories),
city_score(City1, Category, S1, V1),
city_score(City2, Category, S2, V2),
compare_two_cities(City1, S1, City2, S2).
validate_category_two(Category, _, _) :-
nl,
write("✖✖✖ ERROR: bad input. Redirecting to 2 city query options - please try again. ✖✖✖"),
nl,
nl,
main_options_input(2).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *** VISUALIZATION HELPERS *** %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% true if Str appended to list List N times is L1
attach_point(0, List, Str, List).
attach_point(N, [], E, L2):-
N1 is N-1,
append([], E, L1),
attach_point(N1, [], E, T2),
append(L1, T2, L2).
% true if L2 is the visualized score list of Score for City
visualize_score(City, Score, L2):-
S is round(Score),
attach_point(S, [],["★"], L2).
% true when D is the difference between numbers L1 and L2.
dif(L1, L2, 0):-
L1==L2.
dif(L1, L2, D):-
L1>L2,
D is L1-L2.
dif(L1, L2, D):-
L2>L1,
D is L2-L1.
% true when Str2 is Str with N spaces appended to the end of Str.
add_space(0, Str, Str).
add_space(N, Str, Str2):-
string_concat("", " ", S),
N1 is N-1,
add_space(N1, S, Str3),
string_concat(Str, Str3, Str2).
% makes a visualization of city C1 with score S1 and city C2 with score S2.
visualize_two_cities(C1, S1, C2, S2):-
string_codes(C1, List1),
string_codes(C2, List2),
length(List1, L1),
length(List2, L2),
L1>=L2,
dif(L1, L2, D),
add_space(D, C2, SS),
visualize_score(C1, S1, V1),
visualize_score(C2,S2,V2),
string_concat(C1, "=", P1),
write(P1),
write(V1),
nl,
string_concat(SS, "=", P2),
write(P2),
write(V2).
visualize_two_cities(C1, S1, C2, S2):-
string_codes(C1, List1),
string_codes(C2, List2),
length(List1, L1),
length(List2, L2),
L2>L1,
dif(L1, L2, D),
add_space(D, C1, SS),
visualize_score(C1, S1, V1),
visualize_score(C2,S2,V2),
string_concat(C2, "=", P2),
write(P2),
write(V2),
nl,
string_concat(SS, "=", P1),
write(P1),
write(V1).