@@ -61,13 +61,15 @@ export function categorizeProjectReviews(
61
61
}
62
62
63
63
// Separate evaluations into AI and non-AI
64
- const aiEvaluations = application . evaluations . filter (
65
- ( evaluation ) => evaluation . evaluator . toLowerCase ( ) === AI_EVALUATOR_ADDRESS . toLowerCase ( ) ,
66
- ) ;
64
+ const aiEvaluations =
65
+ application . evaluations ?. filter (
66
+ ( evaluation ) => evaluation . evaluator . toLowerCase ( ) === AI_EVALUATOR_ADDRESS . toLowerCase ( ) ,
67
+ ) ?? [ ] ;
67
68
68
- const humanEvaluations = application . evaluations . filter (
69
- ( evaluation ) => evaluation . evaluator . toLowerCase ( ) !== AI_EVALUATOR_ADDRESS . toLowerCase ( ) ,
70
- ) ;
69
+ const humanEvaluations =
70
+ application . evaluations ?. filter (
71
+ ( evaluation ) => evaluation . evaluator . toLowerCase ( ) !== AI_EVALUATOR_ADDRESS . toLowerCase ( ) ,
72
+ ) ?? [ ] ;
71
73
72
74
// Determine the category based on the number of human evaluations
73
75
const isReadyForReview = humanEvaluations . length >= 2 ;
@@ -76,7 +78,7 @@ export function categorizeProjectReviews(
76
78
: "INREVIEW" ;
77
79
78
80
// Map human evaluations to reviews
79
- const reviews : Review [ ] = humanEvaluations . map ( ( evaluation ) => {
81
+ const reviews : Review [ ] = humanEvaluations ? .map ( ( evaluation ) => {
80
82
const isApproved = evaluation . evaluatorScore >= 50 ; // Assuming 50 as the approval threshold
81
83
const reviewerAddress : `0x${string } ` = evaluation . evaluator . startsWith ( "0x" )
82
84
? ( evaluation . evaluator as `0x${string } `)
@@ -88,18 +90,14 @@ export function categorizeProjectReviews(
88
90
} ) ;
89
91
90
92
// Calculate the average score including both AI and human evaluations
91
- const totalScore = application . evaluations . reduce (
92
- ( sum , evaluation ) => sum + evaluation . evaluatorScore ,
93
- 0 ,
94
- ) ;
95
- const totalEvaluations = application . evaluations . length ;
93
+ const totalScore =
94
+ application . evaluations ?. reduce ( ( sum , evaluation ) => sum + evaluation . evaluatorScore , 0 ) ?? 0 ;
95
+ const totalEvaluations = application . evaluations ?. length ?? 0 ;
96
96
const scoreAverage = totalEvaluations > 0 ? totalScore / totalEvaluations : 0 ;
97
97
98
98
// Calculate AI suggestion score (average AI evaluator scores)
99
- const aiTotalScore = aiEvaluations . reduce (
100
- ( sum , evaluation ) => sum + evaluation . evaluatorScore ,
101
- 0 ,
102
- ) ;
99
+ const aiTotalScore =
100
+ aiEvaluations ?. reduce ( ( sum , evaluation ) => sum + evaluation . evaluatorScore , 0 ) ?? 0 ;
103
101
const aiSuggestion = aiEvaluations . length > 0 ? aiTotalScore / aiEvaluations . length : 0 ;
104
102
105
103
const projectData = application . metadata . application . project ;
0 commit comments