# -*- coding: utf-8 -*-
import csv
# =============================================================================
# import os
#
# os.chdir(os.getcwd())
# print(os.getcwd())
# =============================================================================
with open('2017_4th_education_evaluation.csv') as f:
csv_reader = csv.DictReader(f)
dic_A_add = {}
dic_A = {}
dic_A_delete = {}
dic_B_add = {}
dic_B = {}
dic_B_delete = {}
dic_C_add = {}
dic_C = {}
dic_C_delete = {}
school_names = []
def count(dic,rank,key,value):
if dic.__contains__(key) == False:
#print(key + " "+ value)
dic[key] = 1
elif dic.__contains__(key) == True:
#print(dic.get(key))
dic[key] = dic.get(key) + 1
return dic
for row in csv_reader:
key = row['school_name']
value = row['result']
#print(key + " "+ value)
if (not school_names.__contains__(key)):
school_names.append(key)
if value == 'A+':
dic_A_add = count(dic_A_add,'A+',key,value)
elif value == 'A':
dic_A = count(dic_A,'A',key,value)
elif value == 'A-':
dic_A_delete = count(dic_A_delete,'A-',key,value)
elif value == 'B+':
dic_B_add = count(dic_B_add,'B+',key,value)
elif value == 'B':
dic_B = count(dic_B,'B',key,value)
elif value == 'B-':
dic_B_delete = count(dic_B_delete,'B-',key,value)
elif value == 'C+':
dic_C_add = count(dic_C_add,'C+',key,value)
elif value == 'C':
dic_C = count(dic_C,'C',key,value)
elif value == 'C-':
dic_C_delete = count(dic_C_delete,'C-',key,value)
f.close()
def ouput(dic):
for key, value in dic.items():
print (key, ' : ', value)
# =============================================================================
# ouput(dic_A_add)
# ouput(dic_A)
# ouput(dic_A_delete)
#
# ouput(dic_B_add)
# ouput(dic_B)
# ouput(dic_B_delete)
#
# ouput(dic_C_add)
# ouput(dic_C)
# ouput(dic_C_delete)
# =============================================================================
headers = ['school_name','A+','A','A-','B+','B','B-','C+', 'C', 'C-',
'value_score','teacher_num', 'mean_score']
#print(school_names)
def getData(rows):
for data in school_names:
school_name = data
#print(school_name)
if dic_A_add.__contains__(school_name):
A_add = dic_A_add.get(school_name)
else :
A_add = 0
if dic_A.__contains__(school_name):
A = dic_A.get(school_name)
else :
A = 0
if dic_A_delete.__contains__(school_name):
A_delete = dic_A_delete.get(school_name)
else :
A_delete = 0
if dic_B_add.__contains__(school_name):
B_add = dic_B_add.get(school_name)
else :
B_add = 0
if dic_B.__contains__(school_name):
B = dic_B.get(school_name)
else :
B = 0
if dic_B_delete.__contains__(school_name):
B_delete = dic_B_delete.get(school_name)
else :
B_delete = 0
if dic_C_add.__contains__(school_name):
C_add = dic_C_add.get(school_name)
else :
C_add = 0
if dic_C.__contains__(school_name):
C = dic_C.get(school_name)
else :
C = 0
if dic_C_delete.__contains__(school_name):
C_delete = dic_C_delete.get(school_name)
else :
C_delete = 0
value_score = A_add * 98 + A * 95 + A_delete * 90 + + \
B_add * 88 + B * 85 + B_delete * 80 + + \
C_add * 78 + C * 75 + B_delete * 70
teacher_num = 0
mean_score = 0
row_insert = [school_name, A_add, A, A_delete, B_add, B, B_delete, C_add, C, C_delete,
value_score, teacher_num, mean_score]
rows.append(row_insert)
return rows
#print(type(dic_A_add))
# =============================================================================
# rows = [('AA', 39.48, '6/11/2007', '9:36am', -0.18, 181800),
# ('AIG', 71.38, '6/11/2007', '9:36am', -0.15, 195500),
# ('AXP', 62.58, '6/11/2007', '9:36am', -0.46, 935000),
# ]
#
# =============================================================================
with open('change.csv','w') as fw:
fw_csv = csv.writer(fw)
fw_csv.writerow(headers)
rows_insert = []
rows_insert = getData(rows_insert)
print(rows_insert)
print(type(rows_insert))
fw_csv.writerows(rows_insert)
fw.close()