From 8e462b5ffe30ba0ef33a0a3f5dc20660a7c7d45a Mon Sep 17 00:00:00 2001 From: Tue Herlau <tuhe@dtu.dk> Date: Fri, 28 Apr 2023 13:46:11 +0200 Subject: [PATCH] updtes --- setup.py | 2 +- src/coursebox.egg-info/PKG-INFO | 2 +- src/coursebox/core/info.py | 114 ++++++++++++++++-- src/coursebox/core/projects_info.py | 5 +- .../material/homepage_lectures_exercises.py | 23 ++-- 5 files changed, 122 insertions(+), 24 deletions(-) diff --git a/setup.py b/setup.py index 3679b0e..e1f037a 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ with open("README.md", "r", encoding="utf-8") as fh: # beamer-slider setuptools.setup( name="coursebox", - version="0.1.16", + version="0.1.17.11", author="Tue Herlau", author_email="tuhe@dtu.dk", description="A course management system currently used at DTU", diff --git a/src/coursebox.egg-info/PKG-INFO b/src/coursebox.egg-info/PKG-INFO index 5da7428..d60a66a 100644 --- a/src/coursebox.egg-info/PKG-INFO +++ b/src/coursebox.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: coursebox -Version: 0.1.16 +Version: 0.1.17.10 Summary: A course management system currently used at DTU Home-page: https://lab.compute.dtu.dk/tuhe/coursebox Author: Tue Herlau diff --git a/src/coursebox/core/info.py b/src/coursebox/core/info.py index 6ef112e..31cf5cd 100644 --- a/src/coursebox/core/info.py +++ b/src/coursebox/core/info.py @@ -173,6 +173,9 @@ def lectures(info, pensum=None): if pensum is not None: rd, html = lecture['reading'], "" + if rd is None: + rd = "" + while True: i = rd.find("\\cite") if i < 0: break @@ -198,11 +201,14 @@ def lectures(info, pensum=None): for i in range(0, len(lecture_info)): l = dict() + l['year'] = d.year l['month'] = d.strftime('%B') l['day'] = d.day l['date'] = d l['preceded_by_holiday'] = i == holiday + l = {**l, **date2format(d)} + if not continuing_education(): ehw = int(info.get('extraordinary_holiday_week', -1)) if 'extraordinary_holiday_week' in info and int(lecture_info[i]['number']) == int(info['extraordinary_holiday_week']) and ehw == 13: @@ -238,10 +244,47 @@ def lectures(info, pensum=None): linfo['homework_problems_long'] = hwp.replace("P", "Problem ") if hwp else "" if linfo["learning_objectives"]: linfo["learning_objectives"] = [s.strip() for s in linfo["learning_objectives"].split("\n")] + linfo['reading_rst'] = bib2rst(linfo['reading']) l.update(linfo) lectures.append(l) return lectures, pensum +def bib2rst(bib): + + if bib is None or 'cite' not in bib: + return bib + bib = bib.split("cite")[1] + where = None + if "[" in bib: + where = bib.split("[")[1].split("]")[0] + what = bib.split("{")[1].split("}")[0] + if where is None: + return f":cite:p:`{what}`" + else: + return f"{where}, :cite:p:`{what}`" + # return "" + pass + +def date2format(nd): + ab = 'st' + if nd.day == 2: + ab = "nd" + elif nd.day == 3: + ab = 'rd' + elif nd.day >= 4: + ab = 'th' + + latex_long = f"{nd.strftime('%A')} {nd.day}{ab} {nd.strftime('%B')}, {nd.year}" + latex_short = f"{nd.strftime('%B')} {nd.day}{ab}, {nd.year}" + return {'latex_short': latex_short, + 'latex_long': latex_long, + 'latex_abbrev': f"{nd.strftime('%b')} {nd.day}{ab}", + 'latex_abbrev_year': f"{nd.strftime('%b')} {nd.day}{ab}, {nd.year}", + } + + + # return latex_short, latex_long + def get_forum(paths): a = xlsx_to_dicts(paths['information.xlsx'], sheet='forum', as_dict_list=True) if a is None: @@ -263,12 +306,12 @@ def get_forum(paths): return d2 # @profile -def class_information(): +def class_information(verbose=False): course_number = core_conf['course_number'] piazza = 'https://piazza.com/dtu.dk/%s%s/%s' % (semester().lower(), year(), course_number) paths = get_paths() teachers = xlsx_to_dicts(paths['information.xlsx'], sheet='teachers') - students, all_groups = populate_student_report_results( get_enrolled_students() ) + students, all_groups = populate_student_report_results( get_enrolled_students(), verbose=verbose) continuing_education_mode = core_conf['continuing_education_mode'] faq = xlsx_to_dicts(paths['information.xlsx'], sheet='faq') @@ -359,6 +402,8 @@ def class_information(): if 'reports_delta' in d: print(234) + + if 'handin_day_delta' in d: d['reports_info'] = {} for k, r in enumerate(d['reports_handin']): @@ -368,15 +413,21 @@ def class_information(): nd = d['lectures'][r-1]['date'] + timedelta(days=int(d['handin_day_delta'])) ri['date'] = nd ri['html'] = f"{nd.day} {nd.strftime('%b')}" - ab = 'st' - if nd.day == 2: - ab = "nd" - elif nd.day == 3: - ab = 'rd' - elif nd.day >= 4: - ab = 'th' - ri['latex_long'] = f"{nd.strftime('%A')} {nd.day}{ab} {nd.strftime('%B')}, {nd.year}" - ri['latex_short'] = f"{nd.strftime('%B')} {nd.day}{ab}, {nd.year}" + # ab = 'st' + # if nd.day == 2: + # ab = "nd" + # elif nd.day == 3: + # ab = 'rd' + # elif nd.day >= 4: + # ab = 'th' + # latex_short, latex_long = date2format(nd) + + # ri['latex_long'] = latex_long # f"{nd.strftime('%A')} {nd.day}{ab} {nd.strftime('%B')}, {nd.year}" + # ri['latex_short'] = latex_short # f"{nd.strftime('%B')} {nd.day}{ab}, {nd.year}" + ri = {**ri, **date2format(nd)} + + + d['reports_info'][k] = ri @@ -384,6 +435,47 @@ def class_information(): if ppi is not None: d = ppi(paths, d) + r_details = {} + + def get_lecture_date(lecture_id, delta_days=0): + ri = {} + ri['lecture'] = lecture_id + + if lecture_id is None: + return ri + l = [l for l in d['lectures'] if l['number'] == lecture_id][0] + + nd = l['date'] + timedelta(days=delta_days) + + ri['date'] = nd + ri['html'] = f"{nd.day} {nd.strftime('%b')}" + # ab = 'st' + # if nd.day == 2: + # ab = "nd" + # elif nd.day == 3: + # ab = 'rd' + # elif nd.day >= 4: + # ab = 'th' + # ri['latex_long'] = f"{nd.strftime('%A')} {nd.day}{ab} {nd.strftime('%B')}, {nd.year}" + # ri['latex_short'] = f"{nd.strftime('%B')} {nd.day}{ab}, {nd.year}" + ri = {**ri, **date2format(nd)} + # d['reports_info'][k] = ri + + return ri + + # TH: This is the new way of specifying projects. Change to this datastructure gradually. + reports = xlsx_to_dicts(paths['information.xlsx'], sheet='reports', as_dict_list=False) + if reports is not None: + d['reports'] = {} + for r in reports: + if 'id' in r: + d['reports'][r['id']] = r + r['handin'] = get_lecture_date(r['handin'], delta_days=int(d['handin_day_delta'])) + r['handout'] = get_lecture_date(r['handout'], delta_days=0) + r['exercises'] = [e.strip() for e in r['exercises'].split(",") if len(e.strip()) > 0] + + + ice = xlsx_to_dicts(paths['information.xlsx'], sheet='ce', as_dict_list=True) return d def fix_instructor_comma(dd, instructors): diff --git a/src/coursebox/core/projects_info.py b/src/coursebox/core/projects_info.py index a716c8a..cb707b1 100644 --- a/src/coursebox/core/projects_info.py +++ b/src/coursebox/core/projects_info.py @@ -200,12 +200,13 @@ def get_groups_from_report(repn): # @profile -def populate_student_report_results(students): +def populate_student_report_results(students, verbose=False): # take students (list-of-dicts in the info format) and assign them the results from the reports. out = get_output_file() import time t0 = time.time() - print("> Loading student report scores from: %s"%out) + if verbose: + print(f"> Loading student report scores from: {out}") if not os.path.exists(out): return students, [] diff --git a/src/coursebox/material/homepage_lectures_exercises.py b/src/coursebox/material/homepage_lectures_exercises.py index 75da37e..89abe21 100644 --- a/src/coursebox/material/homepage_lectures_exercises.py +++ b/src/coursebox/material/homepage_lectures_exercises.py @@ -149,6 +149,8 @@ def make_lectures(week=None, mode=0, gather_pdf_out=True, gather_sixup=True, mak for f in glob.glob(paths['lectures'] + "/templates/*.tex"): ex = "_partial.tex" if f.endswith(ex): + # print(info) + print("Building file", f) jinjafy_template(info, file_in=f, file_out=lecture_texdir + "/templates/"+os.path.basename(f)[:-len(ex)] + ".tex") # Fix questions. @@ -162,7 +164,16 @@ def make_lectures(week=None, mode=0, gather_pdf_out=True, gather_sixup=True, mak if make_quizzes: lecture_question_compiler(paths, info, lecture_texfile) - pdf_out = slider.latexmk(lecture_texfile, Linux=Linux) + print("Making file", lecture_texfile, Linux) + # pdf_out = slider.latexmk(lecture_texfile, Linux=Linux) + try: + pdf_out = slider.latexmk(lecture_texfile, Linux=Linux) + except Exception as e: + log = lecture_texfile[:-4] + ".log" + print("loading log", log) + with open(log, 'r') as f: + print(f.read()) + raise e all_pdfs.append( (w,pdf_out)) if len(all_pdfs) > 0: @@ -198,13 +209,7 @@ def handle_pdf_collection(paths, all_pdfs, gather_pdf_out, gather_sixup, odir): for dpdf in pdf_compiled_all_6up: output_dir = paths['pdf_out'] + odir if not os.path.exists(output_dir): - os.mkdir(output_dir) - - # if not info['slides_showsolutions']: - # odir += "/lectures_without_solutions" - # if not os.path.isdir(odir): - # os.mkdir(odir) - # + os.makedirs(output_dir) shutil.copy(dpdf, output_dir + "/" + os.path.basename(dpdf)) for f in glob.glob(tmp_dir + "/*"): @@ -392,7 +397,7 @@ def make_exercises_projects_tutors(week=None, only_exercises=False, make_exercis 'year': ex0_date.year, 'month': calendar.month_name[ex0_date.month], 'day': ex0_date.day} - all_lectures = [ex0] + info['lectures'][:-1] + all_lectures = [ex0] + info['lectures'] exercises_to_compile = all_lectures[week:week+1] if week != None else all_lectures -- GitLab