@@ 37-55 (lines=19) @@ | ||
34 | self.api = ApiData(1) |
|
35 | ||
36 | ||
37 | def move(self) -> None: |
|
38 | """ Move scooters around the cities. Simulation time is 2 minutes. """ |
|
39 | end_time = time.time() + 120 # 2 minutes |
|
40 | ||
41 | while time.time() <= end_time: |
|
42 | count = 0 |
|
43 | ||
44 | while count < len(self._scooter_id): |
|
45 | id = self._scooter_id[count] |
|
46 | data = self.api.get_scooter_data(scooter_id = id) |
|
47 | ||
48 | self.scooter.add_scooter_to_dict(data) |
|
49 | self.scooter.add_city_to_dict(self._city_data[count]) |
|
50 | self.scooter.set_station_id(self._station_id[count]) |
|
51 | ||
52 | ||
53 | self.run(count, id) |
|
54 | count += 1 |
|
55 | time.sleep(0.001) |
|
56 | ||
57 | ||
58 | def run(self, count: int, id: int): |
|
@@ 105-119 (lines=15) @@ | ||
102 | self.api.update_log() |
|
103 | ||
104 | ||
105 | def return_scooters(self): |
|
106 | """ All scooters will be returned when simulation time ends. """ |
|
107 | count = 0 |
|
108 | ||
109 | while count < len(self._scooter_id): |
|
110 | id = self._scooter_id[count] |
|
111 | data = self.api.get_scooter_data(scooter_id = id) |
|
112 | ||
113 | self.scooter.add_scooter_to_dict(data) |
|
114 | self.scooter.add_city_to_dict(self._city_data[count]) |
|
115 | self.scooter.set_station_id(self._station_id[count]) |
|
116 | ||
117 | self.end(count) |
|
118 | time.sleep(0.001) |
|
119 | count += 1 |
|
120 | ||
121 | ||
122 | def main(self, total:int): |