Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Nov 10, 2023
1 parent 547004a commit aa5b345
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions parse-responses.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import csv
import os

import yaml

here = os.path.dirname(os.path.abspath(__file__))

responses = os.path.join(here, "responses.csv")

rows = []
with open(responses, newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='"')
with open(responses, newline="") as csvfile:
reader = csv.reader(csvfile, delimiter=",", quotechar='"')
for row in reader:
rows.append(row)

Expand All @@ -17,8 +19,8 @@
# Row[-1] is feedback
counts = {}
for row in rows:
votes = row[1].replace('\\,', '[comma]')
noodles = votes.split(',')
votes = row[1].replace("\\,", "[comma]")
noodles = votes.split(",")

# Give one point for rank, lowest score wins
for i, noodle in enumerate(noodles):
Expand All @@ -27,15 +29,15 @@
counts[noodle] = 0
counts[noodle] += score

counts = sorted(counts.items(), reverse=True, key=lambda x:x[1])
counts = sorted(counts.items(), reverse=True, key=lambda x: x[1])

# Replace commas back in
finals = {"items": []}
for item in counts:
key, count = item
key = key.replace('[comma]', ',').strip()
key = key.replace("[comma]", ",").strip()
finals["items"].append({"name": key, "score": count})

data_file = os.path.join(here, "_data", "scores.yaml")
with open(data_file, 'w') as fd:
with open(data_file, "w") as fd:
fd.write(yaml.dump(finals))

0 comments on commit aa5b345

Please sign in to comment.