Skip to content

Commit 3a61b38

Browse files
committed
fix: smoothing factor into the coherence score
1 parent 952ccf0 commit 3a61b38

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

subgraph/core/src/KlerosCore.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { createDisputeKitFromEvent, filterSupportedDisputeKits } from "./entitie
1919
import { createDisputeFromEvent } from "./entities/Dispute";
2020
import { createRoundFromRoundInfo, updateRoundTimeline } from "./entities/Round";
2121
import { updateCases, updateCasesAppealing, updateCasesRuled, updateCasesVoting } from "./datapoint";
22-
import { addUserActiveDispute, ensureUser } from "./entities/User";
22+
import { addUserActiveDispute, computeCoherenceScore, ensureUser } from "./entities/User";
2323
import { updateJurorStake } from "./entities/JurorTokensPerCourt";
2424
import { createDrawFromEvent } from "./entities/Draw";
2525
import { updateTokenAndEthShiftFromEvent } from "./entities/TokenAndEthShift";
@@ -156,8 +156,7 @@ export function handleNewPeriod(event: NewPeriod): void {
156156

157157
// Recalculate coherenceScore
158158
if (juror.totalResolvedVotes.gt(ZERO)) {
159-
const coherenceScore = juror.totalCoherentVotes.times(BigInt.fromI32(100)).div(juror.totalResolvedVotes);
160-
juror.coherenceScore = coherenceScore;
159+
juror.coherenceScore = computeCoherenceScore(juror.totalCoherentVotes, juror.totalResolvedVotes);
161160
}
162161

163162
juror.save();

subgraph/core/src/entities/User.ts

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

5+
export function computeCoherenceScore(totalCoherentVotes: BigInt, totalResolvedVotes: BigInt): BigInt {
6+
const smoothingFactor = BigDecimal.fromString("10");
7+
8+
let denominator = totalResolvedVotes.toBigDecimal().plus(smoothingFactor);
9+
let coherencyRatio = totalCoherentVotes.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+
418
export function ensureUser(id: string): User {
519
const user = User.load(id);
620

subgraph/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kleros/kleros-v2-subgraph",
3-
"version": "0.7.5",
3+
"version": "0.7.6",
44
"license": "MIT",
55
"scripts": {
66
"update:core:arbitrum-sepolia-devnet": "./scripts/update.sh arbitrumSepoliaDevnet arbitrum-sepolia core/subgraph.yaml",

0 commit comments

Comments
 (0)