11import  {  describe ,  it ,  expect  }  from  'vitest' ; 
2- import  {  createStandings ,  sliceRelevantDrivers  }  from  './createStandings' ; 
2+ import  {  createDriverStandings ,   groupStandingsByClass ,  sliceRelevantDrivers  }  from  './createStandings' ; 
33import  type  {  Session ,  Telemetry ,  SessionInfo  }  from  '@irdashies/types' ; 
44
55describe ( 'createStandings' ,  ( )  =>  { 
@@ -150,7 +150,7 @@ describe('createStandings', () => {
150150
151151  describe ( 'sliceRelevantDrivers' ,  ( )  =>  { 
152152    interface  DummyStanding  {  name : string ;  isPlayer ?: boolean  } 
153-     it ( 'should return only top 3 drivers for class without  player' ,  ( )  =>  { 
153+     it ( 'should return only top 3 drivers for classes outside of  player\'s class ' ,  ( )  =>  { 
154154      const  results : [ string ,  DummyStanding [ ] ] [ ]  =  [ 
155155        [ 
156156          'GT3' , 
@@ -174,7 +174,7 @@ describe('createStandings', () => {
174174        ] , 
175175      ] ; 
176176
177-       const  filteredDrivers  =  sliceRelevantDrivers ( results ) ; 
177+       const  filteredDrivers  =  sliceRelevantDrivers ( results ,   'GT4' ) ; 
178178
179179      expect ( filteredDrivers ) . toEqual ( [ 
180180        [ 
@@ -194,12 +194,58 @@ describe('createStandings', () => {
194194      ] ) ; 
195195    } ) ; 
196196
197+     it ( 'should return all player\'s class even when player is not in standings' ,  ( )  =>  { 
198+       const  results : [ string ,  DummyStanding [ ] ] [ ]  =  [ 
199+         [ 
200+           'GT3' , 
201+           [ 
202+             {  name : '1. Bob'  } , 
203+             {  name : '2. Alice'  } , 
204+             {  name : '3. Charlie'  } , 
205+             {  name : '4. David'  } , 
206+             {  name : '5. Eve'  } , 
207+           ] , 
208+         ] , 
209+         [ 
210+           'GT4' , 
211+           [ 
212+             {  name : '1. Clark'  } , 
213+             {  name : '2. Richard'  } , 
214+             {  name : '3. Sam'  } , 
215+             {  name : '4. Bingo'  } , 
216+             {  name : '5. Tod'  } , 
217+             {  name : '6. Wallace'  } , 
218+           ] , 
219+         ] , 
220+       ] ; 
221+ 
222+       const  filteredDrivers  =  sliceRelevantDrivers ( results ,  'GT4' ) ; 
223+ 
224+       expect ( filteredDrivers ) . toEqual ( [ 
225+         [ 
226+           'GT3' , 
227+           [ {  name : '1. Bob'  } ,  {  name : '2. Alice'  } ,  {  name : '3. Charlie'  } ] , 
228+         ] , 
229+         [ 
230+           'GT4' , 
231+           [ 
232+             {  name : '1. Clark'  } , 
233+             {  name : '2. Richard'  } , 
234+             {  name : '3. Sam'  } , 
235+             {  name : '4. Bingo'  } , 
236+             {  name : '5. Tod'  } , 
237+             {  name : '6. Wallace'  } , 
238+           ] , 
239+         ] , 
240+       ] ) ; 
241+     } ) ; 
242+ 
197243    it ( 'should return all drivers when less than 3 available for class without player' ,  ( )  =>  { 
198244      const  results : [ string ,  DummyStanding [ ] ] [ ]  =  [ 
199245        [ 'GT3' ,  [ {  name : 'Bob'  } ,  {  name : 'Alice'  } ] ] , 
200246      ] ; 
201247
202-       const  filteredDrivers  =  sliceRelevantDrivers ( results ) ; 
248+       const  filteredDrivers  =  sliceRelevantDrivers ( results ,   'GT3' ) ; 
203249
204250      expect ( filteredDrivers ) . toEqual ( [ 
205251        [ 'GT3' ,  [ {  name : 'Bob'  } ,  {  name : 'Alice'  } ] ] , 
@@ -227,7 +273,7 @@ describe('createStandings', () => {
227273        ] , 
228274      ] ; 
229275
230-       const  filteredDrivers  =  sliceRelevantDrivers ( results ) ; 
276+       const  filteredDrivers  =  sliceRelevantDrivers ( results ,   'GT3' ) ; 
231277
232278      expect ( filteredDrivers ) . toEqual ( [ 
233279        [ 
@@ -267,7 +313,7 @@ describe('createStandings', () => {
267313        ] , 
268314      ] ; 
269315
270-       const  filteredDrivers  =  sliceRelevantDrivers ( results ) ; 
316+       const  filteredDrivers  =  sliceRelevantDrivers ( results ,   'GT3' ) ; 
271317
272318      expect ( filteredDrivers ) . toEqual ( [ 
273319        [ 
@@ -286,3 +332,44 @@ describe('createStandings', () => {
286332    } ) ; 
287333  } ) ; 
288334} ) ; 
335+ 
336+ 
337+ /** 
338+  * This method will create the standings for the current session 
339+  * It will group the standings by class and slice the relevant drivers 
340+  *  
341+  * Only used to simplify testing 
342+  */ 
343+ function  createStandings ( 
344+   session ?: Session , 
345+   telemetry ?: Telemetry , 
346+   currentSession ?: SessionInfo , 
347+   options ?: { 
348+     buffer ?: number ; 
349+     numNonClassDrivers ?: number ; 
350+   } 
351+ )  { 
352+   const  standings  =  createDriverStandings ( 
353+     { 
354+       playerIdx : session ?. DriverInfo ?. DriverCarIdx , 
355+       drivers : session ?. DriverInfo ?. Drivers , 
356+       qualifyingResults : session ?. QualifyResultsInfo ?. Results , 
357+     } , 
358+     { 
359+       carIdxF2TimeValue : telemetry ?. CarIdxF2Time ?. value , 
360+       carIdxOnPitRoadValue : telemetry ?. CarIdxOnPitRoad ?. value , 
361+       carIdxTrackSurfaceValue : telemetry ?. CarIdxTrackSurface ?. value , 
362+       radioTransmitCarIdx : telemetry ?. RadioTransmitCarIdx ?. value , 
363+     } , 
364+     { 
365+       resultsPositions : currentSession ?. ResultsPositions , 
366+       resultsFastestLap : currentSession ?. ResultsFastestLap , 
367+       sessionType : currentSession ?. SessionType , 
368+     } 
369+   ) ; 
370+   const  driverClass  =  session ?. DriverInfo ?. Drivers ?. find ( 
371+     ( driver )  =>  driver . CarIdx  ===  session ?. DriverInfo ?. DriverCarIdx 
372+   ) ?. CarClassID ; 
373+   const  grouped  =  groupStandingsByClass ( standings ) ; 
374+   return  sliceRelevantDrivers ( grouped ,  driverClass ,  options ) ; 
375+ } ; 
0 commit comments