Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:45

0001 from __future__ import print_function
0002 import sys
0003 
0004 def compare(fn1, fn2):
0005     f1, f2 = open(fn1, "r"), open(fn2, "r")
0006     diff_cols = {}
0007 
0008     for l1, l2 in zip(f1.readlines(), f2.readlines()):
0009         if l1 == l2: continue
0010 
0011         for i, (k1, k2) in enumerate(zip(l1.strip().split(), l2.strip().split())):
0012             if k1 == k2: continue
0013 
0014             if i not in diff_cols:
0015                 diff_cols[i] = []
0016 
0017             diff = diff_cols[i]
0018 
0019             try:
0020                 diff_f = abs(float(k2) - float(k1))
0021                 diff.append((diff_f, k1, k2, "l1: " + l1, "l2: " + l2, ))
0022 
0023                 print("diffrence[f%d]: %s -> %s" % (i, k1, k2))
0024             except ValueError:
0025                 print("non float-type difference[f%d]: %s -> %s" % (i, k1, k2))
0026 
0027     for key, item in sorted(diff_cols.items()):
0028         print("column:", key)
0029         print("\tavg: %f" % (sum(map(lambda x: x[0], item)) / len(item)))
0030 
0031         m = max(item)
0032         print("\tmax:", m[:3])
0033         print("\t\t-:", m[3])
0034         print("\t\t+:", m[4])
0035         
0036     return diff_cols
0037 
0038 if __name__ == "__main__":
0039     if len(sys.argv) != 3:
0040         print("usage %s old.csv new.csv" % sys.argv[0])
0041         sys.exit(1)
0042 
0043     diff = compare(sys.argv[1], sys.argv[2])