fix : game elo estimation
This commit is contained in:
@@ -10,11 +10,12 @@ import {
|
||||
engineMultiPvAtom,
|
||||
engineNameAtom,
|
||||
gameAtom,
|
||||
gameEvalAtom,
|
||||
} from "../../states";
|
||||
import LineEvaluation from "./lineEvaluation";
|
||||
import { useCurrentPosition } from "../../hooks/useCurrentPosition";
|
||||
import { LineEval } from "@/types/eval";
|
||||
import Accuracies from "./accuracies";
|
||||
import PlayersMetric from "./playersMetric";
|
||||
import MoveInfo from "./moveInfo";
|
||||
import Opening from "./opening";
|
||||
|
||||
@@ -24,6 +25,7 @@ export default function AnalysisTab(props: GridProps) {
|
||||
const position = useCurrentPosition(engineName);
|
||||
const game = useAtomValue(gameAtom);
|
||||
const board = useAtomValue(boardAtom);
|
||||
const gameEval = useAtomValue(gameEvalAtom);
|
||||
|
||||
const boardHistory = board.history();
|
||||
const gameHistory = game.history();
|
||||
@@ -57,8 +59,21 @@ export default function AnalysisTab(props: GridProps) {
|
||||
: { overflow: "hidden", overflowY: "auto", ...props.sx }
|
||||
}
|
||||
>
|
||||
<Accuracies params={"accurecy"} />
|
||||
<Accuracies params={"rating"} />
|
||||
{gameEval && (
|
||||
<PlayersMetric
|
||||
title="Accuracy"
|
||||
whiteValue={`${gameEval.accuracy.white.toFixed(1)} %`}
|
||||
blackValue={`${gameEval.accuracy.black.toFixed(1)} %`}
|
||||
/>
|
||||
)}
|
||||
|
||||
{gameEval?.estimatedElo && (
|
||||
<PlayersMetric
|
||||
title="Game Rating"
|
||||
whiteValue={Math.round(gameEval.estimatedElo.white)}
|
||||
blackValue={Math.round(gameEval.estimatedElo.black)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<MoveInfo />
|
||||
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { Grid2 as Grid, Typography } from "@mui/material";
|
||||
import { useAtomValue } from "jotai";
|
||||
import { gameEvalAtom } from "../../states";
|
||||
type props = {
|
||||
params: "accurecy" | "rating";
|
||||
};
|
||||
|
||||
export default function Accuracies(props: props) {
|
||||
const gameEval = useAtomValue(gameEvalAtom);
|
||||
|
||||
if (!gameEval) return null;
|
||||
interface Props {
|
||||
title: string;
|
||||
whiteValue: string | number;
|
||||
blackValue: string | number;
|
||||
}
|
||||
|
||||
export default function PlayersMetric({
|
||||
title,
|
||||
whiteValue,
|
||||
blackValue,
|
||||
}: Props) {
|
||||
return (
|
||||
<Grid
|
||||
container
|
||||
@@ -27,14 +28,10 @@ export default function Accuracies(props: props) {
|
||||
fontWeight="bold"
|
||||
border="1px solid #424242"
|
||||
>
|
||||
{props.params === "accurecy"
|
||||
? `${gameEval?.accuracy.white.toFixed(1)} %`
|
||||
: `${Math.round(gameEval?.estimatedElo.white as number)}`}
|
||||
{whiteValue}
|
||||
</Typography>
|
||||
|
||||
<Typography align="center">
|
||||
{props.params === "accurecy" ? "Accuracies" : "Estimated Elo"}
|
||||
</Typography>
|
||||
<Typography align="center">{title}</Typography>
|
||||
<Typography
|
||||
align="center"
|
||||
sx={{ backgroundColor: "black", color: "white" }}
|
||||
@@ -44,9 +41,7 @@ export default function Accuracies(props: props) {
|
||||
fontWeight="bold"
|
||||
border="1px solid #424242"
|
||||
>
|
||||
{props.params === "accurecy"
|
||||
? `${gameEval?.accuracy.black.toFixed(1)} %`
|
||||
: `${Math.round(gameEval?.estimatedElo.black as number)}`}
|
||||
{blackValue}
|
||||
</Typography>
|
||||
</Grid>
|
||||
);
|
||||
@@ -16,6 +16,7 @@ import { useEngine } from "@/hooks/useEngine";
|
||||
import { logAnalyticsEvent } from "@/lib/firebase";
|
||||
import { SavedEvals } from "@/types/eval";
|
||||
import { useEffect, useCallback } from "react";
|
||||
import { usePlayersData } from "@/hooks/usePlayersData";
|
||||
|
||||
export default function AnalyzeButton() {
|
||||
const engineName = useAtomValue(engineNameAtom);
|
||||
@@ -29,6 +30,7 @@ export default function AnalyzeButton() {
|
||||
const [gameEval, setEval] = useAtom(gameEvalAtom);
|
||||
const game = useAtomValue(gameAtom);
|
||||
const setSavedEvals = useSetAtom(savedEvalsAtom);
|
||||
const { white, black } = usePlayersData(gameAtom);
|
||||
|
||||
const readyToAnalyse =
|
||||
engine?.getIsReady() && game.history().length > 0 && !evaluationProgress;
|
||||
@@ -48,6 +50,10 @@ export default function AnalyzeButton() {
|
||||
depth: engineDepth,
|
||||
multiPv: engineMultiPv,
|
||||
setEvaluationProgress,
|
||||
playersRatings: {
|
||||
white: white?.rating,
|
||||
black: black?.rating,
|
||||
},
|
||||
});
|
||||
|
||||
setEval(newGameEval);
|
||||
@@ -84,6 +90,8 @@ export default function AnalyzeButton() {
|
||||
gameFromUrl,
|
||||
setGameEval,
|
||||
setSavedEvals,
|
||||
white.rating,
|
||||
black.rating,
|
||||
]);
|
||||
|
||||
// Automatically analyze when a new game is loaded and ready to analyze
|
||||
|
||||
Reference in New Issue
Block a user