Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 11 additions & 30 deletions hed/tools/remodeling/operations/summarize_column_values_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ def _get_result_string(self, name, result, indent=BaseSummary.DISPLAY_INDENT):
"""

if name == "Dataset":
return self._get_dataset_string(result, indent=indent)
return self._get_individual_string(result, indent=indent)
sum_list = [f"Dataset: Total events={result.get('Total events', 0)} "
f"Total files={result.get('Total files', 0)}"]
else:
sum_list = [f"Total events={result.get('Total events', 0)}"]
sum_list = sum_list + self._get_detail_list(result, indent=indent)
return ("\n").join(sum_list)

def _get_categorical_string(self, result, offset="", indent=" "):
""" Return a string with the summary for a particular categorical dictionary.
Expand All @@ -192,49 +196,26 @@ def _get_categorical_string(self, result, offset="", indent=" "):
sum_list = sum_list + self._get_categorical_col(entry, count_dict, offset="", indent=" ")
return "\n".join(sum_list)

def _get_dataset_string(self, result, indent=BaseSummary.DISPLAY_INDENT):
""" Return a string with the overall summary for all the tabular files.
def _get_detail_list(self, result, indent=BaseSummary.DISPLAY_INDENT):
""" Return a list of strings with the details

Parameters:
result (dict): Dictionary of merged summary information.
indent (str): String of blanks used as the amount to indent for readability.

Returns:
str: Formatted string suitable for saving in a file or printing.
list: list of formatted strings suitable for saving in a file or printing.

"""
sum_list = [f"Dataset: Total events={result.get('Total events', 0)} "
f"Total files={result.get('Total files', 0)}"]
sum_list = []
specifics = result["Specifics"]
cat_string = self._get_categorical_string(specifics, offset="", indent=indent)
if cat_string:
sum_list.append(cat_string)
val_dict = specifics.get("Value column summaries", {})
if val_dict:
sum_list.append(ColumnValueSummary._get_value_string(val_dict, offset="", indent=indent))
return "\n".join(sum_list)

def _get_individual_string(self, result, indent=BaseSummary.DISPLAY_INDENT):

""" Return a string with the summary for an individual tabular file.

Parameters:
result (dict): Dictionary of summary information for a particular tabular file.
indent (str): String of blanks used as the amount to indent for readability.

Returns:
str: Formatted string suitable for saving in a file or printing.

"""
sum_list = [f"Total events={result.get('Total events', 0)}"]
specifics = result.get("Specifics", {})
cat_dict = specifics.get("Categorical column summaries", {})
if cat_dict:
sum_list.append(self._get_categorical_string(cat_dict, offset=indent, indent=indent))
val_dict = specifics.get("Value column summaries", {})
if val_dict:
sum_list.append(ColumnValueSummary._get_value_string(val_dict, offset=indent, indent=indent))
return "\n".join(sum_list)
return sum_list

def _get_categorical_col(self, entry, count_dict, offset="", indent=" "):
""" Return a string with the summary for a particular categorical column.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def get_details_dict(self, summary_info):

return {"Name": summary_info.name, "Total events": summary_info.total_events,
"Total files": summary_info.total_files,
"Files": summary_info.files.keys(),
"Files": list(summary_info.files.keys()),
"Specifics": {"Categorical info": summary_info.categorical_info,
"Value info": summary_info.value_info,
"Skip columns": summary_info.skip_cols,
Expand Down