Skip to content

Commit

Permalink
Add bh stat endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahdigh committed Oct 10, 2024
1 parent dc1773b commit 1a35c78
Show file tree
Hide file tree
Showing 14 changed files with 3,437 additions and 31,431 deletions.
98 changes: 98 additions & 0 deletions src/flow/flow.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { sortProjectId } from 'src/utils';
import { RemoveLastVoteDto, SetCoIDto } from './dto/bodies';
import { AgoraBallotPost } from 'src/rpgf5-data-import/submit';
import { projects } from 'src/rpgf5-data-import/all-projects-930';
import { ProjectType } from '@prisma/client';
import { badgeholders } from 'src/rpgf5-data-import/badgeholders';

export const getAllProjects = (category: number) => {
switch (category) {
Expand Down Expand Up @@ -203,6 +205,102 @@ export class FlowController {
return 'Success';
}

@ApiOperation({
summary: 'Used for a pairwise vote between two collections',
})
@Get('/temp/finishers')
async findFinishers() {
const allUsers = await this.prismaService.user.findMany();

let count = 0;

const progresses = [];

for (let i = 0; i < allUsers.length; i++) {
const user = allUsers[i];

const userId = user.id;
const res = await this.prismaService.vote.findFirst({
where: {
userId: userId,
},
include: { project1: true },
});
if (!res) progresses.push({ userAddress: user.address, progress: 0 });
const parentCollection = res?.project1.parentId;

const [collection, votes, projects, allStars, projectCoIs] =
await Promise.all([
this.prismaService.project.findUnique({
where: {
id: parentCollection || -1,
type: {
in: [ProjectType.collection, ProjectType.compositeProject],
},
},
select: { name: true, id: true },
}),
this.prismaService.vote.findMany({
where: {
userId: userId,
project1: { parentId: parentCollection },
project2: { parentId: parentCollection },
},
}),
this.prismaService.project.findMany({
where: {
parentId: parentCollection || -1,
},
}),
this.flowService.getUserProjectStars(userId, parentCollection || -1),
this.prismaService.projectCoI.findMany({
where: {
project: { parentId: parentCollection },
userId,
},
}),
]);

// projects except those with conflict of interest
const allProjects = projects
.filter((item) => !projectCoIs.find((el) => el.projectId === item.id))
.sort((a, b) =>
(a.implicitCategory || '').localeCompare(b.implicitCategory || ''),
);

const projectStars = allStars.filter(
(item) => !projectCoIs.find((el) => el.projectId === item.projectId),
);

const allVotes = votes.filter(
(item) =>
!projectCoIs.find(
(el) =>
el.projectId === item.project1Id ||
el.projectId === item.project2Id,
),
);

const realProgress = this.flowService.calculateProgress(
allVotes,
projectStars,
allProjects,
);

count++;
console.log('Done:', count / allUsers.length);
progresses.push({ userAddress: user.address, progress: realProgress });
}

return progresses
.filter((el) => el.progress * 3 >= 1)
.filter((el) =>
badgeholders
.map((item) => item.toLowerCase())
.includes(el.userAddress.toLowerCase()),
);
}

@UseGuards(AuthGuard)
@ApiOperation({
summary: 'Used for a pairwise vote between two collections',
Expand Down
2 changes: 1 addition & 1 deletion src/flow/flow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ export class FlowService {
});
};

private calculateProgress = (
calculateProgress = (
allVotes: { project1Id: number; project2Id: number }[],
projectStars: { projectId: number; star: number }[],
allProjects: { id: number }[],
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2842,7 +2842,7 @@ export const projects = [
},
team: ['230074', '292202'],
},
name: 'Sedge ',
name: 'Sedge',
description:
'Sedge is a command-line tool that simplifies running nodes for the OP Stack, Ethereum mainnet, and other networks, including testnets.\nSedge makes it easy to set up nodes for OP Mainnet, Base Mainnet, OP Sepolia, and Base Sepolia. Sedge also supports various client implementations, not just Nethermind, allowing users to manage OP Stack and Ethereum nodes quickly and efficiently.',
profileAvatarUrl:
Expand Down Expand Up @@ -11231,7 +11231,7 @@ export const projects = [
category: 'Utility',
applicationCategory: 'OP_STACK_TOOLING',
organization: null,
name: 'Understanding-Optimism-Codebase ',
name: 'Understanding-Optimism-Codebase',
description:
'This document provides a comprehensive explanation of the Optimism codebase, aiming to help newcomers to Optimism quickly get started and truly understand how the code flow in the codebase works.\nWritten in two language versions right now, EN & CN.',
profileAvatarUrl:
Expand Down
Loading

0 comments on commit 1a35c78

Please sign in to comment.