Skip to content

Commit

Permalink
ensure calculations consider only approved applications
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Jan 15, 2025
1 parent 5c1a0e8 commit 31d3116
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/utils/calculate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type Metric } from '@/entity/Metric';
import { type Distribution } from '@/entity/Pool';
import { type Vote } from '@/entity/Vote';
import { NotFoundError } from '@/errors';
import { indexerClient, Status } from '@/ext/indexer';
import poolService from '@/service/PoolService';

interface MetricFetcherResponse {
Expand Down Expand Up @@ -51,6 +52,21 @@ const getHardcodedVotes = (): Array<Partial<Vote>> => {
];
};

const getApprovedAlloApplicationIds = async (
alloPoolId: string,
chainId: number
): Promise<string[]> => {
const indexerPoolData = await indexerClient.getRoundWithApplications({
chainId,
roundId: alloPoolId,
});
return (
indexerPoolData?.applications
.filter(application => application.status === Status.APPROVED)
.map(application => application.id) ?? []
);
};

// TODO: Implement the gr8LucasMetricFetcher function to fetch metrics from the external endpoint
const gr8LucasMetricFetcher = async (
alloPoolId: string,
Expand Down Expand Up @@ -167,12 +183,23 @@ export const calculate = async (
// Add unAccountedBallots to the votes
if (unAccountedBallots != null) votes.push(unAccountedBallots);

// Fetch approved allo application ids
const approvedAlloApplicationIds = await getApprovedAlloApplicationIds(
alloPoolId,
chainId
);

// Fetch metrics from the external endpoint
const applicationToMetricsScores = await gr8LucasMetricFetcher(
const fetchedApplicaionMetricScores = await gr8LucasMetricFetcher(
alloPoolId,
chainId
);

// Filter the applicationToMetricsScores array to only include approved applications
const applicationToMetricsScores = fetchedApplicaionMetricScores.filter(
metric => approvedAlloApplicationIds.includes(metric.alloApplicationId)
);

// Precompute min and max values for each metric
const metricBounds: Record<string, { minValue: number; maxValue: number }> =
{};
Expand Down

0 comments on commit 31d3116

Please sign in to comment.