Skip to content

Commit db0d4ba

Browse files
Merge pull request #55 from Giveth/update-givpower-calculation
Update givpower calculation
2 parents 4e63664 + 011e6f2 commit db0d4ba

8 files changed

Lines changed: 161 additions & 216 deletions

File tree

src/modules/data-fetching/graphql/queries.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,6 @@ export const ALL_PROJECTS_WITH_FILTERS_QUERY = gql`
473473
}
474474
`;
475475

476-
/**
477-
* Query to get the top power rank value for GIVpower scoring normalization
478-
*/
479-
export const GET_TOP_POWER_RANK_QUERY = gql`
480-
query GetTopPowerRank {
481-
getTopPowerRank
482-
}
483-
`;
484-
485476
/**
486477
* Mutation to bulk update cause project evaluation scores
487478
* Used to send evaluation results back to Impact Graph after evaluation completion

src/modules/data-fetching/services/data-fetching.service.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -327,38 +327,4 @@ export class DataFetchingService {
327327
return false;
328328
}
329329
}
330-
331-
/**
332-
* Get the top power rank value for GIVpower scoring normalization
333-
* This replaces the need to use totalProjectCount in scoring calculations
334-
* @returns The top power rank value from Impact Graph, or null if unavailable
335-
*/
336-
async getTopPowerRank(): Promise<number | null> {
337-
try {
338-
// Return 100 for staging environment to fix staging-specific issues
339-
const isStaging = this.configService.get<boolean>('IS_STAGING', false);
340-
if (isStaging) {
341-
this.logger.debug(
342-
'Staging environment detected - returning fixed top power rank: 100',
343-
);
344-
return 100;
345-
}
346-
347-
this.logger.debug('Fetching top power rank for scoring normalization');
348-
const topPowerRank = await this.impactGraphService.getTopPowerRank();
349-
this.logger.debug(
350-
`Successfully retrieved top power rank: ${topPowerRank}`,
351-
);
352-
return topPowerRank;
353-
} catch (error) {
354-
this.logger.warn(
355-
'Failed to fetch top power rank - GIVpower scores will be set to 0 for this evaluation',
356-
{
357-
error: error instanceof Error ? error.message : String(error),
358-
},
359-
);
360-
// Return null to indicate that GIVpower scoring should be disabled
361-
return null;
362-
}
363-
}
364330
}

src/modules/data-fetching/services/impact-graph.service.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
ALL_CAUSES_WITH_PROJECTS_QUERY,
1111
CAUSE_BY_ID_QUERY,
1212
ALL_PROJECTS_WITH_FILTERS_QUERY,
13-
GET_TOP_POWER_RANK_QUERY,
1413
BULK_UPDATE_CAUSE_PROJECT_EVALUATION_MUTATION,
1514
} from '../graphql/queries';
1615
import {
@@ -640,41 +639,6 @@ export class ImpactGraphService {
640639
}
641640
}
642641

643-
/**
644-
* Get the top power rank value for GIVpower scoring normalization
645-
* This replaces the need to use totalProjectCount as it provides the actual maximum rank
646-
* @returns The top power rank value
647-
* @throws HttpException when the query fails
648-
*/
649-
async getTopPowerRank(): Promise<number> {
650-
try {
651-
this.logger.debug('Fetching top power rank from Impact-Graph');
652-
653-
const response = await this.graphqlClient.request<{
654-
getTopPowerRank: number;
655-
}>(GET_TOP_POWER_RANK_QUERY);
656-
657-
const topPowerRank = response.getTopPowerRank;
658-
659-
this.logger.debug(`Retrieved top power rank: ${topPowerRank}`);
660-
661-
return topPowerRank;
662-
} catch (error) {
663-
this.logger.error(
664-
'Failed to fetch top power rank from Impact-Graph',
665-
error as GraphQLError,
666-
);
667-
668-
this.handleGraphQLError(error as GraphQLError, 'getTopPowerRank');
669-
670-
// Throw error instead of providing fallback - let calling service handle appropriately
671-
throw new HttpException(
672-
'Failed to fetch top power rank from Impact-Graph',
673-
HttpStatus.SERVICE_UNAVAILABLE,
674-
);
675-
}
676-
}
677-
678642
/**
679643
* Check if the Impact-Graph service is healthy
680644
* @returns Boolean indicating service health

src/modules/evaluation/dto/evaluate-multiple-causes-request.dto.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { IsArray, ValidateNested, ArrayMinSize } from 'class-validator';
1+
import {
2+
IsArray,
3+
ValidateNested,
4+
ArrayMinSize,
5+
IsNumber,
6+
IsOptional,
7+
} from 'class-validator';
28
import { Type } from 'class-transformer';
39
import { EvaluateProjectsRequestDto } from './evaluate-projects-request.dto';
410

@@ -8,4 +14,8 @@ export class EvaluateMultipleCausesRequestDto {
814
@ValidateNested({ each: true })
915
@Type(() => EvaluateProjectsRequestDto)
1016
causes: EvaluateProjectsRequestDto[];
17+
18+
@IsOptional()
19+
@IsNumber()
20+
highestPowerRank?: number;
1121
}

src/modules/evaluation/dto/evaluate-projects-request.dto.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ import {
88
} from 'class-validator';
99
import { Type } from 'class-transformer';
1010

11+
export class ProjectWithPowerDto {
12+
@IsNumber()
13+
@IsNotEmpty()
14+
id: number;
15+
16+
@IsOptional()
17+
@IsNumber()
18+
powerRank?: number;
19+
20+
@IsOptional()
21+
@IsNumber()
22+
totalPower?: number;
23+
}
24+
1125
export class CategoryDto {
1226
@IsString()
1327
@IsNotEmpty()
@@ -53,7 +67,8 @@ export class EvaluateProjectsRequestDto {
5367
cause: CauseDto;
5468

5569
@IsArray()
56-
@IsNumber({}, { each: true })
70+
@ValidateNested({ each: true })
71+
@Type(() => ProjectWithPowerDto)
5772
@IsNotEmpty()
58-
projectIds: number[];
73+
projectIds: ProjectWithPowerDto[];
5974
}

0 commit comments

Comments
 (0)