@@ -18,22 +18,38 @@ const tooltipMsg =
1818 " using the number of times you have been coherent and the total cases you" +
1919 " have been in." ;
2020
21+ const levelTitles = [
22+ { scoreRange : [ 0 , 20 ] , level : 0 , title : "Diogenes" } ,
23+ { scoreRange : [ 20 , 40 ] , level : 1 , title : "Pythagoras" } ,
24+ { scoreRange : [ 40 , 60 ] , level : 2 , title : "Socrates" } ,
25+ { scoreRange : [ 60 , 80 ] , level : 3 , title : "Plato" } ,
26+ { scoreRange : [ 80 , 100 ] , level : 4 , title : "Aristotle" } ,
27+ ] ;
28+
2129const Coherency : React . FC = ( ) => {
2230 const { address } = useAccount ( ) ;
2331 const { data } = useUserQuery ( address ?. toLowerCase ( ) ) ;
2432 const totalCoherent = parseInt ( data ?. user ?. totalCoherent ) ?? 0 ;
2533 const totalResolvedDisputes = parseInt ( data ?. user ?. totalResolvedDisputes ) ?? 1 ;
2634 const coherencyScore = calculateCoherencyScore ( totalCoherent , totalResolvedDisputes ) ;
35+ const roundedCoherencyScore = Math . round ( coherencyScore * 100 ) ;
36+
37+ const { level, title } =
38+ levelTitles . find ( ( { scoreRange } ) => {
39+ return roundedCoherencyScore >= scoreRange [ 0 ] && roundedCoherencyScore < scoreRange [ 1 ] ;
40+ } ) ?? levelTitles [ 0 ] ;
2741
2842 return (
2943 < Container >
30- < small > Aristotle</ small >
31- < label > Level 4</ label >
32- < CircularProgress progress = { ( totalCoherent / Math . max ( totalResolvedDisputes , 1 ) ) * 100 } />
44+ < small > { title } </ small >
45+ < label > Level { level } </ label >
46+ < CircularProgress
47+ progress = { parseFloat ( ( ( totalCoherent / Math . max ( totalResolvedDisputes , 1 ) ) * 100 ) . toFixed ( 2 ) ) }
48+ />
3349 < WithHelpTooltip place = "left" { ...{ tooltipMsg } } >
3450 < label >
3551 Coherency Score:
36- < small > { coherencyScore . toFixed ( 3 ) } </ small >
52+ < small > { coherencyScore . toFixed ( 2 ) } </ small >
3753 </ label >
3854 </ WithHelpTooltip >
3955 </ Container >
0 commit comments