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
17 changes: 9 additions & 8 deletions lib/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ def calc_histogram_mean_var(bins, counts):
return [mean, var, std, n]


def calc_histogram_median(bins, counts):
"""Calculate median from histogram bins and counts."""
def calc_histogram_percentile(bins, counts, q):
"""Calculate the q-th percentile (0 < q < 1) from histogram bins and counts."""
# Convert counts to int in case they're decimal.Decimal from BigQuery
counts = [int(c) for c in counts]
total_count = sum(counts)
if total_count == 0:
return 0.0

# Find the bin containing the median (50th percentile)
target = total_count / 2.0
# Find the bin containing the q-th percentile
target = total_count * q
cumulative = 0

for i, count in enumerate(counts):
Expand All @@ -151,7 +151,7 @@ def calc_histogram_median(bins, counts):
if count == 0:
return bins[i]

# How far into the bin is the median?
# How far into the bin is the target?
remaining = target - (cumulative - count)
fraction = remaining / count

Expand All @@ -175,9 +175,10 @@ def calculate_histogram_stats(bins, counts, data):
data["var"] = var
data["n"] = n

# Calculate median
median = calc_histogram_median(bins, counts)
data["median"] = median
# Calculate median, p75, p95
data["median"] = calc_histogram_percentile(bins, counts, 0.5)
data["p75"] = calc_histogram_percentile(bins, counts, 0.75)
data["p95"] = calc_histogram_percentile(bins, counts, 0.95)

# Calculate densities
[density, cdf] = calc_histogram_density(counts, n)
Expand Down
254 changes: 177 additions & 77 deletions lib/report.py

Large diffs are not rendered by default.

193 changes: 0 additions & 193 deletions lib/templates/html/mean.html

This file was deleted.

Loading