예제 #1
0
 def _load_problems_from_file(self, filepath:str) -> list[Problem,...]:
     # assume that filepath exists
     if os.path.getsize(filepath) == 0:
         return []
     with open(filepath, 'r') as fid:
         data = json.loads(fid.read())
         return [Problem.from_json(p) for p in data.values()]
 def _lazy_init(self, filepath: str):
     if not os.path.exists(filepath) or os.path.getsize(filepath) == 0:
         self._data = dict()
         self._next_id = 1
         self._problems = tuple()
         self._sectors = dict()
     else:
         with open(filepath, 'r') as fid:
             self._data = json.loads(fid.read())
         self._next_id = int(self._data['next_id'])
         self._problems = tuple((Problem.from_json(p)
                                 for p in self._data['problems'].values()))
         self._sectors = self._data['sectors']