@@ -88,31 +88,56 @@ export async function POST(req: NextRequest) {
88
88
}
89
89
90
90
if ( ! dateScoreMap [ date ] [ `${ testId } -${ evaluation . Test ?. name } ` ] ) {
91
- dateScoreMap [ date ] [ `${ testId } -${ evaluation . Test ?. name } ` ] = 0 ;
91
+ dateScoreMap [ date ] [ `${ testId } -${ evaluation . Test ?. name } ` ] = [ 0 , 0 ] ;
92
92
}
93
93
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 ;
96
99
} ) ;
97
100
}
98
101
99
- const chartData = Object . entries ( dateScoreMap ) . map (
102
+ const metricsChartData = Object . entries ( dateScoreMap ) . map (
100
103
( [ date , scoresByTestId ] ) => {
101
104
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
+ ) ;
105
110
return entry ;
106
111
}
107
112
) ;
108
113
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 (
110
132
( a , b ) =>
111
133
new Date ( a . date as string ) . getTime ( ) -
112
134
new Date ( b . date as string ) . getTime ( )
113
135
) ;
114
136
115
- return NextResponse . json ( chartData ) ;
137
+ return NextResponse . json ( {
138
+ metrics : metricsChartData ,
139
+ scores : scoresChartData ,
140
+ } ) ;
116
141
} catch ( error ) {
117
142
return NextResponse . json (
118
143
{
0 commit comments