Skip to content
Permalink
Browse files

Added Time Recording and use it for Time in Zone Percentages

Fixes #2745 which requests this metric plus it allows to fix the issue with
Time in Zone Percentages which don't add to 100% nor aggregate properly
when there are gaps in recording, tipically due to pauses.
When there are no gaps Time Recording equals Duration and Time in Zone
Percentages don't change.
  • Loading branch information...
amtriathlon committed May 14, 2019
1 parent 3f4b7a6 commit 75146af6fece540af704785e41292627c9a4aa89
@@ -368,6 +368,7 @@ LTMPopup::setSummaryHTML(RideItem *item)
// main totals
const QStringList totalColumn = QStringList()
<< "workout_time"
<< "time_recording"
<< "time_riding"
<< (item->isSwim ? "distance_swim" : "total_distance")
<< "total_work"
@@ -473,6 +473,7 @@ RideSummaryWindow::htmlSummary()
static const QStringList columnNames = QStringList() << tr("Totals") << tr("Averages") << tr("Maximums") << tr("Metrics");
static const QStringList totalColumn = QStringList()
<< "workout_time"
<< "time_recording"
<< "time_riding"
<< "total_distance"
<< "ride_count"
@@ -1626,6 +1627,7 @@ RideSummaryWindow::htmlCompareSummary() const
static const QStringList columnNames = QStringList() << tr("Totals") << tr("Averages") << tr("Maximums") << tr("Metrics*");
static const QStringList totalColumn = QStringList()
<< "workout_time"
<< "time_recording"
<< "time_riding"
<< "total_distance"
<< "ride_count"
@@ -143,7 +143,7 @@ class WorkoutTime : public RideMetric {
setName(tr("Duration"));
setMetricUnits(tr("seconds"));
setImperialUnits(tr("seconds"));
setDescription(tr("Total Duration"));
setDescription(tr("Total Duration including pauses a.k.a. Elapsed Time"));
}

