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()