forked from longtao.wu/droboticflow
🐛 Unify Capture frame boundaries and require continuous annotation coverage
This commit is contained in:
parent
13414c13fc
commit
5241ac20a3
@ -786,6 +786,11 @@ def _timestamped_annotation(annotation: dict[str, Any], synchronized: dict[str,
|
||||
if description_contract
|
||||
else result.get("actions") if isinstance(result.get("actions"), list) else []
|
||||
)
|
||||
unified = result.get("boundaryContract") == "hardware-frame-v1"
|
||||
boundary_ids = set(synchronized.get("boundaryTimestampUs") or [])
|
||||
cursor = start_us
|
||||
if unified and (not actions or start_us not in boundary_ids or end_us not in boundary_ids):
|
||||
raise RuntimeError("unified annotation requires continuous descriptions and shared boundaries")
|
||||
for action in actions:
|
||||
if not isinstance(action, dict):
|
||||
continue
|
||||
@ -793,8 +798,17 @@ def _timestamped_annotation(annotation: dict[str, Any], synchronized: dict[str,
|
||||
clip_end_seconds = float(action.get("end") or float(action.get("clipEndMs") or 0.0) / 1000.0)
|
||||
if clip_start_seconds < 0 or clip_end_seconds <= clip_start_seconds:
|
||||
raise RuntimeError("timestamped annotation contains an invalid clip-relative action range")
|
||||
action_start_us = start_us + round(clip_start_seconds * 1_000_000)
|
||||
action_end_us = start_us + round(clip_end_seconds * 1_000_000)
|
||||
if unified:
|
||||
action_start_us = action.get("startTimestampUs")
|
||||
action_end_us = action.get("endTimestampUs")
|
||||
if (type(action_start_us) is not int or type(action_end_us) is not int
|
||||
or action_start_us not in boundary_ids or action_end_us not in boundary_ids
|
||||
or action_start_us != cursor):
|
||||
raise RuntimeError("unified annotation boundaries must be consecutive hardware frame boundaries")
|
||||
cursor = action_end_us
|
||||
else:
|
||||
action_start_us = start_us + round(clip_start_seconds * 1_000_000)
|
||||
action_end_us = start_us + round(clip_end_seconds * 1_000_000)
|
||||
if action_start_us < start_us or action_end_us > end_us or action_end_us <= action_start_us:
|
||||
raise RuntimeError("timestamped annotation action is outside the synchronized half-open window")
|
||||
action["clipStartMs"] = clip_start_seconds * 1000.0
|
||||
@ -803,6 +817,10 @@ def _timestamped_annotation(annotation: dict[str, Any], synchronized: dict[str,
|
||||
action["endTimestampUs"] = action_end_us
|
||||
action["startTimestampMs"] = action_start_us / 1000.0
|
||||
action["endTimestampMs"] = action_end_us / 1000.0
|
||||
if unified and cursor != end_us:
|
||||
raise RuntimeError("unified annotation does not cover the complete slice")
|
||||
if unified and description_contract:
|
||||
result["actions"] = actions
|
||||
return result
|
||||
|
||||
|
||||
|
||||
25
docs/annotation-boundaries.md
Normal file
25
docs/annotation-boundaries.md
Normal file
@ -0,0 +1,25 @@
|
||||
# Continuous annotation boundaries
|
||||
|
||||
The Fanyu Capture workbench uses `hardware-frame-v1` for newly confirmed slices.
|
||||
An ordered boundary grid maps one integer hardware timestamp to both camera frame
|
||||
indices and the CFR left-video media time. Interior edges must advance both camera
|
||||
indices. The common-range endpoints are included; an interval is half-open.
|
||||
|
||||
- Slices partition the common range. Descriptions partition each slice.
|
||||
- New descriptions begin at the selected unannotated gap's start. The operator
|
||||
locates and explicitly confirms its end before saving the description.
|
||||
- Adjacent descriptions share their boundary. Editing it updates both sides.
|
||||
- Empty regions are not automatically assigned meaning. Explicit invalid-region
|
||||
marking is available; final submission rejects uncovered regions and overlaps.
|
||||
- Paused media seek notifications do not overwrite the logical playhead.
|
||||
- New materialized JSON preserves hardware boundary IDs. Packaging must not
|
||||
recalculate them from clip-relative milliseconds. Acceptance uses the exported
|
||||
media boundary grid for the same preview mapping.
|
||||
- Legacy off-grid data is not silently rewritten. The annotator must explicitly
|
||||
confirm a reset/re-slice; its existing warning states that annotations are cleared.
|
||||
Already accepted legacy packages retain their previous export contract.
|
||||
|
||||
Checks: `annotation_boundary_grid_test.go`, `human_slice_materialization_test.go`,
|
||||
`annotation_draft_test.go`, `annotation_submission_conflict_test.go`, frontend
|
||||
`unified-annotation-boundaries.test.mjs` and `annotation-playhead-draft.test.mjs`,
|
||||
and backend `test_delivery_pose_contracts.py`.
|
||||
105
internal/api/annotation_boundary_grid.go
Normal file
105
internal/api/annotation_boundary_grid.go
Normal file
@ -0,0 +1,105 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"droboticflow/internal/domain"
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// One half-open hardware boundary owns a media time and both camera indices.
|
||||
// Adjacent intervals reference the same entry instead of independently rounding.
|
||||
type annotationBoundaryGrid struct {
|
||||
Origin int64
|
||||
Scale float64
|
||||
Timestamps []int64
|
||||
Seconds []float64
|
||||
LeftFrames []int
|
||||
RightFrames []int
|
||||
}
|
||||
|
||||
func newAnnotationBoundaryGrid(left, right []hardwarePTSRow, start, end int64, mediaDuration float64) (annotationBoundaryGrid, error) {
|
||||
g := annotationBoundaryGrid{}
|
||||
leftEnd, err := ptsCoverageEnd(left)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
if len(right) < 2 || end <= start {
|
||||
return g, fmt.Errorf("双目有效公共范围为空")
|
||||
}
|
||||
g.Origin = left[0].TimestampUS
|
||||
g.Scale = mediaDuration / (float64(leftEnd-g.Origin) / 1e6)
|
||||
if math.IsNaN(g.Scale) || math.IsInf(g.Scale, 0) || g.Scale < 0.5 || g.Scale > 2 {
|
||||
return g, fmt.Errorf("视频与 PTS 时间映射无效")
|
||||
}
|
||||
index := func(rows []hardwarePTSRow, t int64) int {
|
||||
return sort.Search(len(rows), func(i int) bool { return rows[i].TimestampUS >= t })
|
||||
}
|
||||
lastLeft, lastRight := index(left, end), index(right, end)
|
||||
// Annotation sources are CFR outputs of the stereo preprocessing operator.
|
||||
// Use their actual frame index, not hardware elapsed time as video seconds.
|
||||
add := func(t int64, l, r int) {
|
||||
g.Timestamps = append(g.Timestamps, t)
|
||||
g.Seconds = append(g.Seconds, float64(l)*mediaDuration/float64(len(left)))
|
||||
g.LeftFrames = append(g.LeftFrames, l)
|
||||
g.RightFrames = append(g.RightFrames, r)
|
||||
}
|
||||
add(start, index(left, start), index(right, start))
|
||||
for _, row := range left {
|
||||
t := row.TimestampUS
|
||||
if t <= start || t >= end {
|
||||
continue
|
||||
}
|
||||
l, r := index(left, t), index(right, t)
|
||||
last := len(g.Timestamps) - 1
|
||||
// Do not expose two different boundaries for the same camera frame, or
|
||||
// offer a cut that would leave either camera with an empty tail segment.
|
||||
if l > g.LeftFrames[last] && r > g.RightFrames[last] && l < lastLeft && r < lastRight {
|
||||
add(t, l, r)
|
||||
}
|
||||
}
|
||||
if lastLeft <= g.LeftFrames[0] || lastRight <= g.RightFrames[0] {
|
||||
return g, fmt.Errorf("公共范围必须包含左右相机有效帧")
|
||||
}
|
||||
add(end, lastLeft, lastRight)
|
||||
return g, nil
|
||||
}
|
||||
|
||||
func (g annotationBoundaryGrid) resolve(seconds float64) (int, error) {
|
||||
i := sort.SearchFloat64s(g.Seconds, seconds)
|
||||
if i == len(g.Seconds) {
|
||||
i--
|
||||
}
|
||||
if i > 0 && math.Abs(g.Seconds[i-1]-seconds) < math.Abs(g.Seconds[i]-seconds) {
|
||||
i--
|
||||
}
|
||||
if i < 0 || math.IsNaN(seconds) || math.Abs(g.Seconds[i]-seconds) > 1e-6 {
|
||||
return 0, fmt.Errorf("边界 %.9f 未对齐统一帧边界,请在切片页重新定位后确认", seconds)
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func validateContinuousDescriptions(slices []domain.SliceSegment, segments []domain.AnnotationSegment) []validationIssue {
|
||||
issues := []validationIssue{}
|
||||
for i, slice := range slices {
|
||||
events := []domain.AnnotationSegment{}
|
||||
for _, e := range segments {
|
||||
if e.Start >= slice.Start-1e-6 && e.End <= slice.End+1e-6 {
|
||||
events = append(events, e)
|
||||
}
|
||||
}
|
||||
sort.Slice(events, func(i, j int) bool { return events[i].Start < events[j].Start })
|
||||
cursor := slice.Start
|
||||
for _, e := range events {
|
||||
if math.Abs(e.Start-cursor) > 1e-6 || e.End <= e.Start {
|
||||
issues = append(issues, validationIssue{Field: fmt.Sprintf("sliceSegments.%d", i), Code: "annotation_coverage_invalid", Message: "动作区间必须首尾相连、无重叠;空白部分请明确标为无效片段"})
|
||||
break
|
||||
}
|
||||
cursor = e.End
|
||||
}
|
||||
if len(events) == 0 || math.Abs(cursor-slice.End) > 1e-6 {
|
||||
issues = append(issues, validationIssue{Field: fmt.Sprintf("sliceSegments.%d", i), Code: "annotation_coverage_gap", Message: "动作描述未完整覆盖切片,请补充动作或显式标记无效片段"})
|
||||
}
|
||||
}
|
||||
return issues
|
||||
}
|
||||
50
internal/api/annotation_boundary_grid_test.go
Normal file
50
internal/api/annotation_boundary_grid_test.go
Normal file
@ -0,0 +1,50 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"droboticflow/internal/domain"
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUnifiedBoundaryGridSharesFrameEdges(t *testing.T) {
|
||||
left, right := []hardwarePTSRow{}, []hardwarePTSRow{}
|
||||
for i := 0; i < 40; i++ {
|
||||
left = append(left, hardwarePTSRow{TimestampUS: 1000000 + int64(i)*33333})
|
||||
right = append(right, hardwarePTSRow{TimestampUS: 1000500 + int64(i)*33333})
|
||||
}
|
||||
g, err := newAnnotationBoundaryGrid(left, right, 1262237, 2264269, 4.0/3)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if math.Abs(g.Seconds[0]-8.0/30) > 1e-12 {
|
||||
t.Fatalf("first frame: %v", g.Seconds[0])
|
||||
}
|
||||
for i := 1; i < len(g.Seconds); i++ {
|
||||
if g.LeftFrames[i] <= g.LeftFrames[i-1] || g.RightFrames[i] <= g.RightFrames[i-1] {
|
||||
t.Fatalf("duplicate frame edge at %d", i)
|
||||
}
|
||||
j, e := g.resolve(g.Seconds[i])
|
||||
if e != nil || j != i {
|
||||
t.Fatal("round trip", i, j, e)
|
||||
}
|
||||
}
|
||||
if _, err = g.resolve(.2622369680188869); err == nil {
|
||||
t.Fatal("legacy off-grid boundary accepted")
|
||||
}
|
||||
if g.Timestamps[0] != 1262237 || g.Timestamps[len(g.Timestamps)-1] != 2264269 {
|
||||
t.Fatal("hardware endpoints changed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContinuousDescriptionsRequireExplicitCoverage(t *testing.T) {
|
||||
slices := []domain.SliceSegment{{ID: "s", Start: 0, End: 1}}
|
||||
valid := []domain.AnnotationSegment{{ID: "a", Start: 0, End: .3}, {ID: "b", Start: .3, End: 1}}
|
||||
if len(validateContinuousDescriptions(slices, valid)) != 0 {
|
||||
t.Fatal("touching intervals rejected")
|
||||
}
|
||||
for _, segments := range [][]domain.AnnotationSegment{nil, {{Start: .01, End: 1}}, {{Start: 0, End: .3}, {Start: .4, End: 1}}, {{Start: 0, End: .4}, {Start: .3, End: 1}}} {
|
||||
if len(validateContinuousDescriptions(slices, segments)) == 0 {
|
||||
t.Fatalf("invalid coverage accepted: %+v", segments)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -340,7 +340,7 @@ func TestReleaseQualityPreservesMaterialization(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSliceConfirmationStartsMaterializationWithoutAdvancingHumanStage(t *testing.T) {
|
||||
func TestSliceConfirmationRejectsMissingFrameSourcesWithoutAdvancingHumanStage(t *testing.T) {
|
||||
fixture := newCombinedDraftFixture(t)
|
||||
recorder := fixture.request(http.MethodPost, "/api/plugins/annotation-qa/tasks/"+fixture.task.ID+"/slice-confirmations", fixture.annotator, map[string]any{
|
||||
"version": fixture.item.Version,
|
||||
@ -349,15 +349,14 @@ func TestSliceConfirmationStartsMaterializationWithoutAdvancingHumanStage(t *tes
|
||||
{"id": "slice-b", "name": "后半段", "start": 5.0, "end": 10.0},
|
||||
},
|
||||
})
|
||||
if recorder.Code != http.StatusAccepted {
|
||||
if recorder.Code != http.StatusUnprocessableEntity || !bytes.Contains(recorder.Body.Bytes(), []byte("frame_boundaries_unavailable")) {
|
||||
t.Fatalf("slice confirmation status=%d body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
stored, err := fixture.store.GetHumanItem(fixture.ctx, fixture.item.ID)
|
||||
if err != nil || stored == nil {
|
||||
t.Fatalf("stored item=%#v err=%v", stored, err)
|
||||
}
|
||||
workflow := mapValue(stored.Subject.Payload["sliceWorkflow"])
|
||||
if stored.CurrentStageID != domain.FanyuV58StageAnnotationCombined || (stringValue(workflow["status"]) != "processing" && stringValue(workflow["status"]) != "failed") {
|
||||
if stored.CurrentStageID != domain.FanyuV58StageAnnotationCombined || stored.Version != fixture.item.Version {
|
||||
t.Fatalf("slice confirmation advanced stage or lost status: %#v", stored)
|
||||
}
|
||||
}
|
||||
@ -369,7 +368,7 @@ func TestCombinedSubmissionCanRequireEverySliceToBeCompleted(t *testing.T) {
|
||||
"sliceSegments": []map[string]any{{"id": "slice", "start": 0.0, "end": 10.0, "annotationStatus": "pending"}},
|
||||
"segments": []any{},
|
||||
})
|
||||
if recorder.Code != http.StatusBadRequest || !bytes.Contains(recorder.Body.Bytes(), []byte("slice_annotation_pending")) {
|
||||
if recorder.Code != http.StatusBadRequest || !bytes.Contains(recorder.Body.Bytes(), []byte("annotation_coverage_gap")) {
|
||||
t.Fatalf("incomplete combined submission status=%d body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
stored, _ := fixture.store.GetHumanItem(fixture.ctx, fixture.item.ID)
|
||||
@ -382,8 +381,8 @@ func TestCombinedSubmissionSupportsImmediateAsynchronousResponse(t *testing.T) {
|
||||
fixture := newCombinedDraftFixture(t)
|
||||
payload := map[string]any{
|
||||
"version": fixture.item.Version, "requireSliceCompletion": true,
|
||||
"sliceSegments": []map[string]any{{"id": "slice", "start": 0.0, "end": 10.0, "annotationStatus": "empty_confirmed"}},
|
||||
"segments": []any{},
|
||||
"sliceSegments": []map[string]any{{"id": "slice", "start": 0.0, "end": 10.0, "annotationStatus": "labeled"}},
|
||||
"segments": []map[string]any{{"id": "invalid", "start": 0, "end": 10, "description": "无效片段"}},
|
||||
}
|
||||
encoded, _ := json.Marshal(payload)
|
||||
request := httptest.NewRequest(http.MethodPost, "/api/plugins/annotation-qa/tasks/"+fixture.task.ID+"/combined-submissions", bytes.NewReader(encoded))
|
||||
@ -407,7 +406,7 @@ func TestCombinedSubmissionSupportsImmediateAsynchronousResponse(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCombinedSubmissionAllowsSlicesWithoutDescriptions(t *testing.T) {
|
||||
func TestCombinedSubmissionCannotBypassContinuousDescriptions(t *testing.T) {
|
||||
fixture := newCombinedDraftFixture(t)
|
||||
payload := map[string]any{
|
||||
"version": fixture.item.Version, "requireSliceCompletion": false,
|
||||
@ -424,8 +423,8 @@ func TestCombinedSubmissionAllowsSlicesWithoutDescriptions(t *testing.T) {
|
||||
request = request.WithContext(context.WithValue(request.Context(), authContextKey{}, &authenticatedPrincipal{User: fixture.annotator, Organization: domain.OrganizationRecord{ID: domain.DefaultOrganizationID, Status: domain.OrganizationStatusActive}}))
|
||||
recorder := httptest.NewRecorder()
|
||||
fixture.handler.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusAccepted {
|
||||
t.Fatalf("optional descriptions status=%d body=%s", recorder.Code, recorder.Body.String())
|
||||
if recorder.Code != http.StatusBadRequest || !bytes.Contains(recorder.Body.Bytes(), []byte("annotation_coverage_gap")) {
|
||||
t.Fatalf("coverage bypass status=%d body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -767,7 +767,85 @@ func (server *server) annotationFrameTimelineForTask(ctx context.Context, task d
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return annotationFrameTimelinePayload(side, rows)
|
||||
leftRows := rows
|
||||
leftVideo := artifactByID(artifactsForTarget(*execution, "fullLeftVideos"), task.ArtifactID)
|
||||
if leftVideo == nil {
|
||||
leftVideo = artifactByID(execution.InputArtifacts, task.ArtifactID)
|
||||
}
|
||||
readPTS := func(port, side string) ([]hardwarePTSRow, error) {
|
||||
a := matchingArtifact(artifactsForTarget(*execution, port), collectionID, side, "pts")
|
||||
p, e := server.safeMaterializationSourcePath(a)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return readHardwarePTS(p)
|
||||
}
|
||||
if camera == "right" {
|
||||
leftRows, err = readPTS("leftTimestamps", "left")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
rightRows, err := readPTS("rightTimestamps", "right")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
imuArtifact := matchingArtifact(artifactsForTarget(*execution, "imu"), collectionID, "imu", ".csv")
|
||||
imuPath, err := server.safeMaterializationSourcePath(imuArtifact)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
imuRows, err := readHardwareIMU(imuPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
leftPath, err := server.safeMaterializationSourcePath(leftVideo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
duration, err := ffprobeDurationSeconds(ctx, leftPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
leftEnd, err := ptsCoverageEnd(leftRows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rightEnd, err := ptsCoverageEnd(rightRows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
imuEnd, err := imuCoverageEnd(imuRows)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
start, end := max(leftRows[0].TimestampUS, rightRows[0].TimestampUS, imuRows[0].TimestampUS), min(leftEnd, rightEnd, imuEnd)
|
||||
grid, err := newAnnotationBoundaryGrid(leftRows, rightRows, start, end, duration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rightVideo := matchingArtifact(artifactsForTarget(*execution, "fullRightVideos"), collectionID, "right", ".mp4")
|
||||
rightPath, err := server.safeMaterializationSourcePath(rightVideo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rightDuration, err := ffprobeDurationSeconds(ctx, rightPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lc, err := ffprobeDeclaredFrameCount(ctx, leftPath)
|
||||
if err != nil || lc != len(leftRows) {
|
||||
return nil, fmt.Errorf("左视频与 PTS 帧数不匹配,不能建立统一边界")
|
||||
}
|
||||
rc, err := ffprobeDeclaredFrameCount(ctx, rightPath)
|
||||
if err != nil || rc != len(rightRows) {
|
||||
return nil, fmt.Errorf("右视频与 PTS 帧数不匹配,不能建立统一边界")
|
||||
}
|
||||
rightSeconds := make([]float64, len(grid.Timestamps))
|
||||
for i, f := range grid.RightFrames {
|
||||
rightSeconds[i] = float64(f) * rightDuration / float64(len(rightRows))
|
||||
}
|
||||
return map[string]any{"camera": camera, "frameCount": len(rows), "originTimestampUs": grid.Origin, "coverageEndTimestampUs": end, "boundariesSeconds": grid.Seconds, "rightBoundariesSeconds": rightSeconds, "boundaryTimestampUs": grid.Timestamps, "leftFrameIndices": grid.LeftFrames, "rightFrameIndices": grid.RightFrames, "rangeStartSecond": grid.Seconds[0], "rangeEndSecond": grid.Seconds[len(grid.Seconds)-1], "boundaryContract": "hardware-frame-v1", "ptsToMediaScale": grid.Scale}, nil
|
||||
}
|
||||
|
||||
func (server *server) handleAnnotationTaskFrameTimelineGet(writer http.ResponseWriter, request *http.Request) {
|
||||
@ -933,7 +1011,8 @@ type sliceConfirmationInput struct {
|
||||
}
|
||||
|
||||
type sliceResetInput struct {
|
||||
Version int `json:"version"`
|
||||
Version int `json:"version"`
|
||||
ResetToUnifiedRange bool `json:"resetToUnifiedRange"`
|
||||
}
|
||||
|
||||
func (payload combinedAnnotationDraftInput) normalizedOperations() []domain.SliceOperation {
|
||||
@ -1330,6 +1409,42 @@ func (server *server) handleAnnotationConfirmationCreate(writer http.ResponseWri
|
||||
return
|
||||
}
|
||||
slices := descriptionOnlySlices(payload.normalizedSliceSegments())
|
||||
if stringValue(sliceWorkflow["boundaryContract"]) == "hardware-frame-v1" {
|
||||
timeline, e := server.annotationFrameTimelineForTask(request.Context(), *task, "left")
|
||||
if e != nil {
|
||||
renderJSON(writer, http.StatusUnprocessableEntity, map[string]string{"error": e.Error()})
|
||||
return
|
||||
}
|
||||
grid := annotationBoundaryGrid{Seconds: timeline["boundariesSeconds"].([]float64), Timestamps: timeline["boundaryTimestampUs"].([]int64)}
|
||||
for i := range slices {
|
||||
a, e := grid.resolve(slices[i].Start)
|
||||
if e != nil {
|
||||
renderValidationError(writer, validationIssue{Field: "sliceSegments", Message: e.Error()})
|
||||
return
|
||||
}
|
||||
b, e := grid.resolve(slices[i].End)
|
||||
if e != nil || b <= a {
|
||||
renderValidationError(writer, validationIssue{Field: "sliceSegments", Message: "切片边界必须包含有效帧"})
|
||||
return
|
||||
}
|
||||
slices[i].Start, slices[i].End = grid.Seconds[a], grid.Seconds[b]
|
||||
slices[i].StartTimestampUS, slices[i].EndTimestampUS = grid.Timestamps[a], grid.Timestamps[b]
|
||||
}
|
||||
for i := range payload.Segments {
|
||||
a, e := grid.resolve(payload.Segments[i].Start)
|
||||
if e != nil {
|
||||
renderValidationError(writer, validationIssue{Field: "segments", Message: e.Error()})
|
||||
return
|
||||
}
|
||||
b, e := grid.resolve(payload.Segments[i].End)
|
||||
if e != nil || b <= a {
|
||||
renderValidationError(writer, validationIssue{Field: "segments", Message: "动作边界必须包含有效帧"})
|
||||
return
|
||||
}
|
||||
payload.Segments[i].Start, payload.Segments[i].End = grid.Seconds[a], grid.Seconds[b]
|
||||
payload.Segments[i].StartTimestampUS, payload.Segments[i].EndTimestampUS = grid.Timestamps[a], grid.Timestamps[b]
|
||||
}
|
||||
}
|
||||
issues := validateSliceSegments(slices, *task)
|
||||
issues = append(issues, validateCompleteSliceCoverage(slices, *task)...)
|
||||
issues = append(issues, validateDraftCombinedAnnotationEvents(payload.Segments, *task)...)
|
||||
@ -1422,7 +1537,8 @@ func (server *server) finishSliceConfirmation(ctx context.Context, taskID string
|
||||
log.Printf("[api] finishSliceConfirmation succeeded for task=%s item=%s requestID=%s revision=%d slices=%d", taskID, itemID, requestID, revision, len(materialization.Slices))
|
||||
workflow = map[string]any{
|
||||
"status": "completed", "phase": "annotate", "requestId": requestID, "revision": revision,
|
||||
"sliceCount": len(materialization.Slices), "materialization": materialization.Payload, "updatedAt": now,
|
||||
"boundaryContract": "hardware-frame-v1",
|
||||
"sliceCount": len(materialization.Slices), "materialization": materialization.Payload, "updatedAt": now,
|
||||
}
|
||||
delete(current.Subject.Payload, "annotationDraft")
|
||||
current.Subject.Payload["annotationWorkspace"] = map[string]any{
|
||||
@ -1477,6 +1593,22 @@ func (server *server) handleSliceConfirmationCreate(writer http.ResponseWriter,
|
||||
return
|
||||
}
|
||||
payload.SliceSegments = descriptionOnlySlices(payload.SliceSegments)
|
||||
if payload.Version != item.Version {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "Human item version conflict", "code": "version_conflict"})
|
||||
return
|
||||
}
|
||||
if stringValue(mapValue(item.Subject.Payload["sliceWorkflow"])["status"]) == "processing" {
|
||||
renderJSON(writer, http.StatusConflict, map[string]string{"error": "切片仍在处理中,请等待完成或返回调整切片", "code": "slice_processing"})
|
||||
return
|
||||
}
|
||||
timeline, timelineErr := server.annotationFrameTimelineForTask(request.Context(), *task, "left")
|
||||
if timelineErr != nil {
|
||||
renderJSON(writer, http.StatusUnprocessableEntity, map[string]string{"error": "无法校验统一帧边界:" + timelineErr.Error(), "code": "frame_boundaries_unavailable"})
|
||||
return
|
||||
}
|
||||
task.CoverageStartSecond = floatValue(timeline["rangeStartSecond"])
|
||||
task.CoverageEndSecond = floatValue(timeline["rangeEndSecond"])
|
||||
task.CoverageMode = "full_common_range"
|
||||
issues := validateSliceSegments(payload.SliceSegments, *task)
|
||||
issues = append(issues, validateCompleteSliceCoverage(payload.SliceSegments, *task)...)
|
||||
if len(issues) > 0 {
|
||||
@ -1592,6 +1724,16 @@ func (server *server) handleSliceResetCreate(writer http.ResponseWriter, request
|
||||
"sliceSegments": slices, "operations": []domain.SliceOperation{}, "segments": []domain.AnnotationSegment{},
|
||||
"statuses": pendingSliceStatuses(slices), "userId": principal.User.ID, "savedAt": now,
|
||||
}
|
||||
if payload.ResetToUnifiedRange {
|
||||
timeline, e := server.annotationFrameTimelineForTask(request.Context(), *task, "left")
|
||||
if e != nil {
|
||||
renderJSON(writer, http.StatusUnprocessableEntity, map[string]string{"error": e.Error()})
|
||||
return
|
||||
}
|
||||
slices = []domain.SliceSegment{{ID: domain.NewID("slice"), Name: "切片 001", Start: floatValue(timeline["rangeStartSecond"]), End: floatValue(timeline["rangeEndSecond"])}}
|
||||
resetDraft["sliceSegments"] = slices
|
||||
resetDraft["statuses"] = pendingSliceStatuses(slices)
|
||||
}
|
||||
delete(item.Subject.Payload, "annotationDraft")
|
||||
item.Subject.Payload["annotationWorkspace"] = resetDraft
|
||||
item.Subject.Payload["sliceWorkflow"] = map[string]any{"status": "editing", "phase": "slice", "resetAt": now, "revision": intValue(mapValue(item.Subject.Payload["sliceWorkflow"])["revision"])}
|
||||
@ -1666,6 +1808,12 @@ func (server *server) handleCombinedAnnotationSubmission(writer http.ResponseWri
|
||||
renderValidationError(writer, issues...)
|
||||
return
|
||||
}
|
||||
if domain.IsFanyuV58ThreeRoleHumanLoop(batch.Stages) {
|
||||
if issues := validateContinuousDescriptions(payload.SliceSegments, payload.Segments); len(issues) > 0 {
|
||||
renderValidationError(writer, issues...)
|
||||
return
|
||||
}
|
||||
}
|
||||
if payload.RequireSliceCompletion {
|
||||
if issues := validateRequiredSliceCompletion(payload.SliceSegments, payload.Segments, task.TemplateVersion >= 6); len(issues) > 0 {
|
||||
renderValidationError(writer, issues...)
|
||||
@ -1961,7 +2109,7 @@ func validateCompleteSliceCoverage(segments []domain.SliceSegment, task domain.A
|
||||
}
|
||||
for index := 1; index < len(sorted); index++ {
|
||||
delta := sorted[index].Start - sorted[index-1].End
|
||||
if math.Abs(delta) <= sliceCoverageToleranceSeconds {
|
||||
if math.Abs(delta) <= 0.000001 {
|
||||
continue
|
||||
}
|
||||
if delta > 0 {
|
||||
|
||||
@ -66,7 +66,7 @@ func TestInvalidatedCombinedReservationRequiresExplicitCurrentVersion(t *testing
|
||||
|
||||
func seedCompletedMaterialization(t *testing.T, fixture combinedDraftFixture, revision int) {
|
||||
t.Helper()
|
||||
artifact := domain.ExecutionArtifact{ID: fmt.Sprintf("%s-%s-%s-materialized-revision-%06d", fixture.task.RunID, fixture.task.NodeID, fixture.task.ID, revision), Data: map[string]any{"sliceCount": 1}}
|
||||
artifact := domain.ExecutionArtifact{ID: fmt.Sprintf("%s-%s-%s-materialized-revision-%06d", fixture.task.RunID, fixture.task.NodeID, fixture.task.ID, revision), Data: map[string]any{"sliceCount": 1, "boundaryContract": "hardware-frame-v1"}}
|
||||
if err := fixture.store.UpsertRun(fixture.ctx, domain.RunRecord{ID: fixture.task.RunID, OrganizationID: fixture.task.OrganizationID, Artifacts: []domain.ExecutionArtifact{artifact}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -87,7 +87,7 @@ func TestInvalidatedSubmissionReplacesSupersededDescriptions(t *testing.T) {
|
||||
seedCompletedMaterialization(t, fixture, 2)
|
||||
r := fixture.request(http.MethodPost, "/api/plugins/annotation-qa/tasks/"+fixture.task.ID+"/combined-submissions", fixture.annotator, map[string]any{
|
||||
"version": item.Version, "sliceSegments": []map[string]any{{"id": "slice", "start": 0, "end": 10}},
|
||||
"segments": []map[string]any{{"id": "confirmed-description", "description": "保留已确认描述", "start": 1, "end": 2}},
|
||||
"segments": []map[string]any{{"id": "confirmed-description", "description": "保留已确认描述", "start": 0, "end": 10}},
|
||||
})
|
||||
if r.Code != http.StatusCreated {
|
||||
t.Fatalf("status=%d body=%s", r.Code, r.Body.String())
|
||||
@ -130,7 +130,7 @@ func TestCombinedSubmissionFinalCASFailureDoesNotPublishQualityTask(t *testing.T
|
||||
seedCompletedMaterialization(t, fixture, 1)
|
||||
fixture.handler = NewHandler(&conflictingSubmissionStore{fixture.store}, nil)
|
||||
r := fixture.request(http.MethodPost, "/api/plugins/annotation-qa/tasks/"+fixture.task.ID+"/combined-submissions", fixture.annotator, map[string]any{
|
||||
"version": fixture.item.Version, "sliceSegments": []map[string]any{{"id": "slice", "start": 0, "end": 10}}, "segments": []any{},
|
||||
"version": fixture.item.Version, "sliceSegments": []map[string]any{{"id": "slice", "start": 0, "end": 10}}, "segments": []map[string]any{{"id": "invalid", "start": 0, "end": 10, "description": "无效片段"}},
|
||||
})
|
||||
if r.Code != http.StatusConflict {
|
||||
t.Fatalf("status=%d body=%s", r.Code, r.Body.String())
|
||||
|
||||
@ -262,8 +262,22 @@ func ffprobeFrameCount(ctx context.Context, path string) (int, error) {
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Timeline loading reads MP4 metadata, not every decoded frame of a long Capture.
|
||||
// Materialization still performs the full frame-count integrity check above.
|
||||
func ffprobeDeclaredFrameCount(ctx context.Context, path string) (int, error) {
|
||||
output, err := exec.CommandContext(ctx, "ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=nb_frames", "-of", "default=nokey=1:noprint_wrappers=1", path).CombinedOutput()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("读取视频帧元数据失败:%s", filepath.Base(path))
|
||||
}
|
||||
count, err := strconv.Atoi(strings.TrimSpace(string(output)))
|
||||
if err != nil || count <= 0 {
|
||||
return 0, fmt.Errorf("视频缺少有效帧数元数据:%s", filepath.Base(path))
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func ffprobeDurationSeconds(ctx context.Context, path string) (float64, error) {
|
||||
output, err := exec.CommandContext(ctx, "ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=nokey=1:noprint_wrappers=1", path).CombinedOutput()
|
||||
output, err := exec.CommandContext(ctx, "ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=duration", "-of", "default=nokey=1:noprint_wrappers=1", path).CombinedOutput()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("ffprobe duration %s: %s", filepath.Base(path), strings.TrimSpace(string(output)))
|
||||
}
|
||||
@ -438,6 +452,9 @@ func (server *server) materializeCombinedSliceSubmission(ctx context.Context, ta
|
||||
artifactID := fmt.Sprintf("%s-%s-%s-materialized-revision-%06d", task.RunID, task.NodeID, task.ID, revision)
|
||||
for _, existing := range run.Artifacts {
|
||||
if existing.ID == artifactID {
|
||||
if stringValue(existing.Data["boundaryContract"]) != "hardware-frame-v1" {
|
||||
return nil, fmt.Errorf("历史切片不使用统一边界,请重新确认切片;不会自动移动已有标注")
|
||||
}
|
||||
manifestSHA := ""
|
||||
if existing.Metadata != nil {
|
||||
manifestSHA = existing.Metadata.SHA256
|
||||
@ -525,6 +542,10 @@ func (server *server) materializeCombinedSliceSubmission(ctx context.Context, ta
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rightMediaDuration, err := ffprobeDurationSeconds(ctx, rightPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
leftCoverageEnd, err := ptsCoverageEnd(leftPTS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -542,17 +563,27 @@ func (server *server) materializeCombinedSliceSubmission(ctx context.Context, ta
|
||||
if commonEnd <= commonStart {
|
||||
return nil, fmt.Errorf("required streams have no common hardware-time range")
|
||||
}
|
||||
leftTimelineOrigin := leftPTS[0].TimestampUS
|
||||
leftPTSDurationSeconds := float64(leftCoverageEnd-leftTimelineOrigin) / 1_000_000
|
||||
ptsToMediaScale := leftMediaDuration / leftPTSDurationSeconds
|
||||
if math.IsNaN(ptsToMediaScale) || math.IsInf(ptsToMediaScale, 0) || ptsToMediaScale < 0.5 || ptsToMediaScale > 2 {
|
||||
return nil, fmt.Errorf("left video and PTS timelines have an implausible scale mismatch")
|
||||
grid, err := newAnnotationBoundaryGrid(leftPTS, rightPTS, commonStart, commonEnd, leftMediaDuration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ptsToMediaScale := grid.Scale
|
||||
timestampToMediaSecond := func(timestampUS int64) float64 {
|
||||
return float64(timestampUS-leftTimelineOrigin) / 1_000_000 * ptsToMediaScale
|
||||
i := sort.Search(len(grid.Timestamps), func(i int) bool { return grid.Timestamps[i] >= timestampUS })
|
||||
if i >= len(grid.Seconds) {
|
||||
i = len(grid.Seconds) - 1
|
||||
}
|
||||
return grid.Seconds[i]
|
||||
}
|
||||
mediaSecondToTimestamp := func(second float64) int64 {
|
||||
return leftTimelineOrigin + int64(math.Round(second/ptsToMediaScale*1_000_000))
|
||||
i := sort.SearchFloat64s(grid.Seconds, second)
|
||||
if i >= len(grid.Seconds) {
|
||||
i--
|
||||
}
|
||||
if i > 0 && math.Abs(grid.Seconds[i-1]-second) < math.Abs(grid.Seconds[i]-second) {
|
||||
i--
|
||||
}
|
||||
return grid.Timestamps[i]
|
||||
}
|
||||
commonMediaStart := timestampToMediaSecond(commonStart)
|
||||
commonMediaEnd := timestampToMediaSecond(commonEnd)
|
||||
@ -568,42 +599,25 @@ func (server *server) materializeCombinedSliceSubmission(ctx context.Context, ta
|
||||
if len(slices) == 0 {
|
||||
return nil, fmt.Errorf("full synchronized coverage requires at least one slice")
|
||||
}
|
||||
requestedStartUS := mediaSecondToTimestamp(slices[0].Start)
|
||||
requestedEndUS := mediaSecondToTimestamp(slices[len(slices)-1].End)
|
||||
boundaryToleranceUS := int64(math.Ceil(sliceCoverageToleranceSeconds / ptsToMediaScale * 1_000_000))
|
||||
if requestedStartUS > commonStart+boundaryToleranceUS || requestedEndUS < commonEnd-boundaryToleranceUS {
|
||||
return nil, fmt.Errorf("submitted slices do not cover the full common hardware-time range")
|
||||
}
|
||||
clippedSlices := make([]domain.SliceSegment, 0, len(slices))
|
||||
for _, slice := range slices {
|
||||
slice.Start = max(slice.Start, commonMediaStart)
|
||||
slice.End = min(slice.End, commonMediaEnd)
|
||||
if slice.End > slice.Start {
|
||||
clippedSlices = append(clippedSlices, slice)
|
||||
}
|
||||
}
|
||||
if len(clippedSlices) == 0 {
|
||||
return nil, fmt.Errorf("submitted slices do not intersect the common hardware-time range")
|
||||
}
|
||||
normalizedSlices := make([]domain.SliceSegment, 0, len(slices))
|
||||
previousEndUS := commonStart
|
||||
for index, slice := range clippedSlices {
|
||||
startUS := mediaSecondToTimestamp(slice.Start)
|
||||
endUS := mediaSecondToTimestamp(slice.End)
|
||||
if index == 0 {
|
||||
startUS = commonStart
|
||||
} else if absInt64(startUS-previousEndUS) <= boundaryToleranceUS {
|
||||
startUS = previousEndUS
|
||||
for _, slice := range slices {
|
||||
startIndex, err := grid.resolve(slice.Start)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if index == len(clippedSlices)-1 {
|
||||
endUS = commonEnd
|
||||
endIndex, err := grid.resolve(slice.End)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
startUS, endUS := grid.Timestamps[startIndex], grid.Timestamps[endIndex]
|
||||
if startUS != previousEndUS || endUS <= startUS || endUS > commonEnd {
|
||||
return nil, fmt.Errorf("slice %s leaves a gap or overlap in the common hardware-time range", slice.ID)
|
||||
}
|
||||
normalized := slice
|
||||
normalized.Start = timestampToMediaSecond(startUS)
|
||||
normalized.End = timestampToMediaSecond(endUS)
|
||||
normalized.StartTimestampUS, normalized.EndTimestampUS = startUS, endUS
|
||||
normalizedSlices = append(normalizedSlices, normalized)
|
||||
previousEndUS = endUS
|
||||
}
|
||||
@ -612,12 +626,27 @@ func (server *server) materializeCombinedSliceSubmission(ctx context.Context, ta
|
||||
}
|
||||
normalizedSegments := make([]domain.AnnotationSegment, 0, len(payload.Segments))
|
||||
for _, segment := range payload.Segments {
|
||||
segment.Start = max(segment.Start, commonMediaStart)
|
||||
segment.End = min(segment.End, commonMediaEnd)
|
||||
if segment.End > segment.Start {
|
||||
normalizedSegments = append(normalizedSegments, segment)
|
||||
si, e := grid.resolve(segment.Start)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
ei, e := grid.resolve(segment.End)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
if ei <= si {
|
||||
return nil, fmt.Errorf("动作区间必须包含有效帧,不能在同一边界上使用不同时间")
|
||||
}
|
||||
segment.Start, segment.End = grid.Seconds[si], grid.Seconds[ei]
|
||||
segment.StartTimestampUS, segment.EndTimestampUS = grid.Timestamps[si], grid.Timestamps[ei]
|
||||
normalizedSegments = append(normalizedSegments, segment)
|
||||
}
|
||||
if len(normalizedSegments) > 0 {
|
||||
if issues := validateContinuousDescriptions(normalizedSlices, normalizedSegments); len(issues) > 0 {
|
||||
return nil, fmt.Errorf("%s", issues[0].Message)
|
||||
}
|
||||
}
|
||||
sort.Slice(normalizedSegments, func(i, j int) bool { return normalizedSegments[i].Start < normalizedSegments[j].Start })
|
||||
leftCommonStart := sort.Search(len(leftPTS), func(index int) bool { return leftPTS[index].TimestampUS >= commonStart })
|
||||
leftCommonEnd := sort.Search(len(leftPTS), func(index int) bool { return leftPTS[index].TimestampUS >= commonEnd })
|
||||
rightCommonStart := sort.Search(len(rightPTS), func(index int) bool { return rightPTS[index].TimestampUS >= commonStart })
|
||||
@ -698,7 +727,7 @@ func (server *server) materializeCombinedSliceSubmission(ctx context.Context, ta
|
||||
relativeEnd := segmentEnd - slice.Start
|
||||
actions = append(actions, map[string]any{"id": segment.ID, "description": segment.Description, "descriptionTemplateId": segment.LabelID, "phrases": segment.Phrases, "source": segment.Source, "confidence": segment.Confidence, "clipStartMs": relativeStart * 1000, "clipEndMs": relativeEnd * 1000, "startTimestampUs": mediaSecondToTimestamp(segmentStart), "endTimestampUs": mediaSecondToTimestamp(segmentEnd)})
|
||||
}
|
||||
annotation := map[string]any{"schemaVersion": "droboticflow.timestamped-description/v3", "sliceId": sliceID, "sliceName": slice.Name, "window": map[string]any{"startTimestampUs": startUS, "endTimestampUs": endUS, "semantics": "half-open"}, "descriptions": actions, "actions": actions}
|
||||
annotation := map[string]any{"schemaVersion": "droboticflow.timestamped-description/v3", "boundaryContract": "hardware-frame-v1", "sliceId": sliceID, "sliceName": slice.Name, "window": map[string]any{"startTimestampUs": startUS, "endTimestampUs": endUS, "semantics": "half-open"}, "descriptions": actions, "actions": actions}
|
||||
annotationSHA, annotationBytes, err := writeJSONFile(filepath.Join(directory, "annotation.json"), annotation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -706,6 +735,16 @@ func (server *server) materializeCombinedSliceSubmission(ctx context.Context, ta
|
||||
leftVideo := artifactForMaterializationPath(leftOutput, "leftVideo", domain.PortTypeVideo)
|
||||
rightVideo := artifactForMaterializationPath(rightOutput, "rightVideo", domain.PortTypeVideo)
|
||||
maximumAlignmentUS := maximumNearestAlignmentUS(leftPTS, leftStart, leftEnd, rightPTS, rightStart, rightEnd)
|
||||
boundaryTimes, rightBoundaryTimes := []float64{}, []float64{}
|
||||
boundaryIDs := []int64{}
|
||||
for k, stamp := range grid.Timestamps {
|
||||
if stamp < startUS || stamp > endUS {
|
||||
continue
|
||||
}
|
||||
boundaryIDs = append(boundaryIDs, stamp)
|
||||
boundaryTimes = append(boundaryTimes, grid.Seconds[k]-slice.Start)
|
||||
rightBoundaryTimes = append(rightBoundaryTimes, float64(grid.RightFrames[k]-rightStart)*rightMediaDuration/float64(len(rightPTS)))
|
||||
}
|
||||
synchronization := map[string]any{"schemaVersion": "droboticflow.synchronized-slice/v1", "collectionId": collectionID, "sliceIndex": index + 1, "sliceCount": len(normalizedSlices), "sliceName": slice.Name, "window": map[string]any{"startTimestampUs": startUS, "endTimestampUs": endUS, "semantics": "half-open"}, "commonRange": map[string]any{"startTimestampUs": commonStart, "endTimestampUs": commonEnd, "startSecond": commonMediaStart, "endSecond": commonMediaEnd}, "coverage": map[string]any{"mode": "full_common_range", "contiguous": true, "previousEndTimestampUs": func() any {
|
||||
if index == 0 {
|
||||
return nil
|
||||
@ -717,6 +756,10 @@ func (server *server) materializeCombinedSliceSubmission(ctx context.Context, ta
|
||||
}
|
||||
return endUS
|
||||
}()}, "maxStereoAlignmentErrorUs": maximumAlignmentUS, "left": map[string]any{"video": leftVideo, "pts": leftManifest}, "right": map[string]any{"video": rightVideo, "pts": rightManifest}, "imu": imuManifest, "lineage": map[string]any{"leftVideoArtifactId": leftArtifact.ID, "rightVideoArtifactId": rightArtifact.ID, "leftPtsArtifactId": leftPTSArtifact.ID, "rightPtsArtifactId": rightPTSArtifact.ID, "imuArtifactId": imuArtifact.ID}}
|
||||
synchronization["boundaryContract"] = "hardware-frame-v1"
|
||||
synchronization["boundaryTimestampUs"] = boundaryIDs
|
||||
synchronization["boundarySeconds"] = boundaryTimes
|
||||
synchronization["rightBoundarySeconds"] = rightBoundaryTimes
|
||||
syncSHA, syncBytes, err := writeJSONFile(filepath.Join(directory, "synchronized-slice.json"), synchronization)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -746,6 +789,7 @@ func (server *server) materializeCombinedSliceSubmission(ctx context.Context, ta
|
||||
}
|
||||
artifact := domain.ExecutionArtifact{ID: artifactID, RunID: task.RunID, NodeID: task.NodeID, PortID: "materializedSliceDirectory", PortName: "materializedSliceDirectory", Name: fmt.Sprintf("revision-%06d.directory.index", revision), Type: domain.PortTypeFile, Size: fmt.Sprintf("%d files", len(manifestItems)*7+1), SizeBytes: manifestBytes, Path: root, Metadata: &domain.ArtifactMetadata{SHA256: manifestSHA, MimeType: "application/json"}, Data: map[string]any{"schemaVersion": "droboticflow.directory-index/v1", "presentation": "collection", "datasetType": "directory", "dataSource": "FILESYSTEM", "rootPath": root, "manifestPath": manifestPath, "revision": revision, "sliceCount": len(manifestItems), "coverage": coverage, "normalizedSlices": normalizedSlices, "normalizedSegments": normalizedSegments}}
|
||||
run.Artifacts = append(run.Artifacts, artifact)
|
||||
artifact.Data["boundaryContract"] = "hardware-frame-v1"
|
||||
for index := range run.NodeExecutions {
|
||||
if run.NodeExecutions[index].NodeID == task.NodeID {
|
||||
run.NodeExecutions[index].Artifacts = append(run.NodeExecutions[index].Artifacts, artifact)
|
||||
|
||||
@ -82,6 +82,7 @@ func TestMaterializeCombinedSliceSubmissionCreatesStereoPTSImuAndTimestampedAnno
|
||||
task := domain.AnnotationTaskRecord{ID: "task", OrganizationID: domain.DefaultOrganizationID, ProjectID: "project", WorkflowID: "workflow", RunID: run.ID, NodeID: "human", ArtifactID: leftArtifact.ID, ClipStart: 0, ClipEnd: 1, SourceIsFullVideo: true, SourceDurationSeconds: 1}
|
||||
item := domain.HumanItemRecord{ID: "item", OrganizationID: domain.DefaultOrganizationID, RunID: run.ID, GateNodeID: "human", Subject: domain.HumanSubjectRef{ItemKey: "capture", Payload: map[string]any{}}}
|
||||
payload := combinedAnnotationSubmissionInput{SliceSegments: []domain.SliceSegment{{ID: "slice-a", Name: "拿取前", Start: 0, End: 0.5}, {ID: "slice-b", Name: "拿取后", Start: 0.5, End: 1}}, Segments: []domain.AnnotationSegment{{ID: "description", LabelID: "dict-01", Description: "拿取商品", Start: 0, End: 0.5, Confidence: 1, Source: "human"}}}
|
||||
payload.Segments = append(payload.Segments, domain.AnnotationSegment{ID: "invalid", Description: "无效片段", Start: .5, End: 1})
|
||||
materialization, err := server.materializeCombinedSliceSubmission(ctx, task, item, payload, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@ -99,17 +99,19 @@ type AnnotationTemplateRecord struct {
|
||||
}
|
||||
|
||||
type AnnotationSegment struct {
|
||||
ID string `json:"id" bson:"id"`
|
||||
LabelID string `json:"labelId" bson:"labelId"`
|
||||
Label string `json:"label" bson:"label"`
|
||||
Description string `json:"description,omitempty" bson:"description,omitempty"`
|
||||
Handedness string `json:"handedness,omitempty" bson:"handedness,omitempty"`
|
||||
Start float64 `json:"start" bson:"start"`
|
||||
End float64 `json:"end" bson:"end"`
|
||||
Confidence float64 `json:"confidence,omitempty" bson:"confidence,omitempty"`
|
||||
Phrases []string `json:"phrases,omitempty" bson:"phrases,omitempty"`
|
||||
Source string `json:"source,omitempty" bson:"source,omitempty"`
|
||||
IsInvalid bool `json:"isInvalid,omitempty" bson:"isInvalid,omitempty"`
|
||||
ID string `json:"id" bson:"id"`
|
||||
LabelID string `json:"labelId" bson:"labelId"`
|
||||
Label string `json:"label" bson:"label"`
|
||||
Description string `json:"description,omitempty" bson:"description,omitempty"`
|
||||
Handedness string `json:"handedness,omitempty" bson:"handedness,omitempty"`
|
||||
Start float64 `json:"start" bson:"start"`
|
||||
End float64 `json:"end" bson:"end"`
|
||||
StartTimestampUS int64 `json:"startTimestampUs,omitempty" bson:"startTimestampUs,omitempty"`
|
||||
EndTimestampUS int64 `json:"endTimestampUs,omitempty" bson:"endTimestampUs,omitempty"`
|
||||
Confidence float64 `json:"confidence,omitempty" bson:"confidence,omitempty"`
|
||||
Phrases []string `json:"phrases,omitempty" bson:"phrases,omitempty"`
|
||||
Source string `json:"source,omitempty" bson:"source,omitempty"`
|
||||
IsInvalid bool `json:"isInvalid,omitempty" bson:"isInvalid,omitempty"`
|
||||
}
|
||||
|
||||
type SliceAnnotationStatus string
|
||||
@ -125,6 +127,8 @@ type SliceSegment struct {
|
||||
Name string `json:"name,omitempty" bson:"name,omitempty"`
|
||||
Start float64 `json:"start" bson:"start"`
|
||||
End float64 `json:"end" bson:"end"`
|
||||
StartTimestampUS int64 `json:"startTimestampUs,omitempty" bson:"startTimestampUs,omitempty"`
|
||||
EndTimestampUS int64 `json:"endTimestampUs,omitempty" bson:"endTimestampUs,omitempty"`
|
||||
SourceIDs []string `json:"sourceIds,omitempty" bson:"sourceIds,omitempty"`
|
||||
TaskLabelID string `json:"taskLabelId,omitempty" bson:"taskLabelId,omitempty"`
|
||||
TaskLabel string `json:"taskLabel,omitempty" bson:"taskLabel,omitempty"`
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -197,7 +197,7 @@ export function FinalAcceptanceWorkspace({
|
||||
setMetadata({
|
||||
key: activeKey,
|
||||
actions: acceptanceActions(document),
|
||||
frames,
|
||||
frames: synchronization.boundaryContract === "hardware-frame-v1" ? synchronization.boundarySeconds : frames,
|
||||
sync: synchronization,
|
||||
error: "",
|
||||
loading: false,
|
||||
@ -219,9 +219,11 @@ export function FinalAcceptanceWorkspace({
|
||||
|
||||
const currentMetadata = metadata.key === activeKey ? metadata : null;
|
||||
const duration =
|
||||
mediaDuration.key === activeKey && mediaDuration.value > 0
|
||||
? mediaDuration.value
|
||||
: Math.max(0.001, Number(active?.end - active?.start) || 0.001);
|
||||
currentMetadata?.sync?.boundaryContract === "hardware-frame-v1"
|
||||
? Number(currentMetadata.frames.at(-1))
|
||||
: mediaDuration.key === activeKey && mediaDuration.value > 0
|
||||
? mediaDuration.value
|
||||
: Math.max(0.001, Number(active?.end - active?.start) || 0.001);
|
||||
const frames = useMemo(() => {
|
||||
const values = (currentMetadata?.frames || []).filter((v) => v >= 0 && v < duration - 0.000001);
|
||||
if (!values.length) return [];
|
||||
@ -365,6 +367,8 @@ export function FinalAcceptanceWorkspace({
|
||||
statuses={{}}
|
||||
phase="annotate"
|
||||
frameBoundaries={frames}
|
||||
rightMediaBoundaries={currentMetadata?.sync?.rightBoundarySeconds}
|
||||
unifiedBoundaries={currentMetadata?.sync?.boundaryContract === "hardware-frame-v1"}
|
||||
onChange={noChange}
|
||||
onPlayheadChange={setCurrentTime}
|
||||
onMediaDuration={(value) => setMediaDuration({ key: activeKey, value })}
|
||||
|
||||
@ -102,9 +102,10 @@ export function annotationDraftAtPlayhead(slice, segments, playhead, excludedId
|
||||
|
||||
export function annotationDraftCheckAtPlayhead(slice, segments, playhead, excludedId = "") {
|
||||
let start = Number(playhead);
|
||||
const lower = Number(slice?.start), upper = Number(slice?.end);
|
||||
const us = value => Math.round(value * 1_000_000);
|
||||
const fail = reason => ({ draft: null, reason });
|
||||
const lower = Number(slice?.start),
|
||||
upper = Number(slice?.end);
|
||||
const us = (value) => Math.round(value * 1_000_000);
|
||||
const fail = (reason) => ({ draft: null, reason });
|
||||
if (![start, lower, upper].every(Number.isFinite) || upper <= lower) return fail("outside");
|
||||
// Compare at hardware timestamp precision, but keep the true slice boundary
|
||||
// in the new draft. Never round or move existing annotation/PTS data.
|
||||
@ -112,14 +113,92 @@ export function annotationDraftCheckAtPlayhead(slice, segments, playhead, exclud
|
||||
if (Math.abs(start - lower) <= 0.000001 + roundingSlack) start = lower;
|
||||
if (start < lower || us(start) < us(lower)) return fail("outside");
|
||||
if (start >= upper || us(start) >= us(upper)) return fail("end");
|
||||
const others = segments.filter(segment => segment.id !== excludedId);
|
||||
const others = segments.filter((segment) => segment.id !== excludedId);
|
||||
// The exact comparison is a conservative guard against admitting a real
|
||||
// overlap that happens to round onto an interval's exclusive end.
|
||||
if (others.some(segment => (start >= segment.start && start < segment.end) || (us(start) >= us(segment.start) && us(start) < us(segment.end)))) return fail("occupied");
|
||||
const limit = Math.min(slice.end, ...others.filter(segment => segment.start > start).map(segment => segment.start));
|
||||
if (
|
||||
others.some(
|
||||
(segment) =>
|
||||
(start >= segment.start && start < segment.end) ||
|
||||
(us(start) >= us(segment.start) && us(start) < us(segment.end)),
|
||||
)
|
||||
)
|
||||
return fail("occupied");
|
||||
const limit = Math.min(
|
||||
slice.end,
|
||||
...others.filter((segment) => segment.start > start).map((segment) => segment.start),
|
||||
);
|
||||
if (!excludedId)
|
||||
start = Math.max(lower, ...others.filter((segment) => segment.end <= start).map((segment) => segment.end));
|
||||
return { draft: { start, end: start, limit }, reason: "" };
|
||||
}
|
||||
|
||||
export function annotationCoverageGaps(slice, segments = []) {
|
||||
if (!slice) return [];
|
||||
const ordered = annotationSegmentsForSlice(slice, segments)
|
||||
.slice()
|
||||
.sort((a, b) => a.start - b.start);
|
||||
const gaps = [];
|
||||
let cursor = slice.start;
|
||||
for (const segment of ordered) {
|
||||
if (segment.start - cursor > 0.000001) gaps.push({ start: cursor, end: segment.start });
|
||||
cursor = Math.max(cursor, segment.end);
|
||||
}
|
||||
if (slice.end - cursor > 0.000001) gaps.push({ start: cursor, end: slice.end });
|
||||
return gaps;
|
||||
}
|
||||
|
||||
export function continuousAnnotationIssues(slices, segments) {
|
||||
return slices.flatMap((slice) =>
|
||||
annotationCoverageGaps(slice, segments).map((gap) => ({ code: "annotation_gap", sliceId: slice.id, ...gap })),
|
||||
);
|
||||
}
|
||||
|
||||
export function frameBoundaryAtOrBefore(boundaries, time) {
|
||||
if (!boundaries.length) return time;
|
||||
let lo = 0,
|
||||
hi = boundaries.length;
|
||||
while (lo < hi) {
|
||||
const mid = (lo + hi) >>> 1;
|
||||
if (Math.round(boundaries[mid] * 1e6) <= Math.round(time * 1e6)) lo = mid + 1;
|
||||
else hi = mid;
|
||||
}
|
||||
return boundaries[Math.max(0, lo - 1)];
|
||||
}
|
||||
|
||||
export function frameBoundaryAligned(boundaries, time) {
|
||||
const i = nearestFrameBoundaryIndex(boundaries, time);
|
||||
return i >= 0 && Math.abs(boundaries[i] - time) <= 0.000001;
|
||||
}
|
||||
|
||||
export function mapCameraBoundaryTime(left, right, time) {
|
||||
if (left.length < 2 || left.length !== right?.length) return time;
|
||||
let i = 0,
|
||||
hi = left.length - 1;
|
||||
while (i < hi) {
|
||||
const m = Math.ceil((i + hi) / 2);
|
||||
if (left[m] <= time) i = m;
|
||||
else hi = m - 1;
|
||||
}
|
||||
if (i === left.length - 1) return right[i];
|
||||
const ratio = Math.max(0, Math.min(1, (time - left[i]) / (left[i + 1] - left[i])));
|
||||
return right[i] + ratio * (right[i + 1] - right[i]);
|
||||
}
|
||||
|
||||
export function replaceAnnotationSharedBoundaries(segments, candidate) {
|
||||
const old = segments.find((s) => s.id === candidate.id);
|
||||
if (!old) return [...segments, candidate];
|
||||
return segments.map((s) =>
|
||||
s.id === candidate.id
|
||||
? candidate
|
||||
: {
|
||||
...s,
|
||||
...(Math.abs(s.end - old.start) <= 1e-6 ? { end: candidate.start } : {}),
|
||||
...(Math.abs(s.start - old.end) <= 1e-6 ? { start: candidate.end } : {}),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export function annotationEventOverlaps(segments = [], candidate, excludedId = "", toleranceSeconds = 0.001) {
|
||||
if (!candidate) return false;
|
||||
const tolerance = Math.max(Number(toleranceSeconds) || 0.001, 0.000001);
|
||||
|
||||
@ -79,6 +79,8 @@ import {
|
||||
stepFrameBoundary,
|
||||
summarizeSliceProgress,
|
||||
validateAnnotationWorkspace,
|
||||
continuousAnnotationIssues,
|
||||
frameBoundaryAligned,
|
||||
} from "../lib/annotation-workbench.js";
|
||||
import { getActionErrorMessage, recoverableGatewayStatus } from "../lib/action-errors.js";
|
||||
import { combinedSubmissionState, combinedSubmissionFinished } from "../lib/annotation-submission-state.js";
|
||||
@ -156,7 +158,12 @@ export const deriveDetailedTaskStatus = (
|
||||
| { status?: string; phase?: string; error?: string }
|
||||
| undefined;
|
||||
|
||||
if (task.status === "rework" || humanItem?.status === "rework" || (Number(humanItem?.reviewRound || 0) > 0 && humanItem?.currentStageId === "annotation_combined")) return "rework";
|
||||
if (
|
||||
task.status === "rework" ||
|
||||
humanItem?.status === "rework" ||
|
||||
(Number(humanItem?.reviewRound || 0) > 0 && humanItem?.currentStageId === "annotation_combined")
|
||||
)
|
||||
return "rework";
|
||||
|
||||
if (livePhase === "materializing" || sliceWorkflow?.status === "processing") {
|
||||
return "slicing";
|
||||
@ -467,7 +474,7 @@ export default function AnnotationOperations() {
|
||||
const [rejects, setRejects] = useState<HumanReject[]>([]);
|
||||
const [deliveryPackages, setDeliveryPackages] = useState<DeliveryPackage[]>([]);
|
||||
const [expandedDeliveryPackageId, setExpandedDeliveryPackageId] = useState("");
|
||||
const [prepackageComments,setPrepackageComments] = useState<Record<string,string>>({});
|
||||
const [prepackageComments, setPrepackageComments] = useState<Record<string, string>>({});
|
||||
const [deliveryPackageContents, setDeliveryPackageContents] = useState<Record<string, DeliveryPackageContents>>({});
|
||||
const [deliveryPackageContentsLoading, setDeliveryPackageContentsLoading] = useState("");
|
||||
const [deliveryPackageContentsErrors, setDeliveryPackageContentsErrors] = useState<Record<string, string>>({});
|
||||
@ -870,14 +877,21 @@ export default function AnnotationOperations() {
|
||||
)
|
||||
return;
|
||||
const storedDraft = annotationDraftFromHumanItem(next.humanItem);
|
||||
const discardedWorkspace = Boolean((next.humanItem?.subject?.payload?.sliceWorkflow as { discardedWorkspace?: boolean } | undefined)?.discardedWorkspace);
|
||||
const discardedWorkspace = Boolean(
|
||||
(next.humanItem?.subject?.payload?.sliceWorkflow as { discardedWorkspace?: boolean } | undefined)
|
||||
?.discardedWorkspace,
|
||||
);
|
||||
const restoreDraft = Boolean(
|
||||
storedDraft &&
|
||||
storedDraft.userId === currentUser?.id &&
|
||||
next.humanItem?.assignedUserId === currentUser?.id &&
|
||||
["claimed", "in_progress"].includes(next.humanItem.status),
|
||||
);
|
||||
const nextAnnotations = restoreDraft ? storedDraft.segments : discardedWorkspace ? [] : humanEditableAnnotationSegments(next.revisions);
|
||||
const nextAnnotations = restoreDraft
|
||||
? storedDraft.segments
|
||||
: discardedWorkspace
|
||||
? []
|
||||
: humanEditableAnnotationSegments(next.revisions);
|
||||
const nextSlices = initialCaptureSlices(
|
||||
next.task,
|
||||
discardedWorkspace ? [] : next.sliceRevisions,
|
||||
@ -943,11 +957,20 @@ export default function AnnotationOperations() {
|
||||
if (requestID !== taskDetailRequestRef.current) return;
|
||||
setFrameTimeline(timeline);
|
||||
setFrameTimelineNotice("");
|
||||
if (!restoreDraft && !next.sliceRevisions.length && timeline.boundaryContract === "hardware-frame-v1") {
|
||||
setSliceSegments((current) =>
|
||||
current.length === 1 &&
|
||||
current[0].start === nextSlices[0]?.start &&
|
||||
current[0].end === nextSlices[0]?.end
|
||||
? [{ ...current[0], start: timeline.rangeStartSecond!, end: timeline.rangeEndSecond! }]
|
||||
: current,
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((timelineError) => {
|
||||
if (requestID !== taskDetailRequestRef.current || (timelineError as Error)?.name === "AbortError") return;
|
||||
setFrameTimeline(null);
|
||||
setFrameTimelineNotice("该历史任务没有可读取的左目 PTS,将退化为时间微调;新 Capture 使用真实帧序列。");
|
||||
setFrameTimelineNotice("无法建立统一帧边界,请检查视频、PTS 和 IMU;未校验前不能确认切片或提交。");
|
||||
});
|
||||
})
|
||||
.catch((loadError) => {
|
||||
@ -984,7 +1007,9 @@ export default function AnnotationOperations() {
|
||||
?.segments.filter((segment) => segment.source === "qwen" || segment.source === "workflow-prelabel") || [],
|
||||
[detail?.revisions],
|
||||
);
|
||||
const { start: editableTimelineStart, end: editableTimelineEnd } = annotationTaskEditableRange(detail?.task);
|
||||
const fallbackRange = annotationTaskEditableRange(detail?.task);
|
||||
const editableTimelineStart = frameTimeline?.rangeStartSecond ?? fallbackRange.start;
|
||||
const editableTimelineEnd = frameTimeline?.rangeEndSecond ?? fallbackRange.end;
|
||||
const frameBoundaries = useMemo(
|
||||
() => normalizeFrameBoundaries(frameTimeline?.boundariesSeconds || [], editableTimelineStart, editableTimelineEnd),
|
||||
[editableTimelineEnd, editableTimelineStart, frameTimeline?.boundariesSeconds],
|
||||
@ -1003,7 +1028,10 @@ export default function AnnotationOperations() {
|
||||
[segments, sliceSegments, sliceStatuses],
|
||||
);
|
||||
const annotationWorkspaceIssues = useMemo(
|
||||
() => validateAnnotationWorkspace(sliceSegments, segments),
|
||||
() => [
|
||||
...validateAnnotationWorkspace(sliceSegments, segments),
|
||||
...continuousAnnotationIssues(sliceSegments, segments),
|
||||
],
|
||||
[segments, sliceSegments],
|
||||
);
|
||||
const annotationFingerprint = useMemo(
|
||||
@ -1331,8 +1359,16 @@ export default function AnnotationOperations() {
|
||||
if (!sliceCoverage.complete) {
|
||||
return { canSubmit: false, reason: "视频片段尚未完全由切片覆盖" };
|
||||
}
|
||||
if (
|
||||
!exactFrameEditing ||
|
||||
[...sliceSegments, ...segments].some(
|
||||
(s) => !frameBoundaryAligned(frameBoundaries, s.start) || !frameBoundaryAligned(frameBoundaries, s.end),
|
||||
)
|
||||
) {
|
||||
return { canSubmit: false, reason: "存在未对齐统一帧边界的数据,请先调整确认;不会自动移动旧标注" };
|
||||
}
|
||||
if (annotationWorkspaceIssues.length > 0) {
|
||||
return { canSubmit: false, reason: "切片存在数据异常或重叠" };
|
||||
return { canSubmit: false, reason: "动作区间须连续覆盖;请处理空洞、重叠或明确标记无效片段" };
|
||||
}
|
||||
if (segments.some((segment) => !segment.description?.trim())) {
|
||||
return { canSubmit: false, reason: "请填写已添加的描述,或删除未填写的描述区间" };
|
||||
@ -1485,17 +1521,8 @@ export default function AnnotationOperations() {
|
||||
candidateSegments = segments,
|
||||
) => {
|
||||
const sorted = [...next].sort((left, right) => left.start - right.start);
|
||||
// When slice boundaries are adjusted or resliced, automatically prune obsolete/conflicting
|
||||
// description segments that no longer completely fit within a single slice.
|
||||
const validSegments = candidateSegments.filter((segment) => {
|
||||
const container = sorted.find(
|
||||
(slice) => segment.start >= slice.start - 0.005 && segment.end <= slice.end + 0.005,
|
||||
);
|
||||
return Boolean(container);
|
||||
});
|
||||
if (validSegments.length !== candidateSegments.length) {
|
||||
setSegments(validSegments);
|
||||
}
|
||||
// Preserve old descriptions; invalid boundaries are reported, never pruned.
|
||||
const validSegments = candidateSegments;
|
||||
setError("");
|
||||
setSliceHistory((history) => [...history, sliceSegments]);
|
||||
setSliceOperations((operations) => [...operations, { ...operation, before: sliceSegments, after: sorted }]);
|
||||
@ -1538,10 +1565,10 @@ export default function AnnotationOperations() {
|
||||
|
||||
// Synchronously adjust action segments touching this boundary so no gaps or deletions occur
|
||||
const updatedSegments = segments.map((seg) => {
|
||||
if (Math.abs(seg.end - oldBoundary) <= 0.05 && value > seg.start + 0.01) {
|
||||
if (Math.abs(seg.end - oldBoundary) <= 0.000001 && value > seg.start + 0.01) {
|
||||
return { ...seg, end: value };
|
||||
}
|
||||
if (Math.abs(seg.start - oldBoundary) <= 0.05 && value < seg.end - 0.01) {
|
||||
if (Math.abs(seg.start - oldBoundary) <= 0.000001 && value < seg.end - 0.01) {
|
||||
return { ...seg, start: value };
|
||||
}
|
||||
return seg;
|
||||
@ -1587,7 +1614,7 @@ export default function AnnotationOperations() {
|
||||
|
||||
const splitSlice = (index: number, requestedAt = annotationPlayhead) => {
|
||||
const current = sliceSegments[index];
|
||||
if (!current || current.end - current.start < 0.2) return;
|
||||
if (!current) return;
|
||||
if (requestedAt <= current.start + 0.001 || requestedAt >= current.end - 0.001) {
|
||||
setError(`请先把播放头移动到切片 ${index + 1} 内需要拆分的位置。`);
|
||||
return;
|
||||
@ -1830,8 +1857,7 @@ export default function AnnotationOperations() {
|
||||
};
|
||||
|
||||
const submitCombined = async () => {
|
||||
// Descriptions are optional. Quality review receives the complete Capture
|
||||
// slicing result plus whichever sparse description intervals were added.
|
||||
// Descriptions (including explicit invalid intervals) cover every slice.
|
||||
if (!detail?.humanItem || !selectedClaimedByMe || sliceSegments.length === 0 || combinedSubmissionProcessing)
|
||||
return;
|
||||
if (annotationWorkspaceIssues.length > 0) {
|
||||
@ -1860,7 +1886,7 @@ export default function AnnotationOperations() {
|
||||
),
|
||||
sliceOperations,
|
||||
segments: segments.map((segment) => ({ ...segment, label: "", handedness: "" })),
|
||||
requireSliceCompletion: false,
|
||||
requireSliceCompletion: true,
|
||||
changeReason: detail.task.currentRevision > 0 ? "逐片 JSON 描述返工" : "逐片 JSON 描述完成",
|
||||
});
|
||||
if (submission.item) setDetail((current) => (current ? { ...current, humanItem: submission.item } : current));
|
||||
@ -2345,7 +2371,11 @@ export default function AnnotationOperations() {
|
||||
version: item.version,
|
||||
decision,
|
||||
reviewedRevision: item.currentRevision,
|
||||
comment: acceptanceComment.trim() || ((statistics.headpose === "exclude" || statistics.handpose === "exclude") ? statistics.exclusionReason.trim() : ""),
|
||||
comment:
|
||||
acceptanceComment.trim() ||
|
||||
(statistics.headpose === "exclude" || statistics.handpose === "exclude"
|
||||
? statistics.exclusionReason.trim()
|
||||
: ""),
|
||||
reasonCodes:
|
||||
decision === "rejected"
|
||||
? ["batch_acceptance_rejected"]
|
||||
@ -2365,7 +2395,7 @@ export default function AnnotationOperations() {
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
setPrepackageComments(current=>({...current,[item.id]:""}));
|
||||
setPrepackageComments((current) => ({ ...current, [item.id]: "" }));
|
||||
await loadProject();
|
||||
} catch (confirmError) {
|
||||
setError(
|
||||
@ -2784,15 +2814,29 @@ export default function AnnotationOperations() {
|
||||
</div>
|
||||
)}
|
||||
{prepackageAcceptanceItems.map((item) => (
|
||||
<AcceptanceTaskCard key={item.id} item={item}
|
||||
<AcceptanceTaskCard
|
||||
key={item.id}
|
||||
item={item}
|
||||
name={captureDirectoriesFromHumanTask(item)[0] || item.display?.projectName || "Capture 验收任务"}
|
||||
selected={expandedDeliveryPackageId === item.id} mine={item.assignedUserId === currentUser?.id}
|
||||
assignee={users.find(user => user.id === item.assignedUserId)?.name || (item.assignedUserId === currentUser?.id ? currentUser?.name || "" : "已领取")}
|
||||
claimable={!isManager && !item.assignedUserId && ["ready", "rework", "submitted"].includes(item.status) && canCurrentUserClaimItem(item)} saving={saving}
|
||||
selected={expandedDeliveryPackageId === item.id}
|
||||
mine={item.assignedUserId === currentUser?.id}
|
||||
assignee={
|
||||
users.find((user) => user.id === item.assignedUserId)?.name ||
|
||||
(item.assignedUserId === currentUser?.id ? currentUser?.name || "" : "已领取")
|
||||
}
|
||||
claimable={
|
||||
!isManager &&
|
||||
!item.assignedUserId &&
|
||||
["ready", "rework", "submitted"].includes(item.status) &&
|
||||
canCurrentUserClaimItem(item)
|
||||
}
|
||||
saving={saving}
|
||||
onPreview={() => {
|
||||
setSelectedTaskId("");
|
||||
setExpandedDeliveryPackageId(item.id);
|
||||
}} onClaim={() => void claimPrepackageAcceptance(item)} />
|
||||
setSelectedTaskId("");
|
||||
setExpandedDeliveryPackageId(item.id);
|
||||
}}
|
||||
onClaim={() => void claimPrepackageAcceptance(item)}
|
||||
/>
|
||||
))}
|
||||
{filteredVisibleTasks.map((task) => {
|
||||
const poolItem = visibleHumanItemByTaskId.get(task.id);
|
||||
@ -2816,8 +2860,15 @@ export default function AnnotationOperations() {
|
||||
const isTaskPendingQuality = detailedStatus === "pending_quality";
|
||||
const isTaskPendingAcceptance = detailedStatus === "pending_acceptance";
|
||||
const isTaskAccepted = detailedStatus === "accepted";
|
||||
const awaitingDownstream = workspaceMode === "annotate" && (isTaskPendingQuality || isTaskPendingAcceptance || isTaskAccepted);
|
||||
const taskAction = annotationTaskAction({ awaitingDownstream, status: detailedStatus, claimable, claimedByMe, saving });
|
||||
const awaitingDownstream =
|
||||
workspaceMode === "annotate" && (isTaskPendingQuality || isTaskPendingAcceptance || isTaskAccepted);
|
||||
const taskAction = annotationTaskAction({
|
||||
awaitingDownstream,
|
||||
status: detailedStatus,
|
||||
claimable,
|
||||
claimedByMe,
|
||||
saving,
|
||||
});
|
||||
return (
|
||||
<article
|
||||
key={task.id}
|
||||
@ -2961,13 +3012,32 @@ export default function AnnotationOperations() {
|
||||
handpose: "include",
|
||||
};
|
||||
const mine = item.assignedUserId === currentUser?.id;
|
||||
return <FinalAcceptanceWorkspace key={item.id} item={item} mine={mine} saving={saving} error={error} timeZone={timeZone}
|
||||
draft={stats} comment={prepackageComments[item.id] || ""}
|
||||
onDraftChange={patch=>setPrepackageAcceptanceDrafts(current=>({...current,[item.id]:{...(current[item.id]||stats),...patch}}))}
|
||||
onCommentChange={value=>setPrepackageComments(current=>({...current,[item.id]:value}))}
|
||||
onApprove={()=>void decidePrepackageAcceptance(item,stats,"approved",true,prepackageComments[item.id]||"")}
|
||||
onReject={()=>void decidePrepackageAcceptance(item,stats,"rejected",true,prepackageComments[item.id]||"")}
|
||||
onRelease={()=>void releasePrepackageAcceptance(item)}/>;
|
||||
return (
|
||||
<FinalAcceptanceWorkspace
|
||||
key={item.id}
|
||||
item={item}
|
||||
mine={mine}
|
||||
saving={saving}
|
||||
error={error}
|
||||
timeZone={timeZone}
|
||||
draft={stats}
|
||||
comment={prepackageComments[item.id] || ""}
|
||||
onDraftChange={(patch) =>
|
||||
setPrepackageAcceptanceDrafts((current) => ({
|
||||
...current,
|
||||
[item.id]: { ...(current[item.id] || stats), ...patch },
|
||||
}))
|
||||
}
|
||||
onCommentChange={(value) => setPrepackageComments((current) => ({ ...current, [item.id]: value }))}
|
||||
onApprove={() =>
|
||||
void decidePrepackageAcceptance(item, stats, "approved", true, prepackageComments[item.id] || "")
|
||||
}
|
||||
onReject={() =>
|
||||
void decidePrepackageAcceptance(item, stats, "rejected", true, prepackageComments[item.id] || "")
|
||||
}
|
||||
onRelease={() => void releasePrepackageAcceptance(item)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{detail ? (
|
||||
<div className="min-w-0 space-y-3 break-words pb-20">
|
||||
@ -3130,9 +3200,7 @@ export default function AnnotationOperations() {
|
||||
data-testid="slice-materialization-progress"
|
||||
>
|
||||
<Loader2 className="mx-auto h-10 w-10 animate-spin text-blue-500 dark:text-blue-300" />
|
||||
<div className="text-lg font-semibold text-gray-900 dark:text-white">
|
||||
正在生成切片…
|
||||
</div>
|
||||
<div className="text-lg font-semibold text-gray-900 dark:text-white">正在生成切片…</div>
|
||||
<div className="mx-auto max-w-lg text-xs leading-relaxed text-gray-600 dark:text-gray-300">
|
||||
正在处理您确认的{" "}
|
||||
<span className="font-semibold text-blue-600 dark:text-blue-300">
|
||||
@ -3152,84 +3220,103 @@ export default function AnnotationOperations() {
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div key={detail.task.id} className="min-w-0"><CaptureAnnotationWorkbench
|
||||
taskId={detail.task.id}
|
||||
videoSource={selectedVideoSource}
|
||||
rightVideoSource={selectedRightVideoSource}
|
||||
clipStart={editableTimelineStart}
|
||||
clipEnd={editableTimelineEnd}
|
||||
sourceIsFullVideo={detail.task.sourceIsFullVideo}
|
||||
slices={sliceSegments}
|
||||
segments={segments}
|
||||
labels={selectedLabels}
|
||||
statuses={sliceProgress.statuses}
|
||||
phase={combinedEditorPhase === "slice" ? "slice" : "annotate"}
|
||||
frameBoundaries={frameBoundaries}
|
||||
readOnlyStatusLabel={statusLabels[detail.task.status] || "只读查看"}
|
||||
readOnly={
|
||||
(workspaceMode === "annotate" &&
|
||||
(detail.task.status === "pending_quality" ||
|
||||
detail.task.status === "pending_acceptance" ||
|
||||
detail.task.status === "accepted")) ||
|
||||
((workspaceMode === "quality" ||
|
||||
<div key={detail.task.id} className="min-w-0">
|
||||
<CaptureAnnotationWorkbench
|
||||
taskId={detail.task.id}
|
||||
videoSource={selectedVideoSource}
|
||||
rightVideoSource={selectedRightVideoSource}
|
||||
clipStart={editableTimelineStart}
|
||||
clipEnd={editableTimelineEnd}
|
||||
sourceIsFullVideo={detail.task.sourceIsFullVideo}
|
||||
slices={sliceSegments}
|
||||
segments={segments}
|
||||
labels={selectedLabels}
|
||||
statuses={sliceProgress.statuses}
|
||||
phase={combinedEditorPhase === "slice" ? "slice" : "annotate"}
|
||||
frameBoundaries={frameBoundaries}
|
||||
rightMediaBoundaries={frameTimeline?.rightBoundariesSeconds}
|
||||
unifiedBoundaries={frameTimeline?.boundaryContract === "hardware-frame-v1"}
|
||||
readOnlyStatusLabel={statusLabels[detail.task.status] || "只读查看"}
|
||||
readOnly={
|
||||
(workspaceMode === "annotate" &&
|
||||
(detail.task.status === "pending_quality" ||
|
||||
detail.task.status === "pending_acceptance" ||
|
||||
detail.task.status === "accepted")) ||
|
||||
((workspaceMode === "quality" ||
|
||||
workspaceMode === "acceptance" ||
|
||||
workspaceMode === "clip-quality") &&
|
||||
(detail.task.status === "accepted" || (!selectedClaimedByMe && !isManager))) ||
|
||||
(!selectedClaimedByMe && !isManager) ||
|
||||
combinedSubmissionProcessing
|
||||
}
|
||||
isQualityReview={
|
||||
(workspaceMode === "quality" ||
|
||||
workspaceMode === "acceptance" ||
|
||||
workspaceMode === "clip-quality") &&
|
||||
(selectedClaimedByMe || isManager) &&
|
||||
detail.task.status !== "accepted"
|
||||
}
|
||||
reviewMode={workspaceMode === "acceptance" ? "acceptance" : "quality"}
|
||||
reviewComment={
|
||||
workspaceMode === "quality" ||
|
||||
workspaceMode === "acceptance" ||
|
||||
workspaceMode === "clip-quality") &&
|
||||
(detail.task.status === "accepted" || (!selectedClaimedByMe && !isManager))) ||
|
||||
(!selectedClaimedByMe && !isManager) ||
|
||||
combinedSubmissionProcessing
|
||||
}
|
||||
isQualityReview={
|
||||
(workspaceMode === "quality" ||
|
||||
workspaceMode === "clip-quality"
|
||||
? reviewComment
|
||||
: ""
|
||||
}
|
||||
onReviewCommentChange={setReviewComment}
|
||||
onApprove={
|
||||
workspaceMode === "quality" ||
|
||||
workspaceMode === "acceptance" ||
|
||||
workspaceMode === "clip-quality") &&
|
||||
(selectedClaimedByMe || isManager) &&
|
||||
detail.task.status !== "accepted"
|
||||
}
|
||||
reviewMode={workspaceMode === "acceptance" ? "acceptance" : "quality"}
|
||||
reviewComment={
|
||||
workspaceMode === "quality" || workspaceMode === "acceptance" || workspaceMode === "clip-quality"
|
||||
? reviewComment
|
||||
: ""
|
||||
}
|
||||
onReviewCommentChange={setReviewComment}
|
||||
onApprove={
|
||||
workspaceMode === "quality" || workspaceMode === "acceptance" || workspaceMode === "clip-quality"
|
||||
? () => void review(workspaceMode === "acceptance" ? "acceptance" : "quality", "approved")
|
||||
: undefined
|
||||
}
|
||||
onReject={
|
||||
workspaceMode === "quality" || workspaceMode === "acceptance" || workspaceMode === "clip-quality"
|
||||
? () => void review(workspaceMode === "acceptance" ? "acceptance" : "quality", "rejected")
|
||||
: undefined
|
||||
}
|
||||
reworkNotice={reworkNotice}
|
||||
onChange={updateSegments}
|
||||
onPlayheadChange={setAnnotationPlayhead}
|
||||
onSliceNameChange={updateSliceName}
|
||||
onSliceBoundaryChange={adjustSlice}
|
||||
onSplitSlice={(sliceIndex, at) => {
|
||||
setAnnotationPlayhead(at);
|
||||
splitSlice(sliceIndex, at);
|
||||
}}
|
||||
onDeleteSlice={deleteSlice}
|
||||
onConfirmSlices={() => void confirmSlicesAndMaterialize()}
|
||||
canConfirmSlices={sliceCoverage.complete && !saving && selectedClaimedByMe}
|
||||
onConfirmAnnotations={confirmAnnotationDescription}
|
||||
problemSliceIds={problemSliceIds}
|
||||
onProblemSliceIdsChange={setProblemSliceIds}
|
||||
onRequestReslice={() => setShowResliceWarning(true)}
|
||||
onReleaseTask={
|
||||
!selectedClaimedByMe || detail.task.status === "pending_quality"
|
||||
? undefined
|
||||
: () => void releaseSelectedTask()
|
||||
}
|
||||
onSubmitTask={() => void submitCombined()}
|
||||
canSubmitTask={submissionCheck.canSubmit}
|
||||
submissionBlockerReason={submissionCheck.reason}
|
||||
saving={saving || combinedSubmissionProcessing}
|
||||
initialSliceId={requestedSliceId}
|
||||
onReturnToPool={() => selectTask("")}
|
||||
/>
|
||||
workspaceMode === "clip-quality"
|
||||
? () => void review(workspaceMode === "acceptance" ? "acceptance" : "quality", "approved")
|
||||
: undefined
|
||||
}
|
||||
onReject={
|
||||
workspaceMode === "quality" ||
|
||||
workspaceMode === "acceptance" ||
|
||||
workspaceMode === "clip-quality"
|
||||
? () => void review(workspaceMode === "acceptance" ? "acceptance" : "quality", "rejected")
|
||||
: undefined
|
||||
}
|
||||
reworkNotice={reworkNotice}
|
||||
onChange={updateSegments}
|
||||
onPlayheadChange={setAnnotationPlayhead}
|
||||
onSliceNameChange={updateSliceName}
|
||||
onSliceBoundaryChange={adjustSlice}
|
||||
onSplitSlice={(sliceIndex, at) => {
|
||||
setAnnotationPlayhead(at);
|
||||
splitSlice(sliceIndex, at);
|
||||
}}
|
||||
onDeleteSlice={deleteSlice}
|
||||
onConfirmSlices={() => void confirmSlicesAndMaterialize()}
|
||||
canConfirmSlices={
|
||||
sliceCoverage.complete &&
|
||||
exactFrameEditing &&
|
||||
sliceSegments.every(
|
||||
(s) =>
|
||||
frameBoundaryAligned(frameBoundaries, s.start) &&
|
||||
frameBoundaryAligned(frameBoundaries, s.end),
|
||||
) &&
|
||||
!saving &&
|
||||
selectedClaimedByMe
|
||||
}
|
||||
onConfirmAnnotations={confirmAnnotationDescription}
|
||||
problemSliceIds={problemSliceIds}
|
||||
onProblemSliceIdsChange={setProblemSliceIds}
|
||||
onRequestReslice={() => setShowResliceWarning(true)}
|
||||
onReleaseTask={
|
||||
!selectedClaimedByMe || detail.task.status === "pending_quality"
|
||||
? undefined
|
||||
: () => void releaseSelectedTask()
|
||||
}
|
||||
onSubmitTask={() => void submitCombined()}
|
||||
canSubmitTask={submissionCheck.canSubmit}
|
||||
submissionBlockerReason={submissionCheck.reason}
|
||||
saving={saving || combinedSubmissionProcessing}
|
||||
initialSliceId={requestedSliceId}
|
||||
onReturnToPool={() => selectTask("")}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@ -174,7 +174,11 @@ export const annotationOperationsApi = {
|
||||
segments: AnnotationSegment[];
|
||||
statuses: Record<string, NonNullable<SliceSegment["annotationStatus"]>>;
|
||||
};
|
||||
}>(`/api/plugins/annotation-qa/tasks/${taskId}/slice-reset`, { method: "POST" }, { version }),
|
||||
}>(
|
||||
`/api/plugins/annotation-qa/tasks/${taskId}/slice-reset`,
|
||||
{ method: "POST" },
|
||||
{ version, resetToUnifiedRange: true },
|
||||
),
|
||||
review: (
|
||||
taskId: string,
|
||||
payload: {
|
||||
|
||||
@ -1006,8 +1006,8 @@ export interface CaptureAutomationConfig {
|
||||
}
|
||||
|
||||
export interface WorkflowRuntimePolicyRevision {
|
||||
previousAcceptanceSampleProbability?: number;
|
||||
updatedByUserName?: string;
|
||||
previousAcceptanceSampleProbability?: number;
|
||||
updatedByUserName?: string;
|
||||
revision: number;
|
||||
maxConcurrentCaptureRuns: number;
|
||||
acceptanceSampleProbability: number;
|
||||
@ -1953,6 +1953,11 @@ export interface AnnotationFrameTimeline {
|
||||
originTimestampUs: number;
|
||||
coverageEndTimestampUs: number;
|
||||
boundariesSeconds: number[];
|
||||
boundaryTimestampUs?: number[];
|
||||
rightBoundariesSeconds?: number[];
|
||||
rangeStartSecond?: number;
|
||||
rangeEndSecond?: number;
|
||||
boundaryContract?: string;
|
||||
}
|
||||
|
||||
export interface SliceOperation {
|
||||
|
||||
@ -573,6 +573,20 @@ def test_timestamped_description_contract_uses_clip_milliseconds():
|
||||
assert result["descriptions"][0]["endTimestampUs"] == 1_600_000
|
||||
|
||||
|
||||
def test_unified_descriptions_preserve_hardware_edges_not_media_duration():
|
||||
synchronized = {"window": {"startTimestampUs": 1_000_000, "endTimestampUs": 2_000_000},
|
||||
"boundaryTimestampUs": [1_000_000, 1_400_000, 2_000_000]}
|
||||
annotation = {"boundaryContract": "hardware-frame-v1", "descriptions": [
|
||||
{"clipStartMs": 0, "clipEndMs": 300, "startTimestampUs": 1_000_000, "endTimestampUs": 1_400_000},
|
||||
{"clipStartMs": 300, "clipEndMs": 900, "startTimestampUs": 1_400_000, "endTimestampUs": 2_000_000}]}
|
||||
result = package_operator._timestamped_annotation(annotation, synchronized)
|
||||
assert result["descriptions"][0]["endTimestampUs"] == result["descriptions"][1]["startTimestampUs"] == 1_400_000
|
||||
assert result["descriptions"][1]["endTimestampUs"] == 2_000_000
|
||||
annotation["descriptions"].pop(0)
|
||||
with pytest.raises(RuntimeError, match="consecutive"):
|
||||
package_operator._timestamped_annotation(annotation, synchronized)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("schema", ["droboticflow.headpose/v1", "droboticflow.wilor.hand_pose_result/v1"])
|
||||
def test_v5_pose_free_package_rejects_unexpected_pose_payloads(tmp_path, schema):
|
||||
accepted = {
|
||||
|
||||
@ -1,46 +1,70 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {annotationDraftAtPlayhead,annotationDraftCheckAtPlayhead,annotationConfirmationInterval,annotationEventOverlaps,stepFrameBoundary} from '../../src/lib/annotation-workbench.js';
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
annotationDraftAtPlayhead,
|
||||
annotationDraftCheckAtPlayhead,
|
||||
annotationConfirmationInterval,
|
||||
annotationEventOverlaps,
|
||||
stepFrameBoundary,
|
||||
} from "../../src/lib/annotation-workbench.js";
|
||||
|
||||
test('actual slice-start sub-microsecond discrepancy allows an empty draft without changing data',()=>{
|
||||
const slice={start:0.3000564311705609,end:1.2642688846358063};
|
||||
const segments=[{id:'existing',start:1.10007,end:1.233401}];
|
||||
const before=JSON.stringify({slice,segments});
|
||||
assert.deepEqual(annotationDraftAtPlayhead(slice,segments,0.300056),{start:slice.start,end:slice.start,limit:1.10007});
|
||||
assert.equal(JSON.stringify({slice,segments}),before);
|
||||
test("actual slice-start sub-microsecond discrepancy allows an empty draft without changing data", () => {
|
||||
const slice = { start: 0.3000564311705609, end: 1.2642688846358063 };
|
||||
const segments = [{ id: "existing", start: 1.10007, end: 1.233401 }];
|
||||
const before = JSON.stringify({ slice, segments });
|
||||
assert.deepEqual(annotationDraftAtPlayhead(slice, segments, 0.300056), {
|
||||
start: slice.start,
|
||||
end: slice.start,
|
||||
limit: 1.10007,
|
||||
});
|
||||
assert.equal(JSON.stringify({ slice, segments }), before);
|
||||
});
|
||||
test('one microsecond start tolerance never expands to a frame or permits real overlap',()=>{
|
||||
const slice={start:0.3,end:1.2};
|
||||
assert.equal(annotationDraftAtPlayhead(slice,[],slice.start-0.000001).start,slice.start);
|
||||
assert.equal(annotationDraftAtPlayhead(slice,[],slice.start+0.000001).start,slice.start);
|
||||
for(const point of [slice.start-0.0000011,slice.start-0.03]) assert.equal(annotationDraftCheckAtPlayhead(slice,[],point).reason,'outside');
|
||||
assert.equal(annotationDraftCheckAtPlayhead(slice,[],slice.end).reason,'end');
|
||||
assert.equal(annotationDraftCheckAtPlayhead(slice,[{id:'a',start:0.3,end:0.5}],0.3).reason,'occupied');
|
||||
assert.equal(annotationDraftCheckAtPlayhead(slice,[{id:'a',start:0.3,end:0.5000004}],0.5).reason,'occupied');
|
||||
assert.equal(annotationDraftAtPlayhead(slice,[{id:'a',start:0.3,end:0.5}],0.5).start,0.5);
|
||||
const longSlice={start:2515.486218,end:2520};
|
||||
assert.equal(annotationDraftAtPlayhead(longSlice,[],longSlice.start-0.000001).start,longSlice.start);
|
||||
assert.equal(annotationDraftCheckAtPlayhead(longSlice,[],longSlice.start-0.0000011).reason,'outside');
|
||||
test("one microsecond start tolerance never expands to a frame or permits real overlap", () => {
|
||||
const slice = { start: 0.3, end: 1.2 };
|
||||
assert.equal(annotationDraftAtPlayhead(slice, [], slice.start - 0.000001).start, slice.start);
|
||||
assert.equal(annotationDraftAtPlayhead(slice, [], slice.start + 0.000001).start, slice.start);
|
||||
for (const point of [slice.start - 0.0000011, slice.start - 0.03])
|
||||
assert.equal(annotationDraftCheckAtPlayhead(slice, [], point).reason, "outside");
|
||||
assert.equal(annotationDraftCheckAtPlayhead(slice, [], slice.end).reason, "end");
|
||||
assert.equal(annotationDraftCheckAtPlayhead(slice, [{ id: "a", start: 0.3, end: 0.5 }], 0.3).reason, "occupied");
|
||||
assert.equal(
|
||||
annotationDraftCheckAtPlayhead(slice, [{ id: "a", start: 0.3, end: 0.5000004 }], 0.5).reason,
|
||||
"occupied",
|
||||
);
|
||||
assert.equal(annotationDraftAtPlayhead(slice, [{ id: "a", start: 0.3, end: 0.5 }], 0.5).start, 0.5);
|
||||
const longSlice = { start: 2515.486218, end: 2520 };
|
||||
assert.equal(annotationDraftAtPlayhead(longSlice, [], longSlice.start - 0.000001).start, longSlice.start);
|
||||
assert.equal(annotationDraftCheckAtPlayhead(longSlice, [], longSlice.start - 0.0000011).reason, "outside");
|
||||
});
|
||||
|
||||
test('new action starts exactly at the playhead and does not fill the gap',()=>{
|
||||
assert.deepEqual(annotationDraftAtPlayhead({start:0,end:1.038},[],0.205),{start:0.205,end:0.205,limit:1.038});
|
||||
test("new action starts at the selected gap boundary for continuous coverage", () => {
|
||||
assert.deepEqual(annotationDraftAtPlayhead({ start: 0, end: 1.038 }, [], 0.205), { start: 0, end: 0, limit: 1.038 });
|
||||
});
|
||||
test('new action cannot start in an existing action or outside the slice',()=>{
|
||||
const slice={start:0,end:1};const segments=[{id:'existing',start:0.2,end:0.5}];
|
||||
for(const point of [-1,0.3,1,NaN])assert.equal(annotationDraftAtPlayhead(slice,segments,point),null);
|
||||
assert.deepEqual(annotationDraftAtPlayhead(slice,segments,0.1),{start:0.1,end:0.1,limit:0.2});
|
||||
assert.deepEqual(annotationDraftAtPlayhead(slice,segments,0.5),{start:0.5,end:0.5,limit:1});
|
||||
test("new action cannot start in an existing action or outside the slice", () => {
|
||||
const slice = { start: 0, end: 1 };
|
||||
const segments = [{ id: "existing", start: 0.2, end: 0.5 }];
|
||||
for (const point of [-1, 0.3, 1, NaN]) assert.equal(annotationDraftAtPlayhead(slice, segments, point), null);
|
||||
assert.deepEqual(annotationDraftAtPlayhead(slice, segments, 0.1), { start: 0, end: 0, limit: 0.2 });
|
||||
assert.deepEqual(annotationDraftAtPlayhead(slice, segments, 0.5), { start: 0.5, end: 0.5, limit: 1 });
|
||||
});
|
||||
test('editing an existing end excludes itself but is capped by the next action',()=>{
|
||||
const segments=[{id:'a',start:0.1,end:0.4},{id:'b',start:0.6,end:1}];
|
||||
const draft=annotationDraftAtPlayhead({start:0,end:1},segments,0.1,'a');
|
||||
assert.equal(draft.limit,0.6);
|
||||
assert.equal(annotationEventOverlaps(segments,{...draft,id:'a',end:0.6},'a'),false);
|
||||
test("editing an existing end excludes itself but is capped by the next action", () => {
|
||||
const segments = [
|
||||
{ id: "a", start: 0.1, end: 0.4 },
|
||||
{ id: "b", start: 0.6, end: 1 },
|
||||
];
|
||||
const draft = annotationDraftAtPlayhead({ start: 0, end: 1 }, segments, 0.1, "a");
|
||||
assert.equal(draft.limit, 0.6);
|
||||
assert.equal(annotationEventOverlaps(segments, { ...draft, id: "a", end: 0.6 }, "a"), false);
|
||||
});
|
||||
test('real PTS frame steps preserve the fixed start and confirmation preserves the end',()=>{
|
||||
const frames=[0.2,0.237819,0.271155,0.304491];const draft=annotationDraftAtPlayhead({start:0.2,end:0.304491},[],0.237819);
|
||||
let end=stepFrameBoundary(frames,draft.end,1);assert.equal(end,0.271155);
|
||||
end=stepFrameBoundary(frames,end,-1);assert.equal(end,draft.start);
|
||||
assert.deepEqual(annotationConfirmationInterval({...draft,end:0.304491},{start:0.2,end:0.304491}),{start:0.237819,end:0.304491});
|
||||
test("real PTS frame steps preserve the fixed start and confirmation preserves the end", () => {
|
||||
const frames = [0.2, 0.237819, 0.271155, 0.304491];
|
||||
const draft = annotationDraftAtPlayhead({ start: 0.2, end: 0.304491 }, [], 0.237819);
|
||||
let end = stepFrameBoundary(frames, draft.end, 1);
|
||||
assert.equal(end, 0.237819);
|
||||
end = stepFrameBoundary(frames, end, -1);
|
||||
assert.equal(end, draft.start);
|
||||
assert.deepEqual(annotationConfirmationInterval({ ...draft, end: 0.304491 }, { start: 0.2, end: 0.304491 }), {
|
||||
start: 0.2,
|
||||
end: 0.304491,
|
||||
});
|
||||
});
|
||||
|
||||
@ -69,10 +69,10 @@ test("production shell keeps real users, collapsible navigation, and a persisted
|
||||
assert.match(annotationOperations, /annotation-operations-page/);
|
||||
assert.match(css, /html:not\(\.dark\) \.annotation-operations-page/);
|
||||
assert.match(annotationOperations, /claimTask\(task, humanItem\)/);
|
||||
assert.match(annotationOperations, /claimable \? "领取" : claimedByMe \? "继续处理" : "查看"/);
|
||||
assert.match(annotationOperations, /annotationTaskAction/);
|
||||
assert.doesNotMatch(annotationOperations, /领取标注任务|领取剪切任务/);
|
||||
assert.match(css, /capture-media-controls/);
|
||||
assert.match(annotationOperations, /requireSliceCompletion: false/);
|
||||
assert.match(annotationOperations, /requireSliceCompletion: true/);
|
||||
assert.doesNotMatch(annotationOperations, /sliceProgress\.pending > 0/);
|
||||
assert.match(workbench, /已连续填满|已标记为不可用/);
|
||||
assert.doesNotMatch(workbench, /个切片已完成标注/);
|
||||
|
||||
42
tests/frontend/unified-annotation-boundaries.test.mjs
Normal file
42
tests/frontend/unified-annotation-boundaries.test.mjs
Normal file
@ -0,0 +1,42 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
annotationDraftAtPlayhead,
|
||||
annotationCoverageGaps,
|
||||
frameBoundaryAligned,
|
||||
frameBoundaryAtOrBefore,
|
||||
replaceAnnotationSharedBoundaries,
|
||||
mapCameraBoundaryTime,
|
||||
} from "../../src/lib/annotation-workbench.js";
|
||||
|
||||
test("new annotations continue from gap start rather than leaving a hidden leading gap", () => {
|
||||
const slice = { start: 8 / 30, end: 38 / 30 };
|
||||
const first = annotationDraftAtPlayhead(slice, [], 9 / 30);
|
||||
assert.equal(first.start, slice.start);
|
||||
const segments = [{ id: "a", start: slice.start, end: 12 / 30 }];
|
||||
assert.equal(annotationDraftAtPlayhead(slice, segments, 14 / 30).start, 12 / 30);
|
||||
assert.deepEqual(annotationCoverageGaps(slice, segments), [{ start: 12 / 30, end: slice.end }]);
|
||||
assert.equal(annotationDraftAtPlayhead(slice, segments, 10 / 30), null);
|
||||
});
|
||||
test("shared edge edit updates both sides without changing outer edges", () => {
|
||||
const source = [
|
||||
{ id: "a", start: 0, end: 0.3 },
|
||||
{ id: "b", start: 0.3, end: 1 },
|
||||
];
|
||||
const next = replaceAnnotationSharedBoundaries(source, { ...source[0], end: 0.4 });
|
||||
assert.deepEqual(next, [
|
||||
{ id: "a", start: 0, end: 0.4 },
|
||||
{ id: "b", start: 0.4, end: 1 },
|
||||
]);
|
||||
assert.deepEqual(annotationCoverageGaps({ start: 0, end: 1 }, next), []);
|
||||
assert.equal(source[1].start, 0.3);
|
||||
});
|
||||
test("one logical frame edge survives playback and JSON reload", () => {
|
||||
const edges = Array.from({ length: 31 }, (_, i) => i / 30);
|
||||
assert.equal(frameBoundaryAtOrBefore(edges, 8 / 30 + 0.004483), 8 / 30);
|
||||
assert.equal(frameBoundaryAligned(edges, 0.262236968), false);
|
||||
const saved = JSON.parse(JSON.stringify({ start: 8 / 30, end: 9 / 30 }));
|
||||
assert.equal(saved.start, edges[8]);
|
||||
assert.equal(saved.end, edges[9]);
|
||||
assert.equal(mapCameraBoundaryTime([0, 0.1, 0.2], [0, 0.2, 0.3], 0.1), 0.2);
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user