def _gen_grades(): filedir = os.path.dirname(os.path.abspath(__file__)) if common.DEBUG: studentdir = './test/students' else: studentdir = '../../../students' studentdir = os.path.abspath(os.path.join(filedir, studentdir)) assignmentsfile = os.path.join(studentdir, 'assignments.gen.py') scandir = os.path.join(studentdir, 'scans') # ......................................................................... name2cwid = { v['github'].lower(): k for k, v in students.students.items() if 'github' in v } grades = { cwid: OrderedDict([ ('extra credit', 0), ('overall', None), ('predictions', OrderedDict()), ] + [(( g, s, ), OrderedDict()) for g, ss in standards.groups.items() for s in ss]) for cwid in students.students } # ......................................................................... # from github github = github3.GitHub() try: for r in sorted([r.name for r in github.iter_user_repos(common.org)]): if r in ('course-materials', ): continue assignment = 'a' + r[-2:] for cwid in students.students: grades[cwid][('assignment completion', '')][assignment] = None for pr in github.iter_repo_issues(common.org, r, state='all'): name = pr.user.login if name not in name2cwid: continue grades[name2cwid[name]] \ [('assignment completion', '')] \ [assignment] = True with open(assignmentsfile, 'w') as f: f.write( repr({ cwid: grades[cwid][('assignment completion', '')] for cwid in grades })) except (requests.exceptions.ConnectionError, github3.models.GitHubError): assignments = eval(open(assignmentsfile).read()) none = OrderedDict([(a, None) for a in assignments[list(assignments.keys())[0]]]) for cwid in grades: if cwid in assignments: grades[cwid][('assignment completion', '')] = assignments[cwid] else: grades[cwid][('assignment completion', '')] = none # ......................................................................... # from scans for d in sorted(os.listdir(scandir)): if d.startswith('.'): continue i = Namespace() (i.date, i.assessment, i.standards) = d.split(',', maxsplit=2) i.standards = [standards.lookup(s) for s in i.standards.split(',')] for cwid in students.students: for sta in i.standards: grades[cwid][sta][i.assessment] = None for f in os.listdir(os.path.join(scandir, d)): if f.startswith('.'): continue (i.name, i.scores) = \ f.split('.',maxsplit=1)[0].split(',', maxsplit=1) i.scores = i.scores.split(',') if '' in i.scores: raise Error('WARNING: empty score in' + ' "' + os.path.join(d, f) + '"') if len(i.scores) != len(i.standards): raise Error('WARNING: mismatch in number of scores for' + ' "' + os.path.join(d, f) + '"') i.scores = [ None if s == 'x' else 3.5 if s == '5' else 3.75 if s == '7' else int(s) for s in i.scores ] for sta, sco in zip(i.standards, i.scores): grades[students.lookup(i.name)][sta][i.assessment] = sco # ......................................................................... # from file private = common.importfile(os.path.join(studentdir, 'grades.py')) for cwid in private.grades: if cwid in grades: grades[cwid].update(private.grades[cwid]) else: grades[cwid] = private.grades[cwid] # ......................................................................... for cwid in grades: overall = 0 maximum = 0 for sta, assessments in grades[cwid].items(): if isinstance(sta, str): continue scos = [sco for sco in assessments.values() if sco is not None] if sta == ('assignment completion', ''): sco = len(scos) / len(assessments) if len( assessments) > 0 else 0 assessments['overall'] = sco overall += sco * standards.multipliers[sta] maximum += standards.multipliers[sta] continue if len(scos) == 0: assessments['overall'] = None else: if len(scos) == 1 or scos[-1] >= scos[-2]: sco = scos[-1] else: # scos[-1] < scos[-2] sco = [ sco for sco in [1, 2, 3, 3.5, 3.75, 4] if (scos[-1] + scos[-2]) / 2 <= sco ][0] assessments['overall'] = sco if sco >= 3: overall += sco / 4 * standards.multipliers[sta] maximum += standards.multipliers[sta] ec = grades[cwid]['extra credit'] * 0.002 if grades[cwid]['overall'] is None: grades[cwid]['overall'] = overall + ec grades[cwid]['predictions']['current grade'] = grades[cwid]['overall'] if maximum == 0: grades[cwid]['predictions']['average'] = None grades[cwid]['predictions']['maximum without reassessing'] = None else: grades[cwid]['predictions']['average'] = overall / maximum grades[cwid]['predictions']['maximum without reassessing'] = \ 1 - maximum + overall + ec # ......................................................................... return grades
def _gen_grades(): org = '2016-spring-csuf-benblazak-cpsc-121' filedir = os.path.dirname(os.path.abspath(__file__)) if common.DEBUG: studentdir = './test/students' else: studentdir = '../../../students' studentdir = os.path.abspath(os.path.join(filedir, studentdir)) assignmentsfile = os.path.join(studentdir, 'assignments.gen.py') scandir = os.path.join(studentdir, 'scans') # ......................................................................... name2cwid = { v['github'].lower():k for k,v in students.students.items() if 'github' in v } grades = { cwid: OrderedDict( [ ('extra credit', 0) ] + [ ((g,s,),OrderedDict()) for g,ss in standards.groups.items() for s in ss ]) for cwid in students.students } # ......................................................................... github = github3.GitHub() try: for r in sorted([ r.name for r in github.iter_user_repos(org) ]): if r in ( 'course-materials', ): continue assignment = 'a' + r[-2:] for cwid in students.students: grades[cwid][('assignment completion', '')][assignment] = None for pr in github.iter_repo_issues(org, r, state='all'): name = pr.user.login if name not in name2cwid: continue grades[name2cwid[name]] \ [('assignment completion', '')] \ [assignment] = 4 with open(assignmentsfile, 'w') as f: f.write(repr({ cwid: grades[cwid][('assignment completion', '')] for cwid in grades })) except (requests.exceptions.ConnectionError, github3.models.GitHubError): assignments = eval(open(assignmentsfile).read()) none = OrderedDict([ (a, None) for a in assignments[list(assignments.keys())[0]] ]) for cwid in grades: if cwid in assignments: grades[cwid][('assignment completion', '')] = assignments[cwid] else: grades[cwid][('assignment completion', '')] = none # ......................................................................... for d in sorted(os.listdir(scandir)): if d.startswith('.'): continue i = Namespace() (i.date, i.assessment, i.standards) = d.split(',', maxsplit=2) i.standards = [ standards.lookup(s) for s in i.standards.split(',') ] for cwid in students.students: for sta in i.standards: grades[cwid][sta][i.assessment] = None for f in os.listdir(os.path.join(scandir, d)): if f.startswith('.'): continue (i.name, i.scores) = \ f.split('.',maxsplit=1)[0].split(',', maxsplit=1) i.scores = [ None if s == '' else 3.5 if s == '5' else 3.75 if s == '7' else int(s) for s in i.scores.split(',') ] for sta,sco in zip(i.standards,i.scores): grades[students.lookup(i.name)][sta][i.assessment] = sco # ......................................................................... # TODO: calculate overall grades # ......................................................................... # TODO: update grades from other file # ......................................................................... return grades
# ............................................................................. sp = subprocess.Popen( './gen-grade-sheets--pdf.command', shell = True ) sp.communicate() files = {} for d in os.listdir(scandir): if d.startswith('.'): continue for f in os.listdir(os.path.join(scandir, d)): if f.startswith('.'): continue if len(f.split('.')) > 2 and f.split('.')[-2] == 'sent': continue cwid = students.lookup(os.path.basename(f).split(',')[0]) fname = ( '-'.join(os.path.basename(d).split(',')[:2]) + '--' + students.students[cwid]['alias'].lower().replace(' ','-') + '.' + os.path.basename(f).split('.')[-1] ) if cwid not in files: files[cwid] = [] files[cwid].append([fname, os.path.join(scandir, d, f)]) for f in os.listdir(gradedir): if f.startswith('.'): continue if f.startswith('_'): continue cwid = students.lookup(os.path.basename(f).split('.')[0])
def _gen_grades(): filedir = os.path.dirname(os.path.abspath(__file__)) if common.DEBUG: studentdir = './test/students' else: studentdir = '../../../students' studentdir = os.path.abspath(os.path.join(filedir, studentdir)) assignmentsfile = os.path.join(studentdir, 'assignments.gen.py') scandir = os.path.join(studentdir, 'scans') # ......................................................................... name2cwid = { v['github'].lower():k for k,v in students.students.items() if 'github' in v } grades = { cwid: OrderedDict( [ ('extra credit', 0), ('overall', None), ('predictions', OrderedDict()), ] + [ ((g,s,),OrderedDict()) for g,ss in standards.groups.items() for s in ss ] ) for cwid in students.students } # ......................................................................... # from github github = github3.GitHub() try: for r in sorted([ r.name for r in github.iter_user_repos(common.org) ]): if r in ( 'course-materials', ): continue assignment = 'a' + r[-2:] for cwid in students.students: grades[cwid][('assignment completion', '')][assignment] = None for pr in github.iter_repo_issues(common.org, r, state='all'): name = pr.user.login.lower() if name not in name2cwid: continue grades[name2cwid[name]] \ [('assignment completion', '')] \ [assignment] = True with open(assignmentsfile, 'w') as f: f.write(repr({ cwid: grades[cwid][('assignment completion', '')] for cwid in grades })) except (requests.exceptions.ConnectionError, github3.models.GitHubError): assignments = eval(open(assignmentsfile).read()) none = OrderedDict([ (a, None) for a in assignments[list(assignments.keys())[0]] ]) for cwid in grades: if cwid in assignments: grades[cwid][('assignment completion', '')] = assignments[cwid] else: grades[cwid][('assignment completion', '')] = none # ......................................................................... # from scans for d in sorted(os.listdir(scandir)): if d.startswith('.'): continue i = Namespace() (i.date, i.assessment, i.standards) = d.split(',', maxsplit=2) i.standards = [ standards.lookup(s) for s in i.standards.split(',') ] for cwid in students.students: for sta in i.standards: grades[cwid][sta][i.assessment] = None for f in os.listdir(os.path.join(scandir, d)): if f.startswith('.'): continue (i.name, i.scores) = \ f.split('.',maxsplit=1)[0].split(',', maxsplit=1) i.scores = i.scores.split(',') if '' in i.scores: raise Error( 'WARNING: empty score in' + ' "' + os.path.join(d, f) + '"' ) if len(i.scores) != len(i.standards): raise Error( 'WARNING: mismatch in number of scores for' + ' "' + os.path.join(d, f) + '"' ) i.scores = [ None if s == 'x' else 3.5 if s == '5' else 3.75 if s == '7' else int(s) for s in i.scores ] for sta,sco in zip(i.standards,i.scores): grades[students.lookup(i.name)][sta][i.assessment] = sco # ......................................................................... # from file private = common.importfile(os.path.join(studentdir, 'grades.py')) for cwid in private.grades: if cwid in grades: grades[cwid].update(private.grades[cwid]) else: grades[cwid] = private.grades[cwid] # ......................................................................... for cwid in grades: overall = 0 maximum = 0 for sta,assessments in grades[cwid].items(): if isinstance(sta, str): continue scos = [ sco for sco in assessments.values() if sco is not None ] if sta == ('assignment completion', ''): sco = len(scos)/len(assessments) if len(assessments) > 0 else 0 assessments['overall'] = sco overall += sco * standards.multipliers[sta] maximum += standards.multipliers[sta] continue if len(scos) == 0: assessments['overall'] = None else: if len(scos) == 1 or scos[-1] >= scos[-2]: sco = scos[-1] else: # scos[-1] < scos[-2] sco = [ sco for sco in [1, 2, 3, 3.5, 3.75, 4] if (scos[-1]+scos[-2])/2 <= sco ][0] assessments['overall'] = sco if sco >= 3: overall += sco / 4 * standards.multipliers[sta] maximum += standards.multipliers[sta] ec = grades[cwid]['extra credit'] * 0.002 if grades[cwid]['overall'] is None: grades[cwid]['overall'] = overall + ec grades[cwid]['predictions']['current grade'] = grades[cwid]['overall'] if maximum == 0: grades[cwid]['predictions']['average'] = None grades[cwid]['predictions']['maximum without reassessing'] = None else: grades[cwid]['predictions']['average'] = overall / maximum grades[cwid]['predictions']['maximum without reassessing'] = \ 1 - maximum + overall + ec # ......................................................................... return grades
# ............................................................................. sp = subprocess.Popen('./gen-grade-sheets--pdf.command', shell=True) sp.communicate() files = {} for d in os.listdir(scandir): if d.startswith('.'): continue for f in os.listdir(os.path.join(scandir, d)): if f.startswith('.'): continue if len(f.split('.')) > 2 and f.split('.')[-2] == 'sent': continue cwid = students.lookup(os.path.basename(f).split(',')[0]) fname = ('-'.join(os.path.basename(d).split(',')[:2]) + '--' + students.students[cwid]['alias'].lower().replace(' ', '-') + '.' + os.path.basename(f).split('.')[-1]) if cwid not in files: files[cwid] = [] files[cwid].append([fname, os.path.join(scandir, d, f)]) for f in os.listdir(gradedir): if f.startswith('.'): continue if f.startswith('_'): continue cwid = students.lookup(os.path.basename(f).split('.')[0]) fname = ('grade-sheet--' +
def _gen_grades(): org = "2016-spring-csuf-benblazak-cpsc-121" filedir = os.path.dirname(os.path.abspath(__file__)) if common.DEBUG: studentdir = "./test/students" else: studentdir = "../../../students" studentdir = os.path.abspath(os.path.join(filedir, studentdir)) assignmentsfile = os.path.join(studentdir, "assignments.gen.py") scandir = os.path.join(studentdir, "scans") # ......................................................................... name2cwid = {v["github"].lower(): k for k, v in students.students.items() if "github" in v} grades = { cwid: OrderedDict( [("extra credit", 0), ("overall", None), ("predictions", OrderedDict())] + [((g, s), OrderedDict()) for g, ss in standards.groups.items() for s in ss] ) for cwid in students.students } # ......................................................................... github = github3.GitHub() try: for r in sorted([r.name for r in github.iter_user_repos(org)]): if r in ("course-materials",): continue assignment = "a" + r[-2:] for cwid in students.students: grades[cwid][("assignment completion", "")][assignment] = None for pr in github.iter_repo_issues(org, r, state="all"): name = pr.user.login if name not in name2cwid: continue grades[name2cwid[name]][("assignment completion", "")][assignment] = 4 with open(assignmentsfile, "w") as f: f.write(repr({cwid: grades[cwid][("assignment completion", "")] for cwid in grades})) except (requests.exceptions.ConnectionError, github3.models.GitHubError): assignments = eval(open(assignmentsfile).read()) none = OrderedDict([(a, None) for a in assignments[list(assignments.keys())[0]]]) for cwid in grades: if cwid in assignments: grades[cwid][("assignment completion", "")] = assignments[cwid] else: grades[cwid][("assignment completion", "")] = none # ......................................................................... for d in sorted(os.listdir(scandir)): if d.startswith("."): continue i = Namespace() (i.date, i.assessment, i.standards) = d.split(",", maxsplit=2) i.standards = [standards.lookup(s) for s in i.standards.split(",")] for cwid in students.students: for sta in i.standards: grades[cwid][sta][i.assessment] = None for f in os.listdir(os.path.join(scandir, d)): if f.startswith("."): continue (i.name, i.scores) = f.split(".", maxsplit=1)[0].split(",", maxsplit=1) i.scores = [ None if s == "" else 3.5 if s == "5" else 3.75 if s == "7" else int(s) for s in i.scores.split(",") ] for sta, sco in zip(i.standards, i.scores): grades[students.lookup(i.name)][sta][i.assessment] = sco # ......................................................................... # TODO: update grades from other file # ......................................................................... for cwid in grades: overall = 0 maximum = 0 for sta, assessments in grades[cwid].items(): if isinstance(sta, str): continue scos = [sco for sco in assessments.values() if sco is not None] if len(scos) == 0: assessments["overall"] = sco else: if len(scos) == 1 or scos[-1] >= scos[-2]: sco = scos[-1] else: # scos[-1] < scos[-2] sco = [sco for sco in [1, 2, 3, 3.5, 3.75, 4] if (scos[-1] + scos[-2]) / 2 <= sco][0] assessments["overall"] = sco overall += sco / 4 * standards.multipliers[sta] maximum += standards.multipliers[sta] ec = grades[cwid]["extra credit"] * 0.002 if grades[cwid]["overall"] is None: grades[cwid]["overall"] = overall + ec if maximum == 0: grades[cwid]["predictions"]["average"] = None grades[cwid]["predictions"]["maximum without reassessing"] = None else: grades[cwid]["predictions"]["average"] = overall / maximum grades[cwid]["predictions"]["maximum without reassessing"] = 1 - maximum + overall + ec # ......................................................................... # import pprint # pprint.pprint(grades) return grades