def write_review(user_id,submission_number,score,review,timestamp,path_to_data=PATH_TO_DATA): message,j=is_valid_review(user_id,submission_number,score,review,timestamp,path_to_data) if j!=0: #write the review CONSTANT_DATA = get_constant_data() roster_name = CONSTANT_DATA['roster_name'] S=SheetObject(path_to_data + roster_name, "submissions") old_entry = S.get({'submission_number':submission_number})[0] #NEVER DO THIS WITH DICTIONARIES: new_entry = old_entry #it have new_entry point to old_entry in memory #note: copyd function in ../excel_tools/table_functions.py new_entry = {} for key in S.keys: new_entry[key] = old_entry[key] new_entry['review%s' % j] = review new_entry['reviewer%s_score' % j] = int(score) #not scorej, holy shit this bug took me forever. new_entry['review%s_timestamp' % j] = timestamp new_entry['new_review%s' % j] = 1 #check to see if this new review makes the entry complete. k = (j%2) +1 #other index if old_entry['reviewer%s_score' % k]>-1: new_entry['new_completion']=1 #DEBUG #A=set(list(new_entry.keys())) #B=set(list(old_entry.keys())) #print(B.issubset(A)) # #for a in list(old_entry): # print(a) # #for b in list(new_entry): # print(b) #no such entry old_entry S.replace(old_entry,new_entry) S.save() return message
def authenticate(user_id, pass1, newpass1, newpass2,path_to_data=PATH_TO_DATA): CONSTANT_DATA = get_constant_data(path_to_data) roster_name = CONSTANT_DATA['roster_name'] R = SheetObject(path_to_data + roster_name,'roster') students = R.get({'netid':user_id}) n = len(students) authenticated = 0 #print(students) if n==0: message = "invalid user_id and password. <br>" authenticated = 0 #print('n=0') if n==1: old_entry = students[0] password = old_entry['password'] if password == pass1: authenticated = 1 if newpass1 == newpass2 and len(newpass1) >0: new_entry = copyd(old_entry) new_entry['password'] = newpass1 R.remove([old_entry]) R.append(new_entry) R.save() message = "new password has been set. <br>" else: message = "<i> %s upload report </i> <br>" % user_id else: #print('In the "else" case') authenticated = 0 message = "invalid user_id and password. <br>" if n>2: authenticated = 0 message = """ invalid user_id and password. (multiple users! please copy-paste this entire upload report in an email to [email protected].) <br> """ return message, authenticated
sub1 = search1[0] sub2 = search2[0] r1=sub1['total_score1'] r2=sub2['total_score1'] w1 = float(r1/(r1+r2)) w2 = float(r2/(r1+r2)) ts2=w1*s1+w2*s2 #print(f"s1={s1},s2={s2},r1={r1},r2={r2},w1={w1},w2={w2},ts2={ts2},w1+w2={w1+w2}") mnew['total_score2']=ts2 mnew['closed']=1 mnew['w1']=w1 mnew['w2']=w2 scored2.append(mnew) update(S,scored2) S.save() """ Histogram """ total_scored2 = [m["total_score2"] for m in scored2] n = len(total_scored2) #plt.hist(total_scored2, bins=7) # arguments are passed to np.histogram #plt.title(f"assignment {ass}, problem {pro} (n={n})") #plt.show() plot2filename=score2_hist(p0,total_scored2,PATH_TO_DASHBOARD) #average distance scorechanges=[] for m in scored2: scorechanges.append([m['total_score1']-m['total_score2']])
def submit_problem(user_id,assignment,problem,timestamp,path_to_data=PATH_TO_DATA,check_due_date=False): """ """ CONSTANT_DATA = get_constant_data(path_to_data) roster_name = CONSTANT_DATA['roster_name'] S = SheetObject(path_to_data + roster_name,'submissions') query = {'netid':user_id, 'assignment':assignment,'problem':problem} if is_valid_assignment(assignment,problem,timestamp,path_to_data): old_entries = S.get(query) n = len(old_entries) write_file = 1 new_submission_number = get_submission_count(path_to_data) if n==0: new_entry = {} new_entry['netid'] = user_id new_entry['assignment'] = assignment new_entry['problem'] = problem new_entry['submission_number'] = new_submission_number new_entry['submission_time'] = timestamp new_entry['new_submission']=1 new_entry['submission_locked']=0 new_entry['closed']=0 new_entry['total_score1']=0 new_entry['total_score2']=0 new_entry['reviewer1_assignment_time']=-1 new_entry['reviewer1']='' new_entry['reviewer1_score']=-1 new_entry['review1']='' new_entry['review1_timestamp']=-1 new_entry['review1_locked']=0 new_entry['reviewer2_assignment_time']=-1 new_entry['reviewer2']='' new_entry['reviewer2_score']=-1 new_entry['review2']='' new_entry['review2_timestamp']=-1 new_entry['review2_locked']=0 new_entry['new_submission']=1 new_entry['new_match']=0 new_entry['new_review1']=0 new_entry['new_review2']=0 new_entry['new_completion']=0 new_entry['w1']=1 new_entry['w2']=1 S.append(new_entry) S.save() message = """ *submission %s, assignment %s, problem %s created. new. <br> """ % (new_submission_number, assignment, problem) write_file = 1 elif n==1: old_entry = old_entries[0] #The trickiest f*****g bug in the world: #new_entry = old_entry #you need to make a new blank dictionary... #...otherwise it just points to the old one new_entry = {} for key in S.set_of_keys: new_entry[key] = old_entry[key] #new_entry['netid'] = user_id #new_entry['assignment'] = assignment #new_entry['problem'] = problem new_entry['submission_number'] = new_submission_number new_entry['submission_time'] = timestamp #new_entry['new_submission']=1 #new_entry['submission_locked']=0 is_locked = old_entry['submission_locked'] #bug: entries -> entry if is_locked ==1: message = """ *assignment %s, problem %s rejected. locked. <br> """ % (assignment,problem) write_file =0 if is_locked ==0: S.replace(old_entry,new_entry) S.save() message = """ *submission %s, assignment %s, problem %s created. <br> submission %s overwritten. <br> """ % (new_submission_number,assignment,problem,old_entry['submission_number']) write_file = 1 else: message = """ *assigment %s, problem %s rejected. multiple entries in database. contact instructor with this message and copy-paste this message. <br> """ write_file =0 if write_file ==1: increment_submission_number(path_to_data) else: message = """ *assignment %s, problem %s rejected. not a valid submission. <br> """ % (assignment,problem) write_file = 0 dataentry = {} dataentry["uploadOk"] = write_file if write_file ==1: dataentry["submission_number"]=new_submission_number else: dataentry["submission_number"]=-1 return message,dataentry
late_reviews[reviewer2].append(sub_num) if time_difference(tnow, trev1) > 2: snew['new_review1'] = 0 if time_difference(tnow, trev2) > 2: snew['new_review2'] = 0 cleaned.append(snew) f = open(PATH_TO_DATA + 'late_reviews.json', 'w') json.dump(late_reviews, f) f.close() update(S, cleaned) S.save() ############# #Now we update the participation scores ############# matched = S.get({'submission_locked': 1}) for m in matched: matched_dict[m['netid']].append(m['submission_number']) for user in users: usernew = copyd(user) total = 14 + 2 * len(matched_dict[user['netid']]) num = total - len(late_reviews[user['netid']]) usernew['participation'] = num / total U.remove([user])