def parse_wuprop(projects): applications = list() badges = list() # hmm, well, there is only 1 but one can always dream for key, project in sorted(projects.items()): for key, app in sorted(project.applications.items()): try: runtime = app.statistics.wuRuntime except AttributeError: logger.debug('skipping %s since there are no wuprop stats', app.name) continue runtime_sec = runtime.total_seconds() color, value = Badge_wuprop.getColor(runtime_sec) applications.append((value, color, '{} {}'.format(project.name, app.name), app)) for _, badge in project.badges: if hasattr(badge, 'isWuprop'): # isinstance failed, see http://mail.python.org/pipermail/python-bugs-list/2005-August/029861.html badges.append(badge) # def my_cmp(app1, app2): # """This shouldn't be needed""" # if app1[0] != app2[0]: # return cmp(app1[0], app2[0]) # else: # return cmp(app1[2].name, app2[2].name) applications.sort(reverse=True)#, cmp=my_cmp) return applications, badges
def plot_wuprop(fig, applications, badges, browser): ax = fig.add_subplot(111) labels = list() width = 0.75 totalRuntime = datetime.timedelta(0) for ix, data in enumerate(applications): badgeLine = data[0] color = data[1] label = data[2] app = data[3] stat = app.statistics h = stat.wuRuntime.total_seconds() totalRuntime += stat.wuRuntime color, b = Badge_wuprop.getColor(h) kwargs = dict(width=width, color=color) ax.bar(ix, h, **kwargs) pending = stat.wuPending.total_seconds() ax.bar(ix, pending, bottom=h, alpha=0.75, **kwargs) h += pending pending, running, validation = app.pendingTime(include_elapsedCPUtime=False) for t, alpha in ((validation, 0.5), (running, 0.25), (pending, 0.125)): ax.bar(ix, t, bottom=h, alpha=alpha, **kwargs) h += t labels.append(label) days = badgeLine*60*60 plt.axhline(days, color=color) for b in badges: for ix, value in enumerate(b.value): if value != 0: try: showImage(ax, browser, (ix+1)*20, value=value*3600, url=b.url, frameon=False, box_alignment=(0.5, 0.5)) except Exception as e: logger.error('Badge image failed with "%s"', e) pos = np.arange(len(labels)) ax.set_xticks(pos+width/2) ax.set_xticklabels(labels, rotation=17, horizontalalignment='right') ax.yaxis.set_major_formatter(formatter_timedelta) totalRuntime = util.timedeltaToStr(totalRuntime) fig.suptitle('{} applications, total runtime {}'.format(len(labels), totalRuntime)) for mark in pos[::20][1:]: ax.axvline(mark) ax.set_ylim(ymin=0) # Negative runtime values makes no sense