mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Removed RawFile and replaced it with RideFile. I can't remember how we ended
up with both, but they're basically the same class.
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
|
||||
#include <time.h>
|
||||
#include "AllPlot.h"
|
||||
#include "RawFile.h"
|
||||
#include "RideFile.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -213,7 +213,7 @@ AllPlot::setYMax()
|
||||
}
|
||||
|
||||
void
|
||||
AllPlot::setData(RawFile *raw)
|
||||
AllPlot::setData(RideFile *ride)
|
||||
{
|
||||
delete [] wattsArray;
|
||||
delete [] hrArray;
|
||||
@@ -222,21 +222,21 @@ AllPlot::setData(RawFile *raw)
|
||||
delete [] timeArray;
|
||||
delete [] interArray;
|
||||
|
||||
setTitle(raw->startTime.toString(GC_DATETIME_FORMAT));
|
||||
wattsArray = new double[raw->points.size()];
|
||||
hrArray = new double[raw->points.size()];
|
||||
speedArray = new double[raw->points.size()];
|
||||
cadArray = new double[raw->points.size()];
|
||||
timeArray = new double[raw->points.size()];
|
||||
interArray = new int[raw->points.size()];
|
||||
setTitle(ride->startTime().toString(GC_DATETIME_FORMAT));
|
||||
wattsArray = new double[ride->dataPoints().size()];
|
||||
hrArray = new double[ride->dataPoints().size()];
|
||||
speedArray = new double[ride->dataPoints().size()];
|
||||
cadArray = new double[ride->dataPoints().size()];
|
||||
timeArray = new double[ride->dataPoints().size()];
|
||||
interArray = new int[ride->dataPoints().size()];
|
||||
arrayLength = 0;
|
||||
QListIterator<RawFilePoint*> i(raw->points);
|
||||
QListIterator<RideFilePoint*> i(ride->dataPoints());
|
||||
while (i.hasNext()) {
|
||||
RawFilePoint *point = i.next();
|
||||
RideFilePoint *point = i.next();
|
||||
timeArray[arrayLength] = point->secs;
|
||||
wattsArray[arrayLength] = max(0, point->watts);
|
||||
hrArray[arrayLength] = max(0, point->hr);
|
||||
speedArray[arrayLength] = max(0, point->mph);
|
||||
speedArray[arrayLength] = max(0, point->kph * 0.62137119);
|
||||
cadArray[arrayLength] = max(0, point->cad);
|
||||
interArray[arrayLength] = point->interval;
|
||||
++arrayLength;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
class QwtPlotCurve;
|
||||
class QwtPlotGrid;
|
||||
class QwtPlotMarker;
|
||||
class RawFile;
|
||||
class RideFile;
|
||||
|
||||
class AllPlot : public QwtPlot
|
||||
{
|
||||
@@ -44,7 +44,7 @@ class AllPlot : public QwtPlot
|
||||
|
||||
int smoothing() const { return smooth; }
|
||||
|
||||
void setData(RawFile *raw);
|
||||
void setData(RideFile *ride);
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ class WorkoutTime : public RideMetric {
|
||||
QString name() const { return "workout_time"; }
|
||||
QString units(bool) const { return "seconds"; }
|
||||
double value(bool) const { return seconds; }
|
||||
void compute(const RawFile *raw, const Zones *, int,
|
||||
void compute(const RideFile *ride, const Zones *, int,
|
||||
const QHash<QString,RideMetric*> &) {
|
||||
seconds = raw->points.back()->secs;
|
||||
seconds = ride->dataPoints().back()->secs;
|
||||
}
|
||||
bool canAggregate() const { return true; }
|
||||
void aggregateWith(RideMetric *other) { seconds += other->value(true); }
|
||||
@@ -35,9 +35,9 @@ class TimeRiding : public PointwiseRideMetric {
|
||||
QString name() const { return "time_riding"; }
|
||||
QString units(bool) const { return "seconds"; }
|
||||
double value(bool) const { return secsMovingOrPedaling; }
|
||||
void perPoint(const RawFilePoint *point, double secsDelta,
|
||||
const RawFile *, const Zones *, int) {
|
||||
if ((point->mph > 0.0) || (point->cad > 0.0))
|
||||
void perPoint(const RideFilePoint *point, double secsDelta,
|
||||
const RideFile *, const Zones *, int) {
|
||||
if ((point->kph > 0.0) || (point->cad > 0.0))
|
||||
secsMovingOrPedaling += secsDelta;
|
||||
}
|
||||
bool canAggregate() const { return true; }
|
||||
@@ -53,22 +53,22 @@ static bool timeRidingAdded =
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TotalDistance : public RideMetric {
|
||||
double miles;
|
||||
double km;
|
||||
|
||||
public:
|
||||
|
||||
TotalDistance() : miles(0.0) {}
|
||||
TotalDistance() : km(0.0) {}
|
||||
QString name() const { return "total_distance"; }
|
||||
QString units(bool metric) const { return metric ? "km" : "miles"; }
|
||||
double value(bool metric) const {
|
||||
return metric ? (miles / MILES_PER_KM) : miles;
|
||||
return metric ? km : (km * MILES_PER_KM);
|
||||
}
|
||||
void compute(const RawFile *raw, const Zones *, int,
|
||||
void compute(const RideFile *ride, const Zones *, int,
|
||||
const QHash<QString,RideMetric*> &) {
|
||||
miles = raw->points.back()->miles;
|
||||
km = ride->dataPoints().back()->km;
|
||||
}
|
||||
bool canAggregate() const { return true; }
|
||||
void aggregateWith(RideMetric *other) { miles += other->value(false); }
|
||||
void aggregateWith(RideMetric *other) { km += other->value(false); }
|
||||
RideMetric *clone() const { return new TotalDistance(*this); }
|
||||
};
|
||||
|
||||
@@ -86,8 +86,8 @@ class TotalWork : public PointwiseRideMetric {
|
||||
QString name() const { return "total_work"; }
|
||||
QString units(bool) const { return "kJ"; }
|
||||
double value(bool) const { return joules / 1000.0; }
|
||||
void perPoint(const RawFilePoint *point, double secsDelta,
|
||||
const RawFile *, const Zones *, int) {
|
||||
void perPoint(const RideFilePoint *point, double secsDelta,
|
||||
const RideFile *, const Zones *, int) {
|
||||
if (point->watts >= 0.0)
|
||||
joules += point->watts * secsDelta;
|
||||
}
|
||||
@@ -107,33 +107,33 @@ static bool totalWorkAdded =
|
||||
|
||||
class AvgSpeed : public PointwiseRideMetric {
|
||||
double secsMoving;
|
||||
double miles;
|
||||
double km;
|
||||
|
||||
public:
|
||||
|
||||
AvgSpeed() : secsMoving(0.0), miles(0.0) {}
|
||||
AvgSpeed() : secsMoving(0.0), km(0.0) {}
|
||||
QString name() const { return "average_speed"; }
|
||||
QString units(bool metric) const { return metric ? "kph" : "mph"; }
|
||||
double value(bool metric) const {
|
||||
if (secsMoving == 0.0) return 0.0;
|
||||
double mph = miles / secsMoving * 3600.0;
|
||||
return metric ? (mph / MILES_PER_KM) : mph;
|
||||
double kph = km / secsMoving * 3600.0;
|
||||
return metric ? kph : (kph * MILES_PER_KM);
|
||||
}
|
||||
void compute(const RawFile *raw, const Zones *zones, int zoneRange,
|
||||
void compute(const RideFile *ride, const Zones *zones, int zoneRange,
|
||||
const QHash<QString,RideMetric*> &deps) {
|
||||
PointwiseRideMetric::compute(raw, zones, zoneRange, deps);
|
||||
miles = raw->points.back()->miles;
|
||||
PointwiseRideMetric::compute(ride, zones, zoneRange, deps);
|
||||
km = ride->dataPoints().back()->km;
|
||||
}
|
||||
void perPoint(const RawFilePoint *point, double secsDelta,
|
||||
const RawFile *, const Zones *, int) {
|
||||
if (point->mph > 0.0) secsMoving += secsDelta;
|
||||
void perPoint(const RideFilePoint *point, double secsDelta,
|
||||
const RideFile *, const Zones *, int) {
|
||||
if (point->kph > 0.0) secsMoving += secsDelta;
|
||||
}
|
||||
bool canAggregate() const { return true; }
|
||||
void aggregateWith(RideMetric *other) {
|
||||
assert(name() == other->name());
|
||||
AvgSpeed *as = dynamic_cast<AvgSpeed*>(other);
|
||||
secsMoving += as->secsMoving;
|
||||
miles += as->miles;
|
||||
km += as->km;
|
||||
}
|
||||
RideMetric *clone() const { return new AvgSpeed(*this); }
|
||||
};
|
||||
@@ -147,8 +147,8 @@ struct AvgPower : public AvgRideMetric {
|
||||
|
||||
QString name() const { return "average_power"; }
|
||||
QString units(bool) const { return "watts"; }
|
||||
void perPoint(const RawFilePoint *point, double,
|
||||
const RawFile *, const Zones *, int) {
|
||||
void perPoint(const RideFilePoint *point, double,
|
||||
const RideFile *, const Zones *, int) {
|
||||
if (point->watts >= 0.0) {
|
||||
total += point->watts;
|
||||
++count;
|
||||
@@ -166,8 +166,8 @@ struct AvgHeartRate : public AvgRideMetric {
|
||||
|
||||
QString name() const { return "average_hr"; }
|
||||
QString units(bool) const { return "bpm"; }
|
||||
void perPoint(const RawFilePoint *point, double,
|
||||
const RawFile *, const Zones *, int) {
|
||||
void perPoint(const RideFilePoint *point, double,
|
||||
const RideFile *, const Zones *, int) {
|
||||
if (point->hr > 0) {
|
||||
total += point->hr;
|
||||
++count;
|
||||
@@ -185,8 +185,8 @@ struct AvgCadence : public AvgRideMetric {
|
||||
|
||||
QString name() const { return "average_cad"; }
|
||||
QString units(bool) const { return "bpm"; }
|
||||
void perPoint(const RawFilePoint *point, double,
|
||||
const RawFile *, const Zones *, int) {
|
||||
void perPoint(const RideFilePoint *point, double,
|
||||
const RideFile *, const Zones *, int) {
|
||||
if (point->cad > 0) {
|
||||
total += point->cad;
|
||||
++count;
|
||||
|
||||
@@ -25,13 +25,13 @@ class XPower : public RideMetric {
|
||||
QString name() const { return "skiba_xpower"; }
|
||||
QString units(bool) const { return "watts"; }
|
||||
double value(bool) const { return xpower; }
|
||||
void compute(const RawFile *raw, const Zones *, int,
|
||||
void compute(const RideFile *ride, const Zones *, int,
|
||||
const QHash<QString,RideMetric*> &) {
|
||||
|
||||
static const double EPSILON = 0.1;
|
||||
static const double NEGLIGIBLE = 0.1;
|
||||
|
||||
double secsDelta = raw->rec_int_ms / 1000.0;
|
||||
double secsDelta = ride->recIntSecs();
|
||||
double sampsPerWindow = 25.0 / secsDelta;
|
||||
double attenuation = sampsPerWindow / (sampsPerWindow + secsDelta);
|
||||
double sampleWeight = secsDelta / (sampsPerWindow + secsDelta);
|
||||
@@ -42,9 +42,9 @@ class XPower : public RideMetric {
|
||||
double total = 0.0;
|
||||
int count = 0;
|
||||
|
||||
QListIterator<RawFilePoint*> i(raw->points);
|
||||
QListIterator<RideFilePoint*> i(ride->dataPoints());
|
||||
while (i.hasNext()) {
|
||||
const RawFilePoint *point = i.next();
|
||||
const RideFilePoint *point = i.next();
|
||||
while ((weighted > NEGLIGIBLE)
|
||||
&& (point->secs > lastSecs + secsDelta + EPSILON)) {
|
||||
weighted *= attenuation;
|
||||
@@ -72,7 +72,7 @@ class RelativeIntensity : public RideMetric {
|
||||
QString name() const { return "skiba_relative_intensity"; }
|
||||
QString units(bool) const { return ""; }
|
||||
double value(bool) const { return reli; }
|
||||
void compute(const RawFile *, const Zones *zones, int zoneRange,
|
||||
void compute(const RideFile *, const Zones *zones, int zoneRange,
|
||||
const QHash<QString,RideMetric*> &deps) {
|
||||
if (zones) {
|
||||
assert(deps.contains("skiba_xpower"));
|
||||
@@ -94,7 +94,7 @@ class BikeScore : public RideMetric {
|
||||
QString name() const { return "skiba_bike_score"; }
|
||||
QString units(bool) const { return ""; }
|
||||
double value(bool) const { return score; }
|
||||
void compute(const RawFile *, const Zones *zones, int zoneRange,
|
||||
void compute(const RideFile *, const Zones *zones, int zoneRange,
|
||||
const QHash<QString,RideMetric*> &deps) {
|
||||
if (!zones)
|
||||
return;
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "CpintPlot.h"
|
||||
#include "DownloadRideDialog.h"
|
||||
#include "PowerHist.h"
|
||||
#include "RawFile.h"
|
||||
#include "RideItem.h"
|
||||
#include "RideFile.h"
|
||||
#include "RideMetric.h"
|
||||
@@ -46,6 +45,7 @@
|
||||
|
||||
#define FOLDER_TYPE 0
|
||||
#define RIDE_TYPE 1
|
||||
#define MILES_PER_KM 0.62137119
|
||||
|
||||
static char *rideFileRegExp = ("^(\\d\\d\\d\\d)_(\\d\\d)_(\\d\\d)"
|
||||
"_(\\d\\d)_(\\d\\d)_(\\d\\d)\\.(raw|srm|csv)$");
|
||||
@@ -446,28 +446,28 @@ MainWindow::exportCSV()
|
||||
QTextStream out(&file);
|
||||
if (units=="English"){
|
||||
out << "Minutes,Torq (N-m),MPH,Watts,Miles,Cadence,Hrate,ID\n";
|
||||
convertUnit = 1.0;
|
||||
convertUnit = MILES_PER_KM;
|
||||
}
|
||||
else {
|
||||
out << "Minutes,Torq (N-m),Km/h,Watts,Km,Cadence,Hrate,ID\n";
|
||||
// TODO: use KM_TO_MI from lib/pt.c instead?
|
||||
convertUnit = 1.60934;
|
||||
convertUnit = 1.0;
|
||||
}
|
||||
|
||||
QListIterator<RawFilePoint*> i(ride->raw->points);
|
||||
QListIterator<RideFilePoint*> i(ride->ride->dataPoints());
|
||||
while (i.hasNext()) {
|
||||
RawFilePoint *point = i.next();
|
||||
RideFilePoint *point = i.next();
|
||||
if (point->secs == 0.0)
|
||||
continue;
|
||||
out << point->secs/60.0;
|
||||
out << ",";
|
||||
out << ((point->nm >= 0) ? point->nm : 0.0);
|
||||
out << ",";
|
||||
out << ((point->mph >= 0) ? (point->mph * convertUnit) : 0.0);
|
||||
out << ((point->kph >= 0) ? (point->kph * convertUnit) : 0.0);
|
||||
out << ",";
|
||||
out << ((point->watts >= 0) ? point->watts : 0.0);
|
||||
out << ",";
|
||||
out << point->miles * convertUnit;
|
||||
out << point->km * convertUnit;
|
||||
out << ",";
|
||||
out << point->cad;
|
||||
out << ",";
|
||||
@@ -490,37 +490,36 @@ void MainWindow::importCSV()
|
||||
|
||||
QFile file ( dpd->fileName );
|
||||
QStringList errors;
|
||||
RawFile *raw = RawFile::readFile ( file, errors );
|
||||
RideFile *ride =
|
||||
CombinedFileReader::instance().openRideFile(file, errors);
|
||||
|
||||
raw->startTime = dpd->date;
|
||||
|
||||
if ( !raw || !errors.empty() )
|
||||
if (!ride || !errors.empty())
|
||||
{
|
||||
QString all =
|
||||
( raw
|
||||
( ride
|
||||
? tr ( "Non-fatal problem(s) opening %1:" )
|
||||
: tr ( "Fatal problem(s) opening %1:" ) ).arg ( dpd->fileName );
|
||||
QStringListIterator i ( errors );
|
||||
while ( i.hasNext() )
|
||||
all += "\n" + i.next();
|
||||
if ( raw )
|
||||
if (ride)
|
||||
QMessageBox::warning ( this, tr ( "Open Warning" ), all );
|
||||
else
|
||||
{
|
||||
else {
|
||||
QMessageBox::critical ( this, tr ( "Open Error" ), all );
|
||||
return;
|
||||
}
|
||||
}
|
||||
ride->setStartTime(dpd->date);
|
||||
|
||||
QChar zero = QLatin1Char ( '0' );
|
||||
|
||||
QString name = QString ( "%1_%2_%3_%4_%5_%6.csv" )
|
||||
.arg ( raw->startTime.date().year(), 4, 10, zero )
|
||||
.arg ( raw->startTime.date().month(), 2, 10, zero )
|
||||
.arg ( raw->startTime.date().day(), 2, 10, zero )
|
||||
.arg ( raw->startTime.time().hour(), 2, 10, zero )
|
||||
.arg ( raw->startTime.time().minute(), 2, 10, zero )
|
||||
.arg ( raw->startTime.time().second(), 2, 10, zero );
|
||||
.arg ( ride->startTime().date().year(), 4, 10, zero )
|
||||
.arg ( ride->startTime().date().month(), 2, 10, zero )
|
||||
.arg ( ride->startTime().date().day(), 2, 10, zero )
|
||||
.arg ( ride->startTime().time().hour(), 2, 10, zero )
|
||||
.arg ( ride->startTime().time().minute(), 2, 10, zero )
|
||||
.arg ( ride->startTime().time().second(), 2, 10, zero );
|
||||
|
||||
if ( !file.copy ( home.absolutePath() + "/" + name ) )
|
||||
{
|
||||
@@ -530,7 +529,7 @@ void MainWindow::importCSV()
|
||||
return;
|
||||
}
|
||||
|
||||
delete raw;
|
||||
delete ride;
|
||||
delete dpd;
|
||||
addRide ( name );
|
||||
}
|
||||
@@ -546,15 +545,16 @@ MainWindow::importSRM()
|
||||
QString fileName = i.next();
|
||||
QFile file(fileName);
|
||||
QStringList errors;
|
||||
RawFile *raw = RawFile::readFile(file, errors);
|
||||
if (!raw || !errors.empty()) {
|
||||
QString all = (raw
|
||||
RideFile *ride =
|
||||
CombinedFileReader::instance().openRideFile(file, errors);
|
||||
if (!ride || !errors.empty()) {
|
||||
QString all = (ride
|
||||
? tr("Non-fatal problem(s) opening %1:")
|
||||
: tr("Fatal problem(s) opening %1:")).arg(fileName);
|
||||
QStringListIterator i(errors);
|
||||
while (i.hasNext())
|
||||
all += "\n" + i.next();
|
||||
if (raw)
|
||||
if (ride)
|
||||
QMessageBox::warning(this, tr("Open Warning"), all);
|
||||
else {
|
||||
QMessageBox::critical(this, tr("Open Error"), all);
|
||||
@@ -564,12 +564,12 @@ MainWindow::importSRM()
|
||||
|
||||
QChar zero = QLatin1Char('0');
|
||||
QString name = QString("%1_%2_%3_%4_%5_%6.srm")
|
||||
.arg(raw->startTime.date().year(), 4, 10, zero)
|
||||
.arg(raw->startTime.date().month(), 2, 10, zero)
|
||||
.arg(raw->startTime.date().day(), 2, 10, zero)
|
||||
.arg(raw->startTime.time().hour(), 2, 10, zero)
|
||||
.arg(raw->startTime.time().minute(), 2, 10, zero)
|
||||
.arg(raw->startTime.time().second(), 2, 10, zero);
|
||||
.arg(ride->startTime().date().year(), 4, 10, zero)
|
||||
.arg(ride->startTime().date().month(), 2, 10, zero)
|
||||
.arg(ride->startTime().date().day(), 2, 10, zero)
|
||||
.arg(ride->startTime().time().hour(), 2, 10, zero)
|
||||
.arg(ride->startTime().time().minute(), 2, 10, zero)
|
||||
.arg(ride->startTime().time().second(), 2, 10, zero);
|
||||
|
||||
if (!file.copy(home.absolutePath() + "/" + name)) {
|
||||
QMessageBox::critical(this, tr("Copy Error"),
|
||||
@@ -577,7 +577,7 @@ MainWindow::importSRM()
|
||||
return;
|
||||
}
|
||||
|
||||
delete raw;
|
||||
delete ride;
|
||||
addRide(name);
|
||||
}
|
||||
}
|
||||
@@ -592,12 +592,12 @@ MainWindow::rideSelected()
|
||||
RideItem *ride = (RideItem*) which;
|
||||
rideSummary->setHtml(ride->htmlSummary());
|
||||
rideSummary->setAlignment(Qt::AlignCenter);
|
||||
if (ride->raw)
|
||||
allPlot->setData(ride->raw);
|
||||
if (ride->ride)
|
||||
allPlot->setData(ride->ride);
|
||||
if (tabWidget->currentIndex() == 2)
|
||||
cpintPlot->calculate(ride->fileName, ride->dateTime);
|
||||
if (ride->raw)
|
||||
powerHist->setData(ride->raw);
|
||||
if (ride->ride)
|
||||
powerHist->setData(ride->ride);
|
||||
|
||||
QDate wstart = ride->dateTime.date();
|
||||
wstart = wstart.addDays(Qt::Monday - wstart.dayOfWeek());
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "PowerHist.h"
|
||||
#include "RawFile.h"
|
||||
#include "RideFile.h"
|
||||
#include "Settings.h"
|
||||
|
||||
#include <assert.h>
|
||||
@@ -84,17 +84,26 @@ PowerHist::setYMax()
|
||||
}
|
||||
|
||||
void
|
||||
PowerHist::setData(RawFile *raw)
|
||||
PowerHist::setData(RideFile *ride)
|
||||
{
|
||||
setTitle(raw->startTime.toString(GC_DATETIME_FORMAT));
|
||||
assert(raw->powerHist.keys().first() >= 0);
|
||||
int maxPower = (int) round(raw->powerHist.keys().last());
|
||||
setTitle(ride->startTime().toString(GC_DATETIME_FORMAT));
|
||||
QMap<double,double> powerHist;
|
||||
QListIterator<RideFilePoint*> j(ride->dataPoints());
|
||||
while (j.hasNext()) {
|
||||
const RideFilePoint *p1 = j.next();
|
||||
if (powerHist.contains(p1->watts))
|
||||
powerHist[p1->watts] += ride->recIntSecs();
|
||||
else
|
||||
powerHist[p1->watts] = ride->recIntSecs();
|
||||
}
|
||||
assert(powerHist.keys().first() >= 0);
|
||||
int maxPower = (int) round(powerHist.keys().last());
|
||||
delete [] array;
|
||||
arrayLength = maxPower + 1;
|
||||
array = new double[arrayLength];
|
||||
for (int i = 0; i < arrayLength; ++i)
|
||||
array[i] = 0.0;
|
||||
QMapIterator<double,double> i(raw->powerHist);
|
||||
QMapIterator<double,double> i(powerHist);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
array[(int) round(i.key())] += i.value();
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
class QwtPlotCurve;
|
||||
class QwtPlotGrid;
|
||||
class RawFile;
|
||||
class RideFile;
|
||||
|
||||
class PowerHist : public QwtPlot
|
||||
{
|
||||
@@ -39,7 +39,7 @@ class PowerHist : public QwtPlot
|
||||
|
||||
int binWidth() const { return binw; }
|
||||
|
||||
void setData(RawFile *raw);
|
||||
void setData(RideFile *ride);
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* $Id: RawFile.cpp,v 1.2 2006/08/11 19:58:07 srhea Exp $
|
||||
*
|
||||
* Copyright (c) 2006 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 "RawFile.h"
|
||||
#include "RideFile.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#define KM_TO_MILES 0.62137119
|
||||
|
||||
RawFile *RawFile::readFile(QFile &file, QStringList &errors)
|
||||
{
|
||||
RideFile *rideFile =
|
||||
CombinedFileReader::instance().openRideFile(file, errors);
|
||||
if (!rideFile)
|
||||
return NULL;
|
||||
RawFile *result = new RawFile(file.fileName());
|
||||
result->startTime = rideFile->startTime();
|
||||
result->rec_int_ms = (unsigned) round(rideFile->recIntSecs() * 1000.0);
|
||||
QListIterator<RideFilePoint*> i(rideFile->dataPoints());
|
||||
while (i.hasNext()) {
|
||||
const RideFilePoint *p1 = i.next();
|
||||
RawFilePoint *p2 = new RawFilePoint(
|
||||
p1->secs, p1->nm, p1->kph * KM_TO_MILES, p1->watts,
|
||||
p1->km * KM_TO_MILES, (int) p1->cad, (int) p1->hr, p1->interval);
|
||||
|
||||
if (result->powerHist.contains(p2->watts))
|
||||
result->powerHist[p2->watts] += rideFile->recIntSecs();
|
||||
else
|
||||
result->powerHist[p2->watts] = rideFile->recIntSecs();
|
||||
result->points.append(p2);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* $Id: RawFile.h,v 1.3 2006/08/11 19:58:07 srhea Exp $
|
||||
*
|
||||
* Copyright (c) 2006 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
|
||||
*/
|
||||
|
||||
#ifndef _GC_RawFile_h
|
||||
#define _GC_RawFile_h 1
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QStringList>
|
||||
|
||||
struct RawFilePoint
|
||||
{
|
||||
double secs, nm, mph, watts, miles;
|
||||
unsigned cad, hr, interval;
|
||||
RawFilePoint(double secs, double nm, double mph, double watts,
|
||||
double miles, unsigned cad, unsigned hr, unsigned interval) :
|
||||
secs(secs), nm(nm), mph(mph), watts(watts), miles(miles),
|
||||
cad(cad), hr(hr), interval(interval) {}
|
||||
};
|
||||
|
||||
class RawFile
|
||||
{
|
||||
private:
|
||||
|
||||
QFile file;
|
||||
|
||||
RawFile(QString fileName) {
|
||||
file.setFileName(fileName);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
QDateTime startTime;
|
||||
int rec_int_ms;
|
||||
QList<RawFilePoint*> points;
|
||||
QMap<double,double> powerHist;
|
||||
static RawFile *readFile(QFile &file, QStringList &errors);
|
||||
};
|
||||
|
||||
#endif // _GC_RawFile_h
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "RideItem.h"
|
||||
#include "RideMetric.h"
|
||||
#include "RawFile.h"
|
||||
#include "RideFile.h"
|
||||
#include "Settings.h"
|
||||
#include "TimeUtils.h"
|
||||
#include "Zones.h"
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <math.h>
|
||||
#include <QtXml/QtXml>
|
||||
|
||||
#define MILES_PER_KM 0.62137119
|
||||
|
||||
RideItem::RideItem(QTreeWidgetItem *parent, int type,
|
||||
QString path, QString fileName, const QDateTime &dateTime,
|
||||
const Zones *zones, QString notesFileName) :
|
||||
@@ -56,23 +58,23 @@ RideItem::~RideItem()
|
||||
|
||||
static void summarize(QString &intervals,
|
||||
unsigned last_interval,
|
||||
double mile_start, double mile_end,
|
||||
double km_start, double km_end,
|
||||
double &int_watts_sum,
|
||||
double &int_hr_sum,
|
||||
double &int_cad_sum,
|
||||
double &int_mph_sum,
|
||||
double &int_kph_sum,
|
||||
double &int_secs_hr,
|
||||
double &int_max_power,
|
||||
double int_dur)
|
||||
{
|
||||
double dur = int_dur;
|
||||
double len = mile_end - mile_start;
|
||||
double mile_len = (km_end - km_start) * MILES_PER_KM;
|
||||
double minutes = (int) (dur/60.0);
|
||||
double seconds = dur - (60 * minutes);
|
||||
double watts_avg = int_watts_sum / dur;
|
||||
double hr_avg = int_hr_sum / int_secs_hr;
|
||||
double cad_avg = int_cad_sum / dur;
|
||||
double mph_avg = int_mph_sum / dur;
|
||||
double mph_avg = int_kph_sum * MILES_PER_KM / dur;
|
||||
double energy = int_watts_sum / 1000.0; // watts_avg / 1000.0 * dur;
|
||||
|
||||
intervals += "<tr><td align=\"center\">%1</td>";
|
||||
@@ -87,7 +89,7 @@ static void summarize(QString &intervals,
|
||||
intervals = intervals.arg(last_interval);
|
||||
intervals = intervals.arg(minutes, 0, 'f', 0);
|
||||
intervals = intervals.arg(seconds, 2, 'f', 0, QLatin1Char('0'));
|
||||
intervals = intervals.arg(len, 0, 'f', 1);
|
||||
intervals = intervals.arg(mile_len, 0, 'f', 1);
|
||||
intervals = intervals.arg(energy, 0, 'f', 0);
|
||||
intervals = intervals.arg(int_max_power, 0, 'f', 0);
|
||||
intervals = intervals.arg(watts_avg, 0, 'f', 0);
|
||||
@@ -103,7 +105,7 @@ static void summarize(QString &intervals,
|
||||
int_watts_sum = 0.0;
|
||||
int_hr_sum = 0.0;
|
||||
int_cad_sum = 0.0;
|
||||
int_mph_sum = 0.0;
|
||||
int_kph_sum = 0.0;
|
||||
int_max_power = 0.0;
|
||||
}
|
||||
|
||||
@@ -126,7 +128,7 @@ double RideItem::timeInZone(int zone)
|
||||
{
|
||||
if (summary.isEmpty())
|
||||
htmlSummary();
|
||||
if (!raw)
|
||||
if (!ride)
|
||||
return 0.0;
|
||||
assert(zone_range >= 0);
|
||||
assert(zone < num_zones);
|
||||
@@ -172,10 +174,9 @@ RideItem::htmlSummary()
|
||||
if (summary.isEmpty()) {
|
||||
QFile file(path + "/" + fileName);
|
||||
QStringList errors;
|
||||
raw = RawFile::readFile(file, errors);
|
||||
if (!raw) {
|
||||
summary = ("<p>Couldn't read file \"" +
|
||||
file.fileName() + "\":");
|
||||
ride = CombinedFileReader::instance().openRideFile(file, errors);
|
||||
if (!ride) {
|
||||
summary = "<p>Couldn't read file \"" + file.fileName() + "\":";
|
||||
QListIterator<QString> i(errors);
|
||||
while (i.hasNext())
|
||||
summary += "<br>" + i.next();
|
||||
@@ -184,10 +185,6 @@ RideItem::htmlSummary()
|
||||
summary = ("<p><center><h2>"
|
||||
+ dateTime.toString("dddd MMMM d, yyyy, h:mm AP")
|
||||
+ "</h2><p><h2>Summary</h2>");
|
||||
if (raw == NULL) {
|
||||
summary += "<p>Error: Can't read file.";
|
||||
return summary;
|
||||
}
|
||||
|
||||
if (zones) {
|
||||
zone_range = zones->whichRange(dateTime.date());
|
||||
@@ -216,7 +213,7 @@ later:
|
||||
if (!metrics.contains(deps[j]))
|
||||
goto later;
|
||||
RideMetric *metric = factory.newMetric(name);
|
||||
metric->compute(raw, zones, zone_range, metrics);
|
||||
metric->compute(ride, zones, zone_range, metrics);
|
||||
metrics.insert(name, metric);
|
||||
i.remove();
|
||||
}
|
||||
@@ -226,39 +223,39 @@ later:
|
||||
|
||||
QString intervals = "";
|
||||
int interval_count = 0;
|
||||
unsigned last_interval = UINT_MAX;
|
||||
int last_interval = INT_MAX;
|
||||
double int_watts_sum = 0.0;
|
||||
double int_hr_sum = 0.0;
|
||||
double int_cad_sum = 0.0;
|
||||
double int_mph_sum = 0.0;
|
||||
double int_kph_sum = 0.0;
|
||||
double int_secs_hr = 0.0;
|
||||
double int_max_power = 0.0;
|
||||
|
||||
double time_start, time_end, mile_start, mile_end, int_dur;
|
||||
double time_start, time_end, km_start, km_end, int_dur;
|
||||
|
||||
QListIterator<RawFilePoint*> i(raw->points);
|
||||
QListIterator<RideFilePoint*> i(ride->dataPoints());
|
||||
while (i.hasNext()) {
|
||||
RawFilePoint *point = i.next();
|
||||
RideFilePoint *point = i.next();
|
||||
|
||||
double secs_delta = raw->rec_int_ms / 1000.0;
|
||||
double secs_delta = ride->recIntSecs();
|
||||
|
||||
if (point->interval != last_interval) {
|
||||
|
||||
if (last_interval != UINT_MAX) {
|
||||
if (last_interval != INT_MAX) {
|
||||
summarize(intervals, last_interval,
|
||||
mile_start, mile_end, int_watts_sum,
|
||||
int_hr_sum, int_cad_sum, int_mph_sum,
|
||||
km_start, km_end, int_watts_sum,
|
||||
int_hr_sum, int_cad_sum, int_kph_sum,
|
||||
int_secs_hr, int_max_power, int_dur);
|
||||
}
|
||||
interval_count++;
|
||||
last_interval = point->interval;
|
||||
time_start = point->secs;
|
||||
mile_start = point->miles;
|
||||
km_start = point->km;
|
||||
int_secs_hr = secs_delta;
|
||||
int_dur = 0.0;
|
||||
}
|
||||
|
||||
if ((point->mph > 0.0) || (point->cad > 0.0)) {
|
||||
if ((point->kph > 0.0) || (point->cad > 0.0)) {
|
||||
int_dur += secs_delta;
|
||||
}
|
||||
if (point->watts >= 0.0) {
|
||||
@@ -278,15 +275,15 @@ later:
|
||||
}
|
||||
if (point->cad > 0)
|
||||
int_cad_sum += point->cad * secs_delta;
|
||||
if (point->mph >= 0)
|
||||
int_mph_sum += point->mph * secs_delta;
|
||||
if (point->kph >= 0)
|
||||
int_kph_sum += point->kph * secs_delta;
|
||||
|
||||
mile_end = point->miles;
|
||||
km_end = point->km;
|
||||
time_end = point->secs + secs_delta;
|
||||
}
|
||||
summarize(intervals, last_interval,
|
||||
mile_start, mile_end, int_watts_sum,
|
||||
int_hr_sum, int_cad_sum, int_mph_sum,
|
||||
km_start, km_end, int_watts_sum,
|
||||
int_hr_sum, int_cad_sum, int_kph_sum,
|
||||
int_secs_hr, int_max_power, int_dur);
|
||||
|
||||
summary += "<p>";
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
class RawFile;
|
||||
class RideFile;
|
||||
class Zones;
|
||||
class RideMetric;
|
||||
|
||||
@@ -41,7 +41,7 @@ class RideItem : public QTreeWidgetItem {
|
||||
QString fileName;
|
||||
QDateTime dateTime;
|
||||
QString summary;
|
||||
RawFile *raw;
|
||||
RideFile *ride;
|
||||
const Zones *zones;
|
||||
QString notesFileName;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <QVector>
|
||||
#include <assert.h>
|
||||
|
||||
#include "RawFile.h"
|
||||
#include "RideFile.h"
|
||||
|
||||
class Zones;
|
||||
|
||||
@@ -16,7 +16,7 @@ struct RideMetric {
|
||||
virtual QString name() const = 0;
|
||||
virtual QString units(bool metric) const = 0;
|
||||
virtual double value(bool metric) const = 0;
|
||||
virtual void compute(const RawFile *raw,
|
||||
virtual void compute(const RideFile *ride,
|
||||
const Zones *zones,
|
||||
int zoneRange,
|
||||
const QHash<QString,RideMetric*> &deps) = 0;
|
||||
@@ -29,17 +29,16 @@ struct RideMetric {
|
||||
};
|
||||
|
||||
struct PointwiseRideMetric : public RideMetric {
|
||||
void compute(const RawFile *raw, const Zones *zones, int zoneRange,
|
||||
void compute(const RideFile *ride, const Zones *zones, int zoneRange,
|
||||
const QHash<QString,RideMetric*> &) {
|
||||
QListIterator<RawFilePoint*> i(raw->points);
|
||||
double secsDelta = raw->rec_int_ms / 1000.0;
|
||||
QListIterator<RideFilePoint*> i(ride->dataPoints());
|
||||
while (i.hasNext()) {
|
||||
const RawFilePoint *point = i.next();
|
||||
perPoint(point, secsDelta, raw, zones, zoneRange);
|
||||
const RideFilePoint *point = i.next();
|
||||
perPoint(point, ride->recIntSecs(), ride, zones, zoneRange);
|
||||
}
|
||||
}
|
||||
virtual void perPoint(const RawFilePoint *point, double secsDelta,
|
||||
const RawFile *raw, const Zones *zones,
|
||||
virtual void perPoint(const RideFilePoint *point, double secsDelta,
|
||||
const RideFile *ride, const Zones *zones,
|
||||
int zoneRange) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ HEADERS += \
|
||||
LogTimeScaleEngine.h \
|
||||
MainWindow.h \
|
||||
PowerHist.h \
|
||||
RawFile.h \
|
||||
RawRideFile.h \
|
||||
RideFile.h \
|
||||
RideItem.h \
|
||||
@@ -54,7 +53,6 @@ SOURCES += \
|
||||
LogTimeScaleEngine.cpp \
|
||||
MainWindow.cpp \
|
||||
PowerHist.cpp \
|
||||
RawFile.cpp \
|
||||
RawRideFile.cpp \
|
||||
RideFile.cpp \
|
||||
RideItem.cpp \
|
||||
|
||||
Reference in New Issue
Block a user