|
3 | 3 | import sys |
4 | 4 | import glob |
5 | 5 |
|
| 6 | +from collections import defaultdict |
| 7 | + |
6 | 8 | import pandas as pd |
7 | 9 | import numpy as np |
8 | 10 | import matplotlib as mpl |
@@ -228,6 +230,7 @@ def get_pilot_series(session, pilot, tmap, resrc, percent=True): |
228 | 230 |
|
229 | 231 | td = entity.description |
230 | 232 | etype = entity.etype |
| 233 | + check = defaultdict(list) |
231 | 234 |
|
232 | 235 | transitions = tmap.get(etype) |
233 | 236 | if not transitions: |
@@ -287,18 +290,38 @@ def get_pilot_series(session, pilot, tmap, resrc, percent=True): |
287 | 290 |
|
288 | 291 | ts = entity.timestamps(event=event) |
289 | 292 | if not ts: |
290 | | - # print('%s: no event %s for %s' % (uid, event, etype)) |
| 293 | + # print('%s: no event %s for %s' % (entity.uid, event, etype)) |
291 | 294 | continue |
292 | 295 |
|
293 | 296 | for r in resrc: |
294 | 297 | amount = t_resrc[r] |
295 | 298 | if amount == 0: |
296 | 299 | continue |
297 | 300 | t = (ts[0] - t_min) |
| 301 | + check['%s:%s' % (r, p_from)].append([event, -amount]) |
| 302 | + check['%s:%s' % (r, p_to )].append([event, +amount]) |
298 | 303 | contribs[r][p_from].append([t, -amount]) |
299 | 304 | contribs[r][p_to ].append([t, +amount]) |
300 | | - # print('%6.3f : %-30s : %-25s : %-15s --> %-15s [%s]' % |
301 | | - # (t, uid, event, p_from, p_to, amount)) |
| 305 | + # print('%6.3f : %-30s : %-25s : %-15s =-> %-15s [%s]' % |
| 306 | + # (t, entity.uid, event, p_from, p_to, amount)) |
| 307 | + |
| 308 | + |
| 309 | + for metric in check: |
| 310 | + |
| 311 | + # all contributions to a metric should sum to zero |
| 312 | + # if not, pprint them |
| 313 | + tot = sum([x[1] for x in check[metric]]) |
| 314 | + if tot != 0: |
| 315 | + print('=== %s: %s' % (entity.uid, etype)) |
| 316 | + print('WARNING: unbalanced contributions to %s: %s' % |
| 317 | + (metric, tot)) |
| 318 | + |
| 319 | + for m in check: |
| 320 | + print(' %-20s : %8d' % (m, sum([x[1] for x in check[m]]))) |
| 321 | + # for e in entity.events: |
| 322 | + # print(' %6.3f : %-20s : %s' % (e[ru.TIME] - t_min, |
| 323 | + # e[ru.EVENT], e[ru.STATE])) |
| 324 | + break |
302 | 325 |
|
303 | 326 | # we now have, for all metrics, a list of resource changes, in the form of |
304 | 327 | # |
|
0 commit comments