From 57cf8d4557459f34538d2ce653530e1cf7f2cf52 Mon Sep 17 00:00:00 2001 From: Tue Herlau <tuhe@dtu.dk> Date: Sun, 23 Jun 2024 13:52:25 +0200 Subject: [PATCH] Minor updates for grading in 02465 --- src/coursebox/core/info.py | 1 + src/coursebox/core/projects.py | 43 ++++++++++++++++++++++++++++- src/coursebox/core/projects_info.py | 5 ++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/coursebox/core/info.py b/src/coursebox/core/info.py index 2123b5d..fd3364d 100644 --- a/src/coursebox/core/info.py +++ b/src/coursebox/core/info.py @@ -60,6 +60,7 @@ def xlsx_to_dicts(xlsx_file,sheet=None, as_dict_list=False, columns=None): return dd def get_enrolled_students(): + # s224202 paths = get_paths() students = xlsx_to_dicts(paths['information.xlsx'], sheet='students') students2 = {} diff --git a/src/coursebox/core/projects.py b/src/coursebox/core/projects.py index f34d500..65ba0d4 100644 --- a/src/coursebox/core/projects.py +++ b/src/coursebox/core/projects.py @@ -119,6 +119,10 @@ def handle_projects(verbose=False, gather_main_xlsx_file=True, plagiarism_check= print("> Done gathering main .xlsx file from instructor .xlsx files") cache_update_dir(cache_base, cache_base, pattern="*.xlsx") info = class_information() + id = 's225785' + pid = 1 + print(info['students'][id]['reports'][pid]) + zip1 = instructor_path + "/zip1.zip" zip2 = instructor_path + "/zip2.zip" @@ -147,7 +151,7 @@ def handle_projects(verbose=False, gather_main_xlsx_file=True, plagiarism_check= else: print("When available, please move downloaded copy of all reports from campusnet to destination:") print(zf) - + info['students']['s225785']['reports'][1] mkboxplots(info['students'],paths) if cache_changed_xlsx_files: @@ -666,13 +670,50 @@ def gather_instructor_sheets(info): ts.save(out) ts.close() print("Collected xlsx instructor files. Using xlwings to load main worksheet, evaluate and save it") + # 024 import xlwings try: + # def main() -> None: + + # info = class_information() + # id = 's225785' + # pid = 1 + # print(info['students'][id]['reports'][pid]) + + # shutil.run( ) + # from ooodev.loader.lo import Lo + # from ooodev.office.calc import Calc + # + # # fnm = sys.argv[1:] # get file from first args + # fnm = out + # + # loader = Lo.load_office(Lo.ConnectSocket(headless=True)) + # doc = Lo.open_doc(fnm=fnm, loader=loader) + # + # # use the Office API to manipulate doc... + # Lo.save_doc(doc, out) # save as a Word file + # Lo.close_doc(doc) + # Lo.close_office() + + book = xw.Book(out) book.save(out) book.close() except xlwings.XlwingsError as e: print("No xlsxwings installed. Sheets are not correctly evaluated.") + + # import shutil + import subprocess + cmd = f'cd {os.path.basename(out)} && libreoffice --calc --headless --invisible --convert-to xlsx --outdir ../ {os.path.basename(out)}' + output = subprocess.run(cmd, capture_output=True, shell=True) + time.sleep(3) + od = os.path.dirname(os.path.dirname(out)) + "/" + os.path.basename(out) + while not os.path.isfile(od): + time.sleep(1) + print("Waiting for file", od) + + shutil.move(od, out) + print(e) diff --git a/src/coursebox/core/projects_info.py b/src/coursebox/core/projects_info.py index 30a4f12..a86ddac 100644 --- a/src/coursebox/core/projects_info.py +++ b/src/coursebox/core/projects_info.py @@ -287,7 +287,12 @@ def populate_student_report_results(students, verbose=False): # 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) + if repn == 1 and 1 > 2: + # info['students']['s225785']['reports'][1] + pass + # cp = parse_column(wb.worksheets[repn], report_number=repn, column=i) if not cp['student_ids']: break -- GitLab