polish(anim): 结果按「先答案后过程」排序,per_frame 默认不返回(include_frames 开启);试用页画布画候选点与轨迹
Build and Push / build (push) Successful in 9m11s
Build and Push / build (push) Successful in 9m11s
This commit is contained in:
@@ -53,16 +53,18 @@ type Track struct {
|
||||
Frames []int `json:"frames"`
|
||||
}
|
||||
|
||||
// AnimResult 动图任务的返回
|
||||
// AnimResult 动图任务的返回。
|
||||
// 字段顺序按「先给答案、再给过程」排:调用方最关心 click / candidates,
|
||||
// per_frame 只在显式要求(include_frames=true)时返回,避免默认响应几百 KB。
|
||||
type AnimResult struct {
|
||||
UnvisitedCnt int `json:"unvisited_count"`
|
||||
Click []Point `json:"click"`
|
||||
Candidates []CandidatePoint `json:"candidates"`
|
||||
Tracks []Track `json:"tracks"`
|
||||
Frames int `json:"frames"`
|
||||
UsedFrames int `json:"used_frames"`
|
||||
PerFrame []FrameObjects `json:"per_frame"`
|
||||
Tracks []Track `json:"tracks"`
|
||||
Candidates []CandidatePoint `json:"candidates"`
|
||||
Click []Point `json:"click"`
|
||||
Model string `json:"model"`
|
||||
UnvisitedCnt int `json:"unvisited_count"`
|
||||
PerFrame []FrameObjects `json:"per_frame,omitempty"`
|
||||
}
|
||||
|
||||
// decodeFrames 把输入拆成多帧。
|
||||
|
||||
@@ -26,9 +26,10 @@ type taskRequest struct {
|
||||
X int `json:"x"`
|
||||
Y int `json:"y"`
|
||||
} `json:"candidates"`
|
||||
Radius float64 `json:"radius"`
|
||||
ClassFilter string `json:"class_filter"`
|
||||
Step int `json:"step"`
|
||||
Radius float64 `json:"radius"`
|
||||
ClassFilter string `json:"class_filter"`
|
||||
Step int `json:"step"`
|
||||
IncludeFrames bool `json:"include_frames"`
|
||||
}
|
||||
|
||||
// TaskTypes GET /api/task/types —— 列出当前支持的多帧任务类型
|
||||
@@ -68,6 +69,9 @@ func (h *CaptchaHandler) RunTask(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if !req.IncludeFrames {
|
||||
res.PerFrame = nil
|
||||
}
|
||||
c.JSON(http.StatusOK, model.CaptchaResult{Result: res})
|
||||
default:
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
|
||||
@@ -146,6 +146,43 @@ export default function PlaygroundPage({ token, role, onLogout }: Props) {
|
||||
ctx.lineTo(r, cv.height)
|
||||
ctx.stroke()
|
||||
}
|
||||
// 动图任务:画候选点(未经过=白色实心,已跳过=灰色空心)+ 轨迹折线
|
||||
const anim = (result as { result?: { candidates?: {x:number;y:number;visited:boolean;hits:number}[]; tracks?: {class:string;path:{x:number;y:number}[]}[] } })?.result
|
||||
if (anim?.tracks?.length) {
|
||||
anim.tracks.slice(0, 6).forEach((tr, ti) => {
|
||||
if (!tr.path || tr.path.length < 2) return
|
||||
ctx.strokeStyle = ti === 0 ? 'rgba(255,255,255,0.55)' : 'rgba(255,255,255,0.25)'
|
||||
ctx.lineWidth = 1.2 * scale
|
||||
ctx.beginPath()
|
||||
tr.path.forEach((pt, i) => (i ? ctx.lineTo(pt.x, pt.y) : ctx.moveTo(pt.x, pt.y)))
|
||||
ctx.stroke()
|
||||
})
|
||||
}
|
||||
if (anim?.candidates?.length) {
|
||||
anim.candidates.forEach((pt, i) => {
|
||||
const rad = 8 * scale
|
||||
ctx.lineWidth = 1.6 * scale
|
||||
if (pt.visited) {
|
||||
ctx.strokeStyle = 'rgba(255,255,255,0.45)'
|
||||
ctx.beginPath()
|
||||
ctx.arc(pt.x, pt.y, rad, 0, Math.PI * 2)
|
||||
ctx.stroke()
|
||||
} else {
|
||||
ctx.fillStyle = '#ffffff'
|
||||
ctx.beginPath()
|
||||
ctx.arc(pt.x, pt.y, rad, 0, Math.PI * 2)
|
||||
ctx.fill()
|
||||
ctx.strokeStyle = '#0d0d0d'
|
||||
ctx.beginPath()
|
||||
ctx.arc(pt.x, pt.y, rad + 2 * scale, 0, Math.PI * 2)
|
||||
ctx.stroke()
|
||||
}
|
||||
ctx.fillStyle = pt.visited ? 'rgba(255,255,255,0.6)' : '#ffffff'
|
||||
ctx.font = `${11 * scale}px ui-monospace, monospace`
|
||||
ctx.fillText(`${i + 1}`, pt.x + rad + 3 * scale, pt.y - rad)
|
||||
})
|
||||
}
|
||||
|
||||
if (capKey === 'slider_comparison' && Array.isArray(r) && r.length >= 2) {
|
||||
const [x, y] = r as number[]
|
||||
ctx.strokeStyle = '#c0c0c0'
|
||||
|
||||
Reference in New Issue
Block a user