Esempio n. 1
0
def get_stats_ensemble(payload, req): 
    uid = UR.getUserId(req)
    id_ensemble = payload["id_ensemble"]
    if not auth.canSeeGrades(uid, id_ensemble):
        return UR.prepare_response({}, 1,  "NOT ALLOWED")
    retval = annotations.get_stats_ensemble(payload)
    return UR.prepare_response(retval)
Esempio n. 2
0
def get_stats_ensemble(payload, req): 
    uid = UR.getUserId(req)
    id_ensemble = payload["id_ensemble"]
    if not auth.canSeeGrades(uid, id_ensemble):
        return UR.prepare_response({}, 1,  "NOT ALLOWED")
    retval = annotations.get_stats_ensemble(payload)
    return UR.prepare_response(retval)
Esempio n. 3
0
def add_count_sheets(id_ensemble, workbook):
    a = annotations.get_stats_ensemble({"id_ensemble": id_ensemble})
    files = a["files"]
    stats = a["stats"]
    users = a["users"]
    sections = a["sections"]

    s_wd = workbook.add_sheet("word_count")
    s_ch = workbook.add_sheet("char_count")
    s_cm = workbook.add_sheet("comments_count")

    # Default order: file id and user email
    file_ids = sorted(files)
    user_ids = sorted(users, key=lambda o: users[o]["email"])

    row = 0
    col = 0
    s_wd.write(row, col, "WORDS")
    s_ch.write(row, col, "CHARACTERS")
    s_cm.write(row, col, "COMMENTS")
    col += 1
    s_wd.write(row, col, "SECTION")
    s_ch.write(row, col, "SECTION")
    s_cm.write(row, col, "SECTION")
    col += 1
    val = None
    for f in file_ids:
        val = files[f]["title"]
        s_wd.write(row, col, val)
        s_ch.write(row, col, val)
        s_cm.write(row, col, val)
        col += 1
    row += 1
    for u in user_ids:
        col = 0
        val = users[u]["email"]
        s_wd.write(row, col, val)
        s_ch.write(row, col, val)
        s_cm.write(row, col, val)
        col += 1
        val = "" if users[u]["section_id"] is None else sections[
            users[u]["section_id"]]["name"]
        s_wd.write(row, col, val)
        s_ch.write(row, col, val)
        s_cm.write(row, col, val)
        col += 1
        for f in file_ids:
            stat_id = "%s_%s" % (u, f)
            s_wd.write(row, col,
                       stats[stat_id]["numwords"] if stat_id in stats else "")
            s_ch.write(row, col,
                       stats[stat_id]["numchars"] if stat_id in stats else "")
            s_cm.write(row, col,
                       stats[stat_id]["cnt"] if stat_id in stats else "")
            col += 1
        row += 1
    return a
Esempio n. 4
0
def add_count_sheets(id_ensemble, workbook): 
    a  = annotations.get_stats_ensemble({"id_ensemble": id_ensemble})    
    files = a["files"]
    stats = a["stats"]
    users = a["users"]
    sections = a["sections"]
  
    s_wd = workbook.add_sheet("word_count")
    s_ch = workbook.add_sheet("char_count")
    s_cm = workbook.add_sheet("comments_count")

    # Default order: file id and user email 
    file_ids = sorted(files)
    user_ids = sorted(users, key=lambda o:users[o]["email"]) 

    row=0
    col=0
    s_wd.write(row, col, "WORDS")
    s_ch.write(row, col, "CHARACTERS")
    s_cm.write(row, col, "COMMENTS")
    col+=1
    s_wd.write(row, col, "SECTION")
    s_ch.write(row, col, "SECTION")
    s_cm.write(row, col, "SECTION")
    col+=1
    val = None
    for f in file_ids: 
        val = files[f]["title"]
        s_wd.write(row, col, val)
        s_ch.write(row, col, val)
        s_cm.write(row, col, val)
        col+=1
    row+=1
    for u in user_ids: 
        col=0
        val = users[u]["email"]
        s_wd.write(row, col, val)
        s_ch.write(row, col, val)
        s_cm.write(row, col, val)
        col+=1
        val = "" if  users[u]["section_id"] is None else  sections[users[u]["section_id"]]["name"] 
        s_wd.write(row, col, val)
        s_ch.write(row, col, val)
        s_cm.write(row, col, val)
        col+=1
        for f in file_ids: 
            stat_id = "%s_%s" % (u,f)
            s_wd.write(row, col, stats[stat_id]["numwords"] if stat_id in stats else "")
            s_ch.write(row, col, stats[stat_id]["numchars"] if stat_id in stats else "")
            s_cm.write(row, col, stats[stat_id]["cnt"] if stat_id in stats else "")
            col+=1
        row+=1
    return a 
