From 1cce8fe30a73f538ed63e88d7c09e18456d333b9 Mon Sep 17 00:00:00 2001
From: Hong-Phuc Bui <hong-phuc.bui@htwsaar.de>
Date: Wed, 19 Jun 2024 10:01:45 +0200
Subject: [PATCH] test
---
study-effort/src/mystudy/lecture.py | 51 +++++++++++++---
study-effort/vorlesung.csv | 3 +
study-effort/src/mystudy/main.py | 25 +++++--
study-effort/tests/mystudy/lecture_test.py | 50 +++++++++++-----
study-effort/pyproject.toml | 2
5 files changed, 95 insertions(+), 36 deletions(-)
diff --git a/study-effort/pyproject.toml b/study-effort/pyproject.toml
index 26b7f61..042a0be 100644
--- a/study-effort/pyproject.toml
+++ b/study-effort/pyproject.toml
@@ -10,8 +10,6 @@
# All the following settings are optional:
where = ["src"]
-
-
[project.scripts]
mystudy = "mystudy.main:main"
diff --git a/study-effort/src/mystudy/lecture.py b/study-effort/src/mystudy/lecture.py
index 778a4bb..b6861de 100644
--- a/study-effort/src/mystudy/lecture.py
+++ b/study-effort/src/mystudy/lecture.py
@@ -4,19 +4,48 @@
ects_effort: Final[int] = 30
-def lecture_effort(lecture_pre_week, ects):
- """
- :param lecture_pre_week: wie viel Veranstaltungen hat eine Vorlesung in der Woche
- :param ects: Anzahl der ECTS der Vorlesung
- :return:
- """
- effort_in_time = ects * ects_effort
- effort_per_week = effort_in_time / lecture_time # how many hours for a week
- return effort_per_week - (lecture_pre_week * 1.5)
+class Lecture():
+ def __init__(self, name, ects, frequency):
+ """
+
+ :param name:
+ :param ects:
+ :param frequency:
+ """
+ self._name = name
+ self._ects = ects
+ self._frequency = frequency
+
+ def cal_effort(self, time_per_ects = ects_effort, duration = lecture_time) -> float:
+ """
+ Berechnet den Zeitaufwand pro woche für diese Vorlesung
+ :param time_per_ects:
+ :param duration:
+ :return:
+ """
+ effort_in_time = self._ects * time_per_ects
+ effort_per_week = effort_in_time / duration
+ return effort_per_week - (self._frequency * 1.5)
+
+ def __repr__(self):
+ return f"Vorlesungsname {self._name} ECTS: {self._ects}"
+
+ # def __str__(self):
+ # return self.__repr__()
-def format_lecture_effort(name, lecture_count, ects, effort):
- return f"Für die Vorlesung {name} mit {ects} ECTS und {lecture_count} Veranstaltung pro Woche brauchen Sie {effort} Stunden zu lernen."
+def parse_lecture_line(line: str) -> Lecture:
+ words = line.split(";")
+ words = [w.strip() for w in words]
+ name = words[0]
+ count = float(words[1])
+ ects = int(words[2])
+ return Lecture(name, ects, count)
+ pass
+
+
+
+
diff --git a/study-effort/src/mystudy/main.py b/study-effort/src/mystudy/main.py
index d5d8a94..f90d7d9 100644
--- a/study-effort/src/mystudy/main.py
+++ b/study-effort/src/mystudy/main.py
@@ -1,12 +1,21 @@
-from mystudy import lecture
+from mystudy.lecture import Lecture, parse_lecture_line
+from sys import argv
-lecture_count = input("Geben Sie die Anzahl der Veranstaltungen ein!")
-lecture_per_week = int(lecture_count)
-ects_input = input("Geben Sie die ECTS-Zahl der Vorlesung ein!")
-ects = int(ects_input)
+def read_file_to_lecture(filename: str) -> list[Lecture]:
+ lectures = []
+ with open(filename, 'r') as file:
+ while line := file.readline():
+ if len(line.strip()) > 0:
+ l = parse_lecture_line(line)
+ lectures.append(l)
+ return lectures
-effort = lecture.lecture_effort(lecture_per_week, ects)
-text = lecture.format_lecture_effort("Mathematik", lecture_per_week, ects, effort)
-print(text)
+def main():
+ filename = argv[1]
+ print(filename)
+ lectures = read_file_to_lecture(filename)
+ for l in lectures:
+ print(l)
+
diff --git a/study-effort/tests/mystudy/lecture_test.py b/study-effort/tests/mystudy/lecture_test.py
index d82108a..cc6f0f8 100644
--- a/study-effort/tests/mystudy/lecture_test.py
+++ b/study-effort/tests/mystudy/lecture_test.py
@@ -1,22 +1,42 @@
import unittest
-from mystudy import lecture
+from mystudy.lecture import Lecture, parse_lecture_line
+
+EPSILON = 0.01
+
+class LectureTestCase(unittest.TestCase):
+ def test_constructor(self):
+ n = "Mathematik"
+ ects = 5
+ f = 2.5
+ mathe2 = Lecture(n, ects, f)
+ english = Lecture("English", 2, 1)
+ print(mathe2)
+ print(english)
+ text = f"{mathe2} am Montag"
+ text2 = f"{mathe2} im Studiengang MAM"
+ print(text)
-class MyTestCase(unittest.TestCase):
- def test_something(self):
- ects_python = 2
- lecture_per_week = 2
- effort_per_week = lecture.lecture_effort(lecture_per_week, ects_python)
- self.assertEqual(effort_per_week, 1.0) # add assertion here
+ def test_cal_effort(self):
+ n = "Mathematik",
+ ects = 5
+ f = 2.5
+ mathe2 = Lecture(n, ects, f)
+ e1 = mathe2.cal_effort()
+ # self.assertEqual(e1, 6)
+ diff = abs(e1 - 6.25)
+ self.assertTrue(diff < EPSILON)
- def test_format(self):
- ects = 3
- lecture_per_week = 2
- name = "Informatik"
- text = lecture.format_lecture_effort(name, lecture_per_week, ects, 8)
- self.assertTrue(text.index(f"{ects}") >= 0)
- self.assertTrue(text.index(name) >= 0)
- self.assertTrue(text.index("8"))
+ e2 = mathe2.cal_effort(time_per_ects=20)
+ diff = abs(e2 - 2.92)
+ # self.assertEqual(e2, 7)
+ self.assertTrue(diff < EPSILON)
+
+ def test_parse_lecture_line(self):
+ data = "English; 3; 2"
+ english = parse_lecture_line(data)
+ text = "Vorlesungsname English ECTS: 2"
+ self.assertEqual(text, f"{english}")
if __name__ == '__main__':
diff --git a/study-effort/vorlesung.csv b/study-effort/vorlesung.csv
new file mode 100644
index 0000000..88eab23
--- /dev/null
+++ b/study-effort/vorlesung.csv
@@ -0,0 +1,3 @@
+Mathematik; 2.5; 5
+Prog-2 ; 2 ; 5
+
--
Gitblit v1.10.0