Files
GoldenCheetah/src/RideMetric.cpp
Mark Liversedge 2e248c3e26 Manual entries compute metrics
A few months ago I commented out the calculation of metrics
for manual ride files. This was a hack to avoid fixing the code
to handle metric calculations from overrides where there are no
data points.

This annoyingly meant that the 'rides' metric was zero for manual
ride files, and any derived metrics similarly were zero.

This patch fixes that.
2012-07-08 16:22:40 +01:00

70 lines
2.6 KiB
C++

/*
* Copyright (c) 2008 Sean C. Rhea (srhea@srhea.net)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "RideMetric.h"
#include "Zones.h"
#include "HrZones.h"
RideMetricFactory *RideMetricFactory::_instance;
QVector<QString> RideMetricFactory::noDeps;
QHash<QString,RideMetricPtr>
RideMetric::computeMetrics(const MainWindow *main, const RideFile *ride, const Zones *zones, const HrZones *hrZones,
const QStringList &metrics)
{
int zoneRange = zones->whichRange(ride->startTime().date());
int hrZoneRange = hrZones->whichRange(ride->startTime().date());
const RideMetricFactory &factory = RideMetricFactory::instance();
QStringList todo = metrics;
QHash<QString,RideMetric*> done;
while (!todo.isEmpty()) {
QString symbol = todo.takeFirst();
if (!factory.haveMetric(symbol)) continue;
const QVector<QString> &deps = factory.dependencies(symbol);
bool ready = true;
foreach (QString dep, deps) {
if (!done.contains(dep)) {
ready = false;
if (!todo.contains(dep))
todo.append(dep);
}
}
if (ready) {
RideMetric *m = factory.newMetric(symbol);
//if (!ride->dataPoints().isEmpty())
m->compute(ride, zones, zoneRange, hrZones, hrZoneRange, done, main);
if (ride->metricOverrides.contains(symbol))
m->override(ride->metricOverrides.value(symbol));
done.insert(symbol, m);
}
else {
if (!todo.contains(symbol))
todo.append(symbol);
}
}
QHash<QString,RideMetricPtr> result;
foreach (QString symbol, metrics) {
result.insert(symbol, QSharedPointer<RideMetric>(done.value(symbol)));
done.remove(symbol);
}
foreach (QString symbol, done.keys())
delete done.value(symbol);
return result;
}