From 404a2497571400f46eb001d88915c56bbcf27f9f Mon Sep 17 00:00:00 2001 From: "a.jurcenko" Date: Fri, 11 Aug 2023 15:46:01 +0200 Subject: [PATCH] First Version of App and Installed Flet --- .idea/.gitignore | 3 + .idea/dieselbestellrechner.iml | 10 ++++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 +++ app.py | 54 ++++++++++++++++++ config.json | 20 +++++++ config.py | 0 main.py | 12 ++++ requirements.txt | Bin 0 -> 1346 bytes tank.py | 36 ++++++++++++ 11 files changed, 153 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/dieselbestellrechner.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 app.py create mode 100644 config.json create mode 100644 config.py create mode 100644 main.py create mode 100644 requirements.txt create mode 100644 tank.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/dieselbestellrechner.iml b/.idea/dieselbestellrechner.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/.idea/dieselbestellrechner.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f6b2d5a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a38def7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..e9f29cf --- /dev/null +++ b/app.py @@ -0,0 +1,54 @@ +import json +from tank import Tank + +configfile = "config.json" + + +class App: + + def __init__(self): + self._tanks = [] + self._refuel_max = None + self._refuel_goal = None + self.load_preferences() + self.calculate_refuel() + + def load_preferences(self): + with open(configfile, 'r') as json_file: + json_row = json.load(json_file) + for t in json_row['tanks']: + tank = Tank(t['name'], t['total'], t['actual'], t['dead']) + self._tanks.append(tank) + self._refuel_max = json_row["refuel"]["max"] + self._refuel_goal = json_row["refuel"]["goal"] + + def calculate_refuel(self): + total_empty_space = 0 + for tank in self._tanks: + total_empty_space += tank.refuel_volume + print("total empty space: ", total_empty_space) + if total_empty_space < self._refuel_max: + print("total empty space is lower as refuel") + return + elif self._refuel_max > total_empty_space - self._refuel_goal: + print("maybe is empty space to low") + return + else: + # todo: formel ausdenken + portion = self._refuel_max // len(self._tanks) + print("portion", portion) + portion_ok = True + for tank in self._tanks: + if tank.refuel_volume < portion: + print("tank ", tank.name, " empty space is to low") + portion_ok = False + if portion_ok: + print("portion is ok") + + @property + def tanks(self): + return self._tanks + + def refuel(self, tank: Tank, portion): + """ just to test """ + tank.refuel_volume() diff --git a/config.json b/config.json new file mode 100644 index 0000000..07ffaab --- /dev/null +++ b/config.json @@ -0,0 +1,20 @@ +{ + "tanks": [ + { + "name": "Tank 1", + "total": 30000, + "actual": 10000, + "dead": 2000 + }, + { + "name": "Tank 2", + "total": 35000, + "actual": 15000, + "dead": 2000 + } + ], + "refuel": { + "max": 33000, + "goal": -6000 + } +} \ No newline at end of file diff --git a/config.py b/config.py new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py new file mode 100644 index 0000000..e9d803f --- /dev/null +++ b/main.py @@ -0,0 +1,12 @@ +import flet as ft +from app import App + + +def main(page: ft.Page): + name_row = ft.Row(controls=[ft.Text(tank.name) for tank in app.tanks]) + page.add(name_row) + + +if __name__ == '__main__': + app = App() + ft.app(target=main) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..b0e0ba80346148ef1ce10df03d7d0882adbbd270 GIT binary patch literal 1346 zcmaKsOHboK5QO`@5*eoY**y0)Kwtt8R~jl+`Ml#BtYD zS6BDU=ij+)?ZejA*e#!#o!b>Fvorf)g;myBPjtajJhv$;p>m!B*H{fhXLH-Igq*^1 z!MYp~Ega%g^xAWrgVO$z_rK z<^F~5`Gv-^OV_h>Ow3T!CWIJvWYQcY$K~dcr6$jY4Eh#A zG4(!W>Cm!)p|=UE;Zu`!&2!SEiJT4d*wVd{yj$YyA*UEKpWAF;eE_xeDG)APiux}d zD+k2X!V`5VN1PFTU%{s-jwulG;2zAtgsSPFN16WEo!#4SkBDDf$)OM8n*EyU)boO; zy`P)pg*q4LH~Oa2q*JA+&a+NpIQ7Q9ids~61CzS^eUg*f4pi!lSfu87qBKb{so`4a zl^;7ebzkVlh&x3HsS6i+vgsy}V^8FGM@hv$F-lLkEWO8j=-?AlFe4?Ha5@+h>w${p sZ3)}TtBy{j`{zK8XSf@1uRLo?