Skip to content

Commit

Permalink
def + cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Palazzo committed Nov 2, 2023
1 parent d7a8888 commit 716e5bc
Showing 1 changed file with 8 additions and 35 deletions.
43 changes: 8 additions & 35 deletions sdmetrics/reports/multi_table/_properties/cardinality.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _generate_details(self, real_data, synthetic_data, metadata, progress_bar=No
float:
The average score for the property for all the individual metric scores computed.
"""
child_tables, parent_tables = [], []
child_tables, parent_tables, child_foreign_key = [], [], []
metric_names, scores, error_messages = [], [], []
for relation in metadata.get('relationships', []):
relationships_metadata = {'relationships': [relation]}
Expand All @@ -53,50 +53,20 @@ def _generate_details(self, real_data, synthetic_data, metadata, progress_bar=No

child_tables.append(relation['child_table_name'])
parent_tables.append(relation['parent_table_name'])
child_foreign_key.append(relation['child_foreign_key'])
metric_names.append('CardinalityShapeSimilarity')
scores.append(relation_score)
error_messages.append(error_message)

self.details = pd.DataFrame({
'Child Table': child_tables,
'Parent Table': parent_tables,
'Foreign Key': child_foreign_key,
'Metric': metric_names,
'Score': scores,
'Error': error_messages,
})

def _get_details_for_table_name(self, table_name):
"""Return the details for the given table name.
Args:
table_name (str):
Table name to get the details for.
Returns:
pandas.DataFrame:
The details for the given table name.
"""
is_child = self.details['Child Table'] == table_name
is_parent = self.details['Parent Table'] == table_name
return self.details[is_child | is_parent].copy()

def get_details(self, table_name=None):
"""Return the details for the property.
Args:
table_name (str):
Table name to get the details for.
Defaults to ``None``.
Returns:
pandas.DataFrame:
The details for the property.
"""
if table_name is None:
return self.details.copy()

return self._get_details_for_table_name(table_name)

def _get_table_relationships_plot(self, table_name):
"""Get the table relationships plot from the parent child relationship scores for a table.
Expand All @@ -107,9 +77,12 @@ def _get_table_relationships_plot(self, table_name):
Returns:
plotly.graph_objects._figure.Figure
"""
plot_data = self._get_details_for_table_name(table_name).copy()
plot_data = self.get_details(table_name).copy()
column_name = 'Child → Parent Relationship'
plot_data[column_name] = plot_data['Child Table'] + ' → ' + plot_data['Parent Table']
plot_data[column_name] = (
plot_data['Child Table'] + ' (' + plot_data['Foreign Key'] + ') → ' +
plot_data['Parent Table']
)
plot_data = plot_data.drop(['Child Table', 'Parent Table'], axis=1)

average_score = round(plot_data['Score'].mean(), 2)
Expand Down

0 comments on commit 716e5bc

Please sign in to comment.