""" Week12-3 Notes """

import statistics

data = [41, 65, 64, 50, 45, 13, 29, 14, 7, 14]
print(statistics.mean(data)) # 34.2
print(statistics.median(data)) # 35.0
print(statistics.mode(data)) # 14

###

import csv
def readData(filename):
    f = open(filename, "r")
    # Semester, 3 orig, 3 cleaned, 3 categories
    data = list(csv.reader(f))
    return data

def getFlavorCounts(data, flavor):
    allCounts = []
    firstCol = data[0].index("#1 category")
    for i in range(1, len(data)):
        line = data[i]
        flavorCategory = line[firstCol:firstCol+3]
        thisCount = flavorCategory.count(flavor)
        allCounts.append(thisCount)
    return allCounts

d = readData("all-icecream.csv")
counts = getFlavorCounts(d, "chocolate")
print(statistics.mean(counts))

###

def getFlavorProb(data, flavor):
    count = 0
    firstCol = data[0].index("#1 category")
    for i in range(1, len(data)):
        line = data[i]
        if line[firstCol] == flavor:
            count += 1
    return count / (len(data) - 1)

d = readData("all-icecream.csv")
prob = getFlavorProb(d, "chocolate")
print(prob)

###

import matplotlib.pyplot as plt

plt.title("Empty")
plt.show()

###

x = [2, 4, 5, 7, 7, 9]
y = [3, 5, 4, 6, 9, 7]
plt.scatter(x, y)
plt.show()

###

labels = [ "A", "B", "C", "D", "E" ]
yValues = [ 10, 40, 36, 46, 21 ]
colors = [ "red", "yellow", "green",
           "blue", "purple" ]
plt.bar(labels, yValues, color=colors)

plt.xlabel("Categories")
plt.ylabel("Amounts")

plt.show()

###

labels = ['G1', 'G2', 'G3', 'G4', 'G5']
men_means = [20, 34, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]

width = 0.35

xValuesA = []
xValuesB = []
for i in range(len(labels)):
    xValuesA.append(i - width/2)
    xValuesB.append(i + width/2)

plt.bar(xValuesA, men_means, width=width)
plt.bar(xValuesB, women_means, width=width)

plt.show()

###

data = readData("all-icecream.csv")
firstCol = data[0].index("#1 category")
flavors = []
portions = []
for i in range(1, len(data)):
    flavor = data[i][firstCol]
    if flavor not in flavors:
        flavors.append(flavor)
        counts = getFlavorCounts(data, flavor)
        portions.append(sum(counts))

plt.pie(portions, labels=flavors)
plt.show()
