Skip to content
Snippets Groups Projects
Commit c383af59 authored by tuhe's avatar tuhe
Browse files

updates to coursebox for profound

parent 8e462b5f
Branches
No related tags found
No related merge requests found
Metadata-Version: 2.1 Metadata-Version: 2.1
Name: coursebox Name: coursebox
Version: 0.1.17.10 Version: 0.1.17.11
Summary: A course management system currently used at DTU Summary: A course management system currently used at DTU
Home-page: https://lab.compute.dtu.dk/tuhe/coursebox Home-page: https://lab.compute.dtu.dk/tuhe/coursebox
Author: Tue Herlau Author: Tue Herlau
......
...@@ -360,7 +360,7 @@ def search_projects(paths, sheet_number, patterns): ...@@ -360,7 +360,7 @@ def search_projects(paths, sheet_number, patterns):
return all_groups return all_groups
def unpack_zip_file_recursively(zip_file, destination_dir): def unpack_zip_file_recursively(zip_file, destination_dir, remove_zipfiles=False):
""" """
Unpack the zip_file (extension: .zip) to the given directory. Unpack the zip_file (extension: .zip) to the given directory.
...@@ -373,9 +373,9 @@ def unpack_zip_file_recursively(zip_file, destination_dir): ...@@ -373,9 +373,9 @@ def unpack_zip_file_recursively(zip_file, destination_dir):
if os.path.isdir(f): if os.path.isdir(f):
zipfiles = glob.glob(f + "/*.zip") zipfiles = glob.glob(f + "/*.zip")
for zp in zipfiles: for zp in zipfiles:
print("Unpacking student zip file>", zp)
zipfile.ZipFile(zp).extractall(path=os.path.dirname(zp) + "/") zipfile.ZipFile(zp).extractall(path=os.path.dirname(zp) + "/")
if remove_zipfiles:
os.remove(zp)
def copy_populate_from_template(paths, info, sheet_number,zip_file): def copy_populate_from_template(paths, info, sheet_number,zip_file):
# Try to load group ids from the project pdf's # Try to load group ids from the project pdf's
...@@ -657,10 +657,14 @@ def gather_instructor_sheets(info): ...@@ -657,10 +657,14 @@ def gather_instructor_sheets(info):
ts.save(out) ts.save(out)
ts.close() ts.close()
print("Collected xlsx instructor files. Using xlwings to load main worksheet, evaluate and save it") print("Collected xlsx instructor files. Using xlwings to load main worksheet, evaluate and save it")
import xlwings
try:
book = xw.Book(out) book = xw.Book(out)
book.save(out) book.save(out)
book.close() book.close()
except xlwings.XlwingsError as e:
print("No xlsxwings installed. Sheets are not correctly evaluated.")
print(e)
def weave_distribute_groups(info, groups, handins, shortnames): def weave_distribute_groups(info, groups, handins, shortnames):
......
...@@ -4,6 +4,7 @@ import re ...@@ -4,6 +4,7 @@ import re
import openpyxl import openpyxl
import numpy as np import numpy as np
# from line_profiler_pycharm import profile # from line_profiler_pycharm import profile
import pandas as pd
INSTRUCTOR_ROW = 6 INSTRUCTOR_ROW = 6
INSTRUCTOR_CHECKER_ROW = 31 INSTRUCTOR_CHECKER_ROW = 31
...@@ -144,7 +145,7 @@ def parse_column(worksheet, report_number, column): ...@@ -144,7 +145,7 @@ def parse_column(worksheet, report_number, column):
cgroup['score'] = score cgroup['score'] = score
cgroup['pct'] = score2pct(score) cgroup['pct'] = score2pct(score)
if report_number == 3: # this obviously needs fixing for next semester. if report_number == 99: # this obviously needs fixing for next semester.
raise Exception("No report number 3 anymore. ") raise Exception("No report number 3 anymore. ")
I = [] I = []
for i in range(42): # max number of evaluation fields (irrelevant) for i in range(42): # max number of evaluation fields (irrelevant)
...@@ -198,6 +199,59 @@ def get_groups_from_report(repn): ...@@ -198,6 +199,59 @@ def get_groups_from_report(repn):
cls.append(cp) cls.append(cp)
return cls return cls
def load_reports(sheet=1):
"""
Tue 2023: This is a new report loading function which will return a dictionary format. It is more convenient than the
legacy methods that probably need to be refactored at some point.
:param sheets:
:return:
"""
# Load the reports from the excel file.
out = get_output_file()
raise Exception()
# print("> time elapsed", time.time() - t0)
# maximal_groups = []
# maximal_groups_students = []
# for repn in sheets:
#
# pass
repn = sheet
# for repn in sheets:
cls = []
sheet = pd.read_excel(out, sheet_name=repn, index_col=None, header=None)
sheet = sheet.fillna('')
sheet = sheet.to_numpy()
# to_numpy()
for i in range(1, sheet.shape[1]):
# for i in range(2, wb.worksheets[repn].max_column + 1):
# print(i, wb.worksheets[repn].max_column)
# s = pd.read_excel(out, sheet_name=1)
cp = parse_column_numpy(sheet[:, i], report_number=repn, column=i)
# cp = parse_column(wb.worksheets[repn], report_number=repn, column=i)
if not cp['student_ids']:
break
cls.append(cp)
rs = {}
for g in cls:
students = ''
for sid in g['student_ids']:
student = students.get(sid, None)
if student is None:
if repn > 0: # don't care about project 0 (group registration)
print("Bad error: Student id %s not found. report evaluation malformed?" % sid)
else:
# student = student.pop()
student['reports'][repn] = g
if sid not in maximal_groups_students:
maximal_groups.append(g)
maximal_groups_students += g['student_ids']
print("> time elapsed", time.time() - t0)
pass
# @profile # @profile
def populate_student_report_results(students, verbose=False): def populate_student_report_results(students, verbose=False):
...@@ -214,9 +268,11 @@ def populate_student_report_results(students, verbose=False): ...@@ -214,9 +268,11 @@ def populate_student_report_results(students, verbose=False):
students[k]['reports'] = {i: None for i in range(4)} students[k]['reports'] = {i: None for i in range(4)}
import pandas as pd import pandas as pd
wb = openpyxl.load_workbook(out, data_only=True, read_only=True) # wb = openpyxl.load_workbook(out, data_only=True, read_only=True)
# Perhaps find non-empty cols (i.e. those with content) # Perhaps find non-empty cols (i.e. those with content)
if verbose:
print("> time elapsed", time.time() - t0) print("> time elapsed", time.time() - t0)
maximal_groups = [] maximal_groups = []
maximal_groups_students = [] maximal_groups_students = []
...@@ -232,8 +288,6 @@ def populate_student_report_results(students, verbose=False): ...@@ -232,8 +288,6 @@ def populate_student_report_results(students, verbose=False):
# print(i, wb.worksheets[repn].max_column) # print(i, wb.worksheets[repn].max_column)
# s = pd.read_excel(out, sheet_name=1) # s = pd.read_excel(out, sheet_name=1)
cp = parse_column_numpy(sheet[:,i], report_number=repn, column=i) cp = parse_column_numpy(sheet[:,i], report_number=repn, column=i)
# cp = parse_column(wb.worksheets[repn], report_number=repn, column=i) # cp = parse_column(wb.worksheets[repn], report_number=repn, column=i)
if not cp['student_ids']: if not cp['student_ids']:
break break
...@@ -251,5 +305,6 @@ def populate_student_report_results(students, verbose=False): ...@@ -251,5 +305,6 @@ def populate_student_report_results(students, verbose=False):
if sid not in maximal_groups_students: if sid not in maximal_groups_students:
maximal_groups.append(g) maximal_groups.append(g)
maximal_groups_students += g['student_ids'] maximal_groups_students += g['student_ids']
if verbose:
print("> time elapsed", time.time() -t0) print("> time elapsed", time.time() -t0)
return students, maximal_groups return students, maximal_groups
\ No newline at end of file
...@@ -298,7 +298,7 @@ def fix_shared(paths, output_dir, pdf2png=False,dosvg=True,verbose=False, compil ...@@ -298,7 +298,7 @@ def fix_shared(paths, output_dir, pdf2png=False,dosvg=True,verbose=False, compil
# update_source_cache = False # update_source_cache = False
source_extra = {} source_extra = {}
for rel in source: for rel in source:
if rel.endswith(".svg") and source[rel]['modified']: if rel.endswith(".svg") and source[rel]['modified'] and dosvg:
pdf_file = svg2pdf(shared_base + "/"+rel, crop=True, text_to_path=True) pdf_file = svg2pdf(shared_base + "/"+rel, crop=True, text_to_path=True)
rel = os.path.relpath(pdf_file, shared_base) rel = os.path.relpath(pdf_file, shared_base)
source_extra[rel] = dict(mtime=os.path.getmtime(pdf_file), hash=hash_file_(pdf_file), modified=True) source_extra[rel] = dict(mtime=os.path.getmtime(pdf_file), hash=hash_file_(pdf_file), modified=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment