Skip to content

Commit

Permalink
Enable DataFilter zones to be used in Trends View
Browse files Browse the repository at this point in the history
Formula doesn't change.
When date range is set Trends View is assumed and we use the sport of included
activities with default to Bike (Run for Pace) when mixed, and date is the end
date for the date range.
Otherwise we use activity sport and date as before.
  • Loading branch information
amtriathlon committed Aug 4, 2021
1 parent 534a6a4 commit 15bbe28
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/Core/DataFilter.cpp
Expand Up @@ -3540,7 +3540,6 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, const Result &x, long it, R

// zone descriptions and high / lows, but not cp/cv, w'/d' et al
if (leaf->function == "zones") {

// parms
QString series = *leaf->fparms[0]->lvalue.n;
QString field = *leaf->fparms[1]->lvalue.n;
Expand All @@ -3555,10 +3554,24 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, const Result &x, long it, R
// so get the zones and ranges setup
// then loop through the zones in a single
// loop, so lets get the control variables here
QString sport;
QDate date;
const Zones *powerzones;
const HrZones *hrzones;
const PaceZones *pacezones;

// which sport and date?
if (d == DateRange()) {
// Actvities view: activity sport and date
sport = m->sport;
date = m->dateTime.date();
} else {
// Trends view: sport from included activities and range end date
int nActivities, nRides, nRuns, nSwims;
m->context->athlete->rideCache->getRideTypeCounts(s, nActivities, nRides, nRuns, nSwims, sport);
date = d.to;
}

// which range and how many zones are there
int range=-1, nzones = 0;

Expand All @@ -3572,33 +3585,33 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, const Result &x, long it, R
if (series == "power") {

// power zones are for Run or Bike, but not Swim
powerzones = m->context->athlete->zones(m->sport);
range= powerzones->whichRange(m->dateTime.date());
powerzones = m->context->athlete->zones(sport);
range= powerzones->whichRange(date);
if (range >= 0) nzones = powerzones->numZones(range);
metricprefix = "time_in_zone_L";

} else if (series == "hr") {

// hr zones are also for run or bike, but not Swim
hrzones = m->context->athlete->hrZones(m->sport);
range= hrzones->whichRange(m->dateTime.date());
hrzones = m->context->athlete->hrZones(sport);
range= hrzones->whichRange(date);
if (range >= 0) nzones = hrzones->numZones(range);
metricprefix = "time_in_zone_H";

} else if (series == "pace") {

// pace zones are for run or swim
pacezones = m->context->athlete->paceZones(m->sport == "Swim");
range= pacezones->whichRange(m->dateTime.date());
pacezones = m->context->athlete->paceZones(sport == "Swim");
range= pacezones->whichRange(date);
if (range >= 0) nzones = pacezones->numZones(range);
metricprefix = "time_in_zone_P";
metricpace = appsettings->value(nullptr, pacezones->paceSetting(), GlobalContext::context()->useMetricUnits).toBool();

} else if (series == "fatigue") {

int WPRIME = 0;
powerzones = m->context->athlete->zones(m->sport);
range = powerzones->whichRange(m->dateTime.date());
powerzones = m->context->athlete->zones(sport);
range = powerzones->whichRange(date);
if (range >= 0) WPRIME = powerzones->getWprime(range);
// easy for us, they are hardcoded
for (int i=0; i<WPrime::zoneCount(); i++) {
Expand Down Expand Up @@ -3626,16 +3639,20 @@ Result Leaf::eval(DataFilterRuntime *df, Leaf *leaf, const Result &x, long it, R
// time in zones and percent in zones use metrics
for(int n=0; n<nzones; n++) {
QString name = QString("%1%2").arg(metricprefix).arg(n+1);
strings << m->getStringForSymbol(name, GlobalContext::context()->useMetricUnits);
double value = (d==DateRange()) ? m->getForSymbol(name, true)
: m->context->athlete->rideCache->getAggregate(name, s, true, true).toDouble();
strings << time_to_string(value);
}

} else if (field == "percent") {

double duration = m->getForSymbol("workout_time", false);
double total = (d==DateRange()) ? m->getForSymbol("time_recording", true)
: m->context->athlete->rideCache->getAggregate("time_recording", s, true, true).toDouble();
for(int n=0; n<nzones; n++) {
QString name = QString("%1%2").arg(metricprefix).arg(n+1);
double value = m->getForSymbol(name, false);
double percent = round(value/duration * 100.0);
double value = (d==DateRange()) ? m->getForSymbol(name, true)
: m->context->athlete->rideCache->getAggregate(name, s, true, true).toDouble();
double percent = round(value/total * 100.0);
strings << QString("%1").arg(percent);
}

Expand Down

0 comments on commit 15bbe28

Please sign in to comment.