niceeval 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INDEX.md +31 -33
- package/dist/agents/types.d.ts +20 -17
- package/dist/context/types.d.ts +21 -21
- package/dist/i18n/en.d.ts +10 -2
- package/dist/i18n/zh-CN.d.ts +15 -7
- package/dist/o11y/execution-tree.d.ts +103 -0
- package/dist/o11y/otlp/select.d.ts +22 -0
- package/dist/report/{react → assets}/colors.d.ts +8 -0
- package/dist/report/{react → assets}/colors.js +23 -0
- package/dist/report/built-in/index.d.ts +2 -2
- package/dist/report/built-in/index.js +2 -2
- package/dist/report/built-in/standard.d.ts +8 -1
- package/dist/report/built-in/standard.js +17 -7
- package/dist/report/components/attempt-detail/AttemptAssertions.d.ts +6 -0
- package/dist/report/components/attempt-detail/AttemptAssertions.js +17 -0
- package/dist/report/components/attempt-detail/AttemptConversation.d.ts +6 -0
- package/dist/report/components/attempt-detail/AttemptConversation.js +34 -0
- package/dist/report/components/attempt-detail/AttemptDiagnostics.d.ts +6 -0
- package/dist/report/components/attempt-detail/AttemptDiagnostics.js +7 -0
- package/dist/report/components/attempt-detail/AttemptDiff.d.ts +6 -0
- package/dist/report/components/attempt-detail/AttemptDiff.js +11 -0
- package/dist/report/components/attempt-detail/AttemptError.d.ts +6 -0
- package/dist/report/components/attempt-detail/AttemptError.js +16 -0
- package/dist/report/components/attempt-detail/AttemptFixPrompt.d.ts +6 -0
- package/dist/report/components/attempt-detail/AttemptFixPrompt.js +7 -0
- package/dist/report/components/attempt-detail/AttemptSource.d.ts +6 -0
- package/dist/report/components/attempt-detail/AttemptSource.js +27 -0
- package/dist/report/components/attempt-detail/AttemptSummary.d.ts +8 -0
- package/dist/report/components/attempt-detail/AttemptSummary.js +20 -0
- package/dist/report/components/attempt-detail/AttemptTimeline.d.ts +6 -0
- package/dist/report/components/attempt-detail/AttemptTimeline.js +28 -0
- package/dist/report/components/attempt-detail/AttemptTrace.d.ts +6 -0
- package/dist/report/components/attempt-detail/AttemptTrace.js +29 -0
- package/dist/report/components/attempt-detail/AttemptUsage.d.ts +6 -0
- package/dist/report/components/attempt-detail/AttemptUsage.js +20 -0
- package/dist/report/components/attempt-detail/compute.d.ts +24 -0
- package/dist/report/components/attempt-detail/compute.js +254 -0
- package/dist/report/components/attempt-detail/faces.d.ts +14 -0
- package/dist/report/components/attempt-detail/faces.js +235 -0
- package/dist/report/components/attempt-detail/index.d.ts +38 -0
- package/dist/report/components/attempt-detail/index.js +527 -0
- package/dist/report/{react → components}/cell.d.ts +5 -3
- package/dist/report/{react → components}/cell.js +3 -3
- package/dist/report/{react → components/entity-lists}/AttemptList.d.ts +8 -4
- package/dist/report/{react → components/entity-lists}/AttemptList.js +16 -10
- package/dist/report/{react → components/entity-lists}/EvalList.d.ts +3 -3
- package/dist/report/{react → components/entity-lists}/EvalList.js +0 -0
- package/dist/report/{react → components/entity-lists}/ExperimentList.d.ts +3 -3
- package/dist/report/{react → components/entity-lists}/ExperimentList.js +10 -10
- package/dist/report/components/entity-lists/compute.d.ts +23 -0
- package/dist/report/components/entity-lists/compute.js +171 -0
- package/dist/report/components/entity-lists/faces.d.ts +5 -0
- package/dist/report/components/entity-lists/faces.js +174 -0
- package/dist/report/components/entity-lists/index.d.ts +51 -0
- package/dist/report/components/entity-lists/index.js +165 -0
- package/dist/report/{react → components}/fixtures.d.ts +2 -2
- package/dist/report/{react → components}/fixtures.js +1 -1
- package/dist/report/{react → components/metric-views}/DeltaTable.d.ts +2 -2
- package/dist/report/{react → components/metric-views}/DeltaTable.js +4 -4
- package/dist/report/{react → components/metric-views}/MetricBars.d.ts +3 -3
- package/dist/report/{react → components/metric-views}/MetricBars.js +3 -3
- package/dist/report/{react → components/metric-views}/MetricLine.d.ts +2 -2
- package/dist/report/{react → components/metric-views}/MetricLine.js +8 -5
- package/dist/report/{react → components/metric-views}/MetricMatrix.d.ts +3 -3
- package/dist/report/{react → components/metric-views}/MetricMatrix.js +4 -4
- package/dist/report/components/metric-views/MetricScatter.d.ts +11 -0
- package/dist/report/{react → components/metric-views}/MetricScatter.js +26 -23
- package/dist/report/{react → components/metric-views}/MetricTable.d.ts +3 -3
- package/dist/report/{react → components/metric-views}/MetricTable.js +4 -4
- package/dist/report/{react → components/metric-views}/Scoreboard.d.ts +2 -2
- package/dist/report/{react → components/metric-views}/Scoreboard.js +3 -3
- package/dist/report/components/metric-views/compute.d.ts +89 -0
- package/dist/report/{compute.js → components/metric-views/compute.js} +32 -415
- package/dist/report/components/metric-views/faces.d.ts +13 -0
- package/dist/report/components/metric-views/faces.js +381 -0
- package/dist/report/components/metric-views/index.d.ts +50 -0
- package/dist/report/components/metric-views/index.js +273 -0
- package/dist/report/{text → components/metric-views}/plot.js +1 -1
- package/dist/report/components/shared-compute.d.ts +22 -0
- package/dist/report/components/shared-compute.js +47 -0
- package/dist/report/components/shared-faces.d.ts +9 -0
- package/dist/report/components/shared-faces.js +26 -0
- package/dist/report/components/shared.d.ts +68 -0
- package/dist/report/components/shared.js +125 -0
- package/dist/report/{react → components/site-components}/CopyFixPrompt.d.ts +2 -2
- package/dist/report/{react → components/site-components}/CopyFixPrompt.js +2 -2
- package/dist/report/{react → components/site-components}/HeroCard.d.ts +2 -2
- package/dist/report/{react → components/site-components}/HeroCard.js +2 -2
- package/dist/report/{react → components/site-components}/ScopeWarnings.d.ts +2 -2
- package/dist/report/{react → components/site-components}/ScopeWarnings.js +3 -3
- package/dist/report/{react → components/site-components}/TraceWaterfall.d.ts +3 -3
- package/dist/report/{react → components/site-components}/TraceWaterfall.js +5 -5
- package/dist/report/components/site-components/compute.d.ts +28 -0
- package/dist/report/components/site-components/compute.js +132 -0
- package/dist/report/components/site-components/faces.d.ts +21 -0
- package/dist/report/components/site-components/faces.js +75 -0
- package/dist/report/components/site-components/index.d.ts +74 -0
- package/dist/report/components/site-components/index.js +220 -0
- package/dist/report/{scope-warnings.d.ts → components/site-components/scope-warnings.d.ts} +2 -2
- package/dist/report/{scope-warnings.js → components/site-components/scope-warnings.js} +2 -2
- package/dist/report/{react → components/summaries}/ScopeSummary.d.ts +2 -2
- package/dist/report/{react → components/summaries}/ScopeSummary.js +17 -8
- package/dist/report/components/summaries/compute.d.ts +7 -0
- package/dist/report/components/summaries/compute.js +51 -0
- package/dist/report/components/summaries/faces.d.ts +7 -0
- package/dist/report/components/summaries/faces.js +38 -0
- package/dist/report/components/summaries/index.d.ts +27 -0
- package/dist/report/components/summaries/index.js +78 -0
- package/dist/report/definition/grid-layout.d.ts +50 -0
- package/dist/report/definition/grid-layout.js +89 -0
- package/dist/report/{primitives.d.ts → definition/primitives.d.ts} +34 -4
- package/dist/report/{primitives.js → definition/primitives.js} +101 -10
- package/dist/report/{report.d.ts → definition/report.d.ts} +36 -65
- package/dist/report/{report.js → definition/report.js} +58 -90
- package/dist/report/{text/table.d.ts → definition/table-text.d.ts} +2 -2
- package/dist/report/{text/table.js → definition/table-text.js} +2 -2
- package/dist/report/{tree.d.ts → definition/tree.d.ts} +44 -12
- package/dist/report/{tree.js → definition/tree.js} +10 -12
- package/dist/report/index.d.ts +33 -18
- package/dist/report/index.js +23 -14
- package/dist/report/{aggregate.d.ts → model/aggregate.d.ts} +12 -4
- package/dist/report/{aggregate.js → model/aggregate.js} +28 -8
- package/dist/report/{flag.d.ts → model/flag.d.ts} +14 -1
- package/dist/report/{flag.js → model/flag.js} +35 -0
- package/dist/report/{format.d.ts → model/format.d.ts} +11 -5
- package/dist/report/{format.js → model/format.js} +48 -4
- package/dist/report/{locale.d.ts → model/locale.d.ts} +17 -17
- package/dist/report/{locale.js → model/locale.js} +31 -33
- package/dist/report/{metrics.d.ts → model/metrics.d.ts} +2 -2
- package/dist/report/{metrics.js → model/metrics.js} +2 -2
- package/dist/report/{types.d.ts → model/types.d.ts} +140 -20
- package/dist/report/react/index.d.ts +32 -21
- package/dist/report/react/index.js +33 -21
- package/dist/report/{load.d.ts → runtime/load.d.ts} +1 -1
- package/dist/report/{load.js → runtime/load.js} +1 -1
- package/dist/report/runtime/text.d.ts +67 -0
- package/dist/report/runtime/text.js +114 -0
- package/dist/report/runtime/web.d.ts +35 -0
- package/dist/report/runtime/web.js +70 -0
- package/dist/results/annotated-source.d.ts +87 -0
- package/dist/results/attempt-evidence.d.ts +74 -0
- package/dist/results/attempt-source.d.ts +15 -0
- package/dist/results/select.d.ts +12 -2
- package/dist/results/select.js +27 -5
- package/dist/runner/eval-selection.d.ts +26 -0
- package/dist/runner/feedback/sink.d.ts +26 -1
- package/dist/runner/types.d.ts +149 -23
- package/dist/sandbox/docker.d.ts +6 -0
- package/dist/sandbox/types.d.ts +23 -21
- package/dist/scoring/display.d.ts +7 -2
- package/dist/scoring/display.js +42 -4
- package/dist/scoring/types.d.ts +3 -3
- package/dist/shared/aggregate.d.ts +15 -1
- package/dist/shared/aggregate.js +32 -1
- package/dist/shared/types.d.ts +6 -1
- package/docs-site/images/logo-dark.svg +7 -0
- package/docs-site/images/logo.svg +6 -5
- package/docs-site/zh/README.md +8 -7
- package/docs-site/zh/examples/ai-agent-application.mdx +5 -5
- package/docs-site/zh/examples/coding-agent-extensions.mdx +4 -4
- package/docs-site/zh/examples/index.mdx +3 -3
- package/docs-site/zh/examples/integrations/ai-sdk-v7.mdx +1 -1
- package/docs-site/zh/examples/integrations/claude-sdk.mdx +3 -3
- package/docs-site/zh/examples/integrations/codex-sdk.mdx +3 -3
- package/docs-site/zh/examples/integrations/langgraph.mdx +3 -3
- package/docs-site/zh/examples/integrations/pi-sdk.mdx +2 -2
- package/docs-site/zh/explanation/adapter.mdx +19 -19
- package/docs-site/zh/explanation/assert.mdx +9 -9
- package/docs-site/zh/explanation/drive.mdx +4 -4
- package/docs-site/zh/explanation/evals.mdx +8 -8
- package/docs-site/zh/explanation/experiment.mdx +8 -8
- package/docs-site/zh/explanation/hitl.mdx +13 -13
- package/docs-site/zh/explanation/judge.mdx +3 -3
- package/docs-site/zh/explanation/overview.mdx +7 -7
- package/docs-site/zh/explanation/runner.mdx +11 -11
- package/docs-site/zh/explanation/tier.mdx +6 -6
- package/docs-site/zh/index.mdx +14 -14
- package/docs-site/zh/introduction.mdx +13 -16
- package/docs-site/zh/reference/builtin-agents.mdx +61 -28
- package/docs-site/zh/reference/capabilities.mdx +7 -27
- package/docs-site/zh/reference/cli.mdx +35 -32
- package/docs-site/zh/reference/define-agent.mdx +32 -31
- package/docs-site/zh/reference/define-config.mdx +6 -6
- package/docs-site/zh/reference/define-eval.mdx +33 -20
- package/docs-site/zh/reference/events.mdx +4 -4
- package/docs-site/zh/reference/expect.mdx +3 -3
- package/docs-site/zh/reference/official-adapters.mdx +17 -17
- package/docs-site/zh/reference/report-components.mdx +193 -121
- package/docs-site/zh/reference/results-data.mdx +13 -13
- package/docs-site/zh/troubleshooting/debug-sandbox.mdx +11 -11
- package/docs-site/zh/troubleshooting/debugging.mdx +43 -19
- package/docs-site/zh/{how-to → tutorials}/agent-feedback-loop.mdx +38 -38
- package/docs-site/zh/tutorials/agent-onboarding.mdx +100 -0
- package/docs-site/zh/tutorials/authoring.mdx +211 -0
- package/docs-site/zh/{how-to → tutorials}/ci-integration.mdx +8 -8
- package/docs-site/zh/{how-to → tutorials}/connect-otel.mdx +22 -22
- package/docs-site/zh/{how-to → tutorials}/connect-your-agent.mdx +58 -63
- package/docs-site/zh/tutorials/custom-reports.mdx +453 -0
- package/docs-site/zh/{how-to → tutorials}/dataset-fanout.mdx +4 -4
- package/docs-site/zh/tutorials/experiments.mdx +103 -0
- package/docs-site/zh/{how-to → tutorials}/fixtures.mdx +9 -9
- package/docs-site/zh/{how-to → tutorials}/publish-report.mdx +11 -5
- package/docs-site/zh/tutorials/quickstart.mdx +18 -18
- package/docs-site/zh/{how-to → tutorials}/reporters.mdx +6 -6
- package/docs-site/zh/{how-to → tutorials}/sandbox-agent.mdx +6 -6
- package/docs-site/zh/{how-to → tutorials}/sandbox-providers.mdx +41 -19
- package/docs-site/zh/{how-to → tutorials}/scoring-guide.mdx +4 -4
- package/docs-site/zh/{how-to → tutorials}/viewing-results.mdx +59 -50
- package/docs-site/zh/tutorials/write-experiment.mdx +355 -0
- package/docs-site/zh/{how-to → tutorials}/write-send.mdx +40 -40
- package/package.json +8 -4
- package/src/agents/bub.ts +21 -8
- package/src/agents/claude-code.ts +23 -10
- package/src/agents/codex.test.ts +22 -7
- package/src/agents/codex.ts +22 -9
- package/src/agents/index.ts +2 -2
- package/src/agents/openai-compat.ts +1 -1
- package/src/agents/post-setup.ts +45 -22
- package/src/agents/streaming.ts +1 -1
- package/src/agents/types.ts +20 -17
- package/src/agents/ui-message-stream.test.ts +10 -0
- package/src/agents/ui-message-stream.ts +12 -1
- package/src/cli.ts +77 -64
- package/src/context/types.ts +21 -21
- package/src/define.ts +13 -0
- package/src/i18n/en.ts +30 -15
- package/src/i18n/zh-CN.ts +30 -15
- package/src/index.ts +2 -0
- package/src/report/{react → assets}/colors.ts +22 -0
- package/src/report/{react → assets}/enhance.js +1 -33
- package/src/report/{react → assets}/styles.css +136 -112
- package/src/report/built-in/index.tsx +2 -2
- package/src/report/built-in/standard.tsx +18 -6
- package/src/report/components/attempt-detail/AttemptAssertions.tsx +67 -0
- package/src/report/components/attempt-detail/AttemptConversation.tsx +110 -0
- package/src/report/components/attempt-detail/AttemptDiagnostics.tsx +38 -0
- package/src/report/components/attempt-detail/AttemptDiff.tsx +35 -0
- package/src/report/components/attempt-detail/AttemptError.tsx +31 -0
- package/src/report/components/attempt-detail/AttemptFixPrompt.tsx +26 -0
- package/src/report/components/attempt-detail/AttemptSource.tsx +80 -0
- package/src/report/components/attempt-detail/AttemptSummary.tsx +74 -0
- package/src/report/components/attempt-detail/AttemptTimeline.tsx +108 -0
- package/src/report/components/attempt-detail/AttemptTrace.tsx +63 -0
- package/src/report/components/attempt-detail/AttemptUsage.tsx +29 -0
- package/src/report/components/attempt-detail/attempt-components.test.tsx +680 -0
- package/src/report/components/attempt-detail/compute.ts +287 -0
- package/src/report/components/attempt-detail/faces.ts +257 -0
- package/src/report/components/attempt-detail/index.tsx +583 -0
- package/src/report/components/attempt-detail/validate.test.ts +235 -0
- package/src/report/{react → components}/cell.tsx +6 -3
- package/src/report/{report.test.ts → components/compute.test.ts} +316 -46
- package/src/report/{react → components/entity-lists}/AttemptList.tsx +24 -16
- package/src/report/{react → components/entity-lists}/EvalList.tsx +0 -0
- package/src/report/{react → components/entity-lists}/ExperimentList.tsx +23 -20
- package/src/report/components/entity-lists/compute.ts +196 -0
- package/src/report/components/entity-lists/faces.ts +207 -0
- package/src/report/components/entity-lists/index.tsx +241 -0
- package/src/report/components/entity-lists/validate.test.ts +114 -0
- package/src/report/{react → components}/fixtures.ts +2 -2
- package/src/report/{react → components/metric-views}/DeltaTable.tsx +5 -5
- package/src/report/{react → components/metric-views}/MetricBars.tsx +5 -5
- package/src/report/{react → components/metric-views}/MetricLine.tsx +9 -6
- package/src/report/{react → components/metric-views}/MetricMatrix.tsx +6 -6
- package/src/report/{react → components/metric-views}/MetricScatter.tsx +41 -33
- package/src/report/{react → components/metric-views}/MetricTable.tsx +6 -6
- package/src/report/{react → components/metric-views}/Scoreboard.tsx +4 -4
- package/src/report/{compute.ts → components/metric-views/compute.ts} +51 -477
- package/src/report/components/metric-views/faces.ts +423 -0
- package/src/report/components/metric-views/index.tsx +352 -0
- package/src/report/{text → components/metric-views}/plot.ts +1 -1
- package/src/report/components/metric-views/validate.test.ts +211 -0
- package/src/report/{react → components}/render.test.tsx +47 -17
- package/src/report/components/shared-compute.ts +59 -0
- package/src/report/components/shared-faces.ts +30 -0
- package/src/report/components/shared.ts +192 -0
- package/src/report/{react → components/site-components}/CopyFixPrompt.tsx +3 -3
- package/src/report/{react → components/site-components}/HeroCard.tsx +3 -3
- package/src/report/{react → components/site-components}/ScopeWarnings.tsx +4 -4
- package/src/report/{react → components/site-components}/TraceWaterfall.tsx +13 -10
- package/src/report/components/site-components/compute.ts +144 -0
- package/src/report/components/site-components/faces.ts +80 -0
- package/src/report/components/site-components/index.tsx +265 -0
- package/src/report/{scope-warnings.ts → components/site-components/scope-warnings.ts} +3 -3
- package/src/report/{site-components.test.tsx → components/site-components/site-components.test.tsx} +23 -21
- package/src/report/components/site-components/validate.test.ts +89 -0
- package/src/report/{react → components/summaries}/ScopeSummary.tsx +26 -11
- package/src/report/components/summaries/compute.ts +56 -0
- package/src/report/components/summaries/faces.ts +48 -0
- package/src/report/components/summaries/index.tsx +127 -0
- package/src/report/components/summaries/validate.test.ts +49 -0
- package/src/report/definition/grid-layout.test.ts +124 -0
- package/src/report/definition/grid-layout.ts +146 -0
- package/src/report/{primitives.tsx → definition/primitives.tsx} +168 -18
- package/src/report/{report.ts → definition/report.ts} +98 -165
- package/src/report/{shell-head.test.ts → definition/shell-head.test.ts} +2 -2
- package/src/report/{text/table.ts → definition/table-text.ts} +4 -4
- package/src/report/{tree.ts → definition/tree.ts} +58 -22
- package/src/report/index.ts +126 -66
- package/src/report/{aggregate.ts → model/aggregate.ts} +31 -9
- package/src/report/{flag.ts → model/flag.ts} +39 -1
- package/src/report/{format.ts → model/format.ts} +59 -5
- package/src/report/{locale.ts → model/locale.ts} +34 -36
- package/src/report/{metrics.ts → model/metrics.ts} +3 -3
- package/src/report/{types.ts → model/types.ts} +143 -22
- package/src/report/react/index.tsx +52 -26
- package/src/report/{dual-render.test.tsx → runtime/dual-render.test.tsx} +564 -49
- package/src/report/runtime/host.test.ts +44 -0
- package/src/report/runtime/host.ts +138 -0
- package/src/report/{load.ts → runtime/load.ts} +1 -1
- package/src/report/runtime/text.ts +192 -0
- package/src/report/runtime/web.ts +106 -0
- package/src/results/attempt-evidence.ts +5 -1
- package/src/results/host-equivalence.test.ts +54 -3
- package/src/results/select.ts +30 -6
- package/src/runner/attempt.test.ts +48 -1
- package/src/runner/attempt.ts +62 -42
- package/src/runner/cleanup-timeout.test.ts +16 -0
- package/src/runner/cleanup-timeout.ts +23 -0
- package/src/runner/discover.ts +1 -2
- package/src/runner/eval-selection.test.ts +187 -0
- package/src/runner/eval-selection.ts +109 -0
- package/src/runner/experiment-cleanup-registry.test.ts +89 -0
- package/src/runner/experiment-cleanup-registry.ts +39 -0
- package/src/runner/experiment-labels.test.ts +71 -0
- package/src/runner/feedback/agent.test.ts +33 -1
- package/src/runner/feedback/agent.ts +12 -16
- package/src/runner/feedback/ci.test.ts +35 -1
- package/src/runner/feedback/ci.ts +16 -18
- package/src/runner/feedback/coordinator.ts +28 -0
- package/src/runner/feedback/human.test.ts +108 -1
- package/src/runner/feedback/human.ts +71 -21
- package/src/runner/feedback/reducer.test.ts +64 -0
- package/src/runner/feedback/reducer.ts +26 -0
- package/src/runner/feedback/sink.ts +40 -1
- package/src/runner/fingerprint.ts +2 -1
- package/src/runner/report.test.ts +14 -0
- package/src/runner/report.ts +3 -1
- package/src/runner/run.test.ts +390 -12
- package/src/runner/run.ts +259 -26
- package/src/runner/sandbox-selection.test.ts +13 -3
- package/src/runner/sandbox-selection.ts +4 -2
- package/src/runner/types.ts +158 -23
- package/src/sandbox/docker.ts +7 -0
- package/src/sandbox/e2b.ts +12 -13
- package/src/sandbox/types.ts +23 -21
- package/src/scoring/display.test.ts +28 -2
- package/src/scoring/display.ts +38 -5
- package/src/scoring/types.ts +3 -3
- package/src/shared/aggregate.test.ts +52 -0
- package/src/shared/aggregate.ts +30 -1
- package/src/shared/types.ts +6 -1
- package/src/show/command.test.ts +34 -0
- package/src/show/command.ts +16 -0
- package/src/show/compose.ts +1 -1
- package/src/show/index.ts +58 -22
- package/src/show/render.ts +16 -240
- package/src/show/show.test.ts +128 -35
- package/src/view/app/App.test.tsx +8 -7
- package/src/view/app/App.tsx +135 -51
- package/src/view/app/i18n.ts +7 -147
- package/src/view/app/lib/attempt-dialog.test.ts +65 -0
- package/src/view/app/lib/attempt-dialog.ts +69 -0
- package/src/view/app/main.tsx +0 -1
- package/src/view/app/types.ts +3 -86
- package/src/view/artifact-serving.test.ts +22 -38
- package/src/view/client-dist/app.css +1 -1
- package/src/view/client-dist/app.js +15 -22
- package/src/view/data.test.ts +48 -36
- package/src/view/data.ts +122 -89
- package/src/view/index.ts +3 -13
- package/src/view/server.ts +36 -6
- package/src/view/shared/types.ts +6 -31
- package/src/view/site-parity.test.ts +24 -1
- package/src/view/site.ts +144 -17
- package/src/view/styles.css +18 -806
- package/src/view/view-report.test.ts +182 -34
- package/dist/report/components.d.ts +0 -179
- package/dist/report/components.js +0 -544
- package/dist/report/compute.d.ts +0 -139
- package/dist/report/react/ExperimentComparison.d.ts +0 -10
- package/dist/report/react/ExperimentComparison.js +0 -12
- package/dist/report/react/MetricScatter.d.ts +0 -9
- package/dist/report/react/format.d.ts +0 -3
- package/dist/report/react/format.js +0 -7
- package/dist/report/text/faces.d.ts +0 -45
- package/dist/report/text/faces.js +0 -671
- package/dist/report/web.d.ts +0 -32
- package/dist/report/web.js +0 -48
- package/docs-site/zh/how-to/authoring.mdx +0 -162
- package/docs-site/zh/how-to/custom-reports.mdx +0 -414
- package/docs-site/zh/how-to/experiments.mdx +0 -86
- package/docs-site/zh/how-to/write-experiment.mdx +0 -164
- package/src/report/components.tsx +0 -925
- package/src/report/react/ExperimentComparison.tsx +0 -73
- package/src/report/react/format.ts +0 -9
- package/src/report/text/faces.ts +0 -767
- package/src/report/web.ts +0 -77
- package/src/show/report-host.test.ts +0 -205
- package/src/show/report-host.ts +0 -389
- package/src/view/app/components/AttemptModal.tsx +0 -496
- package/src/view/app/components/CodeView.test.tsx +0 -142
- package/src/view/app/components/CodeView.tsx +0 -310
- package/src/view/app/components/CopyControls.tsx +0 -106
- package/src/view/app/components/Trace.tsx +0 -100
- package/src/view/app/components/Transcript.tsx +0 -157
- package/src/view/app/components/ui/badge.tsx +0 -21
- package/src/view/app/lib/artifact-url.ts +0 -17
- package/src/view/app/lib/attempt-route.test.ts +0 -80
- package/src/view/app/lib/attempt-route.ts +0 -52
- package/src/view/app/lib/format.ts +0 -70
- package/src/view/app/lib/guards.test.ts +0 -108
- package/src/view/app/lib/guards.ts +0 -71
- package/src/view/app/lib/rows.ts +0 -22
- package/src/view/app/lib/transcript-data.tsx +0 -151
- package/src/view/app/lib/verdict.ts +0 -23
- package/src/view/app/shared.ts +0 -8
- /package/dist/report/{react → components/metric-views}/chart-math.d.ts +0 -0
- /package/dist/report/{react → components/metric-views}/chart-math.js +0 -0
- /package/dist/report/{text → components/metric-views}/plot.d.ts +0 -0
- /package/dist/report/{react → components/site-components}/PoweredBy.d.ts +0 -0
- /package/dist/report/{react → components/site-components}/PoweredBy.js +0 -0
- /package/dist/report/{text/layout.d.ts → model/text-layout.d.ts} +0 -0
- /package/dist/report/{text/layout.js → model/text-layout.js} +0 -0
- /package/dist/report/{types.js → model/types.js} +0 -0
- /package/src/report/{react → components/metric-views}/chart-math.test.ts +0 -0
- /package/src/report/{react → components/metric-views}/chart-math.ts +0 -0
- /package/src/report/{react → components/site-components}/PoweredBy.tsx +0 -0
- /package/src/report/{text/layout.ts → model/text-layout.ts} +0 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
// 指标图形族(MetricTable / MetricMatrix / MetricBars / Scoreboard / MetricScatter /
|
|
2
|
+
// MetricLine / DeltaTable)的 text 面:同一份算好的数据,渲染成终端字符
|
|
3
|
+
// (niceeval show 的形态)。与 web 面共守诚实契约:排序随 better、samples < total 角标、
|
|
4
|
+
// 缺数据 — 不补 0、截断报剩余。零 react、零 IO、纯同步。
|
|
5
|
+
import { formatMetricValue, formatPlainNumber } from "../../model/format.js";
|
|
6
|
+
import { countText, localeText, resolveLocalizedText, resolveMetricLabel } from "../../model/locale.js";
|
|
7
|
+
import { padDisplay, stringWidth, textBar } from "../../model/text-layout.js";
|
|
8
|
+
import { renderTableText } from "../../definition/table-text.js";
|
|
9
|
+
import { renderCharPlot, renderCoordinateTable } from "./plot.js";
|
|
10
|
+
import { cellText, missingText, MISSING_MARK } from "../shared-faces.js";
|
|
11
|
+
// ───────────────────────── MetricTable ─────────────────────────
|
|
12
|
+
export function tableText(data, ctx) {
|
|
13
|
+
const locale = ctx.locale;
|
|
14
|
+
const columns = [
|
|
15
|
+
{ key: "dimension", header: data.rowDimension },
|
|
16
|
+
// 指标列的键用序号,不用 metric name —— 维度名和指标名在同一个命名空间里,可能撞键。
|
|
17
|
+
...data.columns.map((c, i) => ({ key: `metric${i}`, header: resolveMetricLabel(c.label, locale, c.key) })),
|
|
18
|
+
];
|
|
19
|
+
const rows = data.rows.map((row) => {
|
|
20
|
+
const cells = { dimension: row.key };
|
|
21
|
+
data.columns.forEach((col, i) => {
|
|
22
|
+
const cell = row.cells[col.key];
|
|
23
|
+
cells[`metric${i}`] = cell ? cellText(cell, locale) : null;
|
|
24
|
+
});
|
|
25
|
+
return { key: row.key, cells };
|
|
26
|
+
});
|
|
27
|
+
return renderTableText({ columns: columns, rows, locale }, ctx);
|
|
28
|
+
}
|
|
29
|
+
// ───────────────────────── MetricMatrix ─────────────────────────
|
|
30
|
+
export function matrixText(data, ctx) {
|
|
31
|
+
// 表体全是维度键与 display,没有 chrome 文案;"next:" 是命令提示,不本地化。
|
|
32
|
+
const locale = ctx.locale;
|
|
33
|
+
const rowKeys = [];
|
|
34
|
+
const columnKeys = [];
|
|
35
|
+
const byPosition = new Map();
|
|
36
|
+
for (const entry of data.cells) {
|
|
37
|
+
if (!rowKeys.includes(entry.row))
|
|
38
|
+
rowKeys.push(entry.row);
|
|
39
|
+
if (!columnKeys.includes(entry.column))
|
|
40
|
+
columnKeys.push(entry.column);
|
|
41
|
+
byPosition.set(JSON.stringify([entry.row, entry.column]), entry.cell);
|
|
42
|
+
}
|
|
43
|
+
const columns = [
|
|
44
|
+
{ key: "dimension", header: data.rowDimension },
|
|
45
|
+
...columnKeys.map((column, i) => ({ key: `column${i}`, header: column })),
|
|
46
|
+
];
|
|
47
|
+
const rows = rowKeys.map((row) => {
|
|
48
|
+
const cells = { dimension: row };
|
|
49
|
+
columnKeys.forEach((column, i) => {
|
|
50
|
+
const cell = byPosition.get(JSON.stringify([row, column]));
|
|
51
|
+
cells[`column${i}`] = cell ? cellText(cell, locale) : null; // 稀疏格子在文本里以 — 呈现,不编数
|
|
52
|
+
});
|
|
53
|
+
return { key: row, cells };
|
|
54
|
+
});
|
|
55
|
+
const table = renderTableText({ columns: columns, rows, locale }, ctx);
|
|
56
|
+
// 下钻命令:行维度是 eval 时,指向最值得看的一行(先挑有缺格的,再挑按 better 最差的)
|
|
57
|
+
if (data.rowDimension !== "eval" || rowKeys.length === 0)
|
|
58
|
+
return table;
|
|
59
|
+
const better = data.metric.better ?? "higher";
|
|
60
|
+
let next;
|
|
61
|
+
let worst;
|
|
62
|
+
for (const row of rowKeys) {
|
|
63
|
+
let sum = 0;
|
|
64
|
+
let count = 0;
|
|
65
|
+
for (const column of columnKeys) {
|
|
66
|
+
const cell = byPosition.get(JSON.stringify([row, column]));
|
|
67
|
+
if (!cell || cell.value === null) {
|
|
68
|
+
next ??= row;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
sum += cell.value;
|
|
72
|
+
count += 1;
|
|
73
|
+
}
|
|
74
|
+
if (count > 0) {
|
|
75
|
+
const value = sum / count;
|
|
76
|
+
const isWorse = worst === undefined || (better === "higher" ? value < worst.value : value > worst.value);
|
|
77
|
+
if (isWorse)
|
|
78
|
+
worst = { key: row, value };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
next ??= worst?.key;
|
|
82
|
+
return next === undefined ? table : `${table}\n\nnext: niceeval show ${next}`;
|
|
83
|
+
}
|
|
84
|
+
// ───────────────────────── MetricBars(矩阵数据的另一种摆法)─────────────────────────
|
|
85
|
+
const BAR_WIDTH = 20;
|
|
86
|
+
export function barsText(data, ctx) {
|
|
87
|
+
const locale = ctx.locale;
|
|
88
|
+
const groupKeys = [];
|
|
89
|
+
const seriesKeys = [];
|
|
90
|
+
const byPosition = new Map();
|
|
91
|
+
for (const entry of data.cells) {
|
|
92
|
+
if (!groupKeys.includes(entry.row))
|
|
93
|
+
groupKeys.push(entry.row);
|
|
94
|
+
if (!seriesKeys.includes(entry.column))
|
|
95
|
+
seriesKeys.push(entry.column);
|
|
96
|
+
byPosition.set(JSON.stringify([entry.row, entry.column]), entry.cell);
|
|
97
|
+
}
|
|
98
|
+
const better = data.metric.better ?? "higher";
|
|
99
|
+
// 条长刻度:% 的天然域是 [0,1],其余以全图最大值为满条
|
|
100
|
+
const values = data.cells.map((c) => c.cell.value).filter((v) => v !== null);
|
|
101
|
+
const maxValue = values.length > 0 ? Math.max(...values) : 0;
|
|
102
|
+
const ratioOf = (value) => (data.metric.unit === "%" ? value : maxValue === 0 ? 0 : value / maxValue);
|
|
103
|
+
const seriesWidth = Math.max(...seriesKeys.map((k) => stringWidth(k)), 0);
|
|
104
|
+
const lines = [];
|
|
105
|
+
for (const group of groupKeys) {
|
|
106
|
+
lines.push(group);
|
|
107
|
+
const entries = seriesKeys.map((series) => ({
|
|
108
|
+
series,
|
|
109
|
+
cell: byPosition.get(JSON.stringify([group, series])),
|
|
110
|
+
}));
|
|
111
|
+
// 组内按值排序,方向随 better(缺数据沉底)
|
|
112
|
+
entries.sort((a, b) => {
|
|
113
|
+
const va = a.cell?.value ?? null;
|
|
114
|
+
const vb = b.cell?.value ?? null;
|
|
115
|
+
if (va === null && vb === null)
|
|
116
|
+
return 0;
|
|
117
|
+
if (va === null)
|
|
118
|
+
return 1;
|
|
119
|
+
if (vb === null)
|
|
120
|
+
return -1;
|
|
121
|
+
return better === "lower" ? va - vb : vb - va;
|
|
122
|
+
});
|
|
123
|
+
for (const { series, cell } of entries) {
|
|
124
|
+
const label = padDisplay(series, seriesWidth);
|
|
125
|
+
if (!cell || cell.value === null) {
|
|
126
|
+
lines.push(` ${label} ${MISSING_MARK}`);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
lines.push(` ${label} ${textBar(ratioOf(cell.value), BAR_WIDTH)} ${cellText(cell, locale)}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return lines.join("\n");
|
|
133
|
+
}
|
|
134
|
+
// ───────────────────────── Scoreboard ─────────────────────────
|
|
135
|
+
export function scoreboardText(data, ctx) {
|
|
136
|
+
const locale = ctx.locale;
|
|
137
|
+
const subjectKeys = [];
|
|
138
|
+
for (const row of data.rows) {
|
|
139
|
+
for (const subject of row.subjects) {
|
|
140
|
+
if (!subjectKeys.includes(subject.key))
|
|
141
|
+
subjectKeys.push(subject.key);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const columns = [
|
|
145
|
+
{ key: "dimension", header: data.rowDimension },
|
|
146
|
+
{ key: "total", header: localeText(locale, "scoreboard.totalText") },
|
|
147
|
+
...subjectKeys.map((key, i) => ({ key: `subject${i}`, header: key })),
|
|
148
|
+
];
|
|
149
|
+
const rows = data.rows.map((row) => {
|
|
150
|
+
const totalNotes = [
|
|
151
|
+
...(row.total.notRun > 0 ? [localeText(locale, "scoreboard.notRunText", { n: row.total.notRun })] : []),
|
|
152
|
+
...(row.total.unscorable > 0 ? [localeText(locale, "scoreboard.unscorableText", { n: row.total.unscorable })] : []),
|
|
153
|
+
];
|
|
154
|
+
const cells = {
|
|
155
|
+
dimension: row.key,
|
|
156
|
+
total: `${resolveLocalizedText(row.total.display, locale)}/${data.fullMarks}${totalNotes.length > 0 ? ` ${totalNotes.join(" ")}` : ""}`,
|
|
157
|
+
};
|
|
158
|
+
subjectKeys.forEach((key, i) => {
|
|
159
|
+
const subject = row.subjects.find((s) => s.key === key);
|
|
160
|
+
if (!subject) {
|
|
161
|
+
cells[`subject${i}`] = null;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const score = `${formatPlainNumber(subject.earned)}/${formatPlainNumber(subject.possible)}`;
|
|
165
|
+
const notes = [
|
|
166
|
+
...(subject.notRun > 0 ? [localeText(locale, "scoreboard.notRunText", { n: subject.notRun })] : []),
|
|
167
|
+
...(subject.unscorable > 0 ? [localeText(locale, "scoreboard.unscorableText", { n: subject.unscorable })] : []),
|
|
168
|
+
];
|
|
169
|
+
cells[`subject${i}`] = notes.length > 0 ? `${score} ${notes.join(" ")}` : score;
|
|
170
|
+
});
|
|
171
|
+
return { key: row.key, cells };
|
|
172
|
+
});
|
|
173
|
+
const table = renderTableText({ columns: columns, rows, locale }, ctx);
|
|
174
|
+
const footnotes = [];
|
|
175
|
+
if (data.weights.length > 0) {
|
|
176
|
+
const weights = data.weights.map((w) => `${w.prefix} ×${w.weight}`).join(" · ");
|
|
177
|
+
footnotes.push(`${localeText(locale, "scoreboard.weights")} ${weights} · ${localeText(locale, "scoreboard.othersWeight")}`);
|
|
178
|
+
}
|
|
179
|
+
if (data.ignoredEvals > 0)
|
|
180
|
+
footnotes.push(countText(locale, "scoreboard.ignored", data.ignoredEvals));
|
|
181
|
+
return footnotes.length > 0 ? `${table}\n${footnotes.join("\n")}` : table;
|
|
182
|
+
}
|
|
183
|
+
// ───────────────────────── MetricScatter ─────────────────────────
|
|
184
|
+
const POINT_MARKS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
185
|
+
function axisLabel(col, locale) {
|
|
186
|
+
return resolveMetricLabel(col.label, locale, col.key);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* 方向提示:轴向已随 better 反正(lower 反向),「更好」恒指向右上,文案恒为
|
|
190
|
+
* 「越靠右上越好」;仅当 x、y 都声明 better 时显示——任一轴未声明,组件不猜
|
|
191
|
+
* 「更好」朝哪边,整图无提示(返回 undefined)。
|
|
192
|
+
*/
|
|
193
|
+
function betterCornerText(x, y, locale) {
|
|
194
|
+
if (x.better === undefined || y.better === undefined)
|
|
195
|
+
return undefined;
|
|
196
|
+
return localeText(locale, "scatter.betterUpperRight");
|
|
197
|
+
}
|
|
198
|
+
/** 轴标题行:"<x label>(越低越好) × <y label>"——better 方向如实标注,不虚构轴向。 */
|
|
199
|
+
function scatterHeading(data, locale) {
|
|
200
|
+
const withBetter = (col) => {
|
|
201
|
+
const label = axisLabel(col, locale);
|
|
202
|
+
if (col.better === undefined)
|
|
203
|
+
return label;
|
|
204
|
+
return `${label}(${localeText(locale, col.better === "lower" ? "table.lowerBetter" : "table.higherBetter")})`;
|
|
205
|
+
};
|
|
206
|
+
return `${withBetter(data.x)} × ${withBetter(data.y)}`;
|
|
207
|
+
}
|
|
208
|
+
/** 位移摘要里的带符号差值;`%` 的差是百分点,单位写 pt(docs/feature/reports/show/default-report.md)。 */
|
|
209
|
+
function signedDelta(value, unit) {
|
|
210
|
+
const text = formatMetricValue(value, unit);
|
|
211
|
+
const signed = value >= 0 ? `+${text}` : text;
|
|
212
|
+
return unit === "%" ? signed.replace("%", "pt") : signed;
|
|
213
|
+
}
|
|
214
|
+
export function scatterText(data, ctx, opts) {
|
|
215
|
+
const locale = ctx.locale;
|
|
216
|
+
const connect = opts?.connect === true && data.seriesDimension !== undefined;
|
|
217
|
+
const drawable = data.rows.filter((r) => r.x.value !== null && r.y.value !== null);
|
|
218
|
+
const missing = data.rows.length - drawable.length;
|
|
219
|
+
const footnotes = [];
|
|
220
|
+
if (missing > 0)
|
|
221
|
+
footnotes.push(countText(locale, "pointsMissing", missing));
|
|
222
|
+
const axes = { x: axisLabel(data.x, locale), y: axisLabel(data.y, locale) };
|
|
223
|
+
// 0 个可画点:x/y 指标没有可用数据(与 web 面同一事实)。
|
|
224
|
+
if (drawable.length === 0) {
|
|
225
|
+
return [localeText(locale, "scatter.noData", axes), ...footnotes].join("\n");
|
|
226
|
+
}
|
|
227
|
+
// 标题行尾标注归类维度(· 按 <series> 归类)。
|
|
228
|
+
const heading = data.seriesDimension !== undefined
|
|
229
|
+
? `${scatterHeading(data, locale)} · ${localeText(locale, "scatter.groupedBy", { dim: data.seriesDimension })}`
|
|
230
|
+
: scatterHeading(data, locale);
|
|
231
|
+
// 标记分配顺序即图例顺序:series 按显示键字典序、series 内按 x 原始值升序;
|
|
232
|
+
// 无 series 时保持点键字典序(rows 本身已按维度 key 排序)。
|
|
233
|
+
const ordered = data.seriesDimension === undefined
|
|
234
|
+
? drawable
|
|
235
|
+
: [...drawable].sort((a, b) => {
|
|
236
|
+
const sa = a.series ?? "";
|
|
237
|
+
const sb = b.series ?? "";
|
|
238
|
+
if (sa !== sb)
|
|
239
|
+
return sa < sb ? -1 : 1;
|
|
240
|
+
return a.x.value - b.x.value;
|
|
241
|
+
});
|
|
242
|
+
// 点太密排不下时降级为坐标表,不硬挤
|
|
243
|
+
if (ordered.length > POINT_MARKS.length || ctx.width < 44) {
|
|
244
|
+
const table = renderCoordinateTable(ordered.map((r) => ({
|
|
245
|
+
key: r.key,
|
|
246
|
+
x: resolveLocalizedText(r.x.display, locale),
|
|
247
|
+
y: resolveLocalizedText(r.y.display, locale),
|
|
248
|
+
})), { key: data.pointDimension, x: axes.x, y: axes.y });
|
|
249
|
+
return [heading, "", table, ...footnotes].join("\n");
|
|
250
|
+
}
|
|
251
|
+
const points = ordered.map((r, i) => ({
|
|
252
|
+
mark: POINT_MARKS[i],
|
|
253
|
+
x: r.x.value,
|
|
254
|
+
y: r.y.value,
|
|
255
|
+
}));
|
|
256
|
+
// series 分组(ordered 已按 series、x 排好序);connect 的折线只进 web 面,
|
|
257
|
+
// text 面用图例的 → 串联 + 位移摘要表达同一条线,坐标图内不画折线。
|
|
258
|
+
const rowsBySeries = new Map();
|
|
259
|
+
for (const r of ordered) {
|
|
260
|
+
if (r.series === undefined)
|
|
261
|
+
continue;
|
|
262
|
+
const list = rowsBySeries.get(r.series) ?? [];
|
|
263
|
+
list.push(r);
|
|
264
|
+
rowsBySeries.set(r.series, list);
|
|
265
|
+
}
|
|
266
|
+
const plot = renderCharPlot({
|
|
267
|
+
width: ctx.width,
|
|
268
|
+
points,
|
|
269
|
+
lines: [],
|
|
270
|
+
xLabel: axes.x,
|
|
271
|
+
yLabel: axes.y,
|
|
272
|
+
formatX: (v) => formatMetricValue(v, data.x.unit),
|
|
273
|
+
formatY: (v) => formatMetricValue(v, data.y.unit),
|
|
274
|
+
// 轴方向跟随 better(与 web 面同规则):lower 反向,higher 与未声明正向。
|
|
275
|
+
invertX: data.x.better === "lower",
|
|
276
|
+
invertY: data.y.better === "lower",
|
|
277
|
+
});
|
|
278
|
+
const markByKey = new Map(ordered.map((r, i) => [r.key, POINT_MARKS[i]]));
|
|
279
|
+
let legend;
|
|
280
|
+
if (data.seriesDimension === undefined) {
|
|
281
|
+
legend = ordered.map((r) => `${markByKey.get(r.key)} ${r.key}`).join(" ");
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
// 图例一行一个 series:行首 series 显示键,后接线上各点;connect 用 → 串联并给逐段位移摘要。
|
|
285
|
+
const seriesWidth = Math.max(...[...rowsBySeries.keys()].map(stringWidth));
|
|
286
|
+
const lines = [];
|
|
287
|
+
for (const [series, list] of rowsBySeries) {
|
|
288
|
+
const parts = list.map((r) => `${markByKey.get(r.key)} ${r.key}`);
|
|
289
|
+
lines.push(`${padDisplay(series, seriesWidth)} ${parts.join(connect ? " → " : " ")}`);
|
|
290
|
+
if (connect) {
|
|
291
|
+
for (let i = 1; i < list.length; i++) {
|
|
292
|
+
const a = list[i - 1];
|
|
293
|
+
const b = list[i];
|
|
294
|
+
const dy = signedDelta(b.y.value - a.y.value, data.y.unit);
|
|
295
|
+
const dx = signedDelta(b.x.value - a.x.value, data.x.unit);
|
|
296
|
+
lines.push(`${" ".repeat(seriesWidth + 2)}└ ${axes.y} ${dy} · ${axes.x} ${dx}`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
legend = lines.join("\n");
|
|
301
|
+
}
|
|
302
|
+
const hint = betterCornerText(data.x, data.y, locale);
|
|
303
|
+
return [heading, plot, "", ...(hint !== undefined ? [hint] : []), legend, ...footnotes].join("\n");
|
|
304
|
+
}
|
|
305
|
+
// ───────────────────────── MetricLine ─────────────────────────
|
|
306
|
+
export function lineText(data, ctx) {
|
|
307
|
+
const locale = ctx.locale;
|
|
308
|
+
const drawable = data.rows.filter((r) => r.x !== null && r.y.value !== null);
|
|
309
|
+
const missing = data.rows.length - drawable.length;
|
|
310
|
+
const footnotes = [];
|
|
311
|
+
if (missing > 0)
|
|
312
|
+
footnotes.push(countText(locale, "pointsMissing", missing));
|
|
313
|
+
if (drawable.length === 0)
|
|
314
|
+
return [missingText(locale), ...footnotes].join("\n");
|
|
315
|
+
const xLabel = resolveMetricLabel(data.x.label, locale, data.x.key);
|
|
316
|
+
// 系列 → 字母;无系列 = 单系列
|
|
317
|
+
const seriesKeys = [];
|
|
318
|
+
for (const r of drawable) {
|
|
319
|
+
const key = r.series ?? "";
|
|
320
|
+
if (!seriesKeys.includes(key))
|
|
321
|
+
seriesKeys.push(key);
|
|
322
|
+
}
|
|
323
|
+
if (seriesKeys.length > POINT_MARKS.length || ctx.width < 44) {
|
|
324
|
+
const table = renderCoordinateTable(drawable.map((r) => ({
|
|
325
|
+
key: r.series !== undefined ? `${r.series} (${r.key})` : r.key,
|
|
326
|
+
x: resolveLocalizedText(r.xDisplay, locale),
|
|
327
|
+
y: resolveLocalizedText(r.y.display, locale),
|
|
328
|
+
})), { key: data.seriesDimension ?? xLabel, x: xLabel, y: axisLabel(data.y, locale) });
|
|
329
|
+
return [table, ...footnotes].join("\n");
|
|
330
|
+
}
|
|
331
|
+
const markOf = (r) => POINT_MARKS[seriesKeys.indexOf(r.series ?? "")];
|
|
332
|
+
const points = drawable.map((r) => ({
|
|
333
|
+
mark: markOf(r),
|
|
334
|
+
x: r.x,
|
|
335
|
+
y: r.y.value,
|
|
336
|
+
}));
|
|
337
|
+
const lines = seriesKeys.map((key) => drawable
|
|
338
|
+
.filter((r) => (r.series ?? "") === key)
|
|
339
|
+
.map((r) => ({ x: r.x, y: r.y.value }))
|
|
340
|
+
.sort((a, b) => a.x - b.x));
|
|
341
|
+
const plot = renderCharPlot({
|
|
342
|
+
width: ctx.width,
|
|
343
|
+
points,
|
|
344
|
+
lines: lines.filter((l) => l.length > 1),
|
|
345
|
+
xLabel,
|
|
346
|
+
yLabel: axisLabel(data.y, locale),
|
|
347
|
+
formatX: (v) => formatMetricValue(v, data.x.unit),
|
|
348
|
+
formatY: (v) => formatMetricValue(v, data.y.unit),
|
|
349
|
+
});
|
|
350
|
+
const legend = seriesKeys
|
|
351
|
+
.map((key, i) => `${POINT_MARKS[i]} ${key === "" ? axisLabel(data.y, locale) : key}`)
|
|
352
|
+
.join(" ");
|
|
353
|
+
return [plot, "", legend, ...footnotes].join("\n");
|
|
354
|
+
}
|
|
355
|
+
// ───────────────────────── DeltaTable ─────────────────────────
|
|
356
|
+
export function deltaText(data, ctx) {
|
|
357
|
+
const locale = ctx.locale;
|
|
358
|
+
// 0 对不是错误:明确空态并报告配对域实验数(派生形态携带;字面形态缺省按 0)。
|
|
359
|
+
if (data.rows.length === 0) {
|
|
360
|
+
return localeText(locale, "delta.empty", { experiments: data.experiments ?? 0 });
|
|
361
|
+
}
|
|
362
|
+
const columns = [
|
|
363
|
+
{ key: "pair", header: localeText(locale, "delta.pairHeader") },
|
|
364
|
+
...data.columns.map((c, i) => ({ key: `metric${i}`, header: resolveMetricLabel(c.label, locale, c.key) })),
|
|
365
|
+
];
|
|
366
|
+
const rows = data.rows.map((row) => {
|
|
367
|
+
const cells = { pair: resolveLocalizedText(row.label, locale) };
|
|
368
|
+
data.columns.forEach((col, i) => {
|
|
369
|
+
const cell = row.cells[col.key];
|
|
370
|
+
if (!cell) {
|
|
371
|
+
cells[`metric${i}`] = null;
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const a = cell.a.value === null ? MISSING_MARK : resolveLocalizedText(cell.a.display, locale);
|
|
375
|
+
const b = cell.b.value === null ? MISSING_MARK : resolveLocalizedText(cell.b.display, locale);
|
|
376
|
+
cells[`metric${i}`] = `${a} → ${b} ${resolveLocalizedText(cell.display, locale)}`;
|
|
377
|
+
});
|
|
378
|
+
return { key: row.key, cells };
|
|
379
|
+
});
|
|
380
|
+
return renderTableText({ columns: columns, rows, locale }, ctx);
|
|
381
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ReportComponent } from "../../definition/tree.ts";
|
|
2
|
+
import type { DeltaData, LineData, MatrixData, ScatterData, ScoreboardData, TableData } from "../../model/types.ts";
|
|
3
|
+
import type { AttemptLocator } from "../../../results/locator.ts";
|
|
4
|
+
import { type ChromeProps, type DataProps, type Validator } from "../shared.ts";
|
|
5
|
+
import { type DeltaTableOptions, type MetricLineOptions, type MetricMatrixOptions, type MetricScatterOptions, type MetricTableOptions, type ScoreboardOptions } from "./compute.ts";
|
|
6
|
+
export declare const validateTableData: Validator;
|
|
7
|
+
export declare const validateMatrixData: Validator;
|
|
8
|
+
export declare const validateScatterData: Validator;
|
|
9
|
+
export declare const validateLineData: Validator;
|
|
10
|
+
export declare const validateScoreboardData: Validator;
|
|
11
|
+
export declare const validateDeltaData: Validator;
|
|
12
|
+
export type MetricTableProps = DataProps<TableData, MetricTableOptions, ChromeProps & {
|
|
13
|
+
/** web 面在表格前渲染过滤输入框(enhance.js 接管);无 JS 时表格内容依旧完整。 */
|
|
14
|
+
filter?: boolean;
|
|
15
|
+
attemptHref?: (locator: AttemptLocator) => string;
|
|
16
|
+
}>;
|
|
17
|
+
/** 榜单:一行一个维度值、一列一个指标,回答「谁整体更好」。 */
|
|
18
|
+
export declare const MetricTable: ReportComponent<MetricTableProps>;
|
|
19
|
+
export type MetricMatrixProps = DataProps<MatrixData, MetricMatrixOptions, ChromeProps & {
|
|
20
|
+
attemptHref?: (locator: AttemptLocator) => string;
|
|
21
|
+
}>;
|
|
22
|
+
export type MetricBarsProps = MetricMatrixProps;
|
|
23
|
+
/** 逐题格子:行 × 列两个维度、格子里一个指标,回答「哪道题谁挂了」。 */
|
|
24
|
+
export declare const MetricMatrix: ReportComponent<MetricMatrixProps>;
|
|
25
|
+
/** 分组条形:同一份矩阵数据的另一种摆法;与 MetricMatrix 写同一份 spec 时只计算一次。 */
|
|
26
|
+
export declare const MetricBars: ReportComponent<MetricBarsProps>;
|
|
27
|
+
export type ScoreboardProps = DataProps<ScoreboardData, ScoreboardOptions, ChromeProps & {
|
|
28
|
+
attemptHref?: (locator: AttemptLocator) => string;
|
|
29
|
+
}>;
|
|
30
|
+
/** 考试成绩单:总分 + 分科小计,固定分母、notRun / unscorable 分开如实报。 */
|
|
31
|
+
export declare const Scoreboard: ReportComponent<ScoreboardProps>;
|
|
32
|
+
type ScatterChrome = ChromeProps & {
|
|
33
|
+
/** series 内按 x 升序成线(呈现,不改变 ScatterData):web 面画折线,text 面在图例给逐段位移摘要;默认 false。 */
|
|
34
|
+
connect?: boolean;
|
|
35
|
+
pointHref?: (row: ScatterData["rows"][number]) => string;
|
|
36
|
+
};
|
|
37
|
+
export type MetricScatterProps = DataProps<ScatterData, MetricScatterOptions, ScatterChrome>;
|
|
38
|
+
/** 两个指标之间的取舍:每个点一个维度值,x / y 各一个指标,series 决定颜色和图例归类。 */
|
|
39
|
+
export declare const MetricScatter: ReportComponent<MetricScatterProps>;
|
|
40
|
+
export type MetricLineProps = DataProps<LineData, MetricLineOptions, ChromeProps & {
|
|
41
|
+
pointHref?: (row: LineData["rows"][number]) => string;
|
|
42
|
+
}>;
|
|
43
|
+
/** 趋势线:x 是 NumericAxis(参数轴),点身份 = (series, x)。 */
|
|
44
|
+
export declare const MetricLine: ReportComponent<MetricLineProps>;
|
|
45
|
+
export type DeltaTableProps = DataProps<DeltaData, DeltaTableOptions, ChromeProps & {
|
|
46
|
+
attemptHref?: (locator: AttemptLocator) => string;
|
|
47
|
+
}>;
|
|
48
|
+
/** 成对对比:每行一对(字面声明或 pairsByFlag 派生),格子里 A、B、Δ 三个值。 */
|
|
49
|
+
export declare const DeltaTable: ReportComponent<DeltaTableProps>;
|
|
50
|
+
export {};
|