Skip to content

Commit

Permalink
Show if datasets are identical (#4029)
Browse files Browse the repository at this point in the history
  • Loading branch information
soulgalore authored Dec 14, 2023
1 parent e58f9d9 commit 28bb0ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/plugins/compare/pug/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ table
td
a(href=createGraphLink(groupName, metricName))
b #{groupName + '.' + metricName}
if values.statisticalTestU === "N/A"
td N/A
if values.statisticalTestU === "N/A" || values.statisticalTestU === "Datasets are identical"
td #{values.statisticalTestU}
else
td #{h.decimals(values.statisticalTestU)}
td #{h.decimals(values.baseline.mean)}
Expand All @@ -84,7 +84,7 @@ table
td #{h.decimals(values.current.median)}
td #{h.decimals(values.baseline.stdev)}
td #{h.decimals(values.current.stdev)}
if values.statisticalTestU === "N/A"
if values.statisticalTestU === "N/A" || values.statisticalTestU === "Datasets are identical"
td No Test Conducted
else
td #{values.statisticalTestU < 0.05 ? 'Yes - ' + cliffDeltaHelper(values.cliffsDelta) : 'No'}
Expand All @@ -96,7 +96,7 @@ each metricGroup, groupName in compare.metrics
each values, metricName in metricGroup
- var fullMetricName = groupName + '.' + metricName
- var metricId = fullMetricName.replace(/\./g, '_')
h3 #{fullMetricName} #{values.statisticalTestU === "N/A"? '' : values.statisticalTestU < 0.05 ? '(significant change)' : ''}
h3 #{fullMetricName} #{values.statisticalTestU === "N/A" || values.statisticalTestU === "Datasets are identical" ? '' : values.statisticalTestU < 0.05 ? '(significant change)' : ''}
.ct-chart(id=`chart-${metricId}`)
.ct-legend
span.ct-legend-item
Expand Down
12 changes: 6 additions & 6 deletions lib/plugins/compare/statistical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
import json
from scipy.stats import wilcoxon, mannwhitneyu


def has_variability(sample):
"""Check if the sample has more than one unique value."""
return len(set(sample)) > 1


def perform_test(test_type, baseline, current, **kwargs):
"""Perform the statistical test based on the test type."""
if not has_variability(baseline) or not has_variability(current):
return None, "No variability"
if baseline == current:
return None, "Datasets are identical"
else:
return None, "No variability"

if test_type == 'wilcoxon':
return wilcoxon(current, baseline, **kwargs)
Expand All @@ -20,7 +21,6 @@ def perform_test(test_type, baseline, current, **kwargs):
else:
raise ValueError("Invalid test type. Choose 'wilcoxon' or 'mannwhitneyu'.")


input_data = json.loads(sys.stdin.read())
options = input_data['options']
test_type = options.pop('test_type')
Expand All @@ -31,8 +31,8 @@ def perform_test(test_type, baseline, current, **kwargs):
group_results = {}
for metric_name, metric_data in metrics.items():
stat, p = perform_test(test_type, metric_data['baseline'], metric_data['current'], **options)
if p == "No variability":
group_results[metric_name] = {'statistic': "N/A", 'p-value': "N/A"}
if p == "No variability" or p == "Datasets are identical":
group_results[metric_name] = {'statistic': "N/A", 'p-value': p}
else:
group_results[metric_name] = {'statistic': stat, 'p-value': p}
final_results[group_name] = group_results
Expand Down

0 comments on commit 28bb0ae

Please sign in to comment.