From 8d39ec9761e909bd95e21a7fcc4439cd7b9a40cc Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Thu, 2 Nov 2023 22:17:33 +0100 Subject: [PATCH] intermediate schema is working --- .gitignore | 160 +++++++++++++++++++++++++++++++++++++ LICENSE.md | 7 ++ README.md | 11 +++ coursebuilder/__main__.py | 153 +++++++++++++++++++++++++++++++++++ test/simple/mod.cg.yaml | 92 +++++++++++++++++++++ test/simple/schema.yaml | 163 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 586 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 coursebuilder/__main__.py create mode 100644 test/simple/mod.cg.yaml create mode 100644 test/simple/schema.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68bc17f --- /dev/null +++ b/.gitignore @@ -0,0 +1,160 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..a749f99 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,7 @@ +Copyright 2020-2023 Hartmut Seichter + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cb71675 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# CourseBuilder + +Coursebuilder is a helper and validator for curricula. It helps to amalgate and validate curricula descriptions in order to generate legally required documents for university courses. + +# Author + +(c) Copyright 2020-2023 Hartmut Seichter + +# Licence + +Coursebuilder is licensed under the terms of the MIT License. For details consult https://opensource.org/license/mit/ or the attached license file diff --git a/coursebuilder/__main__.py b/coursebuilder/__main__.py new file mode 100644 index 0000000..bc79a99 --- /dev/null +++ b/coursebuilder/__main__.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python + +""" +CourseBuilder + +Coursebuilder is a preprocessor tool to generate curricula with pandoc from +structured representations. Data scheme and values are kept in YAML files +in order to version content with Git. + +""" + +from argparse import ArgumentParser +import itertools +import yaml +from yaml.loader import Loader +import os +import textwrap + +config_file = 'modulhandbuch.yaml' +line_length = 80 +column_ratio= 0.28 + +def build_curriculum(input_path,lang='de',pagebreak=False,title=False): + + # open the config file + file_path = os.path.realpath(__file__) + config_path = os.path.join(os.path.dirname(file_path),config_file) + transforms = None # for translation + + # load transforms + with open(config_path,'r') as cf: + transforms = yaml.load(cf,Loader=Loader) + + # open meta.yaml in the directory + with open(os.path.join(input_path),'r') as fp: + + # get configuration data + desc = yaml.load(fp,Loader=Loader) + + # collect transformations + ti = [] + + # fix for now + for k,v in desc[lang].items(): + v = v if v else "" + ti.append((transforms[lang][k],str(v))) + + # to limit + h_len = int(line_length * column_ratio) + d_len = line_length-h_len + + if title: + print('#',desc[lang]['name'],'\n') + + + print(''.join(['+',"".ljust(h_len,'-'),'+',"".ljust(d_len,'-'),'+'])) + + headline = False + + for k,v in ti: + + h = textwrap.wrap(k, h_len, break_long_words=False) + wrapper = textwrap.TextWrapper(d_len) + t = [wrapper.wrap(i) for i in v.split('\n') if i != ''] + t = list(itertools.chain.from_iterable(t)) + + # get rows + rows = list(itertools.zip_longest(h,t,fillvalue="")) + + # expand rows + for r in rows: + print(''.join(['|',r[0].ljust(h_len,' '),'|',r[1].ljust(d_len,' '),'|'])) + + if headline: + print(''.join(['+',"".ljust(h_len,'-'),'+',"".ljust(d_len,'-'),'+'])) + else: + print(''.join(['+',"".ljust(h_len,'='),'+',"".ljust(d_len,'='),'+'])) + headline = True + + # to control pagebreaks for pandoc + if pagebreak: + print('\n\\newpage') + +# create a meta file +def create_meta(): + + # open the config file + file_path = os.path.realpath(__file__) + config_path = os.path.join(os.path.dirname(file_path),config_file) + transforms = None # for translation + + # load transforms + with open(config_path,'r') as cf: + while line := cf.readline(): + print(line.rstrip()) + + +class CourseBuilder: + + def __init__(self) -> None: + self.__schema = None + + def load_schema(self,**kwargs) + for k,v in kwargs.items(): + if k == 'schema': + with open(v) as f: + self.__schema = yaml.load(f,Loader=Loader) + print(self.__schema) + + def process_int(self,lang='de'): + pass + + def process_enum(self): + pass + + + +def main(): + + # get command line parameters + parser = ArgumentParser() + + # arguments + parser = ArgumentParser(description='versatile curricula generator') + + # parser.add_argument('-m','--meta',action="extend", nargs="+", type=str,help="Module description(s) as YAML file(s)") + # parser.add_argument('-l','--lang',help="Language to parse from meta file (use de or en)",default='de') + # parser.add_argument('-c','--create',action='store_true',help="Create a meta file from description") + # parser.add_argument('-n','--newpage',action='store_true',help="Create a pagebreak after each table") + # parser.add_argument('-t','--title',action='store_true',help="Create a title ahead of each table") + + parser.add_argument('-s','--schema',help="using provided schema") + + + # get arguments + args = parser.parse_args() + + # only run debug + if args.schema : + cb = CourseBuilder() + cb.load_schema(schema = args.schema) + + # only run if we have a curricullum + elif args.meta: + for m in args.meta: + build_curriculum(m,lang=args.lang,pagebreak=args.newpage,title=args.title) + elif args.create: + create_meta() + else: + parser.print_help() + +if __name__ == '__main__': + main() diff --git a/test/simple/mod.cg.yaml b/test/simple/mod.cg.yaml new file mode 100644 index 0000000..6d8045e --- /dev/null +++ b/test/simple/mod.cg.yaml @@ -0,0 +1,92 @@ +# common +common: + id: CG # fix for any variante + instructor: Prof. Hartmut Seichter, PhD + credits: 5 # numerical value + term: winter # winter, summer, both + frequency: once_per_year, once_per_term + duration: 1 # 1=one term + kind: comp #compulsory, elective + workload: | + - Vorlesung 2SWS + - Übung 2SWS + - Workload: Präsenz (Vorlesung + Übung) 120h Prüfungsvorbereitung 30h + author-of-indenture: + form: lecture # lecture, seminar, lecture_seminar, lecture_exersice, project + + +# German Variant +de: + name: Computergrafik + goal: + Computergrafik ist ein Schmelztiegel von Technologien in der Informatik mit dem Ziel visuelle + Inhalte effizient zu generieren und dem Nutzer zu präsentieren. Studierende können den + Zusammenhang von visuellen Technologien in der Informatik, den zugrunde liegenden mathematischen + Konzepte und der Physiognomie des Menschen, insbesondere des Sehapparates herstellen. + Sie können die Eigenschaften verschiedener Darstellungsformen und -techniken analysieren und + bewerten. Sie lernen grundsätzliche Technologien der 3D Echtzeitdarstellung + kennen und wenden diese an. + content: | + * Grundkenntnisse der menschlichen Wahrnehmung + * Grundkonzepte der Bilderzeugung, Speicherung und Transformation + * Anwendungen von Computergrafik + * Technologien zur Bilddarstellung + * 3D Modelle, insbesondere Surface- und Volumemodelle + * Transformationspipeline + * Homogene Vektorräume und Transformationen + * Szenengraphen und Echtzeit Rendering APIs + * Bildsyntheseverfahren + * Geometrie und Bild Samplingverfahren und Anti-Aliasing Strategien + * Lichttransport, Physikalische Beleuchtungsmodelle + * Texturierungsverfahren + * Überblick Visualisierung + * Graphische Nutzeroberflächen und Systeme + prerequisites: Lineare Algebra, Englisch Kenntnisse min. IELTS Score 6.0 + media-of-instruction: | + * H5P Lernmodule + * Lernforum + * Übungen + * Folien + * Auszug aus der Literaturliste: + * Bar-Zeev, Avi. Scenegraphs: Past, Present and Future, 2003 http://www.realityprime.com/scenegraph.php + * Burley, Brent. “Physically-Based Shading at Disney.” In ACM SIGGRAPH, 2012:1-7, 2012 + * Goldstein, E. Bruce. Sensation and Perception. 3rd ed. Belmont, Calif.: Wadsworth Pub. Co., 1989 + * Hughes, John F. Computer Graphics: Principles and Practice. Third edition. Upper Saddle River, New Jersey: Addison-Wesley, 2014 + * Shirley, Peter, and R. Keith Morley. Realistic Ray Tracing. 2. ed. Natick, Mass: A K Peters, 2003 + +# English +en: + name: Computer Graphics + goal: | + Computer graphics is describing all techniques in computer science + generating images perceivable by humans. Participants will have a broad + overview of techniques and concepts of computer graphics. They will be + able to apply theoretical concepts in practice. + content: | + * Basics of human perception + * Concepts of image storage and manipulation + * Applications of computer graphics + * Display sytems + * 3D models,i.e. surface and volume models + * Transformationspipeline + * Homogenous vector spaces and transformations + * Scenegraphs and rendering APIs + * Methods for image-synthesis + * Sampling in computer graphics + * Light transport and shading models + * Texturing + * Overview visualizations + * Graphical User Interfaces + prerequisites: linear algebra, min. level IELTS score 6.0 + media-of-instruction: | + * H5P learning modules + * learning forum + * exersises + * slides and quizzes + * Literature: + * Bar-Zeev, Avi. Scenegraphs: Past, Present and Future, 2003 http://www.realityprime.com/scenegraph.php. + * Burley, Brent. “Physically-Based Shading at Disney.” In ACM SIGGRAPH, 2012:1–7, 2012 + * Goldstein, E. Bruce. Sensation and Perception. 3rd ed. Belmont, Calif.: Wadsworth Pub. Co., 1989 + * Hughes, John F. Computer Graphics: Principles and Practice. Third edition. Upper Saddle River, New Jersey: Addison-Wesley, 2014 + * Shirley, Peter, and R. Keith Morley. Realistic Ray Tracing. 2. ed. Natick, Mass: A K Peters, 2003 + diff --git a/test/simple/schema.yaml b/test/simple/schema.yaml new file mode 100644 index 0000000..676cd26 --- /dev/null +++ b/test/simple/schema.yaml @@ -0,0 +1,163 @@ +# fields in curricular description +# leaning on methods in OpenAPI 3.0 + +name: + label: { + de: "Modulname", + en: "name of course" + }, + type: str +id: str +instructor: str +goal: str +content: str +form: enum +prerequisites: str +media-of-instruction: str +author-of-indenture: str +used-in: +workload: #tricky! { 'presence': 10, 'exersise': 10, 'exam-prep' : 0 } +# +# credits/ECTS +# +credits: + label: { + en: "Credits and Weight of Mark", + de: "Kreditpunkte und Gewichtung der Note in der Gesamtnote" + } + type: int + template: "${value}CP (${value} / 120) " +# +# Leistungsnachweis +# +form-of-exam: + label: { + de: "Leistungsnachweis", + en: "Form of Examination" + } + type: enum + values: { + 'written' : { + de: "Schriftliche Prüfung", + en: "Written Exam" + }, + 'oral' : { + de: "Mündliche Prüfung", + en: "Oral Exam" + }, + 'alternative' : { + de: "Alternative Prüfungunsleistung", + en: "Alternative Examination" + } + } +# +# term +# +term: + label: { + de: "Semester", + en: "Term" + } + type: 'enum' + values: { + 'winter' : { + de: "Wintersemester", + en: "Winter Term" + }, + 'summer' : { + de: "Sommersemester", + en: "Summer Term" + }, + 'both' : { + de: "Winter- und Sommersemester", + en: "winter and summer term" + } + } +# +# Häufigkeit des Angebots +# +frequency: + label: { + de: "Häufigkeit des Angebots", + en: "Frequency of Offer" + } + type: "enum" + values: { + 'once_per_term' : { + de: "jedes Semester", + en: "every term" + }, + 'once_per_year' : { + de: "einmal im Studienjahr", + en: "once per study year" + } + } +duration: enum +kind: enum +remarks: str + +# test: +# label: { de: "Name", en: "A Test" } +# type: enum +# values: { +# 'brand' : { de: "Marke", en: "Brand" }, +# 'new' : { de: "Neu", en: "New" } +# } + + +# # German +# de: +# name: Modulname +# id: Kürzel +# instructor: Modulverantwortlicher +# goal: Qualifikationsziele +# content: Modulinhalte +# form: Lehrformen +# prerequisites: Voraussetzungen für die Teilnahme +# media-of-instruction: Literatur/ multimediale Lehr- und Lernprogramme +# author-of-indenture: Lehrbriefautor +# used-in: Verwendbarkeit +# workload: Arbeitsaufwand/ Gesamtworkload +# credits: ECTS und Gewichtung der Note in der Gesamtnote +# form-of-exam: Leistungsnachweis +# term: Semester +# frequency: Häufigkeit des Angebots +# duration: Dauer +# kind: Art der Veranstaltung (Pflicht, Wahl, etc.) +# remarks: Bemerkungen + +# # English +# en: +# name: Coursename +# id: Code +# instructor: Instructor +# goal: Goals of Qualification +# content: Content and Topics +# form: Form of Instruction +# prerequisites: Prerequisites +# media-of-instruction: Media of Instruction +# author-of-indenture: Author of Indenture +# used-in: Viable for Course +# workload: Workload +# credits: Credits and Weight of Mark +# form-of-exam: Form of Examination +# term: Term +# frequency: Frequency +# duration: Duration +# kind: Compulsory / Elective +# remarks: Remarks + +# # validators for enum-fields +# enums: +# form: +# - lecture +# - seminar +# - project +# form-of-exam: +# - written +# - oral +# - alternative +# term: +# - summer +# - winter +# - both