From 5131d306a554cbe80cf85fc0f8682987bf8a6c98 Mon Sep 17 00:00:00 2001 From: Hong-Phuc Bui <hong-phuc.bui@htwsaar.de> Date: Tue, 27 May 2025 14:37:37 +0200 Subject: [PATCH] Ub4, vorlesung 26.5.2025 --- aufgabe6-quatal-verbrauch/verbrauch-2025.csv | 6 ++++++ datei-bsp/streck.py | 27 +++++++++++++++++++++++++++ datei-bsp/treibstoff.csv | 6 ++++++ datei-bsp/streck_test.py | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+), 0 deletions(-) diff --git a/aufgabe6-quatal-verbrauch/verbrauch-2025.csv b/aufgabe6-quatal-verbrauch/verbrauch-2025.csv new file mode 100644 index 0000000..f398716 --- /dev/null +++ b/aufgabe6-quatal-verbrauch/verbrauch-2025.csv @@ -0,0 +1,6 @@ +# 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 diff --git a/datei-bsp/streck.py b/datei-bsp/streck.py new file mode 100644 index 0000000..029b2c0 --- /dev/null +++ b/datei-bsp/streck.py @@ -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) \ No newline at end of file diff --git a/datei-bsp/streck_test.py b/datei-bsp/streck_test.py new file mode 100644 index 0000000..5fd267d --- /dev/null +++ b/datei-bsp/streck_test.py @@ -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 \ No newline at end of file diff --git a/datei-bsp/treibstoff.csv b/datei-bsp/treibstoff.csv new file mode 100644 index 0000000..ab22a9c --- /dev/null +++ b/datei-bsp/treibstoff.csv @@ -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 -- Gitblit v1.10.0-SNAPSHOT