StatusManager.py
1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import json
class StatusManager():
status = {}
config_file = "../config/conf.json"
sims = []
status_name = ""
ended = 0
def __init__(self):
super().__init__()
def setStatusManager(self, name, argv):
self.status_name = name
if (len(argv) > 1):
self.config_file = "../config/" + argv[1]
else:
self.statusPrint("Using the default configuration file : conf.json")
def parse(self):
try:
json_data = open(self.config_file, 'r')
except IOError:
self.statusPrint("Configuration file not found")
return (1)
json_content = json.loads(json_data.read())
for dic in json_content:
for key, value in dic.items():
if (key == self.status_name):
self.sims.append(dic)
self.ended = max(dic["time"], self.ended)
self.statusPrint("The simulator will end in " + str(self.ended))
return (0)
def create_status(self):
status = json.dumps(self.status)
return (status)
def updateStatus(self, i: int):
for dic in self.sims:
if (int(dic["time"]) == i):
for key, value in dic[self.status_name].items():
self.status[key] = value
self.statusPrint("Element added to status : %s with value : "%(key) + str(value))
return (0)
def statusPrint(self, message):
print("From : " + self.status_name + " -> " + message)