forked from longtao.wu/droboticflow
67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
package workforcestats
|
|
|
|
import "droboticflow/internal/domain"
|
|
|
|
// SliceVersions returns the exact versions Build can use to price video time.
|
|
// Frozen event/acceptance seconds need no slice read. Legacy quality and final
|
|
// acceptance records retain the reviewed-version lookup and its submission fallback.
|
|
func SliceVersions(d Snapshot) map[string]map[int]bool {
|
|
result := map[string]map[int]bool{}
|
|
add := func(task string, revision int) {
|
|
if task != "" {
|
|
if result[task] == nil {
|
|
result[task] = map[int]bool{}
|
|
}
|
|
result[task][revision] = true
|
|
}
|
|
}
|
|
// Apply exactly the calculator's canonical duplicate selection. History
|
|
// is attribution evidence, not another set of in-window submissions.
|
|
canonical := map[string]domain.AnnotationWorklogEventRecord{}
|
|
for _, e := range append(append([]domain.AnnotationWorklogEventRecord(nil), d.SubmissionHistory...), d.Events...) {
|
|
if !submission(e) {
|
|
continue
|
|
}
|
|
key := submissionKey(e)
|
|
old, ok := canonical[key]
|
|
if !ok || parsedAfter(old.CreatedAt, e.CreatedAt) || (old.CreatedAt == e.CreatedAt && e.ID < old.ID) {
|
|
canonical[key] = e
|
|
}
|
|
}
|
|
for _, e := range d.Events {
|
|
if submission(e) {
|
|
e = canonical[submissionKey(e)]
|
|
} else if e.EventType != "quality_approved" && e.EventType != "quality_rejected" {
|
|
continue
|
|
}
|
|
if !validSeconds(e.VideoSeconds) {
|
|
add(e.TaskID, e.Revision)
|
|
}
|
|
}
|
|
|
|
items := map[string]string{}
|
|
for _, v := range d.SourceItems {
|
|
items[v.ID] = v.LegacyTaskID
|
|
}
|
|
for _, op := range d.AcceptanceDecisions {
|
|
fixed := map[string]domain.ReviewVideoSource{}
|
|
for _, v := range op.ReviewVideoSources {
|
|
fixed[v.SourceItemID] = v
|
|
}
|
|
for _, id := range op.SourceItemIDs {
|
|
v, frozen := fixed[id]
|
|
if frozen && validSeconds(v.VideoSeconds) {
|
|
continue
|
|
}
|
|
task := items[id]
|
|
if frozen && v.TaskID != "" {
|
|
task = v.TaskID
|
|
}
|
|
if revision, ok := LatestQualityApprovedRevision(d.Reviews, task, op.CreatedAt); ok {
|
|
add(task, revision)
|
|
}
|
|
}
|
|
}
|
|
return result
|
|
}
|