db76932935ad46e855f89fe00b914b234d5c250b..a20fadf394be3bd0a535f11751a8038fe814473d
2025-05-27 Hong-Phuc Bui
Testkriterien
a20fad diff | tree
2025-05-27 Hong-Phuc Bui
lösung
75579e diff | tree
2025-05-27 Hong-Phuc Bui
Ub4, vorlesung 26.5.2025
5131d3 diff | tree
6 files added
135 ■■■■■ changed files
aufgabe6-quatal-verbrauch/verbrauch-2025.csv 10 ●●●●● patch | view | raw | blame | history
aufgabe6-quatal-verbrauch/verbrauch.py 42 ●●●●● patch | view | raw | blame | history
aufgabe6-quatal-verbrauch/verbrauch_test.py 32 ●●●●● patch | view | raw | blame | history
datei-bsp/streck.py 27 ●●●●● patch | view | raw | blame | history
datei-bsp/streck_test.py 18 ●●●●● patch | view | raw | blame | history
datei-bsp/treibstoff.csv 6 ●●●●● patch | view | raw | blame | history
aufgabe6-quatal-verbrauch/verbrauch-2025.csv
New file
@@ -0,0 +1,10 @@
# 2025
 5,5;   30;   32; 33,2; 38; 22; 21; 35,3
30,3; 31,2; 35,4; 31.1; 28; 12; 13; 38
23,1; 25,4;   35; 32.3; 36,2; 33,4; 38; 12,5
38,2; 29,4;   31;   30; 28,9; 31,1; 19,2; 25,7
# 2026
5,5; 40; 42; 44,2; 48; 22; 21; 45,4
40,4; 41,2; 45,4; 41.1; 28; 12; 14; 48
24,1; 25,4; 45; 42.4; 46,2; 44,4; 48; 12,5
48,2; 29,4; 41; 40; 28,9; 41,1; 19,2; 25,7
aufgabe6-quatal-verbrauch/verbrauch.py
New file
@@ -0,0 +1,42 @@
yearly_consumption = dict({})
"""
{
    "2025": [
        [3.4, 4.6, 3.7, 2.5],
        [...]
    ],
    "2026": [],
}
"""
year = None
def start_new_year(line: str) -> (bool,int|None):
    try:
        year_part = line.strip()[1:].strip()
        int(year_part)
        return (True, year_part)
    except :
        return (False, None)
def convert_line_to_consumpt(line:str) -> [float]:
    line = line.replace(',', '.')
    line = line.split(';')
    values = []
    for txt in line:
        txt = txt.strip()
        values.append(float(txt))
    return values
with open('./verbrauch-2025.csv') as f:
    for line in f.readlines():
        (is_new_year, year_nr) = start_new_year(line)
        print(is_new_year, year_nr)
        if is_new_year:
            year = [] # new list
            yearly_consumption[year_nr] = year
            continue
        year.append( convert_line_to_consumpt(line) )
# debug
print(yearly_consumption)
aufgabe6-quatal-verbrauch/verbrauch_test.py
New file
@@ -0,0 +1,32 @@
from verbrauch import start_new_year, convert_line_to_consumpt
EPSILON = 0.001
def test_start_new_year():
    line = "# 2025\n"
    (is_new_year, year_nr) = start_new_year(line)
    assert is_new_year
    assert year_nr == "2025"
def test_not_start_new_year():
    line = "[2025]\n"
    (is_new_year, year_nr) = start_new_year(line)
    assert not is_new_year
    assert year_nr is None
def test_not_start_new_year():
    line = " # 2025\n"
    (is_new_year, year_nr) = start_new_year(line)
    print(is_new_year, year_nr)
    assert is_new_year
    assert year_nr == "2025"
def test_convert_line_to_consumpt():
    line = " 5,5;   30;   32; 33,2; 38; 22; 21; 35,3"
    consum = convert_line_to_consumpt(line)
    expected_values = [5.5, 30, 32, 33.2, 38, 22, 21, 35.3]
    print(consum)
    for i in range(len(consum)):
        value = consum[i]
        expected = expected_values[i]
        assert abs(value - expected) < EPSILON
datei-bsp/streck.py
New file
@@ -0,0 +1,27 @@
coordinaten = [] #
def line_to_coordinate(line:str):
    """
    :param line: string, semi-colon separated
    :return: {"x": ... , "y": ...}
    """
    parts = line.split(";")
    x_str = parts[0].strip()
    x_str = x_str.replace(',', '.')
    x = float(x_str)
    y_str = parts[1].strip().replace(',', '.')
    y = float(y_str)
    return {"x": x, "y": y}
def is_line_data(line:str) -> bool:
    stripped = line.strip()
    return len(stripped) > 0 and stripped[0] != '#'
with open("treibstoff.csv") as f:
    for line in f.readlines():
        if is_line_data(line):
            coordinate = line_to_coordinate(line)
            coordinaten.append(coordinate)
print(coordinaten)
datei-bsp/streck_test.py
New file
@@ -0,0 +1,18 @@
from streck import line_to_coordinate
EPSILON = 0.001
def test_line_to_coordinate():
    line = " 12.4; -5.67  "
    c = line_to_coordinate(line)
    x = c["x"]
    y = c["y"]
    assert abs(x - 12.4) < EPSILON
    assert abs(y + 5.67) < EPSILON
def test_line_to_coordinate_coma_sep():
    line = " 12,4; -5,67  "
    c = line_to_coordinate(line)
    x = c["x"]
    y = c["y"]
    assert abs(x - 12.4) < EPSILON
    assert abs(y + 5.67) < EPSILON
datei-bsp/treibstoff.csv
New file
@@ -0,0 +1,6 @@
# Treibstoffverbrauch
# Messung nach jedem zurückgelegten Streck
12.3 ;      -34.6;0.0
34.4;56.6;2.3
45.7;-67.8;5.6