def write_diff(options): diffStats = defaultdict(Statistics) with open(options.out, 'w') as f: f.write("<meandata>\n") for interval_old, interval_new in zip( parse(options.orig, 'interval', heterogeneous=True), parse(options.new, 'interval', heterogeneous=True)): f.write(' <interval begin="%s" end="%s">\n' % (interval_old.begin, interval_old.end)) interval_new_edges = dict([(e.id, e) for e in interval_new.edge]) for edge_old in interval_old.edge: edge_new = interval_new_edges.get(edge_old.id, None) if edge_new is None: continue assert (edge_old.id == edge_new.id) f.write(' <edge id="%s"' % edge_old.id) for attr in edge_old._fields: if attr == 'id': continue try: val_new = float(getattr(edge_new, attr)) val_old = float(getattr(edge_old, attr)) delta = val_new - val_old if not options.no_statistics and attr.startswith( 'std_'): delta = math.sqrt(val_new**2 + val_old**2) else: if options.relative: if val_old != 0: delta /= abs(val_old) else: delta = options.undefined elif options.geh: delta = geh(val_new, val_old) diffStats[attr].add(delta, edge_old.id) f.write(' %s="%s"' % (attr, delta)) except Exception: pass f.write("/>\n") f.write(" </interval>\n") f.write("</meandata>\n") for attr, stats in diffStats.items(): stats.label = attr print(stats)
def write_diff(options): diffStats = defaultdict(Statistics) with open(options.out, 'w') as f: f.write("<meandata>\n") for interval_old, interval_new in zip( parse(options.orig, 'interval', heterogeneous=True), parse(options.new, 'interval', heterogeneous=True)): f.write(' <interval begin="%s" end="%s">\n' % (interval_old.begin, interval_old.end)) interval_new_edges = dict([(e.id, e) for e in interval_new.edge]) for edge_old in interval_old.edge: edge_new = interval_new_edges.get(edge_old.id, None) if edge_new is None: continue assert(edge_old.id == edge_new.id) f.write(' <edge id="%s"' % edge_old.id) for attr in edge_old._fields: if attr == 'id': continue try: val_new = float(getattr(edge_new, attr)) val_old = float(getattr(edge_old, attr)) delta = val_new - val_old if options.relative: if val_old != 0: delta /= abs(val_old) else: delta = options.undefined elif options.geh: delta = geh(val_new, val_old) diffStats[attr].add(delta, edge_old.id) f.write(' %s="%s"' % (attr, delta)) except Exception: pass f.write("/>\n") f.write("</interval>\n") f.write("</meandata>\n") for attr, stats in diffStats.items(): stats.label = attr print(stats)