Save warnings in output

This commit is contained in:
Jose Gracia 2024-02-15 10:29:45 +01:00
parent 1f7dbd80b3
commit a5435e65dc

View file

@ -36,6 +36,7 @@ class Power:
self.epochs = OrderedDict() self.epochs = OrderedDict()
self.first_ts = None self.first_ts = None
self.last_ts = None self.last_ts = None
self.warnings = ""
@classmethod @classmethod
def from_list(cls, data): def from_list(cls, data):
@ -67,14 +68,14 @@ class Power:
e = list(epochs) e = list(epochs)
k = list(values.keys()) k = list(values.keys())
if not e == k: if not e == k:
print("Warning: Unexpected unsorted timestamps.") power.warnings += "# Warning: Unexpected unsorted timestamps.\n"
# check implicit assumptions: 2) each line has #nodes values # check implicit assumptions: 2) each line has #nodes values
nnodes = len(nodes) nnodes = len(nodes)
for epoch in epochs: for epoch in epochs:
actual = len(values[epoch]) actual = len(values[epoch])
if actual != nnodes: if actual != nnodes:
print("Warning: Unexpected number of nodes ({actual}/{expected})".format(actual=actual, expected=nnodes)) power.warnings += "# Warning: Unexpected number of nodes ({actual}/{expected})\n".format(actual=actual, expected=nnodes)
break break
return power return power
@ -96,6 +97,7 @@ class Power:
print("Error: cowardly refusing to overwrite file ", fname) print("Error: cowardly refusing to overwrite file ", fname)
return None return None
header += self.warnings
try: try:
with open(fname, "w+") as f: with open(fname, "w+") as f:
f.write(header + self.header()) f.write(header + self.header())
@ -247,6 +249,8 @@ class App:
fn = power.to_file(jobid, header) fn = power.to_file(jobid, header)
if fn: if fn:
print('Created file {fn}'.format(fn=fn)) print('Created file {fn}'.format(fn=fn))
if power.warnings:
print(power.warnings)
if __name__ == "__main__": if __name__ == "__main__":