Skip to content

Commit

Permalink
add power to kml track descriptions and balloons. (GPSBabel#950)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteven4 authored Nov 27, 2022
1 parent 757b5c7 commit 1abb9ab
Show file tree
Hide file tree
Showing 8 changed files with 436 additions and 370 deletions.
2 changes: 2 additions & 0 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,11 +666,13 @@ struct computed_trkdata {
std::optional<double> min_spd; /* Meters/sec */
std::optional<double> avg_hrt; /* Avg Heartrate */
std::optional<double> avg_cad; /* Avg Cadence */
std::optional<double> avg_pwr; /* Avg Power */
gpsbabel::DateTime start; /* Min time */
gpsbabel::DateTime end; /* Max time */
std::optional<int> min_hrt; /* Min Heartrate */
std::optional<int> max_hrt; /* Max Heartrate */
std::optional<int> max_cad; /* Max Cadence */
std::optional<float> max_pwr; /* Max Power */
};

class route_head
Expand Down
42 changes: 26 additions & 16 deletions kml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,12 @@ void KmlFormat::kml_output_trkdescription(const route_head* header, const comput
}
}
}
if (td->avg_cad) {
kml_td(hwriter, QStringLiteral("Avg Cadence"), QStringLiteral(" %1 rpm ").arg(QString::number(*td->avg_cad, 'f', 1)));
}
if (td->max_cad) {
kml_td(hwriter, QStringLiteral("Max Cadence"), QStringLiteral(" %1 rpm ").arg(QString::number(*td->max_cad)));
}
if (td->avg_hrt) {
kml_td(hwriter, QStringLiteral("Avg Heart Rate"), QStringLiteral(" %1 bpm ").arg(QString::number(*td->avg_hrt, 'f', 1)));
}
Expand All @@ -612,11 +618,11 @@ void KmlFormat::kml_output_trkdescription(const route_head* header, const comput
if (td->max_hrt) {
kml_td(hwriter, QStringLiteral("Max Heart Rate"), QStringLiteral(" %1 bpm ").arg(QString::number(*td->max_hrt)));
}
if (td->avg_cad) {
kml_td(hwriter, QStringLiteral("Avg Cadence"), QStringLiteral(" %1 rpm ").arg(QString::number(*td->avg_cad, 'f', 1)));
if (td->avg_pwr) {
kml_td(hwriter, QStringLiteral("Avg Power"), QStringLiteral(" %1 watts ").arg(QString::number(*td->avg_pwr, 'f', 1)));
}
if (td->max_cad) {
kml_td(hwriter, QStringLiteral("Max Cadence"), QStringLiteral(" %1 rpm ").arg(QString::number(*td->max_cad)));
if (td->max_pwr) {
kml_td(hwriter, QStringLiteral("Max Power"), QStringLiteral(" %1 watts ").arg(QString::number(*td->max_pwr, 'f', 1)));
}
if (td->start.isValid() && td->end.isValid()) {
kml_td(hwriter, QStringLiteral("Start Time"), td->start.toPrettyString());
Expand Down Expand Up @@ -737,12 +743,16 @@ void KmlFormat::kml_output_description(const Waypoint* pt) const
kml_td(hwriter, QStringLiteral("Altitude: %1 %2 ").arg(QString::number(alt, 'f', 3), alt_units));
}

if (pt->cadence) {
kml_td(hwriter, QStringLiteral("Cadence: %1 ").arg(QString::number(pt->cadence)));
}

if (pt->heartrate) {
kml_td(hwriter, QStringLiteral("Heart rate: %1 ").arg(QString::number(pt->heartrate)));
}

if (pt->cadence) {
kml_td(hwriter, QStringLiteral("Cadence: %1 ").arg(QString::number(pt->cadence)));
if (pt->power) {
kml_td(hwriter, QStringLiteral("Power: %1 ").arg(QString::number(pt->power, 'f', 1)));
}

/* Which unit is this temp in? C? F? K? */
Expand Down Expand Up @@ -1525,11 +1535,11 @@ void KmlFormat::write_as_linestring(const route_head* header)

void KmlFormat::kml_mt_hdr(const route_head* header)
{
int has_cadence = 0;
int has_depth = 0;
int has_heartrate = 0;
int has_temperature = 0;
int has_power = 0;
bool has_cadence = false;
bool has_depth = false;
bool has_heartrate = false;
bool has_temperature = false;
bool has_power = false;

// This logic is kind of inside-out for GPSBabel. If a track doesn't
// have enough interesting timestamps, just write it as a LineString.
Expand Down Expand Up @@ -1572,19 +1582,19 @@ void KmlFormat::kml_mt_hdr(const route_head* header)
// Capture interesting traits to see if we need to do an ExtendedData
// section later.
if (tpt->cadence) {
has_cadence = 1;
has_cadence = true;
}
if (WAYPT_HAS(tpt, depth)) {
has_depth = 1;
has_depth = true;
}
if (tpt->heartrate) {
has_heartrate = 1;
has_heartrate = true;
}
if (WAYPT_HAS(tpt, temperature)) {
has_temperature = 1;
has_temperature = true;
}
if (tpt->power) {
has_power = 1;
has_power = true;
}
}

Expand Down
3 changes: 3 additions & 0 deletions random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ RandomFormat::random_generate_wpt(int i, const QDateTime& time, const Waypoint*
if RND(3) {
wpt->heartrate = rand_int(255);
}
if RND(3) {
wpt->power = rand_flt(500.0);
}
} else {
if (doing_rtes && (i > 0)) {
wpt->latitude = prev->latitude + rand_dbl(0.01);
Expand Down
18 changes: 9 additions & 9 deletions reference/realtime.csv
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
-28.606309,41.491196,85.918,Wpt_RD,1970-01-01T00:00:00Z
-28.605513,41.492136,,Wpt_lBahVv7,1970-01-01T00:00:01.745Z
-28.604906,41.492637,31.126,Wpt_hTE,1970-01-01T00:00:03.253Z
-28.604548,41.493038,,Wpt_0H,1970-01-01T00:00:04.655Z
-28.604396,41.493069,24.212,Wpt_k,1970-01-01T00:00:06.328Z
-28.603524,41.493167,5.795,Wpt_iX,1970-01-01T00:00:07.835Z
-28.603490,41.494039,36.201,Wpt_TyhlOke,1970-01-01T00:00:09.090Z
-28.602885,41.494402,73.608,Wpt_rS,1970-01-01T00:00:10.507Z
-28.602833,41.494822,2.947,Wpt_obZdF3b0,1970-01-01T00:00:11.965Z
-28.601890,41.495138,,ESTIMATED Position,1970-01-01T00:00:13.543Z
-28.605513,41.492136,0.027,Wpt_ahVv,1970-01-01T00:00:01.189Z
-28.605013,41.492918,78.576,Wpt_ElFRt5,1970-01-01T00:00:02.317Z
-28.604849,41.492946,,Wpt_Stg4W,1970-01-01T00:00:04.160Z
-28.604045,41.493083,11.875,Wpt_DlFC,1970-01-01T00:00:05.731Z
-28.603882,41.493350,60.271,Wpt_m,1970-01-01T00:00:07.093Z
-28.603126,41.493573,41.702,Wpt_cvYH1aA,1970-01-01T00:00:08.272Z
-28.602827,41.494044,,Wpt_C8obZd,1970-01-01T00:00:09.921Z
-28.602226,41.494598,70.466,Wpt_8cx1JYr7,1970-01-01T00:00:11.351Z
-28.602044,41.494654,,Wpt_ydet6fH,1970-01-01T00:00:13.320Z
Loading

0 comments on commit 1abb9ab

Please sign in to comment.