fix(analysis): fix API field mismatch and enable full game analysis
Map raw backend response (evaluation/continuationMoves) to frontend model (eval/winChance/continuations). Add getFenHistory() call after loading a game or PGN so runAnalysis() gets per-ply FEN history and triggers analyzeGame() instead of falling back to single-position analysis. Remove !hasAnnotations guard so positionAnalysis card shows even when a game is loaded. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { environment } from '../../environments/environment';
|
||||
import {
|
||||
GameFull,
|
||||
@@ -9,7 +10,7 @@ import {
|
||||
LegalMovesResponse,
|
||||
PlayerInfo,
|
||||
} from '../models/game.models';
|
||||
import { AnalysisRequest, AnalysisResponse } from '../models/analysis.models';
|
||||
import { AnalysisRequest, AnalysisResponse, RawAnalysisResponse } from '../models/analysis.models';
|
||||
import { StreamHandlerService } from './stream-handler.service';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@@ -78,8 +79,28 @@ export class GameApiService {
|
||||
return this.http.post<void>(`${this.apiBase}${this.apiPath}/${gameId}/draw/offer`, {});
|
||||
}
|
||||
|
||||
getFenHistory(gameId: string): Observable<string[]> {
|
||||
return this.http
|
||||
.get<{ fens: string[] }>(`${this.apiBase}${this.apiPath}/${gameId}/fen-history`)
|
||||
.pipe(map((r) => r.fens));
|
||||
}
|
||||
|
||||
analyzePosition(request: AnalysisRequest): Observable<AnalysisResponse> {
|
||||
return this.http.post<AnalysisResponse>(`${this.apiBase}/api/analysis/position`, request);
|
||||
return this.http
|
||||
.post<RawAnalysisResponse>(`${this.apiBase}/api/analysis/position`, request)
|
||||
.pipe(map((raw) => this.mapAnalysisResponse(raw)));
|
||||
}
|
||||
|
||||
private mapAnalysisResponse(raw: RawAnalysisResponse): AnalysisResponse {
|
||||
const evalPawns = raw.evaluation / 100;
|
||||
return {
|
||||
eval: evalPawns,
|
||||
winChance: 1 / (1 + Math.exp(-0.374 * evalPawns)),
|
||||
depth: raw.depth,
|
||||
bestMove: raw.bestMove,
|
||||
mate: raw.mate,
|
||||
continuations: raw.continuationMoves ?? [],
|
||||
};
|
||||
}
|
||||
|
||||
private resolveWsBase(): string {
|
||||
|
||||
Reference in New Issue
Block a user