Skip to content

Commit 778fc80

Browse files
fix: fit api schema
1 parent 8c59f6c commit 778fc80

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

src/api/analysis/analysis.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -674,14 +674,10 @@ export interface EngineAnalysisPosition {
674674
}
675675
}
676676

677-
export interface EngineAnalysisData {
678-
positions: EngineAnalysisPosition[]
679-
}
680-
681677
// Store client-side engine analysis to backend
682678
export const storeEngineAnalysis = async (
683679
gameId: string,
684-
analysisData: EngineAnalysisData,
680+
analysisData: EngineAnalysisPosition[],
685681
): Promise<void> => {
686682
const res = await fetch(
687683
buildUrl(`analysis/store_engine_analysis/${gameId}`),
@@ -706,7 +702,7 @@ export const storeEngineAnalysis = async (
706702
// Retrieve stored engine analysis from backend
707703
export const getEngineAnalysis = async (
708704
gameId: string,
709-
): Promise<EngineAnalysisData | null> => {
705+
): Promise<EngineAnalysisPosition[] | null> => {
710706
const res = await fetch(buildUrl(`analysis/get_engine_analysis/${gameId}`))
711707

712708
if (res.status === 401) {

src/hooks/useAnalysisController/useAnalysisController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ export const useAnalysisController = (
9494
const analysisData = collectEngineAnalysisData(game.tree)
9595

9696
// Only save if there's actually some analysis to save
97-
if (analysisData.positions.length === 0) {
97+
if (analysisData.length === 0) {
9898
return
9999
}
100100

101101
// Check if we have meaningful analysis (decent depth or Maia data)
102-
const hasMeaningfulAnalysis = analysisData.positions.some(
102+
const hasMeaningfulAnalysis = analysisData.some(
103103
(pos) => (pos.stockfish && pos.stockfish.depth >= 12) || pos.maia,
104104
)
105105

@@ -117,7 +117,7 @@ export const useAnalysisController = (
117117
setLastSavedCacheKey(cacheKey)
118118
console.log(
119119
'Analysis saved to backend:',
120-
analysisData.positions.length,
120+
analysisData.length,
121121
'positions',
122122
)
123123
} catch (error) {

src/lib/analysisStorage.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { GameTree, GameNode } from 'src/types'
2-
import {
3-
EngineAnalysisData,
4-
EngineAnalysisPosition,
5-
} from 'src/api/analysis/analysis'
2+
import { EngineAnalysisPosition } from 'src/api/analysis/analysis'
63

74
/**
85
* Collects analysis data from a game tree to send to the backend
96
*/
107
export const collectEngineAnalysisData = (
118
gameTree: GameTree,
12-
): EngineAnalysisData => {
9+
): EngineAnalysisPosition[] => {
1310
const positions: EngineAnalysisPosition[] = []
1411
const mainLine = gameTree.getMainLine()
1512

@@ -40,19 +37,19 @@ export const collectEngineAnalysisData = (
4037
positions.push(position)
4138
})
4239

43-
return { positions }
40+
return positions
4441
}
4542

4643
/**
4744
* Applies stored analysis data back to a game tree
4845
*/
4946
export const applyEngineAnalysisData = (
5047
gameTree: GameTree,
51-
analysisData: EngineAnalysisData,
48+
analysisData: EngineAnalysisPosition[],
5249
): void => {
5350
const mainLine = gameTree.getMainLine()
5451

55-
analysisData.positions.forEach((positionData) => {
52+
analysisData.forEach((positionData) => {
5653
const { ply, maia, stockfish } = positionData
5754

5855
// Find the corresponding node (ply is the index in the main line)
@@ -114,10 +111,9 @@ const calculateRelativeCp = (cpVec: {
114111
* Generate a unique cache key for analysis data
115112
*/
116113
export const generateAnalysisCacheKey = (
117-
analysisData: EngineAnalysisData,
114+
analysisData: EngineAnalysisPosition[],
118115
): string => {
119-
// Create a hash-like key based on positions and their analysis
120-
const keyData = analysisData.positions.map((pos) => ({
116+
const keyData = analysisData.map((pos) => ({
121117
ply: pos.ply,
122118
fen: pos.fen,
123119
hasStockfish: !!pos.stockfish,

0 commit comments

Comments
 (0)