11import { Recording , RecordingSession , RecordingSessionAltitude , RecordingSessionBatteryState , RecordingSessionCoordinate , RecordingSessionSpeed , RecordingV1Session , RecordingV1SessionBatteryState } from "@ridetracker/ridetrackertypes" ;
2+ import { getDistance } from "geolib" ;
23
34export default function getActivityRecordingFromArray ( sessions : RecordingV1Session [ ] ) : Recording | null {
45 if ( ! sessions . length )
@@ -11,10 +12,26 @@ export default function getActivityRecordingFromArray(sessions: RecordingV1Sessi
1112 version : 2 ,
1213
1314 sessions : sessions . map < RecordingSession > ( ( session ) => {
15+ let distance = 0 ;
16+ let altitude = 0 ;
17+ let speed = 0 ;
18+
1419 return {
1520 id : session . id ,
1621
17- coordinates : session . locations . map < RecordingSessionCoordinate > ( ( location ) => {
22+ coordinates : session . locations . filter ( ( location , index , array ) => {
23+ if ( index === 0 || index === array . length - 1 )
24+ return true ;
25+
26+ distance += getDistance ( array [ index - 1 ] . coords , location . coords ) ;
27+
28+ if ( distance < 10 )
29+ return false ;
30+
31+ distance = 0 ;
32+
33+ return true ;
34+ } ) . map < RecordingSessionCoordinate > ( ( location ) => {
1835 return {
1936 coordinate : {
2037 latitude : location . coords . latitude ,
@@ -26,7 +43,17 @@ export default function getActivityRecordingFromArray(sessions: RecordingV1Sessi
2643 } ;
2744 } ) ,
2845
29- altitudes : session . locations . map < RecordingSessionAltitude > ( ( location ) => {
46+ altitudes : session . locations . filter ( ( location , index , array ) => {
47+ if ( index === 0 || index === array . length - 1 )
48+ return true ;
49+
50+ if ( Math . abs ( location . coords . altitude - altitude ) < 1 )
51+ return false ;
52+
53+ altitude = location . coords . altitude ;
54+
55+ return true ;
56+ } ) . map < RecordingSessionAltitude > ( ( location ) => {
3057 return {
3158 altitude : location . coords . altitude ,
3259 accuracy : location . coords . altitudeAccuracy ,
@@ -74,7 +101,17 @@ export default function getActivityRecordingFromArray(sessions: RecordingV1Sessi
74101 }
75102 } ) ,
76103
77- speeds : session . locations . map < RecordingSessionSpeed > ( ( location ) => {
104+ speeds : session . locations . filter ( ( location , index , array ) => {
105+ if ( index === 0 || index === array . length - 1 )
106+ return true ;
107+
108+ if ( Math . abs ( location . coords . speed - speed ) < 1 )
109+ return false ;
110+
111+ speed = location . coords . speed ;
112+
113+ return true ;
114+ } ) . map < RecordingSessionSpeed > ( ( location ) => {
78115 return {
79116 speed : location . coords . speed ,
80117 accuracy : location . coords . accuracy ,
0 commit comments