Skip to content

Instantly share code, notes, and snippets.

@OsmanMutlu
Created October 18, 2020 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OsmanMutlu/c4028d976ebfe509aeb7db36cdd3d267 to your computer and use it in GitHub Desktop.
Save OsmanMutlu/c4028d976ebfe509aeb7db36cdd3d267 to your computer and use it in GitHub Desktop.
Takes the comp541 paper selection form results in csv format and writes out each user's first choice. You can use the intermediate dictionaries to solve the conflicts.
import sys
import csv
input_csv_file = sys.argv[1]
user_prefs = {}
first_paper_prefs = {}
with open(input_csv_file, "r", encoding="utf-8") as csv_file:
lines = list(csv.reader(csv_file, delimiter=','))
paper_names = lines[0][2:]
for line in lines[1:]:
_, username, *choices = line
curr_choices = sorted([choices[i] + "-" + str(i) for i in range(len(paper_names)) if choices[i] != ""])
user_prefs[username] = curr_choices
first_paper_prefs[int(curr_choices[0][2:])] = first_paper_prefs.get(int(curr_choices[0][2:]), list()) + [username]
# print(user_prefs)
# print(len(user_prefs))
# print(first_paper_prefs)
# print(len(first_paper_prefs))
# print(paper_names)
print("\n".join([key + "\t" + paper_names[int(val[0][2:])] for key, val in sorted(user_prefs.items())]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment