# Author: Scott Wehrwein
# Date: 05/17/2021
# Read some CSV survey data into a list of dictionaries to
# make it easier to compute some statistics on the data.

# open the survey data file
survey_file = open("AboutYou.csv", "r")

# read the file into a list of lines using readlines()
data_str = survey_file.readlines()
print(data_str[:3]) # print 3 lines to see what that looks like

# convert each line to a list
data_lists = []
for line in data_str:
    data_lists.append(line.strip("\n").split(","))
print(data_lists[:3]) # print 3 lines to see what that looks like
  

# store store the data in a list of dictionaries instead
headers = data_lists[0]
data_dicts = []
for line in data_lists[1:]:
    d = {}
    for i in range(len(headers)):
        d[headers[i]] = line[i]
    data_dicts.append(d)
print(data_dicts[:3]) # print 3 lines to see what that looks like

# calculate the average ratio of programming experience to
# time at western
total = 0
n_responses = 0
for response in data_dicts:
    # assume a quarter is 3 months, and add 1 because
    # the survey went out about a month ago
    months_wwu = float(response["QuartersAtWestern"]) * 3 + 1
    months_prog = float(response["MonthsProgramming"])
    total += months_prog / months_wwu
    n_responses += 1
print(total / n_responses)
    