-
Notifications
You must be signed in to change notification settings - Fork 1
/
program_decision_support.py
49 lines (41 loc) · 2.18 KB
/
program_decision_support.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
from collections import OrderedDict
from generate_clusters import build_interest_clusters
import inquirer
def aggregate_rankings(dict1, dict2):
dict3 = {**dict1, **dict2}
for key, value in dict3.items():
if key in dict1 and key in dict2:
dict3[key]['count'] = value['count'] + dict1[key]['count']
dict3[key]['relative_count'] = value['relative_count'] + \
dict1[key]['relative_count']
return dict3
if __name__ == "__main__":
create_word_clouds = inquirer.prompt([inquirer.Confirm('word_clouds',
message="Would you like to see the clusters visualized as word clouds?", default=False), ])['word_clouds']
print("Getting interest clusters, hold tight...")
interest_clusters = build_interest_clusters(
create_word_clouds=create_word_clouds)
clusters = [cluster.get_tuple() for cluster in interest_clusters]
# prompt user for to select clusters
questions = [inquirer.Checkbox('interest_clusters',
message="Choose the clusters that interest you the most",
choices=clusters),
inquirer.List('programs_sorted_by',
message="How would you like to sort the results?",
choices=[('Counts', 'count'), ('Relative Counts', 'relative_count')])]
answers = inquirer.prompt(questions)
cluster_indexes = answers['interest_clusters']
programs_sorted_by = answers["programs_sorted_by"]
# aggregate clusters
aggregated_cluster_dict = OrderedDict()
for i in cluster_indexes:
aggregated_cluster_dict = aggregate_rankings(aggregated_cluster_dict,
interest_clusters[i].program_ranking)
NUM_PROGRAMS = 20
# print(aggregated_cluster_dict)
# find the top programs for the aggregated cluster
top_programs = sorted(aggregated_cluster_dict.items(),
key=lambda x: x[1][programs_sorted_by], reverse=True)[:]
for key, value in top_programs:
print(f"{key};{value['relative_count']}")
# pprint(OrderedDict(top_programs))