Files
GoldenCheetah/src/LTMOutliers.cpp
Mark Liversedge cd3bbc4e64 Ride editor and tools
A new tab 'Editor' for manually editing ride file data points and
associated menu options under 'Tools' for fixing spikes, gaps, GPS
errors and adjusting torque values. A revert to saved ride option
is also included to 'undo' all changes.

The ride editor supports undo/redo as well as cut and paste and
"paste special" (to append points or swap columns/overwrite
selected data series). The editor also supports search and will
automatically highlight anomalous data.

When a file is saved, the changes are recorded in a new metadata
special field called "Change History" which can be added as a
Textbox in the metadata config.

The data processors can be run manually or automatically when a
ride is opened - these are configured on the ride data tab in
the config pane.

Significant changes have been introduced in the codebase, the most
significant of which are; a RideFileCommand class for modifying
ride data has been introduced (as a member of RideFile) and the
RideItem class is now a QObject as well as QTreeWidgetItem to
enable signalling. The Ride Editor uses a RideFileTableModel that
can be re-used in other parts of the code. LTMoutliers class has been
introduced in support of anomaly detection in the editor (which
highlights anomalies with a wiggly red line).

Fixes #103.
2010-07-17 14:33:39 +01:00

94 lines
2.9 KiB
C++

/*
* Copyright (c) 2010 Mark Liversedge (liversedge@gmail.com)
*
* 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 <math.h>
#include <float.h>
#include <assert.h>
#include "LTMOutliers.h"
#include <QDebug>
LTMOutliers::LTMOutliers(double *xdata, double *ydata, int count, int windowsize, bool absolute) : stdDeviation(0.0)
{
double sum = 0;
int points = 0;
double allSum = 0.0;
int pos=0;
assert(count >= windowsize);
// initial samples from point 0 to windowsize
for (; pos < windowsize; ++pos) {
// we could either use a deviation of zero
// or base it on what we have so far...
// I chose to use sofar since spikes
// are common at the start of a ride
xdev add;
add.x = xdata[pos];
add.y = ydata[pos];
add.pos = pos;
if (absolute) add.deviation = fabs(ydata[pos] - (sum/windowsize));
else add.deviation = ydata[pos] - (sum/windowsize);
rank.append(add);
// when using -ve and +ve values stdDeviation is
// based upon the absolute value of deviation
// when not, we should only look at +ve values
if ((!absolute && add.deviation > 0) || absolute) {
allSum += add.deviation;
points++;
}
sum += ydata[pos]; // initialise the moving average
}
// bulk of samples from windowsize to the end
for (; pos<count; pos++) {
// ranked list
xdev add;
add.x = xdata[pos];
add.y = ydata[pos];
add.pos = pos;
if (absolute) add.deviation = fabs(ydata[pos] - (sum/windowsize));
else add.deviation = ydata[pos] - (sum/windowsize);
rank.append(add);
// calculate the sum for moving average
sum += ydata[pos] - ydata[pos-windowsize];
// when using -ve and +ve values stdDeviation is
// based upon the absolute value of deviation
// when not, we should only look at +ve values
if ((!absolute && add.deviation > 0) || absolute) {
allSum += add.deviation;
points++;
}
}
// and to the list of deviations
// calculate the average deviation across all points
stdDeviation = allSum / (double)points;
// create a ranked list
qSort(rank);
}