From 7df20ac74520ea7cbb38152e14f8bc4e8fb125e5 Mon Sep 17 00:00:00 2001
From: Hong-Phuc Bui <hong-phuc.bui@htwsaar.de>
Date: Wed, 15 May 2024 13:40:56 +0200
Subject: [PATCH] Ende Vorlesung 15.5.
---
funktion-modular/study-effort/effort_semester.py | 52 +++++++++++++++++++++++--
funktion-modular/study-effort/Vorlesungen.txt | 4 +
.gitignore | 5 ++
funktion-modular/study-effort/README.md | 9 ++--
4 files changed, 59 insertions(+), 11 deletions(-)
diff --git a/.gitignore b/.gitignore
index ae4b8a2..17c2bab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
sandbox*
queens*
-*.venv*
\ No newline at end of file
+*.venv*
+
+
+ |test|
\ No newline at end of file
diff --git a/funktion-modular/study-effort/README.md b/funktion-modular/study-effort/README.md
index cbb8720..ffd4fcc 100644
--- a/funktion-modular/study-effort/README.md
+++ b/funktion-modular/study-effort/README.md
@@ -4,7 +4,7 @@
2. In der Ordner legen Sie die Datei `Vorlesungen.txt` mit folgenden Inhalt an:
```text
-#Name; ECTS; Veranstaltung pro Woche
+#Name; ECTS; Veranstaltungen pro Woche
Programmierung 2; 5; 2
Mathematik 2; 5; 3
```
@@ -14,9 +14,9 @@
```shell
$ python3 effort_semester.py Vorlesungen.txt
-Vorlesung ECTS V-Ü-T/Woche Selbstudiumszeit pro Woche
-Programmierung 2 5 2 <>
-Mathematik 2 5 3 <>
+ Vorlesung ECTS V-Ü-T/Woche Selbstudiumszeit pro Woche
+ Programmierung 2 5 2 <>
+ Mathematik 2 5 3 <>
--------------------------------------------------------------------------------
<>
```
@@ -27,6 +27,7 @@
Sie können folgenden Funktionen benutzen:
* String Verarbeitung
+ * `str.split()`
* `str.ljust()`
* `str.rjust()`
* Datei-Handling
diff --git a/funktion-modular/study-effort/Vorlesungen.txt b/funktion-modular/study-effort/Vorlesungen.txt
index dd7a3aa..15eaf01 100644
--- a/funktion-modular/study-effort/Vorlesungen.txt
+++ b/funktion-modular/study-effort/Vorlesungen.txt
@@ -1,3 +1,5 @@
-#Name; ECTS; Veranstaltung pro Woche
+#Vorlesung; ECTS; Veranstaltung
Programmierung 2; 5; 2
Mathematik 2; 5; 3
+# Wahlfach
+Design Pattern in Software; 5; 2
\ No newline at end of file
diff --git a/funktion-modular/study-effort/effort_semester.py b/funktion-modular/study-effort/effort_semester.py
index 33a90fc..2238ffc 100644
--- a/funktion-modular/study-effort/effort_semester.py
+++ b/funktion-modular/study-effort/effort_semester.py
@@ -27,27 +27,69 @@
from typing import Final
SEMESTER_LENGTH: Final[int] = 15 # 15 Woche pro Semester
+ECTS_EFFORT = 30 # 1 ECTS ~ 30 h
+DS = 1.5 # DS = Doppelstunde = 2 Unterrichtstunden
+
+
+def parse_line(line: str) -> tuple[str, float, float]:
+ line = line.strip()
+ line = [e.strip() for e in line.split(";")]
+ return line[0], float(line[1]), float(line[2])
def collect_lectures_from_file(lecture_filename:str) -> list[tuple[str, float, float]]:
# Your code here
- pass
+ lectures = []
+ with open(lecture_filename) as file:
+ while line := file.readline():
+ line = line.strip()
+ if line[0] != '#':
+ line = parse_line(line)
+ lectures.append( line )
+ return lectures
+
+
+def lecture_effort(lecture: tuple[str, float, float]) -> float:
+ sum_effort = lecture[1] * ECTS_EFFORT
+ lecture_effort = SEMESTER_LENGTH * (lecture[2] * DS)
+ return (sum_effort - lecture_effort) / SEMESTER_LENGTH
def compute_semester_effort(lectures: list[tuple[str, float, float]]) -> list[tuple[str, float, float, float]]:
- # Your code here
- pass
+ effort = [
+ (e[0], e[1], e[2], lecture_effort(e)) for e in lectures
+ ]
+ return effort
def print_effort(effort: list[tuple[str, float, float, float]]) -> None:
- # Your code here
- pass
+ max_char = 0
+ sep_width = 3
+ sum_effort = 0
+ for l in effort:
+ if l := len(l[0]) > max_char:
+ max_char = l
+ sum_effort += l[-1]
+
+ lecture_col_width = sep_width + max_char
+ ects_width = len("ECTS") + 1
+ veranstaltung_col_width = 5
+ header = ("Vorlesung", "ECTS", "V;U;T/Woche", "Aufwand/Woche")
+ for l in effort:
+ lecture = l[0].rjust(lecture_col_width)
+ ects = f"{l[1]}".ljust(ects_width)
+ v = f"{l[2]}".rjust(veranstaltung_col_width)
+ e = f"{l[3]}".rjust(veranstaltung_col_width)
+ print(f"{lecture} {ects} {v} {e}")
+ print(f"Summe: {sum_effort}")
if __name__ == "__main__":
lecture_filename = sys.argv[1]
lectures = collect_lectures_from_file(lecture_filename)
+ print(lectures)
effort = compute_semester_effort(lectures)
+ #print(effort)
print_effort(effort)
--
Gitblit v1.10.0