@@ -20,7 +20,13 @@ import TestStudioHeader from './TestStudioHeader';
2020import useLocalStorage from '../common/local-storage' ;
2121import useConfigurationVersions from '../../hooks/use-configuration-versions' ;
2222import { formatConfigVersionLink , formatConfigVersionText , type ConfigVersion as UtilsConfigVersion } from './utils/configVersionUtils' ;
23- import { parseComparisonMetrics , parseWeightedOverallScores , parseConfigSettingValues } from '../../graphql/awsjson-parsers' ;
23+ import {
24+ parseComparisonMetrics ,
25+ parseWeightedOverallScores ,
26+ parseConfigSettingValues ,
27+ calculateAvgCostPerPage ,
28+ } from '../../graphql/awsjson-parsers' ;
29+ import type { CostBreakdown } from '../../graphql/awsjson-types' ;
2430
2531const client = generateClient ( ) ;
2632
@@ -305,14 +311,8 @@ const TestComparison = ({ preSelectedTestRunIds = [] }: TestComparisonProps): Re
305311 [
306312 'Avg Cost/Page' ,
307313 ...Object . values ( completeTestRuns ) . map ( ( run ) => {
308- if ( run . totalCost == null || ! run . costBreakdown ) return 'N/A' ;
309- let totalPages = 0 ;
310- Object . values ( run . costBreakdown as Record < string , Record < string , Record < string , unknown > > > ) . forEach ( ( services ) => {
311- Object . values ( services ) . forEach ( ( details ) => {
312- if ( details . unit === 'pages' ) totalPages += Number ( details . value ) || 0 ;
313- } ) ;
314- } ) ;
315- return totalPages > 0 ? `$${ ( Number ( run . totalCost ) / totalPages ) . toFixed ( 4 ) } ` : 'N/A' ;
314+ const avg = calculateAvgCostPerPage ( run . totalCost as number , run . costBreakdown as CostBreakdown ) ;
315+ return avg !== null ? `$${ avg . toFixed ( 4 ) } ` : 'N/A' ;
316316 } ) ,
317317 ] ,
318318 [
@@ -637,16 +637,7 @@ const TestComparison = ({ preSelectedTestRunIds = [] }: TestComparisonProps): Re
637637 completedFiles : testRun . completedFiles ,
638638 failedFiles : testRun . failedFiles ,
639639 totalCost : testRun . totalCost ,
640- avgCostPerPage : ( ( ) => {
641- if ( testRun . totalCost == null || ! testRun . costBreakdown ) return null ;
642- let totalPages = 0 ;
643- Object . values ( testRun . costBreakdown as Record < string , Record < string , Record < string , unknown > > > ) . forEach ( ( services ) => {
644- Object . values ( services ) . forEach ( ( details ) => {
645- if ( details . unit === 'pages' ) totalPages += Number ( details . value ) || 0 ;
646- } ) ;
647- } ) ;
648- return totalPages > 0 ? Number ( testRun . totalCost ) / totalPages : null ;
649- } ) ( ) ,
640+ avgCostPerPage : calculateAvgCostPerPage ( testRun . totalCost as number , testRun . costBreakdown as CostBreakdown ) ,
650641 averageAccuracy : testRun . overallAccuracy ,
651642 averageConfidence : testRun . averageConfidence ,
652643 averageWeightedOverallScore : ( ( ) => {
@@ -845,16 +836,8 @@ const TestComparison = ({ preSelectedTestRunIds = [] }: TestComparisonProps): Re
845836 metric : 'Avg Cost/Page' ,
846837 ...Object . fromEntries (
847838 Object . entries ( completeTestRuns ) . map ( ( [ testRunId , testRun ] ) => {
848- if ( testRun . totalCost == null || ! testRun . costBreakdown ) return [ testRunId , 'N/A' ] ;
849- let totalPages = 0 ;
850- Object . values ( testRun . costBreakdown as Record < string , Record < string , Record < string , unknown > > > ) . forEach (
851- ( services ) => {
852- Object . values ( services ) . forEach ( ( details ) => {
853- if ( details . unit === 'pages' ) totalPages += Number ( details . value ) || 0 ;
854- } ) ;
855- } ,
856- ) ;
857- return [ testRunId , totalPages > 0 ? `$${ ( Number ( testRun . totalCost ) / totalPages ) . toFixed ( 4 ) } ` : 'N/A' ] ;
839+ const avg = calculateAvgCostPerPage ( testRun . totalCost as number , testRun . costBreakdown as CostBreakdown ) ;
840+ return [ testRunId , avg !== null ? `$${ avg . toFixed ( 4 ) } ` : 'N/A' ] ;
858841 } ) ,
859842 ) ,
860843 } ,
0 commit comments