Skip to content

Commit

Permalink
Merge branch 'automate_exporting_qf_round_analysis_matching_logic' in…
Browse files Browse the repository at this point in the history
…to automate_exporting_qf_round_sybils_analysis_data
  • Loading branch information
mohammadranjbarz committed Nov 9, 2023
2 parents 2b41cdc + b8bad29 commit 557e2c9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/server/adminJs/tabs/qfRoundTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const returnAllQfRoundDonationAnalysis = async (
const qfRoundDonationsRows = await getQfRoundActualDonationDetails(
qfRoundId,
);

logger.debug('qfRoundDonationsRows', qfRoundDonationsRows);
await addQfRoundDonationsSheetToSpreadsheet({
rows: qfRoundDonationsRows,
qfRoundId,
Expand Down
19 changes: 10 additions & 9 deletions src/services/googleSheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface ProjectExport {
secondWalletAddress: string;
secondWalletAddressNetwork: string;
}
interface QfRoundDonationRow {
export interface QfRoundDonationRow {
projectName: string;
// Pattern is networkId-projectAddress,... Example: 1-0x123...456,10,ETH,0x123...456
addresses: string;
Expand Down Expand Up @@ -154,21 +154,22 @@ export const addQfRoundDonationsSheetToSpreadsheet = async (params: {

const currentDate = moment().toDate();
const headers = [
'Project Name',
'Addresses',
'Link',
'All USD Received',
'All USD Received After Sybils Analysis',
'Total Donors',
'Unique Donors',
'Real Matching Fund',
'projectName',
'addresses',
'link',
'allUsdReceived',
'allUsdReceivedAfterSybilsAnalysis',
'totalDonors',
'uniqueDonors',
'realMatchingFund',
];
const { rows, qfRoundId } = params;

const sheet = await spreadSheet.addSheet({
headerValues: headers,
title: `QfRound -${qfRoundId} - ${currentDate.toDateString()} ${currentDate.getTime()}`,
});
logger.debug('addQfRoundDonationsSheetToSpreadsheet', params);
await sheet.addRows(rows);
} catch (e) {
logger.error('addQfRoundDonationsSheetToSpreadsheet error', e);
Expand Down
14 changes: 7 additions & 7 deletions src/services/projectViewsService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { QfRound } from '../entities/qfRound';
import { AppDataSource } from '../orm';
import { logger } from '../utils/logger';
import { QfRoundDonationRow } from './googleSheets';

export const refreshProjectEstimatedMatchingView = async (): Promise<void> => {
logger.debug('Refresh project_estimated_matching_view materialized view');
Expand Down Expand Up @@ -29,7 +30,9 @@ export const refreshProjectDonationSummaryView = async (): Promise<void> => {
);
};

export const getQfRoundActualDonationDetails = async (qfRoundId: Number) => {
export const getQfRoundActualDonationDetails = async (
qfRoundId: Number,
): Promise<QfRoundDonationRow[]> => {
const qfRound = await QfRound.createQueryBuilder('qfRound')
.where('qfRound.id = :id', { id: qfRoundId })
.getOne();
Expand All @@ -47,20 +50,17 @@ export const getQfRoundActualDonationDetails = async (qfRoundId: Number) => {
let totalReward = qfRound!.allocatedFund;
const qfRoundMaxReward =
totalReward * Number(process.env.QF_ROUND_MAX_REWARD_PERCENTAGE || 0.2);
let totalWeight = rows.reduce(
(a, b) => a.donationsSqrtRootSumSquared + b.donationsSqrtRootSumSquared,
0,
);
let totalWeight = rows.reduce((accumulator, currentRow) => {
return accumulator + currentRow.donationsSqrtRootSumSquared;
}, 0);

for (const row of rows) {
const weight = row.donationsSqrtRootSumSquared;
const reward = Math.min(
(totalReward * weight) / totalWeight,
qfRoundMaxReward,
);

row.actualMatching = reward;

totalReward -= reward;
totalWeight -= weight;
}
Expand Down

0 comments on commit 557e2c9

Please sign in to comment.