droboticflow/internal/api/review_video_seconds.go
d-robotics 32e74273ca 🧊 Freeze review video seconds at decision time and fall back to submissions
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit b38d10f0ef4d1ac15202923f2c5e8390e66e651c)
2026-10-27 16:30:49 +08:00

55 lines
1.8 KiB
Go

package api
import (
"context"
"droboticflow/internal/domain"
"droboticflow/internal/workforcestats"
)
// reviewedRevisionVideoSeconds prices the slice version a review decision
// decides, frozen onto the decision so later rework pruning of superseded
// versions cannot erase reviewer statistics. Nil when the version is missing;
// the report then falls back to the version's submission record.
func (s *server) reviewedRevisionVideoSeconds(ctx context.Context, org, taskID string, revision int) *float64 {
if taskID == "" || revision <= 0 {
return nil
}
versions, err := s.store.ListSliceRevisions(ctx, org, taskID)
if err != nil {
return nil
}
for _, version := range versions {
if version.TaskID == taskID && version.Revision == revision {
seconds := workforcestats.SliceVideoSeconds(version.Segments)
return &seconds
}
}
return nil
}
// acceptanceReviewVideoSources freezes, per source, the version final
// acceptance decided: its latest quality-approved version before the decision.
func (s *server) acceptanceReviewVideoSources(ctx context.Context, org string, sources []domain.HumanItemRecord, before string) []domain.ReviewVideoSource {
out := []domain.ReviewVideoSource{}
for _, source := range sources {
if source.LegacyTaskID == "" {
continue
}
reviews, err := s.store.ListAnnotationReviews(ctx, org, source.LegacyTaskID)
if err != nil {
continue
}
revision, ok := workforcestats.LatestQualityApprovedRevision(reviews, source.LegacyTaskID, before)
if !ok {
continue
}
seconds := s.reviewedRevisionVideoSeconds(ctx, org, source.LegacyTaskID, revision)
if seconds == nil {
continue
}
out = append(out, domain.ReviewVideoSource{SourceItemID: source.ID, TaskID: source.LegacyTaskID, Revision: revision, VideoSeconds: seconds})
}
return out
}