@@ -197,6 +197,14 @@ function viewTrack(filename, info) {
197197 menu [ /*LANG*/ 'Plot HRM' ] = function ( ) {
198198 plotGraph ( info , "Heartrate" ) ;
199199 } ;
200+ if ( info . fields . includes ( "Steps" ) )
201+ menu [ /*LANG*/ 'Plot Steps' ] = function ( ) {
202+ plotGraph ( info , "Steps" ) ;
203+ } ;
204+ if ( info . fields . includes ( "Battery Percentage" ) )
205+ menu [ /*LANG*/ 'Plot Battery' ] = function ( ) {
206+ plotGraph ( info , "Battery" ) ;
207+ } ;
200208 // TODO: steps, heart rate?
201209 menu [ /*LANG*/ 'Erase' ] = function ( ) {
202210 E . showPrompt ( /*LANG*/ "Delete Track?" ) . then ( function ( v ) {
@@ -358,12 +366,34 @@ function plotGraph(info, style) { "ram"
358366 infn [ i ] += + c [ altIdx ] ;
359367 infc [ i ] ++ ;
360368 }
369+ } else if ( style == "Steps" ) {
370+ title = /*LANG*/ "Steps/min" ;
371+ var stpIdx = info . fields . indexOf ( "Steps" ) ;
372+ var t , lt = c [ timeIdx ] ;
373+ while ( l !== undefined ) {
374+ c = l . trim ( ) . split ( "," ) ; l = f . readLine ( f ) ;
375+ if ( c [ stpIdx ] == "" ) continue ;
376+ t = c [ timeIdx ] ;
377+ i = Math . round ( 80 * ( t - strt ) / dur ) ;
378+ infn [ i ] += 60 * c [ stpIdx ] ;
379+ infc [ i ] += t - lt ;
380+ lt = t ;
381+ }
382+ } else if ( style == "Battery" ) {
383+ title = /*LANG*/ "Battery %" ;
384+ var batIdx = info . fields . indexOf ( "Battery Percentage" ) ;
385+ while ( l !== undefined ) {
386+ c = l . trim ( ) . split ( "," ) ; l = f . readLine ( f ) ;
387+ if ( c [ batIdx ] == "" ) continue ;
388+ i = Math . round ( 80 * ( c [ timeIdx ] - strt ) / dur ) ;
389+ infn [ i ] += + c [ batIdx ] ;
390+ infc [ i ] ++ ;
391+ }
361392 } else if ( style == "Speed" ) {
362393 // use locate to work out units
363394 var localeStr = require ( "locale" ) . speed ( 1 , 5 ) ; // get what 1kph equates to
364395 let units = localeStr . replace ( / [ 0 - 9 . ] * / , "" ) ;
365396 factor = parseFloat ( localeStr ) * 3.6 ; // m/sec to whatever out units are
366- // title
367397 title = /*LANG*/ "Speed" + ` (${ units } )` ;
368398 var latIdx = info . fields . indexOf ( "Latitude" ) ;
369399 var lonIdx = info . fields . indexOf ( "Longitude" ) ;
@@ -378,19 +408,15 @@ function plotGraph(info, style) { "ram"
378408 while ( l !== undefined ) {
379409 c = l . trim ( ) . split ( "," ) ;
380410 l = f . readLine ( f ) ;
381- if ( c [ latIdx ] == "" ) {
382- continue ;
383- }
411+ if ( c [ latIdx ] == "" ) continue ;
384412 t = c [ timeIdx ] ;
385413 i = Math . round ( 80 * ( t - strt ) / dur ) ;
386414 p = Bangle . project ( { lat :c [ latIdx ] , lon :c [ lonIdx ] } ) ;
387415 dx = p . x - lp . x ;
388416 dy = p . y - lp . y ;
389417 d = Math . sqrt ( dx * dx + dy * dy ) ;
390- if ( t != lt ) {
391- infn [ i ] += d / ( t - lt ) ; // speed
392- infc [ i ] ++ ;
393- }
418+ infn [ i ] += d ; // speed
419+ infc [ i ] += t - lt ;
394420 lp = p ;
395421 lt = t ;
396422 }
@@ -406,6 +432,7 @@ function plotGraph(info, style) { "ram"
406432 if ( n > max ) max = n ;
407433 if ( n < min ) min = n ;
408434 }
435+ if ( style == "Battery" ) { min = 0 ; max = 100 ; }
409436 // work out a nice grid value
410437 var heightDiff = max - min ;
411438 var grid = 1 ;
0 commit comments