def join_team(account, teamID=None, teamPass=None, team=None): # Look up the team if we didn't bring one if team is None: team = Team.objects(teamID=teamID, teamPass=teamPass).first() # We didn't bring a team nor did we find one if team is None: error = "Team with those credentials not found." # We have our team, let's try joining if team: if len(team.members) < 3: team.members.append(account) account.team = team validate_division(team) team.save() account.save() return True else: flash("Team already has 3 members", 'danger') return False flash("Error finding team", 'danger') return False
def extra_credit(results_tsv, output_folder, division): team_scores, user_scores = dict(), dict() student_classes = dict() class_files = dict() names = dict() def format_fsuid(account): # Try and grab fsuid or email fsuid = account.fsuid or account.email # See if user is an idiot and put their fsu email in the 'fsuid' field if 'my.fsu.edu' in fsuid: fsuid = fsuid.split('@')[0] # Make extra sure fsuids from accounts are lower case (see issue #37) return fsuid.lower() # Read the score for each team print("Reading results_tsv...") tsv = csv.reader(results_tsv, delimiter='\t') next(tsv) for row in tsv: # skip header line teamid, solved = row[0], row[3] team_scores[teamid] = solved # Match competitors with questions solved print("Matching teams to scores...") for teamid, score in team_scores.items(): team = Team.objects(teamID=teamid).first() if not (team and team.members): continue for account in team.members: if not account.signin: continue fsuid = format_fsuid(account) user_scores[fsuid] = team_scores[teamid] names[fsuid] = account.first_name, account.last_name # Get student classes print("Reading extra credit survey...") def open_class_file(c): name = str(c).replace(' ', '_').replace('/', '_') fd = open('{}/{}.csv'.format(output_folder, name), 'w') csv_writer = csv.writer(fd) return csv_writer courses = Course.objects.all() for course in courses: students = Account.objects(courses=course) course_students = [] for student in students: fsuid = format_fsuid(student) score = user_scores.get(fsuid, '0') first, last = names.get(fsuid, ('', '')) if type(score) != str: score = '0' if not student.team or student.team.division != division: continue course_students.append((fsuid, last, first, score,)) if len(course_students) > 0: course_file = open_class_file(course) for s in sorted(course_students, key=lambda x: x[1]): course_file.writerow(s) # Put all students in 'all_students.csv' all_students = [] students = Account.objects.all() for student in students: fsuid = format_fsuid(student) score = user_scores.get(fsuid, '0') first, last = names.get(fsuid, ('', '')) if type(score) != str: score = '0' if not student.team or student.team.division != division: continue all_students.append((fsuid, last, first, score,)) all_students_file = open_class_file('all_students') for s in sorted(all_students, key=lambda x: x[1]): print(s) all_students_file.writerow(s)
def extra_credit(results_tsv, courses_csv, output_folder): team_scores, user_scores = dict(), dict() student_classes = dict() class_files = dict() names = dict() # Read the score for each team print("Reading results_tsv...") tsv = csv.reader(results_tsv, delimiter='\t') next(tsv) for row in tsv: # skip header line teamid, solved = row[0], row[3] team_scores[teamid] = solved # Match competitors with questions solved print("Matching teams to scores...") for teamid, score in team_scores.items(): team = Team.objects(teamID=teamid).first() if not (team and team.members): continue for account in team.members: if not account.signin: continue # Try and grab fsuid or email fsuid = account.fsuid or account.email # See if user is an idiot and put their fsu email in the 'fsuid' field if 'my.fsu.edu' in fsuid: fsuid = fsuid.lower().split('@')[0] # Make extra sure fsuids from accounts are lower case (see issue #37) fsuid = fsuid.lower() user_scores[fsuid] = team_scores[teamid] names[fsuid] = account.first_name, account.last_name # Get student classes print("Reading extra credit survey...") courses = csv.reader(courses_csv) next(courses) for row in courses: # skip header line fsuid, course_list = row[1], row[2] fsuid = fsuid.lower().split('@')[0] course_list = course_list.split(', ') student_classes[fsuid] = course_list # Iterate over all students, retrieving their score from the # user_score dict and append "fsuid, score" to the course file def open_class_file(c): fd = open('{}/{}.csv'.format(output_folder, c), 'w') csv_writer = csv.writer(fd) return csv_writer print("Writing class files...") for fsuid, course_list in student_classes.items(): # FSUIDs from the survey not in the EC get None score = user_scores.get(fsuid, None) for course in course_list: if course not in class_files.keys(): class_files[course] = open_class_file(course) first, last = names.get(fsuid, (None, None)) class_files[course].writerow([fsuid, last, first, score]) # If you completed the survey but didn't provide FSUID, your score is None, # but you appear in the class file. Now we generate a file of identifiers in our # user_score that didn't show up in the survey, which will usually be people's # emails for those who did not provide FSUID and didn't get their FSUID # auto-id'ed from a my.fsu.edu email address. print("Processing orphan scores...") orphans = set(user_scores.keys()) - set(student_classes.keys()) orphan_csv = open_class_file('orphans') for orphan in list(orphans): score = user_scores.get(orphan, None) orphan_csv.writerow([orphan, score])