DAS  3.0
Das Analysis System
compareFiles Namespace Reference

Classes

class  Report
 

Functions

def compare_corrections (c1, c2)
 
def compare_files (old, new)
 
def json_load (path)
 

Variables

 parser = argparse.ArgumentParser(description="Compares the content of two correction JSON files. Assumes their content are valid schemav2.")
 
 nargs
 
 help
 
 args = parser.parse_args()
 
 files = map(json_load, args.files)
 
def report = compare_files(*files)
 

Function Documentation

◆ compare_corrections()

def compareFiles.compare_corrections (   c1,
  c2 
)
Return False if the two corrections differ in their content
Differences in name, version or description are not considered
64 def compare_corrections(c1, c2):
65  """Return False if the two corrections differ in their content
66  Differences in name, version or description are not considered"""
67 
68  for key in ["inputs", "output", "data", "generic_formulas"]:
69  if c1.get(key) != c2.get(key):
70  return False
71  return True
72 
73 

◆ compare_files()

def compareFiles.compare_files (   old,
  new 
)
74 def compare_files(old, new):
75  corrs_old = old["corrections"]
76  names_vers_old = { (c["name"], c["version"]) for c in corrs_old }
77  names_old = { nv[0] for nv in names_vers_old }
78  corrs_new = new["corrections"]
79  names_vers_new = { (c["name"], c["version"]) for c in corrs_new }
80 
81  report = Report()
82  report.corrs_removed = names_vers_old - names_vers_new
83 
84  for corr in corrs_new:
85  name = corr["name"]
86  vers = corr["version"]
87 
88  # new correction name, not present in old file
89  if name not in names_old:
90  report.corr_added.append(correctionlib.schemav2.Correction.parse_obj(corr))
91  continue
92 
93  # we know there is a correction with the same name in the old file
94  corrs_old_same_name = [ c for c in corrs_old if c["name"] == name ]
95 
96  # -> check if there is one with the same version
97  old_same_version = next((c for c in corrs_old_same_name if c["version"] == vers), None)
98 
99  if old_same_version:
100  # same version but different content -> problem!
101  if not compare_corrections(old_same_version, corr):
102  report.corr_version_error.add((name, vers))
103  continue
104 
105  # different version -> check the version increased
106  old_max_version = max(corrs_old_same_name, key=lambda c: c["version"])
107  if old_max_version["version"] > vers:
108  report.corr_version_error.add((name, vers))
109  else:
110  report.corr_updated.append(
111  (correctionlib.schemav2.Correction.parse_obj(old_max_version),
112  correctionlib.schemav2.Correction.parse_obj(corr)))
113 
114  return report
115 
116 

◆ json_load()

def compareFiles.json_load (   path)
122  def json_load(path):
123  data = correctionlib.highlevel.open_auto(path)
124  return json.loads(data)

Variable Documentation

◆ args

args = parser.parse_args()

◆ files

files = map(json_load, args.files)

◆ help

help

◆ nargs

nargs

◆ parser

parser = argparse.ArgumentParser(description="Compares the content of two correction JSON files. Assumes their content are valid schemav2.")

◆ report

def report = compare_files(*files)
compareFiles.json_load
def json_load(path)
Definition: compareFiles.py:122
compareFiles.compare_corrections
def compare_corrections(c1, c2)
Definition: compareFiles.py:64
compareFiles.compare_files
def compare_files(old, new)
Definition: compareFiles.py:74