Skip to content

Commit e4cdbe0

Browse files
committed
quartiles
1 parent d1f4d30 commit e4cdbe0

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/trials.jl

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
454454
histtimes = times[1:round(Int, histquantile*end)]
455455
histmin = get(io, :histmin, low_edge(histtimes))
456456
histmax = get(io, :histmax, high_edge(histtimes))
457+
457458
logbins = get(io, :logbins, nothing)
458459
bins = bindata(histtimes, histwidth - 1, histmin, histmax)
459460
append!(bins, [1, floor((1-histquantile) * length(times))])
@@ -466,17 +467,26 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
466467
hist[:,end-1] .= ' '
467468
maxbin = maximum(bins)
468469

469-
delta1 = (histmax - histmin) / (histwidth - 1)
470-
if delta1 > 0
471-
medpos = 1 + round(Int, (histtimes[length(times) ÷ 2] - histmin) / delta1)
472-
avgpos = 1 + round(Int, (mean(times) - histmin) / delta1)
473-
# TODO replace with searchsortedfirst & range?
474-
q25pos = 1 + round(Int, (histtimes[max(1,length(times) ÷ 4)] - histmin) / delta1)
475-
q75pos = 1 + round(Int, (histtimes[3*length(times) ÷ 4] - histmin) / delta1)
476-
else
477-
medpos, avgpos = 1, 1
478-
q25pos, q75pos = 1, 1
479-
end
470+
# delta1 = (histmax - histmin) / (histwidth - 1)
471+
# if delta1 > 0
472+
# medpos = 1 + round(Int, (histtimes[length(times) ÷ 2] - histmin) / delta1)
473+
# avgpos = 1 + round(Int, (mean(times) - histmin) / delta1)
474+
# # TODO replace with searchsortedfirst & range?
475+
# q25pos = 1 + round(Int, (histtimes[max(1,length(times) ÷ 4)] - histmin) / delta1)
476+
# q75pos = 1 + round(Int, (histtimes[3*length(times) ÷ 4] - histmin) / delta1)
477+
# else
478+
# medpos, avgpos = 1, 1
479+
# q25pos, q75pos = 1, 1
480+
# end
481+
_centres = range(histmin, histmax, length=length(bins)-2)
482+
fences = _centres .+ step(_centres)/2
483+
avgpos = searchsortedfirst(fences, mean(times))
484+
medpos = searchsortedfirst(fences, median(times))
485+
# @show medpos medpos2
486+
q25pos = searchsortedfirst(fences, quantile(times, 0.25))
487+
q75pos = searchsortedfirst(fences, quantile(times, 0.75))
488+
# @show q25pos q25pos2
489+
# @show q75pos q75pos2
480490

481491
# Above the histogram bars, print markers for special ones:
482492
printstyled(io, pad, ""; color=padcolor)
@@ -485,8 +495,10 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
485495
i > istop && break
486496
if i == avgpos
487497
printstyled(io, "*", color=:green, bold=true)
488-
elseif i == medpos || (medpos==avgpos && i==medpos-1)
489-
# marker for "median" is moved one to the left if they collide
498+
elseif i == medpos ||
499+
(medpos==avgpos && i==medpos-1 && median(times)<=mean(times)) ||
500+
(medpos==avgpos && i==medpos+1 && median(times)>mean(times))
501+
# marker for "median" is moved one to the left if they collide exactly
490502
# printstyled(io, "½", color=:blue)
491503
printstyled(io, "", color=:blue)
492504
elseif i == q25pos

0 commit comments

Comments
 (0)