Skip to content

Commit 90848f8

Browse files
committed
Fix progress calculation all 1 stars bug
1 parent 4b300b4 commit 90848f8

File tree

3 files changed

+91
-7
lines changed

3 files changed

+91
-7
lines changed

src/flow/dto/responses.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ export const delegateStatusExample = {
149149
],
150150
},
151151
toYou: {
152+
uniqueCollection: 3,
153+
uniqueCollectionDelegators: 1,
154+
uniqueBudgetDelegators: 3,
152155
budget: [
153156
{
154157
metadata: {
@@ -158,13 +161,13 @@ export const delegateStatusExample = {
158161
},
159162
{
160163
metadata: {
161-
username: 'some2.eth',
164+
username: 'some.eth',
162165
profileUrl: 'https://example.com/some.png',
163166
},
164167
},
165168
{
166169
metadata: {
167-
username: 'some3.eth',
170+
username: 'some.eth',
168171
profileUrl: 'https://example.com/some.png',
169172
},
170173
},
@@ -173,14 +176,14 @@ export const delegateStatusExample = {
173176
{
174177
collectionId: 1,
175178
metadata: {
176-
username: 'elon.eth',
179+
username: 'some.eth',
177180
profileUrl: 'https://example.com/elon.png',
178181
},
179182
},
180183
{
181-
collectionId: 1,
184+
collectionId: 2,
182185
metadata: {
183-
username: 'adele.eth',
186+
username: 'some.eth',
184187
profileUrl: 'https://example.com/some.png',
185188
},
186189
},
@@ -202,6 +205,9 @@ export const delegateStatusExample2 = {
202205
],
203206
},
204207
toYou: {
208+
uniqueCollection: 0,
209+
uniqueCollectionDelegators: 0,
210+
uniqueBudgetDelegators: 0,
205211
budget: [],
206212
collections: [],
207213
},

src/flow/flow.controller.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,12 @@ export class FlowController {
11361136
return 'Success';
11371137
}
11381138

1139+
@Get('/test')
1140+
async test() {
1141+
await this.flowService.test();
1142+
return 'Success';
1143+
}
1144+
11391145
// @UseGuards(AuthGuard)
11401146
// @Post('/reset')
11411147
// async resetVotes(@Req() { userId }: AuthedReq, @Body('cid') cid: number) {

src/flow/flow.service.ts

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,8 @@ export class FlowService {
647647

648648
starSubcategories.null = nullProjects.length;
649649

650+
// console.log('dist', starSubcategories);
651+
650652
let total = 0;
651653
for (const key in starSubcategories) {
652654
if (key === '1') continue;
@@ -661,9 +663,79 @@ export class FlowService {
661663
getStarsById(vote.project1Id) !== 1,
662664
);
663665

666+
// console.log('effectiveVotes', effectiveVotes);
667+
// console.log('total:', total);
668+
669+
if (total === 0) {
670+
return allVotes.length / combinations(allProjects.length, 2);
671+
}
672+
664673
return effectiveVotes.length / total;
665674
};
666675

676+
test = async () => {
677+
const userId = 13;
678+
const parentCollection = 1;
679+
680+
const [collection, votes, projects, allStars, projectCoIs] =
681+
await Promise.all([
682+
this.prismaService.project.findUnique({
683+
where: {
684+
id: parentCollection || -1,
685+
type: ProjectType.collection,
686+
},
687+
select: { name: true, id: true },
688+
}),
689+
this.prismaService.vote.findMany({
690+
where: {
691+
userId: userId,
692+
project1: { parentId: parentCollection },
693+
project2: { parentId: parentCollection },
694+
},
695+
}),
696+
this.prismaService.project.findMany({
697+
where: {
698+
parentId: parentCollection || -1,
699+
},
700+
}),
701+
this.getUserProjectStars(userId, parentCollection || -1),
702+
this.prismaService.projectCoI.findMany({
703+
where: {
704+
project: { parentId: parentCollection },
705+
userId,
706+
},
707+
}),
708+
]);
709+
710+
// projects except those with conflict of interest
711+
const allProjects = projects
712+
.filter((item) => !projectCoIs.find((el) => el.projectId === item.id))
713+
.sort((a, b) =>
714+
(a.implicitCategory || '').localeCompare(b.implicitCategory || ''),
715+
);
716+
717+
const projectStars = allStars.filter(
718+
(item) => !projectCoIs.find((el) => el.projectId === item.projectId),
719+
);
720+
721+
const allVotes = votes.filter(
722+
(item) =>
723+
!projectCoIs.find(
724+
(el) =>
725+
el.projectId === item.project1Id ||
726+
el.projectId === item.project2Id,
727+
),
728+
);
729+
730+
const realProgress = this.calculateProgress(
731+
allVotes,
732+
projectStars,
733+
allProjects,
734+
);
735+
736+
console.log(realProgress);
737+
};
738+
667739
// if projectId is provided, the returend pair must include that project if possible
668740
getPairs = async (
669741
userId: number,
@@ -727,7 +799,7 @@ export class FlowService {
727799
allProjects,
728800
);
729801

730-
const progress = Math.min(1, realProgress * 3);
802+
const progress = Math.min(1, realProgress * 10);
731803

732804
if (progress === 1) {
733805
if (collection) {
@@ -998,7 +1070,7 @@ export class FlowService {
9981070

9991071
console.log('summation', summation);
10001072
// console.log("to fn3 summation", summation)
1001-
if (Math.abs(1 - toFixedNumber(summation, 5)) > 0.00001)
1073+
if (Math.abs(1 - toFixedNumber(summation, 3)) > 0.001)
10021074
throw new BadRequestException('Sumamtion of shares must equal 1');
10031075
};
10041076

0 commit comments

Comments
 (0)