Skip to content

Commit

Permalink
make diffs possible
Browse files Browse the repository at this point in the history
  • Loading branch information
MohitYadav-codes committed Nov 5, 2023
1 parent 7fd9137 commit 4f4ffd8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 6 additions & 5 deletions dcmfile_parser/attribute_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _relative_difference(self,a, b):
return 0
return abs(a - b) / max(abs(a), abs(b))

def update_from_and_report_changes(self, other: "BaseParam"):
def update_from_and_report_changes(self, other: "BaseParam",diff_mode=False):
attributes = ['wert', 'size', 'st_x', 'st_y'] ## only these attributes are updated
changes = {}

Expand All @@ -66,9 +66,10 @@ def update_from_and_report_changes(self, other: "BaseParam"):
other_list = getattr(other, attr)

# Ensure both lists have the same length, else there might be structural changes.
if len(current_list) != len(other_list):
if len(current_list) != len(other_list):
changes[attr] = (current_list, other_list)
setattr(self, attr, other_list)
if diff_mode == False:
setattr(self, attr, other_list)
continue

updated_list = []
Expand All @@ -82,8 +83,8 @@ def update_from_and_report_changes(self, other: "BaseParam"):
changes[attr] = ([], []) # Initialize with empty lists
changes[attr][0].append(current_value)
changes[attr][1].append(other_value)

setattr(self, attr, updated_list)
if diff_mode == False:
setattr(self, attr, updated_list)

return changes

Expand Down
10 changes: 8 additions & 2 deletions dcmfile_parser/dcm_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ def __str__(self):


def update_from(self, other: "DCMObject", delete_list=[], logger=None):
self._calc_diff_or_do_update(other,delete_list,logger,diff_mode=False)

def diff_report(self, other: "DCMObject", delete_list=[], logger=None):
self._calc_diff_or_do_update(other,delete_list,logger,diff_mode=True)


def _calc_diff_or_do_update(self, other: "DCMObject", delete_list=[], logger=None, diff_mode=False):
updated_names = []

# Determine the set of names from the current (self) object and the other object
Expand All @@ -92,7 +99,7 @@ def update_from(self, other: "DCMObject", delete_list=[], logger=None):
self_param, _ = self._param_name_dict[name]
other_param, _ = other._param_name_dict[name]
if hasattr(self_param, 'update_from_and_report_changes') and hasattr(other_param, 'update_from_and_report_changes'):
attributes_changed = self_param.update_from_and_report_changes(other_param)
attributes_changed = self_param.update_from_and_report_changes(other_param,diff_mode = diff_mode)
if attributes_changed:
for attribute, (original_value, updated_value) in attributes_changed.items():
if logger:
Expand All @@ -104,7 +111,6 @@ def update_from(self, other: "DCMObject", delete_list=[], logger=None):
self._delete_elements_if_in_list(delete_list,logger,'becuase it was from a higher prio DCM.')

return updated_names, list(missing_names)


def add_new_parameters_from(self, other: "DCMObject", logger=None):
added_names = []
Expand Down

0 comments on commit 4f4ffd8

Please sign in to comment.