@@ -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 ) {
@@ -325,6 +333,7 @@ function plotGraph(info, style) { "ram"
325333 var lt = 0 ; // last time
326334 //var tn = 0; // count for each time period
327335 var strt , dur = info . duration ;
336+ if ( dur < 1 ) dur = 1 ;
328337 var f = require ( "Storage" ) . open ( filename , "r" ) ;
329338 if ( f === undefined ) return ;
330339 var l = f . readLine ( f ) ;
@@ -333,14 +342,14 @@ function plotGraph(info, style) { "ram"
333342 var factor = 1 ; // multiplier used for values when graphing
334343 var timeIdx = info . fields . indexOf ( "Time" ) ;
335344 if ( l !== undefined ) {
336- c = l . split ( "," ) ;
345+ c = l . trim ( ) . split ( "," ) ;
337346 strt = c [ timeIdx ] ;
338347 }
339348 if ( style == "Heartrate" ) {
340349 title = /*LANG*/ "Heartrate (bpm)" ;
341350 var hrmIdx = info . fields . indexOf ( "Heartrate" ) ;
342351 while ( l !== undefined ) {
343- c = l . split ( "," ) ; l = f . readLine ( f ) ;
352+ c = l . trim ( ) . split ( "," ) ; l = f . readLine ( f ) ;
344353 if ( c [ hrmIdx ] == "" ) continue ;
345354 i = Math . round ( 80 * ( c [ timeIdx ] - strt ) / dur ) ;
346355 infn [ i ] += + c [ hrmIdx ] ;
@@ -351,45 +360,63 @@ function plotGraph(info, style) { "ram"
351360 var altIdx = info . fields . indexOf ( "Barometer Altitude" ) ;
352361 if ( altIdx < 0 ) altIdx = info . fields . indexOf ( "Altitude" ) ;
353362 while ( l !== undefined ) {
354- c = l . split ( "," ) ; l = f . readLine ( f ) ;
363+ c = l . trim ( ) . split ( "," ) ; l = f . readLine ( f ) ;
355364 if ( c [ altIdx ] == "" ) continue ;
356365 i = Math . round ( 80 * ( c [ timeIdx ] - strt ) / dur ) ;
357366 infn [ i ] += + c [ altIdx ] ;
358367 infc [ i ] ++ ;
359368 }
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+ }
360392 } else if ( style == "Speed" ) {
361393 // use locate to work out units
362394 var localeStr = require ( "locale" ) . speed ( 1 , 5 ) ; // get what 1kph equates to
363395 let units = localeStr . replace ( / [ 0 - 9 . ] * / , "" ) ;
364396 factor = parseFloat ( localeStr ) * 3.6 ; // m/sec to whatever out units are
365- // title
366397 title = /*LANG*/ "Speed" + ` (${ units } )` ;
367398 var latIdx = info . fields . indexOf ( "Latitude" ) ;
368399 var lonIdx = info . fields . indexOf ( "Longitude" ) ;
369400 // skip until we find our first data
370401 while ( l !== undefined && c [ latIdx ] == "" ) {
371- c = l . split ( "," ) ;
402+ c = l . trim ( ) . split ( "," ) ;
372403 l = f . readLine ( f ) ;
373404 }
374405 // now iterate
375- var p , lp = Bangle . project ( { lat :c [ 1 ] , lon :c [ 2 ] } ) ;
406+ var p , lp = Bangle . project ( { lat :c [ latIdx ] , lon :c [ lonIdx ] } ) ;
376407 var t , dx , dy , d , lt = c [ timeIdx ] ;
377408 while ( l !== undefined ) {
378- c = l . split ( "," ) ;
409+ c = l . trim ( ) . split ( "," ) ;
379410 l = f . readLine ( f ) ;
380- if ( c [ latIdx ] == "" ) {
381- continue ;
382- }
411+ if ( c [ latIdx ] == "" ) continue ;
383412 t = c [ timeIdx ] ;
384413 i = Math . round ( 80 * ( t - strt ) / dur ) ;
385414 p = Bangle . project ( { lat :c [ latIdx ] , lon :c [ lonIdx ] } ) ;
386415 dx = p . x - lp . x ;
387416 dy = p . y - lp . y ;
388417 d = Math . sqrt ( dx * dx + dy * dy ) ;
389- if ( t != lt ) {
390- infn [ i ] += d / ( t - lt ) ; // speed
391- infc [ i ] ++ ;
392- }
418+ infn [ i ] += d ; // speed
419+ infc [ i ] += t - lt ;
393420 lp = p ;
394421 lt = t ;
395422 }
@@ -405,6 +432,7 @@ function plotGraph(info, style) { "ram"
405432 if ( n > max ) max = n ;
406433 if ( n < min ) min = n ;
407434 }
435+ if ( style == "Battery" ) { min = 0 ; max = 100 ; }
408436 // work out a nice grid value
409437 var heightDiff = max - min ;
410438 var grid = 1 ;
0 commit comments