Skip to content

Commit 03b36c6

Browse files
committed
chore(subgraph): simplify coherence calculation
1 parent a41c16d commit 03b36c6

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

subgraph/src/entities/User.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@ import { User } from "../../generated/schema";
33
import { ONE, ZERO } from "../utils";
44

55
export function computeCoherenceScore(totalCoherent: BigInt, totalResolvedDisputes: BigInt): BigInt {
6-
const smoothingFactor = BigInt.fromI32(10);
7-
const shiftFactor = BigInt.fromI32(1000);
8-
let denominator = totalResolvedDisputes.plus(smoothingFactor);
9-
let coherencyRatio = totalCoherent.toBigDecimal().div(denominator.toBigDecimal());
6+
const smoothingFactor = BigDecimal.fromString("10");
7+
8+
let denominator = totalResolvedDisputes.toBigDecimal().plus(smoothingFactor);
9+
let coherencyRatio = totalCoherent.toBigDecimal().div(denominator);
10+
1011
const coherencyScore = coherencyRatio.times(BigDecimal.fromString("100"));
11-
const shiftedValue = coherencyScore.times(BigDecimal.fromString("1000"));
12-
const shiftedBigInt = BigInt.fromString(shiftedValue.toString().split(".")[0]);
13-
const halfShiftFactor = shiftFactor.div(BigInt.fromI32(2));
14-
const remainder = shiftedBigInt.mod(shiftFactor);
1512

16-
if (remainder.ge(halfShiftFactor)) {
17-
return shiftedBigInt.div(shiftFactor).plus(BigInt.fromI32(1));
18-
} else {
19-
return shiftedBigInt.div(shiftFactor);
20-
}
13+
const roundedScore = coherencyScore.plus(BigDecimal.fromString("0.5"));
14+
15+
return BigInt.fromString(roundedScore.toString().split(".")[0]);
2116
}
2217

2318
export function ensureUser(id: string): User {

0 commit comments

Comments
 (0)