mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Added support for gear ratio graphs
Added support for FIT files from Bryton Rider devices
This commit is contained in:
parent
cb80389d74
commit
3424b3e265
@ -49,6 +49,7 @@ HEADERS += src/config.h \
|
||||
src/GUI/format.h \
|
||||
src/GUI/cadencegraph.h \
|
||||
src/GUI/powergraph.h \
|
||||
src/GUI/gearratiograph.h \
|
||||
src/GUI/optionsdialog.h \
|
||||
src/GUI/colorbox.h \
|
||||
src/GUI/stylecombobox.h \
|
||||
@ -61,6 +62,7 @@ HEADERS += src/config.h \
|
||||
src/GUI/temperaturegraphitem.h \
|
||||
src/GUI/cadencegraphitem.h \
|
||||
src/GUI/powergraphitem.h \
|
||||
src/GUI/gearratiographitem.h \
|
||||
src/GUI/oddspinbox.h \
|
||||
src/GUI/settings.h \
|
||||
src/GUI/nicenum.h \
|
||||
@ -164,6 +166,7 @@ SOURCES += src/main.cpp \
|
||||
src/GUI/format.cpp \
|
||||
src/GUI/cadencegraph.cpp \
|
||||
src/GUI/powergraph.cpp \
|
||||
src/GUI/gearratiograph.cpp \
|
||||
src/GUI/optionsdialog.cpp \
|
||||
src/GUI/colorbox.cpp \
|
||||
src/GUI/stylecombobox.cpp \
|
||||
@ -175,6 +178,7 @@ SOURCES += src/main.cpp \
|
||||
src/GUI/temperaturegraphitem.cpp \
|
||||
src/GUI/cadencegraphitem.cpp \
|
||||
src/GUI/powergraphitem.cpp \
|
||||
src/GUI/gearratiographitem.cpp \
|
||||
src/GUI/nicenum.cpp \
|
||||
src/GUI/mapview.cpp \
|
||||
src/map/maplist.cpp \
|
||||
|
94
src/GUI/gearratiograph.cpp
Normal file
94
src/GUI/gearratiograph.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
#include "data/data.h"
|
||||
#include "gearratiographitem.h"
|
||||
#include "gearratiograph.h"
|
||||
|
||||
|
||||
GearRatioGraph::GearRatioGraph(QWidget *parent) : GraphTab(parent)
|
||||
{
|
||||
_showTracks = true;
|
||||
|
||||
GraphView::setYUnits("");
|
||||
setYLabel(tr("Gear ratio"));
|
||||
|
||||
setSliderPrecision(2);
|
||||
}
|
||||
|
||||
void GearRatioGraph::setInfo()
|
||||
{
|
||||
if (_showTracks) {
|
||||
GraphView::addInfo(tr("Most used"), QString::number(top() * yScale(),
|
||||
'f', 2) + UNIT_SPACE + yUnits());
|
||||
GraphView::addInfo(tr("Minimum"), QString::number(min() * yScale(), 'f',
|
||||
2) + UNIT_SPACE + yUnits());
|
||||
GraphView::addInfo(tr("Maximum"), QString::number(max() * yScale(), 'f',
|
||||
2) + UNIT_SPACE + yUnits());
|
||||
} else
|
||||
clearInfo();
|
||||
}
|
||||
|
||||
QList<GraphItem*> GearRatioGraph::loadData(const Data &data)
|
||||
{
|
||||
QList<GraphItem*> graphs;
|
||||
|
||||
for (int i = 0; i < data.tracks().count(); i++) {
|
||||
const Graph &graph = data.tracks().at(i)->ratio();
|
||||
|
||||
if (graph.size() < 2) {
|
||||
skipColor();
|
||||
graphs.append(0);
|
||||
} else {
|
||||
GearRatioGraphItem *gi = new GearRatioGraphItem(graph, _graphType);
|
||||
GraphView::addGraph(gi);
|
||||
|
||||
for (QMap<qreal, qreal>::const_iterator it = gi->map().constBegin();
|
||||
it != gi->map().constEnd(); ++it)
|
||||
_map.insert(it.key(), _map.value(it.key()) + it.value());
|
||||
graphs.append(gi);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.routes().count(); i++) {
|
||||
skipColor();
|
||||
graphs.append(0);
|
||||
}
|
||||
|
||||
setInfo();
|
||||
redraw();
|
||||
|
||||
return graphs;
|
||||
}
|
||||
|
||||
qreal GearRatioGraph::top() const
|
||||
{
|
||||
qreal key, val;
|
||||
|
||||
for (QMap<qreal, qreal>::const_iterator it = _map.constBegin();
|
||||
it != _map.constEnd(); ++it) {
|
||||
if (it == _map.constBegin()) {
|
||||
val = it.value();
|
||||
key = it.key();
|
||||
} else if (it.value() > val) {
|
||||
val = it.value();
|
||||
key = it.key();
|
||||
}
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
void GearRatioGraph::clear()
|
||||
{
|
||||
_map.clear();
|
||||
|
||||
GraphView::clear();
|
||||
}
|
||||
|
||||
void GearRatioGraph::showTracks(bool show)
|
||||
{
|
||||
_showTracks = show;
|
||||
|
||||
showGraph(show);
|
||||
setInfo();
|
||||
|
||||
redraw();
|
||||
}
|
30
src/GUI/gearratiograph.h
Normal file
30
src/GUI/gearratiograph.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef GEARRATIOGRAPH_H
|
||||
#define GEARRATIOGRAPH_H
|
||||
|
||||
#include <QMap>
|
||||
#include "graphtab.h"
|
||||
|
||||
class GearRatioGraph : public GraphTab
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GearRatioGraph(QWidget *parent = 0);
|
||||
|
||||
QString label() const {return tr("Gear ratio");}
|
||||
QList<GraphItem*> loadData(const Data &data);
|
||||
void clear();
|
||||
void showTracks(bool show);
|
||||
|
||||
private:
|
||||
qreal top() const;
|
||||
qreal min() const {return bounds().top();}
|
||||
qreal max() const {return bounds().bottom();}
|
||||
void setInfo();
|
||||
|
||||
QMap<qreal, qreal> _map;
|
||||
|
||||
bool _showTracks;
|
||||
};
|
||||
|
||||
#endif // GEARRATIOGRAPH_H
|
39
src/GUI/gearratiographitem.cpp
Normal file
39
src/GUI/gearratiographitem.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <QMap>
|
||||
#include "tooltip.h"
|
||||
#include "gearratiographitem.h"
|
||||
|
||||
GearRatioGraphItem::GearRatioGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent) : GraphItem(graph, type, parent)
|
||||
{
|
||||
qreal val;
|
||||
|
||||
for (int j = 1; j < graph.size(); j++) {
|
||||
const GraphPoint &p = graph.at(j);
|
||||
qreal val = _map.value(p.y());
|
||||
_map.insert(p.y(), val + (p.s() - graph.at(j-1).s()));
|
||||
}
|
||||
|
||||
for (QMap<qreal, qreal>::const_iterator it = _map.constBegin();
|
||||
it != _map.constEnd(); ++it) {
|
||||
if (it == _map.constBegin()) {
|
||||
val = it.value();
|
||||
_top = it.key();
|
||||
} else if (it.value() > val) {
|
||||
val = it.value();
|
||||
_top = it.key();
|
||||
}
|
||||
}
|
||||
|
||||
setToolTip(toolTip());
|
||||
}
|
||||
|
||||
QString GearRatioGraphItem::toolTip() const
|
||||
{
|
||||
ToolTip tt;
|
||||
|
||||
tt.insert(tr("Minimum"), QString::number(min(), 'f', 2));
|
||||
tt.insert(tr("Maximum"), QString::number(max(), 'f', 2));
|
||||
tt.insert(tr("Most used"), QString::number(top(), 'f', 2));
|
||||
|
||||
return tt.toString();
|
||||
}
|
28
src/GUI/gearratiographitem.h
Normal file
28
src/GUI/gearratiographitem.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef GEARRATIOGRAPHITEM_H
|
||||
#define GEARRATIOGRAPHITEM_H
|
||||
|
||||
#include <QMap>
|
||||
#include "graphitem.h"
|
||||
|
||||
class GearRatioGraphItem : public GraphItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GearRatioGraphItem(const Graph &graph, GraphType type,
|
||||
QGraphicsItem *parent = 0);
|
||||
|
||||
qreal min() const {return -bounds().bottom();}
|
||||
qreal max() const {return -bounds().top();}
|
||||
qreal top() const {return _top;}
|
||||
|
||||
const QMap<qreal, qreal> &map() const {return _map;}
|
||||
|
||||
private:
|
||||
QString toolTip() const;
|
||||
|
||||
QMap<qreal, qreal> _map;
|
||||
qreal _top;
|
||||
};
|
||||
|
||||
#endif // GEARRATIOGRAPHITEM_H
|
@ -81,12 +81,14 @@ GraphView::~GraphView()
|
||||
|
||||
void GraphView::createXLabel()
|
||||
{
|
||||
_xAxis->setLabel(QString("%1 [%2]").arg(_xLabel, _xUnits));
|
||||
_xAxis->setLabel(QString("%1 [%2]").arg(_xLabel,
|
||||
_xUnits.isEmpty() ? "-" : _xUnits));
|
||||
}
|
||||
|
||||
void GraphView::createYLabel()
|
||||
{
|
||||
_yAxis->setLabel(QString("%1 [%2]").arg(_yLabel, _yUnits));
|
||||
_yAxis->setLabel(QString("%1 [%2]").arg(_yLabel,
|
||||
_yUnits.isEmpty() ? "-" : _yUnits));
|
||||
}
|
||||
|
||||
void GraphView::setYLabel(const QString &label)
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "temperaturegraph.h"
|
||||
#include "cadencegraph.h"
|
||||
#include "powergraph.h"
|
||||
#include "gearratiograph.h"
|
||||
#include "mapview.h"
|
||||
#include "trackinfo.h"
|
||||
#include "filebrowser.h"
|
||||
@ -556,6 +557,7 @@ void GUI::createGraphTabs()
|
||||
_tabs.append(new CadenceGraph(_graphTabWidget));
|
||||
_tabs.append(new PowerGraph(_graphTabWidget));
|
||||
_tabs.append(new TemperatureGraph(_graphTabWidget));
|
||||
_tabs.append(new GearRatioGraph(_graphTabWidget));
|
||||
|
||||
for (int i = 0; i < _tabs.count(); i++)
|
||||
connect(_tabs.at(i), SIGNAL(sliderPositionChanged(qreal)), this,
|
||||
|
@ -4,11 +4,20 @@
|
||||
#include "fitparser.h"
|
||||
|
||||
|
||||
const quint32 FIT_MAGIC = 0x5449462E; // .FIT
|
||||
#define FIT_MAGIC 0x5449462E // .FIT
|
||||
|
||||
#define RECORD_MESSAGE 20
|
||||
#define EVENT_MESSAGE 21
|
||||
#define TIMESTAMP_FIELD 253
|
||||
|
||||
struct Event {
|
||||
quint8 id;
|
||||
quint8 type;
|
||||
quint32 data;
|
||||
|
||||
Event() : id(0), type(0), data(0) {}
|
||||
};
|
||||
|
||||
|
||||
FITParser::FITParser()
|
||||
{
|
||||
@ -17,7 +26,9 @@ FITParser::FITParser()
|
||||
_device = 0;
|
||||
_endian = 0;
|
||||
_timestamp = 0;
|
||||
_last = 0;
|
||||
_len = 0;
|
||||
_ratio = NAN;
|
||||
}
|
||||
|
||||
void FITParser::clearDefinitions()
|
||||
@ -160,6 +171,7 @@ bool FITParser::readField(Field *f, quint32 &val)
|
||||
val = (quint32)-1;
|
||||
|
||||
switch (f->type) {
|
||||
case 0: // enum
|
||||
case 1: // sint8
|
||||
case 2: // uint8
|
||||
if (f->size == 1) {
|
||||
@ -191,13 +203,31 @@ bool FITParser::readField(Field *f, quint32 &val)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool FITParser::addEntry(TrackData &track)
|
||||
{
|
||||
if (_trackpoint.coordinates().isValid()) {
|
||||
_trackpoint.setTimestamp(QDateTime::fromTime_t(_timestamp
|
||||
+ 631065600));
|
||||
_trackpoint.setRatio(_ratio);
|
||||
track.append(_trackpoint);
|
||||
} else {
|
||||
if (_trackpoint.coordinates().isNull())
|
||||
warning("Missing coordinates");
|
||||
else {
|
||||
_errorString = "Invalid coordinates";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FITParser::parseData(TrackData &track, MessageDefinition *def,
|
||||
quint8 offset)
|
||||
{
|
||||
Field *field;
|
||||
quint32 timestamp = _timestamp + offset;
|
||||
Event event;
|
||||
quint32 val;
|
||||
Trackpoint trackpoint;
|
||||
int i;
|
||||
|
||||
|
||||
@ -206,7 +236,15 @@ bool FITParser::parseData(TrackData &track, MessageDefinition *def,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (def->globalId == RECORD_MESSAGE && _last != _timestamp) {
|
||||
if (!addEntry(track))
|
||||
return false;
|
||||
_last = _timestamp;
|
||||
_trackpoint = Trackpoint();
|
||||
}
|
||||
|
||||
_endian = def->endian;
|
||||
_timestamp += offset;
|
||||
|
||||
for (i = 0; i < def->numFields; i++) {
|
||||
field = &def->fields[i];
|
||||
@ -214,47 +252,59 @@ bool FITParser::parseData(TrackData &track, MessageDefinition *def,
|
||||
return false;
|
||||
|
||||
if (field->id == TIMESTAMP_FIELD)
|
||||
_timestamp = timestamp = val;
|
||||
_timestamp = val;
|
||||
else if (def->globalId == RECORD_MESSAGE) {
|
||||
switch (field->id) {
|
||||
case 0:
|
||||
if (val != 0x7fffffff)
|
||||
trackpoint.rcoordinates().setLat(
|
||||
_trackpoint.rcoordinates().setLat(
|
||||
((qint32)val / (double)0x7fffffff) * 180);
|
||||
break;
|
||||
case 1:
|
||||
if (val != 0x7fffffff)
|
||||
trackpoint.rcoordinates().setLon(
|
||||
_trackpoint.rcoordinates().setLon(
|
||||
((qint32)val / (double)0x7fffffff) * 180);
|
||||
break;
|
||||
case 2:
|
||||
if (val != 0xffff)
|
||||
trackpoint.setElevation((val / 5.0) - 500);
|
||||
_trackpoint.setElevation((val / 5.0) - 500);
|
||||
break;
|
||||
case 3:
|
||||
if (val != 0xff)
|
||||
trackpoint.setHeartRate(val);
|
||||
_trackpoint.setHeartRate(val);
|
||||
break;
|
||||
case 4:
|
||||
if (val != 0xff)
|
||||
trackpoint.setCadence(val);
|
||||
_trackpoint.setCadence(val);
|
||||
break;
|
||||
case 6:
|
||||
if (val != 0xffff)
|
||||
trackpoint.setSpeed(val / 1000.0f);
|
||||
_trackpoint.setSpeed(val / 1000.0f);
|
||||
break;
|
||||
case 7:
|
||||
if (val != 0xffff)
|
||||
trackpoint.setPower(val);
|
||||
_trackpoint.setPower(val);
|
||||
break;
|
||||
case 13:
|
||||
if (val != 0x7f)
|
||||
trackpoint.setTemperature((qint8)val);
|
||||
_trackpoint.setTemperature((qint8)val);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
} else if (def->globalId == EVENT_MESSAGE) {
|
||||
switch (field->id) {
|
||||
case 0:
|
||||
event.id = val;
|
||||
break;
|
||||
case 1:
|
||||
event.type = val;
|
||||
break;
|
||||
case 3:
|
||||
event.data = val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,19 +314,11 @@ bool FITParser::parseData(TrackData &track, MessageDefinition *def,
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (def->globalId == RECORD_MESSAGE) {
|
||||
if (trackpoint.coordinates().isValid()) {
|
||||
trackpoint.setTimestamp(QDateTime::fromTime_t(timestamp
|
||||
+ 631065600));
|
||||
track.append(trackpoint);
|
||||
} else {
|
||||
if (trackpoint.coordinates().isNull())
|
||||
warning("Missing coordinates");
|
||||
else {
|
||||
_errorString = "Invalid coordinates";
|
||||
return false;
|
||||
}
|
||||
if (def->globalId == EVENT_MESSAGE) {
|
||||
if ((event.id == 42 || event.id == 43) && event.type == 3) {
|
||||
quint32 front = ((event.data & 0xFF000000) >> 24);
|
||||
quint32 rear = ((event.data & 0x0000FF00) >> 8);
|
||||
_ratio = ((qreal)front / (qreal)rear);
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,6 +390,9 @@ bool FITParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
_device = file;
|
||||
_endian = 0;
|
||||
_timestamp = 0;
|
||||
_last = 0;
|
||||
_ratio = NAN;
|
||||
_trackpoint = Trackpoint();
|
||||
|
||||
if (!parseHeader())
|
||||
return false;
|
||||
@ -356,8 +401,10 @@ bool FITParser::parse(QFile *file, QList<TrackData> &tracks,
|
||||
TrackData &track = tracks.last();
|
||||
|
||||
while (_len)
|
||||
if ((ret = parseRecord(track)) == false)
|
||||
if (!(ret = parseRecord(track)))
|
||||
break;
|
||||
if (ret && _trackpoint.coordinates().isValid())
|
||||
ret = addEntry(track);
|
||||
|
||||
clearDefinitions();
|
||||
|
||||
|
@ -52,14 +52,17 @@ private:
|
||||
bool parseDataMessage(TrackData &track, quint8 header);
|
||||
bool parseData(TrackData &track, MessageDefinition *def, quint8 offset);
|
||||
bool readField(Field *f, quint32 &val);
|
||||
bool addEntry(TrackData &track);
|
||||
|
||||
QIODevice *_device;
|
||||
QString _errorString;
|
||||
|
||||
quint32 _len;
|
||||
quint8 _endian;
|
||||
quint32 _timestamp;
|
||||
quint32 _timestamp, _last;
|
||||
MessageDefinition _defs[16];
|
||||
qreal _ratio;
|
||||
Trackpoint _trackpoint;
|
||||
};
|
||||
|
||||
#endif // FITPARSER_H
|
||||
|
@ -209,6 +209,18 @@ Graph Track::temperature() const
|
||||
return raw;
|
||||
}
|
||||
|
||||
Graph Track::ratio() const
|
||||
{
|
||||
Graph raw;
|
||||
|
||||
for (int i = 0; i < _data.size(); i++)
|
||||
if (_data.at(i).hasRatio() && !_outliers.contains(i))
|
||||
raw.append(GraphPoint(_distance.at(i), _time.at(i),
|
||||
_data.at(i).ratio()));
|
||||
|
||||
return raw;
|
||||
}
|
||||
|
||||
Graph Track::cadence() const
|
||||
{
|
||||
Graph raw, filtered;
|
||||
|
@ -22,6 +22,7 @@ public:
|
||||
Graph temperature() const;
|
||||
Graph cadence() const;
|
||||
Graph power() const;
|
||||
Graph ratio() const;
|
||||
|
||||
qreal distance() const;
|
||||
qreal time() const;
|
||||
|
@ -11,10 +11,10 @@ class Trackpoint
|
||||
public:
|
||||
Trackpoint()
|
||||
{_elevation = NAN; _speed = NAN; _heartRate = NAN; _temperature = NAN;
|
||||
_cadence = NAN; _power = NAN;}
|
||||
_cadence = NAN; _power = NAN; _ratio = NAN;}
|
||||
Trackpoint(const Coordinates &coordinates) : _coordinates(coordinates)
|
||||
{_elevation = NAN; _speed = NAN; _heartRate = NAN; _temperature = NAN;
|
||||
_cadence = NAN; _power = NAN;}
|
||||
_cadence = NAN; _power = NAN; _ratio = NAN;}
|
||||
|
||||
const Coordinates &coordinates() const {return _coordinates;}
|
||||
Coordinates &rcoordinates() {return _coordinates;}
|
||||
@ -25,6 +25,7 @@ public:
|
||||
qreal temperature() const {return _temperature;}
|
||||
qreal cadence() const {return _cadence;}
|
||||
qreal power() const {return _power;}
|
||||
qreal ratio() const {return _ratio;}
|
||||
|
||||
void setCoordinates(const Coordinates &coordinates)
|
||||
{_coordinates = coordinates;}
|
||||
@ -35,6 +36,7 @@ public:
|
||||
void setTemperature(qreal temperature) {_temperature = temperature;}
|
||||
void setCadence(qreal cadence) {_cadence = cadence;}
|
||||
void setPower(qreal power) {_power = power;}
|
||||
void setRatio(qreal ratio) {_ratio = ratio;}
|
||||
|
||||
bool hasTimestamp() const {return !_timestamp.isNull();}
|
||||
bool hasElevation() const {return !std::isnan(_elevation);}
|
||||
@ -43,6 +45,7 @@ public:
|
||||
bool hasTemperature() const {return !std::isnan(_temperature);}
|
||||
bool hasCadence() const {return !std::isnan(_cadence);}
|
||||
bool hasPower() const {return !std::isnan(_power);}
|
||||
bool hasRatio() const {return !std::isnan(_ratio);}
|
||||
|
||||
private:
|
||||
Coordinates _coordinates;
|
||||
@ -53,6 +56,7 @@ private:
|
||||
qreal _temperature;
|
||||
qreal _cadence;
|
||||
qreal _power;
|
||||
qreal _ratio;
|
||||
};
|
||||
|
||||
Q_DECLARE_TYPEINFO(Trackpoint, Q_MOVABLE_TYPE);
|
||||
|
Loading…
Reference in New Issue
Block a user