File tree Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -3,21 +3,16 @@ import { User } from "../../generated/schema";
33import { ONE , ZERO } from "../utils" ;
44
55export 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
2318export function ensureUser ( id : string ) : User {
You can’t perform that action at this time.
0 commit comments