void compute(RideItem *item, Specification spec, const QHash<QString,RideMetric*> &) {
@@ -176,6 +176,54 @@ static bool workoutTimeAdded =

//////////////////////////////////////////////////////////////////////////////

class TimeRecording : public RideMetric {
Q_DECLARE_TR_FUNCTIONS(TimeRecording)
double secsRecording;

public:

TimeRecording() : secsRecording(0.0)
{
setSymbol("time_recording");
setInternalName("Time Recording");
}

bool isTime() const { return true; }

void initialize() {
setName(tr("Time Recording"));
setMetricUnits(tr("seconds"));
setImperialUnits(tr("seconds"));
setDescription(tr("Time when device was recording, excludes gaps in recording due to pauses or missing samples"));
}

void compute(RideItem *item, Specification spec, const QHash<QString,RideMetric*> &) {

// no ride or no samples
if (spec.isEmpty(item->ride())) {
setValue(RideFile::NIL);
setCount(0);
return;
}

secsRecording = 0;

// loop through and count
for (RideFileIterator it(item->ride(), spec); it.hasNext(); it.next())
secsRecording += item->ride()->recIntSecs();
setValue(secsRecording);
}

MetricClass classification() const { return Undefined; }
MetricValidity validity() const { return Unknown; }
RideMetric *clone() const { return new TimeRecording(*this); }
};

static bool timeRecordingAdded =
RideMetricFactory::instance().addMetric(TimeRecording());

//////////////////////////////////////////////////////////////////////////////

class TimeRiding : public RideMetric {
Q_DECLARE_TR_FUNCTIONS(TimeRiding)
double secsMovingOrPedaling;
@@ -327,10 +327,10 @@ class HrZonePTime1 : public RideMetric {
void compute(RideItem *, Specification, const QHash<QString,RideMetric*> &deps) {

assert(deps.contains("time_in_zone_H1"));
assert(deps.contains("workout_time"));
assert(deps.contains("time_recording"));

// compute
double time = deps.value("workout_time")->value(true);
double time = deps.value("time_recording")->value(true);
double inzone = deps.value("time_in_zone_H1")->value(true);

if (time && inzone) setValue((inzone / time) * 100.00);
@@ -371,10 +371,10 @@ class HrZonePTime2 : public RideMetric {
void compute(RideItem *, Specification, const QHash<QString,RideMetric*> &deps) {

assert(deps.contains("time_in_zone_H2"));
assert(deps.contains("workout_time"));
assert(deps.contains("time_recording"));

// compute
double time = deps.value("workout_time")->value(true);
double time = deps.value("time_recording")->value(true);
double inzone = deps.value("time_in_zone_H2")->value(true);

if (time && inzone) setValue((inzone / time) * 100.00);
@@ -415,10 +415,10 @@ class HrZonePTime3 : public RideMetric {
void compute(RideItem *, Specification, const QHash<QString,RideMetric*> &deps) {

assert(deps.contains("time_in_zone_H3"));
assert(deps.contains("workout_time"));
assert(deps.contains("time_recording"));

// compute
double time = deps.value("workout_time")->value(true);
double time = deps.value("time_recording")->value(true);
double inzone = deps.value("time_in_zone_H3")->value(true);

if (time && inzone) setValue((inzone / time) * 100.00);
@@ -459,10 +459,10 @@ class HrZonePTime4 : public RideMetric {
void compute(RideItem *, Specification, const QHash<QString,RideMetric*> &deps) {

assert(deps.contains("time_in_zone_H4"));
assert(deps.contains("workout_time"));
assert(deps.contains("time_recording"));

// compute
double time = deps.value("workout_time")->value(true);
double time = deps.value("time_recording")->value(true);
double inzone = deps.value("time_in_zone_H4")->value(true);

if (time && inzone) setValue((inzone / time) * 100.00);
@@ -503,10 +503,10 @@ class HrZonePTime5 : public RideMetric {
void compute(RideItem *, Specification, const QHash<QString,RideMetric*> &deps) {

assert(deps.contains("time_in_zone_H5"));
assert(deps.contains("workout_time"));
assert(deps.contains("time_recording"));

// compute
double time = deps.value("workout_time")->value(true);
double time = deps.value("time_recording")->value(true);
double inzone = deps.value("time_in_zone_H5")->value(true);

if (time && inzone) setValue((inzone / time) * 100.00);
@@ -547,10 +547,10 @@ class HrZonePTime6 : public RideMetric {
void compute(RideItem *, Specification, const QHash<QString,RideMetric*> &deps) {

assert(deps.contains("time_in_zone_H6"));
assert(deps.contains("workout_time"));
assert(deps.contains("time_recording"));

// compute
double time = deps.value("workout_time")->value(true);
double time = deps.value("time_recording")->value(true);
double inzone = deps.value("time_in_zone_H6")->value(true);

if (time && inzone) setValue((inzone / time) * 100.00);
@@ -591,10 +591,10 @@ class HrZonePTime7 : public RideMetric {
void compute(RideItem *, Specification, const QHash<QString,RideMetric*> &deps) {

assert(deps.contains("time_in_zone_H7"));
assert(deps.contains("workout_time"));
assert(deps.contains("time_recording"));

// compute
double time = deps.value("workout_time")->value(true);
double time = deps.value("time_recording")->value(true);
double inzone = deps.value("time_in_zone_H7")->value(true);

if (time && inzone) setValue((inzone / time) * 100.00);
@@ -635,10 +635,10 @@ class HrZonePTime8 : public RideMetric {
void compute(RideItem *, Specification, const QHash<QString,RideMetric*> &deps) {

assert(deps.contains("time_in_zone_H8"));
assert(deps.contains("workout_time"));
assert(deps.contains("time_recording"));

// compute
double time = deps.value("workout_time")->value(true);
double time = deps.value("time_recording")->value(true);
double inzone = deps.value("time_in_zone_H8")->value(true);

if (time && inzone) setValue((inzone / time) * 100.00);
@@ -678,10 +678,10 @@ class HrZonePTime9 : public RideMetric {
void compute(RideItem *, Specification, const QHash<QString,RideMetric*> &deps) {

assert(deps.contains("time_in_zone_H9"));
assert(deps.contains("workout_time"));
assert(deps.contains("time_recording"));

// compute
double time = deps.value("workout_time")->value(true);
double time = deps.value("time_recording")->value(true);
double inzone = deps.value("time_in_zone_H9")->value(true);

if (time && inzone) setValue((inzone / time) * 100.00);
@@ -721,10 +721,10 @@ class HrZonePTime10 : public RideMetric {
void compute(RideItem *, Specification, const QHash<QString,RideMetric*> &deps) {

assert(deps.contains("time_in_zone_H10"));
assert(deps.contains("workout_time"));
assert(deps.contains("time_recording"));

// compute
double time = deps.value("workout_time")->value(true);
double time = deps.value("time_recording")->value(true);
double inzone = deps.value("time_in_zone_H10")->value(true);

if (time && inzone) setValue((inzone / time) * 100.00);
@@ -751,43 +751,43 @@ static bool addAllHrZones() {
RideMetricFactory::instance().addMetric(HrZoneTime10());
QVector<QString> deps;
deps.append("time_in_zone_H1");
deps.append("workout_time");
deps.append("time_recording");
RideMetricFactory::instance().addMetric(HrZonePTime1(), &deps);
deps.clear();
deps.append("time_in_zone_H2");
deps.append("workout_time");
deps.append("time_recording");
RideMetricFactory::instance().addMetric(HrZonePTime2(), &deps);
deps.clear();
deps.append("time_in_zone_H3");
deps.append("workout_time");
deps.append("time_recording");
RideMetricFactory::instance().addMetric(HrZonePTime3(), &deps);
deps.clear();
deps.append("time_in_zone_H4");
deps.append("workout_time");
deps.append("time_recording");
RideMetricFactory::instance().addMetric(HrZonePTime4(), &deps);
deps.clear();
deps.append("time_in_zone_H5");
deps.append("workout_time");
deps.append("time_recording");
RideMetricFactory::instance().addMetric(HrZonePTime5(), &deps);
deps.clear();
deps.append("time_in_zone_H6");
deps.append("workout_time");
deps.append("time_recording");
RideMetricFactory::instance().addMetric(HrZonePTime6(), &deps);
deps.clear();
deps.append("time_in_zone_H7");
deps.append("workout_time");
deps.append("time_recording");
RideMetricFactory::instance().addMetric(HrZonePTime7(), &deps);
deps.clear();
deps.append("time_in_zone_H8");
deps.append("workout_time");
deps.append("time_recording");
RideMetricFactory::instance().addMetric(HrZonePTime8(), &deps);
deps.clear();
deps.append("time_in_zone_H9");
deps.append("workout_time");
deps.append("time_recording");
RideMetricFactory::instance().addMetric(HrZonePTime9(), &deps);
deps.clear();
deps.append("time_in_zone_H10");
deps.append("workout_time");
deps.append("time_recording");
RideMetricFactory::instance().addMetric(HrZonePTime10(), &deps);
return true;
}
Oops, something went wrong.

0 comments on commit 75146af

Please sign in to comment.
You can’t perform that action at this time.