diff --git a/stats/statsvariables.cpp b/stats/statsvariables.cpp index c163fd0df..dc05067c4 100644 --- a/stats/statsvariables.cpp +++ b/stats/statsvariables.cpp @@ -297,7 +297,9 @@ static const char *operation_names[] = { QT_TRANSLATE_NOOP("StatsTranslations", "Median"), QT_TRANSLATE_NOOP("StatsTranslations", "Mean"), QT_TRANSLATE_NOOP("StatsTranslations", "Time-weighted mean"), - QT_TRANSLATE_NOOP("StatsTranslations", "Sum") + QT_TRANSLATE_NOOP("StatsTranslations", "Sum"), + QT_TRANSLATE_NOOP("StatsTranslations", "Minimum"), + QT_TRANSLATE_NOOP("StatsTranslations", "Maximum") }; QStringList StatsVariable::supportedOperationNames() const @@ -413,11 +415,17 @@ StatsOperationResults StatsVariable::applyOperations(const std::vector & if (res.count <= 0) return res; + res.min = std::numeric_limits::max(); + res.max = std::numeric_limits::lowest(); for (auto [v, d]: val) { res.sum += v; res.mean += v; sumTime += d->duration.seconds; res.timeWeightedMean += v * d->duration.seconds; + if (v < res.min) + res.min = v; + if (v > res.max) + res.max = v; } res.mean /= res.count; @@ -426,7 +434,7 @@ StatsOperationResults StatsVariable::applyOperations(const std::vector & } StatsOperationResults::StatsOperationResults() : - count(0), median(0.0), mean(0.0), timeWeightedMean(0.0), sum(0.0) + count(0), median(0.0), mean(0.0), timeWeightedMean(0.0), sum(0.0), min(0.0), max(0.0) { } @@ -442,6 +450,8 @@ double StatsOperationResults::get(StatsOperation op) const case StatsOperation::Mean: return mean; case StatsOperation::TimeWeightedMean: return timeWeightedMean; case StatsOperation::Sum: return sum; + case StatsOperation::Min: return min; + case StatsOperation::Max: return max; case StatsOperation::Invalid: default: return invalid_value(); } @@ -986,9 +996,6 @@ struct DepthVariableBase : public StatsVariableTemplate supportedOperations() const override { - return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::Sum }; - } }; struct MaxDepthVariable : public DepthVariableBase { @@ -998,7 +1005,7 @@ struct MaxDepthVariable : public DepthVariableBase { return StatsTranslations::tr("Max. Depth"); } std::vector supportedOperations() const override { - return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::Sum }; + return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::Sum, StatsOperation::Min, StatsOperation::Max }; } }; @@ -1010,7 +1017,7 @@ struct MeanDepthVariable : public DepthVariableBase { return StatsTranslations::tr("Mean Depth"); } std::vector supportedOperations() const override { - return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::TimeWeightedMean }; + return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::TimeWeightedMean, StatsOperation::Min, StatsOperation::Max }; } }; @@ -1068,7 +1075,7 @@ struct DurationVariable : public StatsVariableTemplateduration.seconds / 60.0; } std::vector supportedOperations() const override { - return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::Sum }; + return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::Sum, StatsOperation::Min, StatsOperation::Max }; } }; @@ -1159,7 +1166,7 @@ struct SACVariable : public StatsVariableTemplate ml_to_cuft(d->sac); } std::vector supportedOperations() const override { - return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::TimeWeightedMean }; + return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::TimeWeightedMean, StatsOperation::Min, StatsOperation::Max }; } }; @@ -1219,7 +1226,7 @@ struct TemperatureVariable : public StatsVariableTemplate supportedOperations() const override { - return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::TimeWeightedMean }; + return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::TimeWeightedMean, StatsOperation::Min, StatsOperation::Max }; } }; @@ -1298,7 +1305,7 @@ struct WeightVariable : public StatsVariableTemplate supportedOperations() const override { - return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::Sum }; + return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::Sum, StatsOperation::Min, StatsOperation::Max }; } }; @@ -1601,7 +1608,7 @@ struct GasContentVariable : public StatsVariableTemplate supportedOperations() const override { - return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::TimeWeightedMean }; + return { StatsOperation::Median, StatsOperation::Mean, StatsOperation::TimeWeightedMean, StatsOperation::Min, StatsOperation::Max }; } double toFloat(const dive *d) const override { int res = get_gas_content(d, he, max_he); diff --git a/stats/statsvariables.h b/stats/statsvariables.h index 06fb90f2a..964878550 100644 --- a/stats/statsvariables.h +++ b/stats/statsvariables.h @@ -26,6 +26,8 @@ enum class StatsOperation : int { Mean, TimeWeightedMean, Sum, + Min, + Max, Invalid }; @@ -36,6 +38,8 @@ struct StatsOperationResults { double mean; double timeWeightedMean; double sum; + double min; + double max; StatsOperationResults(); // Initialize to invalid (e.g. no dives) bool isValid() const; double get(StatsOperation op) const;