diff options
Diffstat (limited to 'stats')
-rw-r--r-- | stats/boxseries.cpp | 2 | ||||
-rw-r--r-- | stats/statsvariables.cpp | 17 | ||||
-rw-r--r-- | stats/statsvariables.h | 2 |
3 files changed, 13 insertions, 8 deletions
diff --git a/stats/boxseries.cpp b/stats/boxseries.cpp index c4f34dbb7..06aa8b095 100644 --- a/stats/boxseries.cpp +++ b/stats/boxseries.cpp @@ -98,7 +98,7 @@ std::vector<QString> BoxSeries::formatInformation(const Item &item) const { QLocale loc; return { - StatsTranslations::tr("%1 (%2 dives)").arg(item.binName, loc.toString(item.q.count)), + StatsTranslations::tr("%1 (%2 dives)").arg(item.binName, loc.toString((int)item.q.dives.size())), QStringLiteral("%1:").arg(variable), infoItem(StatsTranslations::tr("min"), unit, decimals, item.q.min), infoItem(StatsTranslations::tr("Q1"), unit, decimals, item.q.q1), diff --git a/stats/statsvariables.cpp b/stats/statsvariables.cpp index 498314ae7..e5bfc63e7 100644 --- a/stats/statsvariables.cpp +++ b/stats/statsvariables.cpp @@ -92,7 +92,7 @@ template<> QString invalid_value<QString>() template<> StatsQuartiles invalid_value<StatsQuartiles>() { double NaN = std::numeric_limits<double>::quiet_NaN(); - return { NaN, NaN, NaN, NaN, NaN, 0 }; + return { std::vector<dive *>(), NaN, NaN, NaN, NaN, NaN }; } static bool is_invalid_value(int i) @@ -170,7 +170,7 @@ static bool is_invalid_value(const std::vector<StatsValue> &v) static bool is_invalid_value(const StatsQuartiles &q) { - return std::isnan(q.min); + return q.dives.empty(); } bool StatsQuartiles::isValid() const @@ -414,17 +414,22 @@ StatsQuartiles StatsVariable::quartiles(const std::vector<StatsValue> &vec) int s = (int)vec.size(); if (s <= 0) return invalid_value<StatsQuartiles>(); + std::vector<dive *> dives; + dives.reserve(vec.size()); + for (const auto &[v, d]: vec) + dives.push_back(d); + 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, s }; + return { std::move(dives), vec[0].v, q3(&vec[s/4 - 1]), q2(&vec[s/2 - 1]), q1(&vec[s - s/4 - 1]), vec[s - 1].v }; case 1: - return { vec[0].v, vec[s/4].v, vec[s/2].v, vec[s - s/4 - 1].v, vec[s - 1].v, s }; + return { std::move(dives), vec[0].v, vec[s/4].v, vec[s/2].v, vec[s - s/4 - 1].v, vec[s - 1].v }; 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, s }; + return { std::move(dives), vec[0].v, q1(&vec[s/4]), q2(&vec[s/2 - 1]), q3(&vec[s - s/4 - 2]), vec[s - 1].v }; case 3: - return { vec[0].v, q2(&vec[s/4]), vec[s/2].v, q2(&vec[s - s/4 - 2]), vec[s - 1].v, s }; + return { std::move(dives), vec[0].v, q2(&vec[s/4]), vec[s/2].v, q2(&vec[s - s/4 - 2]), vec[s - 1].v }; } } diff --git a/stats/statsvariables.h b/stats/statsvariables.h index 845ee1a67..42f417164 100644 --- a/stats/statsvariables.h +++ b/stats/statsvariables.h @@ -47,10 +47,10 @@ struct StatsOperationResults { // For median and quartiles. struct StatsQuartiles { + std::vector<dive *> dives; double min; double q1, q2, q3; double max; - int count; bool isValid() const; }; |