Skip to content

Commit 061b22a

Browse files
committed
chore: delete totalcoherent references, delete computecoherence test, improve level calculation
1 parent 61bffc7 commit 061b22a

File tree

3 files changed

+23
-48
lines changed

3 files changed

+23
-48
lines changed

subgraph/core/src/entities/User.ts

-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
import { BigInt, BigDecimal } from "@graphprotocol/graph-ts";
21
import { User } from "../../generated/schema";
32
import { ONE, ZERO } from "../utils";
43

5-
export function computeCoherenceScore(totalCoherent: BigInt, totalResolvedDisputes: BigInt): BigInt {
6-
const smoothingFactor = BigDecimal.fromString("10");
7-
8-
let denominator = totalResolvedDisputes.toBigDecimal().plus(smoothingFactor);
9-
let coherencyRatio = totalCoherent.toBigDecimal().div(denominator);
10-
11-
const coherencyScore = coherencyRatio.times(BigDecimal.fromString("100"));
12-
13-
const roundedScore = coherencyScore.plus(BigDecimal.fromString("0.5"));
14-
15-
return BigInt.fromString(roundedScore.toString().split(".")[0]);
16-
}
17-
184
export function ensureUser(id: string): User {
195
const user = User.load(id);
206

subgraph/core/tests/user.test.ts

-9
This file was deleted.

web/src/utils/userLevelCalculation.ts

+23-25
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
1-
export const levelTitles = [
2-
{ level: 0, title: "Diogenes" },
3-
{ level: 1, title: "Pythagoras" },
4-
{ level: 2, title: "Socrates" },
5-
{ level: 3, title: "Plato" },
6-
{ level: 4, title: "Aristotle" },
1+
interface ILevelCriteria {
2+
level: number;
3+
title: string;
4+
minDisputes: number;
5+
minScore: number;
6+
maxScore: number;
7+
}
8+
9+
const levelCriteria: ILevelCriteria[] = [
10+
{ level: 0, title: "Diogenes", minDisputes: 3, minScore: 0, maxScore: 49 },
11+
{ level: 1, title: "Pythagoras", minDisputes: 0, minScore: 0, maxScore: 70 },
12+
{ level: 2, title: "Socrates", minDisputes: 3, minScore: 71, maxScore: 80 },
13+
{ level: 3, title: "Plato", minDisputes: 7, minScore: 81, maxScore: 90 },
14+
{ level: 4, title: "Aristotle", minDisputes: 10, minScore: 91, maxScore: 100 },
715
];
816

917
export const getUserLevelData = (coherencyScore: number, totalResolvedDisputes: number) => {
10-
if (totalResolvedDisputes >= 3 && coherencyScore < 50) {
11-
return levelTitles.find(({ level }) => level === 0);
12-
}
13-
14-
if (totalResolvedDisputes === 0 || (totalResolvedDisputes >= 1 && coherencyScore >= 0 && coherencyScore <= 70)) {
15-
return levelTitles.find(({ level }) => level === 1);
16-
}
17-
18-
if (totalResolvedDisputes >= 3 && coherencyScore > 70 && coherencyScore <= 80) {
19-
return levelTitles.find(({ level }) => level === 2);
20-
}
21-
22-
if (totalResolvedDisputes >= 7 && coherencyScore > 80 && coherencyScore <= 90) {
23-
return levelTitles.find(({ level }) => level === 3);
24-
}
25-
26-
if (totalResolvedDisputes >= 10 && coherencyScore > 90) {
27-
return levelTitles.find(({ level }) => level === 4);
18+
for (const criteria of levelCriteria) {
19+
if (
20+
totalResolvedDisputes >= criteria.minDisputes &&
21+
coherencyScore >= criteria.minScore &&
22+
coherencyScore <= criteria.maxScore
23+
) {
24+
return levelCriteria.find(({ level }) => level === criteria.level);
25+
}
2826
}
2927

30-
return levelTitles.find(({ level }) => level === 1);
28+
return levelCriteria.find(({ level }) => level === 1);
3129
};

0 commit comments

Comments
 (0)