Skip to content

Commit 081108a

Browse files
committed
run/exstats: add ETA stat
1 parent b2fe290 commit 081108a

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

modules/exstats.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ print(ExStats.getList());
1616
{name: "Steps", id:"step"},
1717
{name: "Heart (BPM)", id:"bpm"},
1818
{name: "Max BPM", id:"maxbpm"},
19-
{name: "Pace (avr)", id:"pacea"},
19+
{name: "Pace (avg)", id:"pacea"},
2020
{name: "Pace (current)", id:"pacec"},
2121
{name: "Cadence", id:"caden"},
22+
{name: "ETA (avg)", id:"etaa"},
23+
{name: "ETA (current)", id:"etac"},
2224
]
2325
2426
// Setup and load all statistic types
25-
var exs = ExStats.getStats(["dist", "time", "pacea","bpm","step","caden"], options);
27+
var exs = ExStats.getStats(["dist", "time", "pacea","bpm","step","caden","etaa","etac"], options);
2628
// exs contains
2729
{
2830
stats : { time : {
@@ -143,6 +145,13 @@ function formatPace(speed, paceLength) {
143145
return ('0' + min).substr(-2) + `:` + ('0' + sec).substr(-2);
144146
}
145147

148+
function eta(speed, state) {
149+
if (speed <= 0) return Infinity;
150+
151+
const distRemaining = (state.distance || 0) % 5000;
152+
return distRemaining / speed;
153+
}
154+
146155
Bangle.on("GPS", function(fix) {
147156
if (!fix.fix) return; // only process actual fixes
148157
state.lastGPS = state.thisGPS;
@@ -208,7 +217,9 @@ exports.getList = function() {
208217
{name: "Pace (curr)", id:"pacec"},
209218
{name: "Speed", id:"speed"},
210219
{name: "Cadence", id:"caden"},
211-
{name: "Altitude (GPS)", id:"altg"}
220+
{name: "Altitude (GPS)", id:"altg"},
221+
{name: "ETA (avg)", id:"etaa"},
222+
{name: "ETA (current)", id:"etac"},
212223
];
213224
if (Bangle.setBarometerPower) l.push({name: "Altitude (baro)", id:"altb"});
214225
return l;
@@ -311,6 +322,22 @@ exports.getStats = function(statIDs, options) {
311322
getString : function() { return (state.alt===undefined)?"-":state.alti+"m"; },
312323
};
313324
}
325+
if (statIDs.includes("etaa")) {
326+
needGPS = true;
327+
stats["etaa"]={
328+
title : "ETA (avg)",
329+
getValue : function() { return eta(state.avrSpeed, state); },
330+
getString : function() { return formatTime(this.getValue()) },
331+
};
332+
}
333+
if (statIDs.includes("etaa")) {
334+
needGPS = true;
335+
stats["etac"]={
336+
title : "ETA (current)",
337+
getValue : function() { return eta(state.curSpeed, state); },
338+
getString : function() { return formatTime(this.getValue()) },
339+
};
340+
}
314341
// ======================
315342
for (var i in stats) stats[i].id=i; // set up ID field
316343
if (needGPS) Bangle.setGPSPower(true,"exs");

0 commit comments

Comments
 (0)