Skip to content

Commit

Permalink
chore: add dev script to recalculate donated eval point scores
Browse files Browse the repository at this point in the history
  • Loading branch information
FreekBes committed Nov 4, 2024
1 parent 481b856 commit 3cde403
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/dev/recalculate_pool_donation_scores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();

const TYPE_POINT_DONATED = 'point_donated';

const main = async function(): Promise<void> {
const newFixedPointType = await prisma.codamCoalitionFixedType.findFirst({
where: {
type: TYPE_POINT_DONATED,
}
});
if (!newFixedPointType) {
throw new Error('No point_donated fixed type found');
}
const scores = await prisma.codamCoalitionScore.findMany({
where: {
fixed_type_id: TYPE_POINT_DONATED,
},
});
console.log(`Found ${scores.length} scores`);
for (const score of scores) {
// Parse amount of points donated from the reason... no better way ATM
const pointsDonated = parseInt(score.reason.split(' ')[1]);
if (isNaN(pointsDonated)) {
throw new Error('Invalid amount of points');
}
const newAmount = pointsDonated * newFixedPointType.point_amount;
await prisma.codamCoalitionScore.update({
where: {
id: score.id,
},
data: {
amount: newAmount,
},
});
console.log(`Updated score ${score.id} from ${score.amount} to ${newAmount}`);
}
};

main().then(() => {
try {
console.log('Done');
process.exit(0);
}
catch (err) {
console.error(err);
process.exit(1);
}
});

0 comments on commit 3cde403

Please sign in to comment.