From bbdd34d06927b57ef955eeec8578e2d85957002b Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 10 Jan 2021 23:11:50 +0100 Subject: statistics: add count to box and whisker plots When calculating the quartiles, we need the count of dives anyway, which makes it trivial to export this value to the frontend. Fixes an erroneous "mean", which should be "median". Suggested-by: Peter Zaal Signed-off-by: Berthold Stoeger --- stats/boxseries.cpp | 4 ++-- stats/statsvariables.cpp | 14 +++++++------- stats/statsvariables.h | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) (limited to 'stats') diff --git a/stats/boxseries.cpp b/stats/boxseries.cpp index b5e4422ea..805e8cc8e 100644 --- a/stats/boxseries.cpp +++ b/stats/boxseries.cpp @@ -119,11 +119,11 @@ std::vector BoxSeries::formatInformation(const Item &item) const { QLocale loc; return { - item.binName, + StatsTranslations::tr("%1 (%2 dives)").arg(item.binName, loc.toString(item.q.count)), QStringLiteral("%1:").arg(variable), infoItem(StatsTranslations::tr("min"), unit, decimals, item.q.min), infoItem(StatsTranslations::tr("Q1"), unit, decimals, item.q.q1), - infoItem(StatsTranslations::tr("mean"), unit, decimals, item.q.q2), + infoItem(StatsTranslations::tr("median"), unit, decimals, item.q.q2), infoItem(StatsTranslations::tr("Q3"), unit, decimals, item.q.q3), infoItem(StatsTranslations::tr("max"), unit, decimals, item.q.max) }; diff --git a/stats/statsvariables.cpp b/stats/statsvariables.cpp index f9d75854b..628a63793 100644 --- a/stats/statsvariables.cpp +++ b/stats/statsvariables.cpp @@ -92,7 +92,7 @@ template<> QString invalid_value() template<> StatsQuartiles invalid_value() { double NaN = std::numeric_limits::quiet_NaN(); - return { NaN, NaN, NaN, NaN, NaN }; + return { NaN, NaN, NaN, NaN, NaN, 0 }; } static bool is_invalid_value(int i) @@ -411,20 +411,20 @@ StatsQuartiles StatsVariable::quartiles(const std::vector &dives) const // This expects the value vector to be sorted! StatsQuartiles StatsVariable::quartiles(const std::vector &vec) { - size_t s = vec.size(); - if (s == 0) + int s = (int)vec.size(); + if (s <= 0) return invalid_value(); switch (s % 4) { default: // gcc doesn't recognize that we catch all possible values. disappointing. case 0: - return { vec[0].v, q3(&vec[s/4 - 1]), q2(&vec[s/2 - 1]), q1(&vec[s - s/4 - 1]), vec[s - 1].v }; + return { vec[0].v, q3(&vec[s/4 - 1]), q2(&vec[s/2 - 1]), q1(&vec[s - s/4 - 1]), vec[s - 1].v, s }; case 1: - return { vec[0].v, vec[s/4].v, vec[s/2].v, vec[s - s/4 - 1].v, vec[s - 1].v }; + return { vec[0].v, vec[s/4].v, vec[s/2].v, vec[s - s/4 - 1].v, vec[s - 1].v, s }; case 2: - return { vec[0].v, q1(&vec[s/4]), q2(&vec[s/2 - 1]), q3(&vec[s - s/4 - 2]), vec[s - 1].v }; + return { vec[0].v, q1(&vec[s/4]), q2(&vec[s/2 - 1]), q3(&vec[s - s/4 - 2]), vec[s - 1].v, s }; case 3: - return { vec[0].v, q2(&vec[s/4]), vec[s/2].v, q2(&vec[s - s/4 - 2]), vec[s - 1].v }; + return { vec[0].v, q2(&vec[s/4]), vec[s/2].v, q2(&vec[s - s/4 - 2]), vec[s - 1].v, s }; } } diff --git a/stats/statsvariables.h b/stats/statsvariables.h index 964878550..3469033e2 100644 --- a/stats/statsvariables.h +++ b/stats/statsvariables.h @@ -50,6 +50,7 @@ struct StatsQuartiles { double min; double q1, q2, q3; double max; + int count; bool isValid() const; }; -- cgit v1.2.3-70-g09d2