@@ -88,31 +88,56 @@ export async function POST(req: NextRequest) {
8888 }
8989
9090 if ( ! dateScoreMap [ date ] [ `${ testId } -${ evaluation . Test ?. name } ` ] ) {
91- dateScoreMap [ date ] [ `${ testId } -${ evaluation . Test ?. name } ` ] = 0 ;
91+ dateScoreMap [ date ] [ `${ testId } -${ evaluation . Test ?. name } ` ] = [ 0 , 0 ] ;
9292 }
9393
94- dateScoreMap [ date ] [ `${ testId } -${ evaluation . Test ?. name } ` ] +=
95- evaluation . ltUserScore || 0 ;
94+ const total =
95+ dateScoreMap [ date ] [ `${ testId } -${ evaluation . Test ?. name } ` ] [ 0 ] +
96+ evaluation . ltUserScore || 0 ;
97+ dateScoreMap [ date ] [ `${ testId } -${ evaluation . Test ?. name } ` ] [ 0 ] = total ;
98+ dateScoreMap [ date ] [ `${ testId } -${ evaluation . Test ?. name } ` ] [ 1 ] += 1 ;
9699 } ) ;
97100 }
98101
99- const chartData = Object . entries ( dateScoreMap ) . map (
102+ const metricsChartData = Object . entries ( dateScoreMap ) . map (
100103 ( [ date , scoresByTestId ] ) => {
101104 const entry : any = { date } ;
102- Object . entries ( scoresByTestId as any ) . forEach ( ( [ testId , score ] ) => {
103- entry [ testId ] = score ;
104- } ) ;
105+ Object . entries ( scoresByTestId as any ) . forEach (
106+ ( [ testId , scores ] : any ) => {
107+ entry [ testId ] = scores [ 0 ] ;
108+ }
109+ ) ;
105110 return entry ;
106111 }
107112 ) ;
108113
109- chartData . sort (
114+ // calculate score % test wise and not date wise
115+ // const scoresChartData: any = {
116+ // "test-1": 10,
117+ // };
118+ const scoresChartData : any = { } ;
119+ Object . entries ( dateScoreMap ) . map ( ( [ date , scoresByTestId ] ) => {
120+ Object . entries ( scoresByTestId as any ) . forEach ( ( [ testId , scores ] : any ) => {
121+ if ( ! scoresChartData [ testId ] ) {
122+ scoresChartData [ testId ] = 0 ;
123+ }
124+ if ( scores [ 1 ] === 0 ) {
125+ scoresChartData [ testId ] = 0 ;
126+ }
127+ scoresChartData [ testId ] = scores [ 0 ] / scores [ 1 ] ;
128+ } ) ;
129+ } ) ;
130+
131+ metricsChartData . sort (
110132 ( a , b ) =>
111133 new Date ( a . date as string ) . getTime ( ) -
112134 new Date ( b . date as string ) . getTime ( )
113135 ) ;
114136
115- return NextResponse . json ( chartData ) ;
137+ return NextResponse . json ( {
138+ metrics : metricsChartData ,
139+ scores : scoresChartData ,
140+ } ) ;
116141 } catch ( error ) {
117142 return NextResponse . json (
118143 {
0 commit comments