def weakerstudents(schoolid, file1, file2, arr1, arr2, file3): #weaker_students = weakerstudents(newUser, "/tmp/courseMembers.json", "/tmp/users.json", overallstats, all_students, achievements_dict) #file1,courseMembers.json;file2,users.json;arr1,overallstat;arr2,allstudents;file3,achievements_dict courseMember_data = get_dict_from_file(file1) user_data = get_dict_from_file(file2) failstudents = {} if schoolid not in courseMember_data: return 'School not found' for student in courseMember_data[schoolid]: percentiles = student_function2(student, arr1, file3, arr2) fail = [] ok = 0 for percentile in percentiles: if 0 < percentiles[percentile] < 50: fail.append(percentile) elif percentiles[percentile] > 50: ok += 1 if len(fail) > ok: failstudents[user_data[student]['displayName']] = { 'failed': len(fail), 'passed': ok, 'failed levels': [] } for level in fail: failstudents[ user_data[student]['displayName']]['failed levels'].append( (targetlevel[level - 1], objectives[targetlevel[level - 1]]['topics'])) return failstudents
def get_student_ingame_info(schoolid, file1, file2, file3): courseMember_data = get_dict_from_file(file1) user_data = get_dict_from_file(file2) userAchievements_data = file3 studentinfo = {} if schoolid in courseMember_data.keys(): for student in courseMember_data[schoolid]: studentinfo[student] = {} for student in studentinfo: if student in userAchievements_data.keys(): if student not in user_data.keys( ) or "displayName" not in user_data[student].keys(): studentinfo[student]['name'] = "Has not set name" else: studentinfo[student]['name'] = user_data[student][ "displayName"] studentinfo[student]['level'] = userAchievements_data[student][ "CodeCombat"]["totalAchievements"] studentinfo[student]['gameid'] = userAchievements_data[student][ "CodeCombat"]["id"] else: if student not in user_data.keys( ) or "displayName" not in user_data[student].keys(): studentinfo[student]['name'] = "Has not set name" else: studentinfo[student]['name'] = user_data[student][ "displayName"] studentinfo[student]['level'] = "Has not played CodeCombat" studentinfo[student]['gameid'] = "Has not played CodeCombat" return studentinfo
def getAverageTimingsByStudents(schoolid, file1, file2, file3): students = [] courseMember_data = get_dict_from_file(file1) cohortCourses_data = get_dict_from_file(file2) achievements = file3 if schoolid in courseMember_data.keys(): for student in courseMember_data[schoolid]: students.append(student) numStudents = len(students) for s in students: if s not in achievements.keys(): numStudents -= 1 students.remove(s) totaltime = 0 for student in achievements: if student in students: if achievements[student]['CodeCombat']['totalAchievements'] == 0: numStudents -= 1 if 'achievements' in achievements[student]['CodeCombat']: for level in achievements[student]['CodeCombat'][ 'achievements']: if 'playtime' in achievements[student]['CodeCombat'][ 'achievements'][level]: #print(achievements[student]['CodeCombat']['achievements'][level]['playtime']) totaltime += achievements[student]['CodeCombat'][ 'achievements'][level]['playtime'] return round(((totaltime / numStudents) / 60), 1) # in terms of minutes, to one decimal place
def get_student_overall_performance(schoolid, file1, file2, file3): courseMember_data = get_dict_from_file(file1) user_data = get_dict_from_file(file2) userAchievements_data = file3 studentinfo = {} if schoolid in courseMember_data.keys(): for student in courseMember_data[schoolid]: studentinfo[student] = {} for student in studentinfo: if student in userAchievements_data.keys(): if student not in user_data.keys( ) or "displayName" not in user_data[student].keys(): studentinfo[student]['name'] = "Has not set name" else: studentinfo[student]['name'] = user_data[student][ "displayName"] totaltime = 0 levels = get_studentAchieve(student, userAchievements_data) for level in levels: for info in levels[level]: totaltime += levels[level][info][0] studentinfo[student]['total time'] = totaltime if userAchievements_data[student]["CodeCombat"][ "totalAchievements"] == 0: studentinfo[student]['completed levels'] = 0 studentinfo[student]['time per level'] = 0 else: studentinfo[student][ 'time per level'] = totaltime / userAchievements_data[ student]["CodeCombat"]["totalAchievements"] studentinfo[student][ 'completed levels'] = userAchievements_data[student][ "CodeCombat"]["totalAchievements"] studentinfo[student]['gameid'] = userAchievements_data[student][ "CodeCombat"]["id"] else: if student not in user_data.keys( ) or "displayName" not in user_data[student].keys(): studentinfo[student]['name'] = "Has not set name" else: studentinfo[student]['name'] = user_data[student][ "displayName"] studentinfo[student]['total time'] = "Has not played CodeCombat" studentinfo[student][ 'time per level'] = "Has not played CodeCombat" studentinfo[student]['gameid'] = "Has not played CodeCombat" studentinfo[student]['completed levels'] = 0 return studentinfo
def get_all_schools_performance(schoolid, studentinfo, file1, file2, file3, file4): cohortCourses_data = get_dict_from_file(file1) cohortid = "" for cohort in cohortCourses_data: for school in cohortCourses_data[cohort]: if school == schoolid: cohortid = cohort break schoolavg = {} entire = 0 for school in cohortCourses_data[cohortid].items(): schoolavg[school[0]] = {} schoolavg[school[0]]['name'] = school[1]['name'] studentinfo = get_student_ingame_info(school[0], file2, file3, file4) total = 0 number = 0 for student in studentinfo.values(): if student['level'] != "Has not played CodeCombat": total += int(student['level']) number += 1 if number != 0: schoolavg[school[0]]['avgtime'] = total / number else: schoolavg[school[0]]['avgtime'] = 0 if len(studentinfo) != 0: entire += schoolavg[school[0]]['avgtime'] schoolavg['overall'] = {} schoolavg['overall']['name'] = 'overall' schoolavg['overall']['avgtime'] = entire / len( cohortCourses_data[cohortid]) return schoolavg
def realname(studentIDD, file1): #file1,users.json user_data = get_dict_from_file(file1) students_dict = {} for x in user_data.items(): studentID = x[0] if studentID == studentIDD: for y in x[1:]: #accessing the tuples. taking away studentID if ('displayName') in y.keys(): temp = y['displayName'] return temp
def topthreeflaggedlevels(schoolid, file1, file2, file3, arr1, file4): #file1,courseMembers.json;file2,users.json;file3,achievements_dict;arr1,overallstats;file4,all_students courseMember_data = get_dict_from_file(file1) user_data = get_dict_from_file(file2) levels = {} if schoolid not in courseMember_data: return 'School not found' for student in courseMember_data[schoolid]: percentiles = student_function2(student, arr1, file3, file4) for level in percentiles: if percentiles[level] < 50: if level not in levels: levels[level] = 1 else: levels[level] += 1 first = second = third = 0 for level in levels: if levels[level] > third: third = level if levels[level] > second: temp = second second = third third = temp if levels[level] > first: temp = first first = second second = temp return [{ 'level': targetlevel[first - 1], 'No. students failed': levels[first], 'topic': objectives[targetlevel[first - 1]]['topics'] }, { 'level': targetlevel[second - 1], 'No. students failed': levels[second], 'topic': objectives[targetlevel[second - 1]]['topics'] }, { 'level': targetlevel[third - 1], 'No. students failed': levels[third], 'topic': objectives[targetlevel[third - 1]]['topics'] }]
def getAverageTimeLevels(schoolid, file1, file2, file3, file4): #file1;courseMember, file2;cohortCourses, file3;allEvents, file4;users cohortCourses_data = get_dict_from_file(file2) cleanedFile = clean_cohortCourses(get_dict_from_file(file2)) user_data = get_dict_from_file(file4) averages = {} cohortID = "" for cohort in cohortCourses_data: # from school id, find cohort id for school in cohortCourses_data[cohort]: if school == schoolid: cohortID = cohort break for school in cleanedFile[cohortID]: totalLvls = 0 name = cleanedFile[cohortID][school]['name'] averages[name] = {} numStudents = cleanedFile[cohortID][school]['participants'] temp = get_student_ingame_info(school, file1, file4, file3) averages[name]['avgTimeSpent'] = getAverageTimingsByStudents( school, file1, file2, file3) for student in temp: if type(temp[student]['level']) is int: totalLvls += temp[student]['level'] if temp[student][ 'gameid'] == 'Has not played CodeCombat': #exclude those students who didn't play CoCo numStudents -= 1 try: averages[name]['avgLevels'] = "{0:0.1f}".format( totalLvls / numStudents ) # format to one dp. if u want nearest integer just remove "{0:0.1f}".format() except ZeroDivisionError: print(str(totalLvls) + " " + school) return averages
def getPauseStats(video, file1): solutions_file = get_dict_from_file(file1) intervals = { } #keys are the time intervals, values are the number of ppl who paused during the interval start = [ ] #list to store the start integers of an interval eg 0, 11, 21, 31... end = [] #list to store the end intergers of an interval eg 10, 20, 30 maxx = findMax(video, solutions_file) #get the max length of video i = 0 #create the keys of the dictionary while i < maxx: if i != 0: string = str(i) + " to " + str(i + 9) start.append(i) end.append(i + 9) intervals[string] = 0 i += 10 elif i == 0: string = str(i) + " to " + str(i + 10) intervals[string] = 0 start.append(i) end.append(i + 10) i += 11 analyzed = analyze(video, solutions_file) #get the list of all pause times l = len(analyzed) for j in range(0, len(analyzed)): #add all the pauses num = analyzed[j] x = 0 for key in intervals.keys(): #check through every key s = start[x] #using index e = end[x] if s <= num <= e: #if within the range, add to key intervals[key] += 1 break x += 1 return intervals
def getvideoStats(schoolID, file1, file2): #file1,users.json;file2,solutions.json solutions_data = get_dict_from_file(file2) answer = {} list_of_videos = [ ] # to store key as videos, and empty value for now, later will be number (percentage of complete) for x in solutions_data[schoolID].values(): for y in x.items(): videoID = y[0] if 'value' in y[1].keys(): if 'youtubeEvents' in ( y[1]['value']): # confirmation that this is a video if videoID not in list_of_videos: list_of_videos.append(videoID) #print (list_of_videos) # list of videos supposedly for i in list_of_videos: videoname = whodis(i) answer[i] = {"videoname": videoname, 'student names': []} for x in solutions_data[schoolID].items(): studentID = x[0] this_student_completed = [] for y in x[1].items(): videoID = y[0] if ('value') in y[1].keys(): if ('answers') in y[1]['value']: this_student_completed.append( videoID ) # we have a list of completed videos by this student this_student_incompleted = [] for i in list_of_videos: # this is the full list if i not in this_student_completed: this_student_incompleted.append(i) #print (this_student_incompleted) if len(this_student_incompleted) != 0: for i in this_student_incompleted: name = realname(studentID, file1) answer[i]['student names'].append(name) return answer
def numberOfStudentsInSchool(schoolID, file1): cohortCourses_data = get_dict_from_file(file1) for i in cohortCourses_data.items(): for j in i[1].items(): if j[0] == schoolID: return j[1]['participants']
def getUnwatchedCount(studentID, file1): solutions_data = get_dict_from_file(file1) cumulative_list_of_videos = [] # to store key as videos for x in solutions_data.items(): schoolID = x[0] if studentID in x[1].keys(): for y in x[1].values(): for z in y.items(): videoID = z[0] if 'value' in z[1].keys(): if 'youtubeEvents' in z[1]['value']: if videoID not in cumulative_list_of_videos: cumulative_list_of_videos.append(videoID) #print(cumulative_list_of_videos) store of all cumulative videos videos_watched_by_student=[] for x in solutions_data.items(): for y in x[1].keys(): if y ==studentID: for z in x[1][y].items(): thisvideo=z[0] if 'value' in z[1].keys(): if 'answers' in z[1]['value']: videos_watched_by_student.append(thisvideo) #print (videos_watched_by_student) cumulative videos watched by particular student list_of_unwatched=[] for i in cumulative_list_of_videos: if i not in videos_watched_by_student: list_of_unwatched.append(i) #print (list_of_unwatched) #list of unwatched by this student numberOfUnwatched=len(list_of_unwatched) weeknumbers=[] for i in list_of_unwatched: hehe = i[2] if hehe not in weeknumbers: weeknumbers.append(hehe) stringy='' if len(weeknumbers)!=0: for i in weeknumbers[:-1]: stringy+=i stringy+=", " stringy+=weeknumbers[-1] else: stringy = "0" #print (stringy) #print (weeknumbers) list_of_video_names=[] for i in list_of_unwatched: list_of_video_names.append(whodis(i)) #print (list_of_video_names) stringnames = '' if len(weeknumbers)!=0: for i in list_of_video_names[:-1]: stringnames+=i stringnames+=", " stringnames+=list_of_video_names[-1] final = 'You have ' + str(numberOfUnwatched) + " videos incompleted" if numberOfUnwatched == 0: final+=". " else: final += " from Weeks(s) " + stringy + ". They are " + stringnames+ "." return final