@@ -275,14 +275,25 @@ export class VoteService {
275275 ? Object . values ( finalResults ) . reduce ( ( sum , r ) => sum + r . votes , 0 )
276276 : Object . values ( optionCounts ) . reduce ( ( sum , count ) => sum + count , 0 ) ;
277277
278+ // Calculate totalEligiblePoints and pointsVoted for eReputation
279+ let totalEligiblePoints : number | undefined ;
280+ let pointsVoted : number | undefined ;
281+ if ( isWeighted && reputationResults ) {
282+ // eReputation weighted normal voting: sum of all scores
283+ totalEligiblePoints = reputationResults . results . reduce ( ( sum , r ) => sum + r . score , 0 ) ;
284+ pointsVoted = totalWeightedVotes ; // Sum of weighted votes
285+ }
286+
278287 return {
279288 pollId,
280289 totalVotes : votes . length , // Actual number of votes cast
281290 totalWeightedVotes : totalWeightedVotes , // Sum of all weighted votes (if weighted)
282291 totalEligibleVoters,
283292 turnout : totalEligibleVoters > 0 ? ( votes . length / totalEligibleVoters ) * 100 : 0 ,
284293 mode : isWeighted ? "ereputation" : "normal" ,
285- results : finalResults
294+ results : finalResults ,
295+ ...( totalEligiblePoints !== undefined && { totalEligiblePoints } ) ,
296+ ...( pointsVoted !== undefined && { pointsVoted } )
286297 } ;
287298 } else if ( poll . mode === "point" ) {
288299 // STEP 1: Calculate point-based results normally (without eReputation weighting)
@@ -341,14 +352,25 @@ export class VoteService {
341352 // Sort by total points (highest first)
342353 finalResults . sort ( ( a , b ) => b . totalPoints - a . totalPoints ) ;
343354
355+ // Calculate totalEligiblePoints and pointsVoted for eReputation weighted points-based voting
356+ let totalEligiblePoints : number | undefined ;
357+ let pointsVoted : number | undefined ;
358+ if ( reputationResults ) {
359+ // eReputation weighted points-based voting: sum of all scores * 100 (each user has 100 points)
360+ totalEligiblePoints = reputationResults . results . reduce ( ( sum , r ) => sum + r . score , 0 ) * 100 ;
361+ pointsVoted = totalWeightedPoints ; // Sum of weighted points
362+ }
363+
344364 return {
345365 pollId,
346366 totalVotes,
347367 totalWeightedPoints,
348368 totalEligibleVoters,
349369 turnout : totalEligibleVoters > 0 ? ( totalVotes / totalEligibleVoters ) * 100 : 0 ,
350370 mode : "ereputation" ,
351- results : finalResults
371+ results : finalResults ,
372+ ...( totalEligiblePoints !== undefined && { totalEligiblePoints } ) ,
373+ ...( pointsVoted !== undefined && { pointsVoted } )
352374 } ;
353375 } else {
354376 // No weighting - use normal points
@@ -369,14 +391,21 @@ export class VoteService {
369391 // Sort by total points (highest first)
370392 finalResults . sort ( ( a , b ) => b . totalPoints - a . totalPoints ) ;
371393
394+ // Calculate totalEligiblePoints for simple points-based voting (not eReputation)
395+ // Each user has 100 points by default
396+ const totalEligiblePoints = totalEligibleVoters * 100 ;
397+ const pointsVoted = totalPoints ; // Sum of all points distributed
398+
372399 return {
373400 pollId,
374401 totalVotes,
375402 totalWeightedPoints : totalPoints ,
376403 totalEligibleVoters,
377404 turnout : totalEligibleVoters > 0 ? ( totalVotes / totalEligibleVoters ) * 100 : 0 ,
378405 mode : "point" ,
379- results : finalResults
406+ results : finalResults ,
407+ totalEligiblePoints,
408+ pointsVoted
380409 } ;
381410 }
382411 } else if ( poll . mode === "rank" ) {
0 commit comments