From 247d5fa6c87da580f36f56620bc4fd20998b9c92 Mon Sep 17 00:00:00 2001 From: stepandel Date: Thu, 5 Sep 2024 17:20:46 -0700 Subject: [PATCH] :sparkles: unable top_weighted disribution method --- .../ballots/ballotDistributionStrategy.ts | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/app/api/common/ballots/ballotDistributionStrategy.ts b/src/app/api/common/ballots/ballotDistributionStrategy.ts index 406338629..6efba25d3 100644 --- a/src/app/api/common/ballots/ballotDistributionStrategy.ts +++ b/src/app/api/common/ballots/ballotDistributionStrategy.ts @@ -5,7 +5,7 @@ import { fetchBallot } from "./getBallots"; export enum DistributionStrategy { IMPACT_GROUPS = "IMPACT_GROUPS", TOP_TO_BOTTOM = "TOP_TO_BOTTOM", - // TOP_WEIGHTED = "TOP_WEIGHTED", + TOP_WEIGHTED = "TOP_WEIGHTED", } const applyDistributionStrategyApi = async ( @@ -75,27 +75,27 @@ async function applyDistributionStrategyForAddress({ }); } - // if (strategy === DistributionStrategy.TOP_WEIGHTED) { - // const y = topWeighted({ - // max, - // total: totalFunding, - // n, - // }); - - // projectsAllocation.forEach((project, i) => { - // if (project.impact) { - // newProjectsAllocation.push({ - // ...project, - // allocation: y(i), - // }); - // } - // }); - - // console.log( - // "total", - // newProjectsAllocation.reduce((acc, p) => acc + (p.allocation ?? 0), 0) - // ); - // } + if (strategy === DistributionStrategy.TOP_WEIGHTED) { + const y = topWeighted({ + max: 500_000, // TODO: adjust this number + total: totalFunding, + n, + }); + + projectsAllocation.forEach((project, i) => { + if (project.impact) { + newProjectsAllocation.push({ + ...project, + allocation: y(i), + }); + } + }); + + console.log( + "total", + newProjectsAllocation.reduce((acc, p) => acc + (p.allocation ?? 0), 0) + ); + } if (strategy === DistributionStrategy.IMPACT_GROUPS) { const nk = projectsAllocation.reduce(