Esempio n. 5
0
def serve_grades_spreadsheet(req, id_ensemble): 
    uid = UR.getUserId(req)
    if not auth.canSeeGrades(uid, id_ensemble):
        return HttpResponse("Error: You don't have credentials to see grades for class %s" % (id_ensemble,))
    a  = annotations.get_stats_ensemble({"id_ensemble": id_ensemble})    
    files = a["files"]
    stats = a["stats"]
    users = a["users"]
    sections = a["sections"]
    import xlwt
    wbk = xlwt.Workbook()
    s_wd = wbk.add_sheet("word_count")
    s_ch = wbk.add_sheet("char_count")
    s_cm = wbk.add_sheet("comments_count")

    # Default order: file id and user email 
    file_ids = sorted(files)
    user_ids = sorted(users, key=lambda o:users[o]["email"]) 

    row=0
    col=0
    s_wd.write(row, col, "WORDS")
    s_ch.write(row, col, "CHARACTERS")
    s_cm.write(row, col, "COMMENTS")
    col+=1
    s_wd.write(row, col, "SECTION")
    s_ch.write(row, col, "SECTION")
    s_cm.write(row, col, "SECTION")
    col+=1
    val = None
    for f in file_ids: 
        val = files[f]["title"]
        s_wd.write(row, col, val)
        s_ch.write(row, col, val)
        s_cm.write(row, col, val)
        col+=1
    row+=1
    for u in user_ids: 
        col=0
        val = users[u]["email"]
        s_wd.write(row, col, val)
        s_ch.write(row, col, val)
        s_cm.write(row, col, val)
        col+=1
        val = "" if  users[u]["section_id"] is None else  sections[users[u]["section_id"]]["name"] 
        s_wd.write(row, col, val)
        s_ch.write(row, col, val)
        s_cm.write(row, col, val)
        col+=1
        for f in file_ids: 
            stat_id = "%s_%s" % (u,f)
            s_wd.write(row, col, stats[stat_id]["numwords"] if stat_id in stats else "")
            s_ch.write(row, col, stats[stat_id]["numchars"] if stat_id in stats else "")
            s_cm.write(row, col, stats[stat_id]["cnt"] if stat_id in stats else "")
            col+=1
        row+=1
    #now add a sheet for labeled comments if there are any: 
    lcs = M.LabelCategory.objects.filter(ensemble__id=id_ensemble).order_by("id")
    lcs_ids = list(lcs.values_list('id', flat=True))
    cls = M.CommentLabel.objects.select_related("comment", "location").filter(category__in=lcs, grader__id=uid).order_by("comment__location__source__id", "comment__id", "category__id")
    if len(cls)>0:
        s_lc = wbk.add_sheet("labeled_comments")
        #Header row: 
        row=0
        col=0
        s_lc.write(row, col,"SOURCE_ID")
        col+=1
        s_lc.write(row, col,"COMMENT_ID")
        col+=1
        s_lc.write(row, col,"PARENT_ID")
        col+=1
        s_lc.write(row, col,"LOCATION_ID")
        col+=1
        s_lc.write(row, col,"AUTHOR_ID")
        col+=1
        s_lc.write(row, col,"BODY")
        for i in xrange(0,len(lcs)):
            col+=1
            s_lc.write(row, col,"%s - [0:%s]" %(lcs[i].name, lcs[i].pointscale))       
        #Data Rows: 
        previous_comment_id=0
        for j in xrange(0, len(cls)):
            rec = cls[j]
            if previous_comment_id == rec.comment.id:
                #We just need to complete the data that we missed on the previous row. 
                col_grade = col+lcs_ids.index(rec.category_id) #move to the column for the next category for which we have data
                s_lc.write(row, col_grade, rec.grade)
            else: 
                row+=1
                col=0
                s_lc.write(row, col,rec.comment.location.source_id)
                col+=1
                s_lc.write(row, col,rec.comment.id)
                col+=1
                s_lc.write(row, col,rec.comment.parent_id)
                col+=1
                s_lc.write(row, col,rec.comment.location_id)
                col+=1
                s_lc.write(row, col, rec.comment.author_id)
                col+=1
                s_lc.write(row, col, rec.comment.body)
                col+=1
                col_grade = col+lcs_ids.index(rec.category_id) #move to the column for the next category for which we have data
                s_lc.write(row, col_grade, rec.grade) 
            previous_comment_id = rec.comment.id
    import datetime
    a = datetime.datetime.now()
    fn = "stats_%s_%04d%02d%02d_%02d%02d.xls" % (id_ensemble,a.year, a.month, a.day, a.hour, a.minute)
    wbk.save("/tmp/%s" %(fn,))
    response = serve(req, fn,"/tmp/")
    os.remove("/tmp/%s" %(fn,))
    response["Content-Type"]='application/vnd.ms-excel'   
    response['Content-Disposition'] = "attachment; filename=%s" % (fn, )
    return response