mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 23:23:23 +00:00
statistics: add a dive-# variable
This was requested on the mailing list and it makes sense to have it. Of course, not all charts make sense: e.g. a plot dive-# vs. count is a bit redundant... Sadly, this can't use the generic IntRangeBinner, because dive-#s start at 1, not 0. Suggested-by: Christof Arnosti <charno@charno.ch> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
b00009ef4e
commit
83848fb2a8
1 changed files with 61 additions and 1 deletions
|
@ -1302,6 +1302,65 @@ struct WeightVariable : public StatsVariableTemplate<StatsVariable::Type::Numeri
|
|||
}
|
||||
};
|
||||
|
||||
// ============ Dive number ============
|
||||
|
||||
// Binning dive numbers can't use the IntRangeBinner,
|
||||
// because dive numbers start at 1, not 0! Since 0 means
|
||||
// "no number", these dives aren't registered.
|
||||
struct DiveNrBinner : public IntBinner<DiveNrBinner, IntBin> {
|
||||
int bin_size;
|
||||
DiveNrBinner(int bin_size) : bin_size(bin_size)
|
||||
{
|
||||
}
|
||||
QString format(const StatsBin &bin) const override {
|
||||
int value = derived_bin(bin).value;
|
||||
QLocale loc;
|
||||
return StatsTranslations::tr("%1–%2").arg(loc.toString(value * bin_size + 1),
|
||||
loc.toString((value + 1) * bin_size));
|
||||
}
|
||||
QString formatLowerBound(const StatsBin &bin) const override {
|
||||
int value = derived_bin(bin).value;
|
||||
return QStringLiteral("%L1").arg(value * bin_size + 1);
|
||||
}
|
||||
double lowerBoundToFloatBase(int value) const {
|
||||
return static_cast<double>(value * bin_size + 1);
|
||||
}
|
||||
QString name() const override {
|
||||
return StatsTranslations::tr("in %L2 steps").arg(bin_size);
|
||||
}
|
||||
int to_bin_value(const dive *d) const {
|
||||
if (d->number <= 0)
|
||||
return invalid_value<int>();
|
||||
return (d->number - 1) / bin_size;
|
||||
}
|
||||
};
|
||||
|
||||
static DiveNrBinner dive_nr_binner_5(5);
|
||||
static DiveNrBinner dive_nr_binner_10(10);
|
||||
static DiveNrBinner dive_nr_binner_20(20);
|
||||
static DiveNrBinner dive_nr_binner_50(50);
|
||||
static DiveNrBinner dive_nr_binner_100(100);
|
||||
static DiveNrBinner dive_nr_binner_200(200);
|
||||
|
||||
struct DiveNrVariable : public StatsVariableTemplate<StatsVariable::Type::Numeric> {
|
||||
QString name() const override {
|
||||
return StatsTranslations::tr("Dive #");
|
||||
}
|
||||
std::vector<const StatsBinner *> binners() const override {
|
||||
if (dive_table.nr > 1000)
|
||||
return { &dive_nr_binner_20, &dive_nr_binner_50, &dive_nr_binner_100, &dive_nr_binner_200 };
|
||||
else
|
||||
return { &dive_nr_binner_5, &dive_nr_binner_10, &dive_nr_binner_20, &dive_nr_binner_50 };
|
||||
}
|
||||
double toFloat(const dive *d) const override {
|
||||
return d->number >= 0 ? static_cast<double>(d->number)
|
||||
: invalid_value<double>();
|
||||
}
|
||||
std::vector<StatsOperation> supportedOperations() const override {
|
||||
return { StatsOperation::Median, StatsOperation::Mean };
|
||||
}
|
||||
};
|
||||
|
||||
// ============ Dive mode ============
|
||||
|
||||
struct DiveModeBinner : public SimpleBinner<DiveModeBinner, IntBin> {
|
||||
|
@ -1773,6 +1832,7 @@ static SACVariable sac_variable;
|
|||
static WaterTemperatureVariable water_temperature_variable;
|
||||
static AirTemperatureVariable air_temperature_variable;
|
||||
static WeightVariable weight_variable;
|
||||
static DiveNrVariable dive_nr_variable;
|
||||
static DiveModeVariable dive_mode_variable;
|
||||
static BuddyVariable buddy_variable;
|
||||
static GasTypeVariable gas_type_variable;
|
||||
|
@ -1789,7 +1849,7 @@ static VisibilityVariable visibility_variable;
|
|||
|
||||
const std::vector<const StatsVariable *> stats_variables = {
|
||||
&date_variable, &max_depth_variable, &mean_depth_variable, &duration_variable, &sac_variable,
|
||||
&water_temperature_variable, &air_temperature_variable, &weight_variable,
|
||||
&water_temperature_variable, &air_temperature_variable, &weight_variable, &dive_nr_variable,
|
||||
&gas_content_o2_variable, &gas_content_o2_he_max_variable, &gas_content_he_variable,
|
||||
&dive_mode_variable, &buddy_variable, &gas_type_variable, &suit_variable,
|
||||
&weightsystem_variable, &cylinder_type_variable, &location_variable, &day_of_week_variable,
|
||||
|
|
Loading…
Add table
Reference in a new issue