Last active
March 11, 2019 19:56
-
-
Save Bowenislandsong/d24f54a68297b83749f1d4a4b6af12ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# we edit the grades off-line from blackboard | |
# we assume the combination of Student ID and BU emails as unique and valid identity (either should do) | |
# group assignment list should be with this script | |
# Mode 1: | |
# we input csv files for grade assignments | |
# Mode 2: | |
# we input a grade for a group | |
import csv | |
import os | |
import copy as c | |
# import subprocess | |
# subprocess.call(["cp", "../Downloads/gc_19sprgcascs528_a1_fullgc_2019-02-21-09-51-12.csv","../Downloads/copy.csv"]) | |
def readcsv(csv_file): | |
content = [] | |
with open(csv_file, 'rb') as csvfile: | |
f = csv.reader(csvfile, delimiter=',') | |
for row in f: | |
row[0] = str(row[0].decode('utf-8-sig').encode('ascii').replace('\"','')) | |
content.append(row) | |
return content | |
def print_choice(choices): | |
for i in range(len(choices)): | |
print str(i)+": " + choices[i] | |
def getcolum(ary2d,i,dlmt): | |
res = [] | |
for row in ary2d: | |
res.append(row[i].split(dlmt)[0]) | |
return res | |
def get_group(): | |
group = [] | |
f = open("group_assign.txt",'r') | |
content = f.readlines() | |
f.close() | |
j = -1 | |
for line in content: | |
line = line[:-1] | |
if (line.startswith("group")): | |
j+=1 | |
print str(j)+": "+line[6:] | |
group.append([]) | |
elif(line): | |
group[j].append(line.split(',')) | |
return group | |
def assign_individual_grade(content,csv_file,person_grade_dict,grade_column): | |
'''this is N^2 time, my class has 31 people so i dont care''' | |
with open(csv_file, 'wb') as csvfile: | |
written = c.copy(person_grade_dict.keys()) | |
f = csv.writer(csvfile, delimiter=',',quotechar='\"',quoting=csv.QUOTE_ALL) | |
for row in content: | |
if(row[2] in person_grade_dict.keys()): | |
row[grade_column] = person_grade_dict[row[2]] | |
written.remove(row[2]) | |
for i in range(len(row)): | |
row[i] = str(row[i]) | |
f.writerow(row) | |
for p in written: | |
if(p!="Email Address"): | |
print("we did not write grade for: "+ p) | |
def assign_grade(content,csv_file,person,grade_column,grade_point): | |
'''this is N^2 time, my class has 31 people so i dont care''' | |
with open(csv_file, 'wb') as csvfile: | |
written = c.copy(person) | |
f = csv.writer(csvfile, delimiter=',',quotechar='\"',quoting=csv.QUOTE_ALL) | |
for row in content: | |
if(row[2] in person): | |
row[grade_column] = grade_point | |
written.remove(row[2]) | |
for i in range(len(row)): | |
row[i] = str(row[i]) | |
f.writerow(row) | |
for p in written: | |
print("we did not write grade for: "+ p) | |
def GEN_IDgrade_dict(ID,grade): | |
res = {} | |
if (len(ID)!=len(grade)): print("we dont have the same number of grads and IDs") | |
for i in range(len(ID)): | |
res[ID[i]]=grade[i] | |
return res | |
print("Choose from the following mode:") | |
print("1: Grade by cvs individually") | |
print("2: Grade by hand in groups") | |
mode = int(input()) # select mode | |
# mode 1: individual assignments | |
if (mode ==1): | |
inputfilenames = os.listdir("../Downloads/") | |
print_choice(inputfilenames) | |
print("input grade filename:") | |
grade_f_name = inputfilenames[int(input())] | |
inputfileName = '../Downloads/'+grade_f_name | |
inputgrades = readcsv(inputfileName) # get the input grades | |
# print_choice(inputgrades[0]) | |
# print("Which ID? Choose email!") | |
# id_col = int(input()) | |
IDs = getcolum(inputgrades,1,'@') | |
# print("Which Grade? Google form special!(score)") | |
# grade_col = int(input()) | |
grade = getcolum(inputgrades,2,'/') | |
fileName = os.listdir("../Downloads/") | |
print_choice(fileName) | |
print("Grade Center File Name:") | |
fileName = '../Downloads/'+ fileName[int(input())] | |
grade_center = readcsv(fileName) | |
print_choice(grade_center[0]) | |
print("grade choice:") | |
grade_column = int(input()) | |
inputgrade_dict = GEN_IDgrade_dict(IDs,grade) | |
assign_individual_grade(grade_center,fileName,inputgrade_dict,grade_column) | |
# mode 2: group assignments | |
if (mode ==2): | |
# get group assignments | |
# select what to grade | |
# input a grade | |
# select a group | |
inputfilenames = os.listdir("../Downloads/") | |
print_choice(inputfilenames) | |
print("Grading Center filename:") | |
grade_f_name = inputfilenames[int(input())] | |
fileName = '../Downloads/'+grade_f_name | |
grade_center = readcsv(fileName) # get grading sheets | |
grade_column = -1 | |
while True: | |
print_choice(grade_center[0]) | |
print("grade choice:") | |
grade_column = int(raw_input() or grade_column) # select what to grade | |
print("choice: " + str(grade_column)) | |
group = get_group() | |
print("group number:") # select who to grade | |
grade_group = int(input()) | |
print("grade point") | |
grade = float(input()) | |
persons = group[grade_group] | |
p_emails = [] | |
for p in persons: | |
p_emails.append(p[1].split("@")[0]) | |
assign_grade(grade_center,fileName,p_emails,grade_column,grade) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment