✨ Count production milestones only after all required parts complete
This commit is contained in:
parent
e630d93def
commit
36eb8540ba
@ -48,6 +48,7 @@ Status: approved
|
||||
- 默认近7个北京时间自然日,含今天;提供今日、近7日、近30日、自定义。自定义结束日包含整天,查询边界使用次日零点,避免重复包含相邻窗口边界。
|
||||
- 日期只影响期间产出,不声称可还原某历史时刻的完整在途快照。
|
||||
- 新增源数据、成功送检、质检通过、终审通过、成功交付分别按期间内发生的可靠事件统计,每个指标内按项目源数据去重;同源在本周送检三次仍计一份。
|
||||
- 2026-09-28 补充确认 A:一源包含多个 part 时,送检、质检通过、终审通过和交付均须全部所需 part 有可靠完成证据,完成时间为最后一个 part 达成的时刻;之前完成的 part 可跨日期参与汇总。正式重跑及退回使对应 part 的旧完成证据失效,旧轮次已经成立的历史整源完成仍保留。供应商计参与完成整源的贡献,明细分别显示整源完成时间及原 part 证据时间。
|
||||
- 退回单列次数;不同指标不能相加当作新增数据量。一个源跨天重复完成时,每天可各有记录,但整个周范围仍应去重,不能简单累加日去重数。
|
||||
- 供应商按事件当时生产归属计期间参与产出。历史同源由两家供应商先后完成同一环节,各家各计一份,总览仍去重一份;只有存在交叉时提示供应商小计不可直接相加。
|
||||
- 来源不明的历史事件不倒推给当前人员或供应商;新增源数据尚无生产供应商时不能补算给之后领取者。
|
||||
|
||||
@ -34,10 +34,12 @@ User approved release and PR after successful live verification. Live scope rema
|
||||
- Targeted aggregation, HTTP permission/scope tests, local Mongo persistence/projection tests, TypeScript checking and frontend build passed. Browser checks passed on 251 included synthetic sources plus one excluded project: configured scope, filters, project/supplier drilldown, pagination/search, historical warning, archived projects and refresh-error retention. No business mutation was sent by the drawer.
|
||||
- Full-suite comparison against 5f2d796d found the same 79 Go top-level failing cases and the same 14 frontend failing cases (608/622 passing). These remain baseline debt, not a clean full-suite pass. Raw evidence is in the untracked local verification directory.
|
||||
|
||||
## Pending business decision
|
||||
## Multipart period decision
|
||||
|
||||
A source directory can contain multiple independently processed parts. Current progress requires all parts; the period milestone definition (all parts complete versus any part produces an event) is awaiting the user's explicit answer. Current period code still uses any recorded event, so it is not approved for release until that answer is applied and verified.
|
||||
User selected A: all required parts must complete before counting a source milestone. Temporal aggregation now uses the last part completion time, keeps original contributing evidence, and invalidates corresponding part evidence on formal retry or rejection. Regression tests cover cross-day completion, missing parts, retries with late old events, historical supplier ownership and rejection/resubmission.
|
||||
|
||||
Live deployment and PR have not been performed for this feature. Production scope must remain administrator-configured.
|
||||
|
||||
The delayed-response browser check exposed filter options disappearing during reload. The options now retain their last authorized response while numeric results reload. Re-tested by holding project A's response, selecting project B, then releasing A: B's 51-source result and selection remained intact. Typecheck/build and browser race verification passed.
|
||||
|
||||
All-parts follow-up also verifies multiple tasks within one part, acceptance returns preserving submitted work, dependency-scoped sibling invalidation, and replacement packages completing the same production units. Current progress excludes explicitly superseded packages and their linked acceptance items, while retaining historical decisions. Final full-suite comparison still has the baseline's 79 Go top-level failures and 14 frontend failures; differing diagnostics were checked for cause (membership 403, deleted-account 410, concurrent route 404, video-fixture dependency failure), with no new cause found.
|
||||
|
||||
@ -11,7 +11,7 @@ _Avoid_:全局唯一源文件数、累计提交次数、切片数量(均不
|
||||
|
||||
**当前生产进度**:项目源数据在最新一轮正式处理中的当前主阶段,每份数据只占一个主阶段;同轮存在多条任务时按最早尚未完成的环节归类。正式重跑可使当前阶段回退,旧交付结果保留为历史;调试运行不改变当前生产进度。
|
||||
|
||||
**期间阶段完成量**:在所选期间内发生过指定阶段成功完成事件的项目源数据份数,同一项目的同一源数据在该指标中只计一次。新增、送检、质检通过、终审通过与交付分别计算,退回另计发生次数。
|
||||
**期间阶段完成量**:在所选期间内发生过指定阶段成功完成事件的项目源数据份数,同一项目的同一源数据在该指标中只计一次。新增、送检、质检通过、终审通过与交付分别计算,退回另计发生次数。一源包含多个 part 时,阶段完成须所有所需 part 达成,按最后一个 part 完成时间计入期间;正式重跑或退回后的对应 part 不能复用已失效的完成证据。
|
||||
_Avoid_:操作次数(同一份数据可以重复操作,但期间完成份数不因此重复累计)
|
||||
|
||||
**供应商期间参与产出量**:供应商在所选期间内参与完成某环节的项目源数据份数,按事件当时的生产归属统计。同一份数据在期间内可先后由多家供应商处理,各家可分别计入,总览仍按项目源数据去重;存在交叉时供应商小计不能直接相加。
|
||||
|
||||
@ -166,6 +166,16 @@ func Build(d Snapshot) Report {
|
||||
for _, task := range d.Tasks {
|
||||
attemptTasks[root(task.RunID)] = append(attemptTasks[root(task.RunID)], task)
|
||||
}
|
||||
itemPartitions := map[string]string{}
|
||||
for _, item := range d.Items {
|
||||
itemPartitions[item.ID] = item.ReleasePartitionID
|
||||
}
|
||||
supersededAcceptance := map[string]bool{}
|
||||
for _, p := range d.Packages {
|
||||
if supersededPackage(p, itemPartitions) {
|
||||
supersededAcceptance[p.AcceptanceHumanItemID] = true
|
||||
}
|
||||
}
|
||||
attemptPackages := map[string][]domain.DeliveryPackageRecord{}
|
||||
for _, p := range d.Packages {
|
||||
rid := root(p.ParentRunID)
|
||||
@ -203,6 +213,9 @@ func Build(d Snapshot) Report {
|
||||
hasTasks := false
|
||||
minStage := "ended"
|
||||
for _, i := range attemptItems[r.ID] {
|
||||
if supersededAcceptance[i.ID] {
|
||||
continue
|
||||
}
|
||||
if itemSource[i.ID] != key || root(i.RunID) != r.ID || r.ID == "" {
|
||||
continue
|
||||
}
|
||||
@ -285,6 +298,9 @@ func Build(d Snapshot) Report {
|
||||
if p.Mode == domain.RunModeDebug || p.Temporary || r.ID == "" || (root(p.ParentRunID) != r.ID && root(p.ChildRunID) != r.ID) {
|
||||
continue
|
||||
}
|
||||
if supersededPackage(p, itemPartitions) {
|
||||
continue
|
||||
}
|
||||
packageCount++
|
||||
stage := "unknown"
|
||||
switch p.Status {
|
||||
@ -325,6 +341,14 @@ func Build(d Snapshot) Report {
|
||||
}
|
||||
sort.Slice(result.Sources, func(i, j int) bool { return result.Sources[i].ID < result.Sources[j].ID })
|
||||
buildEvents(d, &result, runSource, itemSource, taskSource, runs)
|
||||
for n := range result.Events {
|
||||
result.Events[n].AttemptID = root(result.Events[n].RunID)
|
||||
}
|
||||
for _, run := range d.Runs {
|
||||
if run.Mode != domain.RunModeDebug && run.Trigger != domain.RunTriggerHumanRelease && runSource[run.ID] != "" {
|
||||
result.Events = append(result.Events, Event{ID: run.ID, SourceID: runSource[run.ID], Metric: "attempt_started", At: run.CreatedAt, AttemptID: run.ID})
|
||||
}
|
||||
}
|
||||
// An unadmitted parent may be replaced by discovered part directories.
|
||||
// Preserve its registration date, but it is no longer required production work.
|
||||
hasParts := map[string]bool{}
|
||||
@ -346,7 +370,7 @@ func Build(d Snapshot) Report {
|
||||
}
|
||||
placeholders[key] = unadmitted
|
||||
}
|
||||
return rollupParts(result, parents, parentNames, placeholders)
|
||||
return rollupParts(result, parents, parentNames, placeholders, requiredMilestoneUnits(d, result.Events, root))
|
||||
}
|
||||
|
||||
func later(a, b string) bool {
|
||||
@ -357,7 +381,7 @@ func later(a, b string) bool {
|
||||
|
||||
// A physical Capture may register several part directories. Retries are resolved
|
||||
// per part first; completion of one part must not hide unfinished sibling work.
|
||||
func rollupParts(parts Report, parents, names map[string]string, placeholders map[string]bool) Report {
|
||||
func rollupParts(parts Report, parents, names map[string]string, placeholders map[string]bool, units milestoneUnits) Report {
|
||||
out := Report{Sources: []Source{}, Events: parts.Events, Incomplete: parts.Incomplete}
|
||||
combined := map[string]*Source{}
|
||||
discovery := map[string]string{}
|
||||
@ -400,9 +424,7 @@ func rollupParts(parts Report, parents, names map[string]string, placeholders ma
|
||||
out.Sources = append(out.Sources, *s)
|
||||
}
|
||||
sort.Slice(out.Sources, func(i, j int) bool { return out.Sources[i].ID < out.Sources[j].ID })
|
||||
for n := range out.Events {
|
||||
out.Events[n].SourceID = parents[out.Events[n].SourceID]
|
||||
}
|
||||
out.Events = sourceMilestones(parts.Events, parents, placeholders, units)
|
||||
for _, s := range out.Sources {
|
||||
if s.DiscoveredAt != "" {
|
||||
out.Events = append(out.Events, Event{ID: "new:" + s.ID, SourceID: s.ID, SupplierID: Unassigned, Metric: "new", At: s.DiscoveredAt})
|
||||
@ -410,3 +432,17 @@ func rollupParts(parts Report, parents, names map[string]string, placeholders ma
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Rework preserves the old package for audit but moves its production items to
|
||||
// a new partition. Only explicit current pointers justify excluding it.
|
||||
func supersededPackage(p domain.DeliveryPackageRecord, itemPartitions map[string]string) bool {
|
||||
if p.ReleasePartitionID == "" || len(p.ItemIDs) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, id := range p.ItemIDs {
|
||||
if itemPartitions[id] == "" || itemPartitions[id] == p.ReleasePartitionID {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"droboticflow/internal/domain"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -62,12 +63,14 @@ func buildEvents(d Snapshot, out *Report, runSource, itemSource, taskSource map[
|
||||
// Package acceptance worklogs use package IDs rather than annotation-task IDs.
|
||||
packageReviews := map[string][]domain.DeliveryPackageAcceptanceReview{}
|
||||
packageOwners := map[string]string{}
|
||||
packageUnits := map[string][]string{}
|
||||
firstReview := map[string]string{}
|
||||
for _, p := range d.Packages {
|
||||
if p.Mode == domain.RunModeDebug || p.Temporary {
|
||||
continue
|
||||
}
|
||||
packageOwners[p.ID] = p.SupplierID
|
||||
packageUnits[p.ID] = index.productionTasks(p.ItemIDs)
|
||||
if _, copied := p.QualitySummary["prePackageAcceptance"]; copied {
|
||||
continue
|
||||
}
|
||||
@ -123,7 +126,11 @@ func buildEvents(d Snapshot, out *Report, runSource, itemSource, taskSource map[
|
||||
out.Incomplete = true
|
||||
}
|
||||
rid := taskRuns[e.TaskID]
|
||||
out.Events = append(out.Events, Event{ID: e.ID, SourceID: key, SupplierID: supplier, Metric: metric, At: e.CreatedAt, RunID: rid, WorkflowID: runs[rid].WorkflowID, TaskID: e.TaskID})
|
||||
productionUnits := []string{e.TaskID}
|
||||
if _, pkg := packageOwners[e.TaskID]; pkg {
|
||||
productionUnits = packageUnits[e.TaskID]
|
||||
}
|
||||
out.Events = append(out.Events, Event{ID: e.ID, SourceID: key, SupplierID: supplier, Metric: metric, At: e.CreatedAt, RunID: rid, WorkflowID: runs[rid].WorkflowID, TaskID: e.TaskID, InvalidateFrom: rejectionReturn(e.EventType), ProductionUnits: productionUnits})
|
||||
}
|
||||
for _, e := range d.Events {
|
||||
key := itemSource[e.ItemID]
|
||||
@ -151,7 +158,13 @@ func buildEvents(d Snapshot, out *Report, runSource, itemSource, taskSource map[
|
||||
supplier = packageOwners[pkg]
|
||||
}
|
||||
rid := itemRuns[e.ItemID]
|
||||
out.Events = append(out.Events, Event{ID: e.ID, SourceID: key, SupplierID: supplier, Metric: metric, At: e.CreatedAt, RunID: rid, WorkflowID: runs[rid].WorkflowID, TaskID: e.ItemID})
|
||||
unit := e.ItemID
|
||||
productionUnits := index.productionTasks(e.Payload["sourceItemIds"])
|
||||
if pkg, _ := e.Payload["deliveryPackageId"].(string); pkg != "" {
|
||||
unit = pkg
|
||||
productionUnits = packageUnits[pkg]
|
||||
}
|
||||
out.Events = append(out.Events, Event{ID: e.ID, SourceID: key, SupplierID: supplier, Metric: metric, At: e.CreatedAt, RunID: rid, WorkflowID: runs[rid].WorkflowID, TaskID: unit, InvalidateFrom: "quality", ProductionUnits: productionUnits})
|
||||
if supplier == Unknown {
|
||||
out.Incomplete = true
|
||||
}
|
||||
@ -167,7 +180,7 @@ func buildEvents(d Snapshot, out *Report, runSource, itemSource, taskSource map[
|
||||
}
|
||||
rid := taskRuns[pkg]
|
||||
for _, review := range reviews {
|
||||
out.Events = append(out.Events, Event{ID: review.ID, SourceID: key, SupplierID: supplier, Metric: worklogMetric("acceptance_" + string(review.Decision)), At: review.CreatedAt, RunID: rid, WorkflowID: runs[rid].WorkflowID, TaskID: pkg})
|
||||
out.Events = append(out.Events, Event{ID: review.ID, SourceID: key, SupplierID: supplier, Metric: worklogMetric("acceptance_" + string(review.Decision)), At: review.CreatedAt, RunID: rid, WorkflowID: runs[rid].WorkflowID, TaskID: pkg, InvalidateFrom: "quality", ProductionUnits: packageUnits[pkg]})
|
||||
}
|
||||
}
|
||||
for _, p := range d.Packages {
|
||||
@ -180,7 +193,7 @@ func buildEvents(d Snapshot, out *Report, runSource, itemSource, taskSource map[
|
||||
supplier = Unknown
|
||||
}
|
||||
rid := taskRuns[p.ID]
|
||||
out.Events = append(out.Events, Event{ID: "delivery:" + p.ID, SourceID: key, SupplierID: supplier, Metric: "delivered", At: p.FinalExportedAt, RunID: rid, WorkflowID: runs[rid].WorkflowID, TaskID: p.ID})
|
||||
out.Events = append(out.Events, Event{ID: "delivery:" + p.ID, SourceID: key, SupplierID: supplier, Metric: "delivered", At: p.FinalExportedAt, RunID: rid, WorkflowID: runs[rid].WorkflowID, TaskID: p.ID, ProductionUnits: packageUnits[p.ID]})
|
||||
}
|
||||
// Older versions did not persist all transitions; reliable facts are a lower
|
||||
// bound, never evidence that an absent event means zero actual production.
|
||||
@ -232,3 +245,27 @@ func (index eventIndex) acceptanceSupplier(event domain.HumanEventRecord) string
|
||||
func acceptanceStage(stage string) bool {
|
||||
return stage == "acceptance" || stage == "final_acceptance" || stage == "prepackage_acceptance"
|
||||
}
|
||||
|
||||
// Quality rejection reopens annotation; acceptance rejection reopens quality.
|
||||
func rejectionReturn(kind string) string {
|
||||
if strings.HasPrefix(kind, "acceptance_") {
|
||||
return "quality"
|
||||
}
|
||||
return "submitted"
|
||||
}
|
||||
|
||||
func (index eventIndex) productionTasks(value any) []string {
|
||||
ids := reflect.ValueOf(value)
|
||||
if !ids.IsValid() || (ids.Kind() != reflect.Slice && ids.Kind() != reflect.Array) {
|
||||
return nil
|
||||
}
|
||||
tasks := []string{}
|
||||
for n := 0; n < ids.Len(); n++ {
|
||||
id, ok := ids.Index(n).Interface().(string)
|
||||
if !ok || index.itemTasks[id] == "" {
|
||||
return nil
|
||||
}
|
||||
tasks = append(tasks, index.itemTasks[id])
|
||||
}
|
||||
return tasks
|
||||
}
|
||||
|
||||
234
internal/productionstats/milestones.go
Normal file
234
internal/productionstats/milestones.go
Normal file
@ -0,0 +1,234 @@
|
||||
package productionstats
|
||||
|
||||
import (
|
||||
"droboticflow/internal/domain"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
// A source milestone occurs at the last required part's completion. Contributors
|
||||
// retain their actual evidence timestamps, while period filters use that common
|
||||
// completion time. Missing part evidence is never inferred from today's state.
|
||||
func sourceMilestones(events []Event, parents map[string]string, placeholders map[string]bool, units milestoneUnits) []Event {
|
||||
required := map[string]map[string]bool{}
|
||||
for part, parent := range parents {
|
||||
if placeholders[part] {
|
||||
continue
|
||||
}
|
||||
if required[parent] == nil {
|
||||
required[parent] = map[string]bool{}
|
||||
}
|
||||
required[parent][part] = true
|
||||
}
|
||||
ordered := append([]Event(nil), events...)
|
||||
sort.SliceStable(ordered, func(i, j int) bool {
|
||||
if ordered[i].At == ordered[j].At {
|
||||
if (ordered[i].Metric == "attempt_started") != (ordered[j].Metric == "attempt_started") {
|
||||
return ordered[i].Metric == "attempt_started"
|
||||
}
|
||||
return ordered[i].ID < ordered[j].ID
|
||||
}
|
||||
return later(ordered[j].At, ordered[i].At)
|
||||
})
|
||||
ready := map[string]map[string]map[string]Event{}
|
||||
attempts := map[string]string{}
|
||||
out := []Event{}
|
||||
for _, e := range ordered {
|
||||
part := e.SourceID
|
||||
parent := parents[part]
|
||||
if parent == "" || placeholders[part] {
|
||||
continue
|
||||
}
|
||||
if _, err := time.Parse(time.RFC3339Nano, e.At); err != nil {
|
||||
continue
|
||||
}
|
||||
if e.Metric == "attempt_started" {
|
||||
attempts[part] = e.AttemptID
|
||||
for _, metric := range Metrics {
|
||||
delete(ready[parent+":"+metric], part)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if e.Metric == "rejected" {
|
||||
if attempts[part] == "" || e.AttemptID == attempts[part] {
|
||||
for _, metric := range []string{"submitted", "quality", "acceptance", "delivered"} {
|
||||
if metric == "submitted" && e.InvalidateFrom == "quality" {
|
||||
continue
|
||||
}
|
||||
for unit, fact := range ready[parent+":"+metric][part] {
|
||||
if affectedProductionUnits(e.ProductionUnits, fact.ProductionUnits) {
|
||||
delete(ready[parent+":"+metric][part], unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
e.SourceID = parent
|
||||
out = append(out, e)
|
||||
continue
|
||||
}
|
||||
if attempts[part] != "" && e.AttemptID != attempts[part] {
|
||||
continue
|
||||
}
|
||||
key := parent + ":" + e.Metric
|
||||
if ready[key] == nil {
|
||||
ready[key] = map[string]map[string]Event{}
|
||||
}
|
||||
if ready[key][part] == nil {
|
||||
ready[key][part] = map[string]Event{}
|
||||
}
|
||||
for _, unit := range completionUnits(e) {
|
||||
ready[key][part][unit] = e
|
||||
}
|
||||
complete := true
|
||||
for requiredPart := range required[parent] {
|
||||
facts := ready[key][requiredPart]
|
||||
if len(facts) == 0 {
|
||||
complete = false
|
||||
break
|
||||
}
|
||||
for _, fact := range facts {
|
||||
for unit := range units[fact.AttemptID+":"+e.Metric] {
|
||||
if _, ok := facts[unit]; !ok {
|
||||
complete = false
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
if !complete {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !complete {
|
||||
continue
|
||||
}
|
||||
emitted := map[string]bool{}
|
||||
for _, facts := range ready[key] {
|
||||
for _, fact := range facts {
|
||||
if emitted[fact.ID] {
|
||||
continue
|
||||
}
|
||||
emitted[fact.ID] = true
|
||||
if fact.ID != e.ID {
|
||||
fact.ID = e.ID + ":" + fact.ID
|
||||
}
|
||||
fact.SourceID = parent
|
||||
fact.EvidenceAt = fact.At
|
||||
fact.At = e.At
|
||||
out = append(out, fact)
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Required units come from persisted tasks, not just successful events. Event
|
||||
// references also cover legacy package/item identities absent from task records.
|
||||
type milestoneUnits map[string]map[string]bool
|
||||
|
||||
func requiredMilestoneUnits(d Snapshot, events []Event, root func(string) string) milestoneUnits {
|
||||
units := milestoneUnits{}
|
||||
add := func(attempt, metric, id string) {
|
||||
if attempt == "" || id == "" {
|
||||
return
|
||||
}
|
||||
key := attempt + ":" + metric
|
||||
if units[key] == nil {
|
||||
units[key] = map[string]bool{}
|
||||
}
|
||||
units[key][id] = true
|
||||
}
|
||||
for _, e := range events {
|
||||
if e.Metric != "rejected" && e.Metric != "attempt_started" {
|
||||
for _, unit := range completionUnits(e) {
|
||||
add(e.AttemptID, e.Metric, unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, task := range d.Tasks {
|
||||
for _, metric := range []string{"submitted", "quality"} {
|
||||
add(root(task.RunID), metric, task.ID)
|
||||
}
|
||||
}
|
||||
eventProduction := map[string][]string{}
|
||||
for _, e := range events {
|
||||
if len(e.ProductionUnits) > 0 {
|
||||
eventProduction[e.TaskID] = e.ProductionUnits
|
||||
}
|
||||
}
|
||||
index := indexEvents(d)
|
||||
packageForItem := map[string]string{}
|
||||
packageProduction := map[string][]string{}
|
||||
for _, event := range d.Events {
|
||||
if pkg, _ := event.Payload["deliveryPackageId"].(string); pkg != "" {
|
||||
packageForItem[event.ItemID] = pkg
|
||||
}
|
||||
}
|
||||
for _, p := range d.Packages {
|
||||
if p.Mode == domain.RunModeDebug || p.Temporary {
|
||||
continue
|
||||
}
|
||||
attempt := root(p.ParentRunID)
|
||||
if attempt == "" {
|
||||
attempt = root(p.ChildRunID)
|
||||
}
|
||||
production := index.productionTasks(p.ItemIDs)
|
||||
packageProduction[p.ID] = production
|
||||
for _, unit := range completionUnits(Event{TaskID: p.ID, Metric: "delivered", ProductionUnits: production}) {
|
||||
add(attempt, "delivered", unit)
|
||||
}
|
||||
if p.AcceptanceHumanItemID != "" {
|
||||
packageForItem[p.AcceptanceHumanItemID] = p.ID
|
||||
}
|
||||
if _, copied := p.QualitySummary["prePackageAcceptance"]; !copied && (p.AcceptanceHumanItemID != "" || len(p.AcceptanceReviews) > 0 || p.Status == domain.DeliveryPackagePendingAcceptance || p.Status == domain.DeliveryPackageRejected) {
|
||||
for _, unit := range completionUnits(Event{TaskID: p.ID, Metric: "acceptance", ProductionUnits: production}) {
|
||||
add(attempt, "acceptance", unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, item := range d.Items {
|
||||
for _, metric := range []string{"submitted", "quality"} {
|
||||
add(root(item.RunID), metric, item.LegacyTaskID)
|
||||
}
|
||||
if acceptanceStage(item.CurrentStageID) {
|
||||
unit := item.ID
|
||||
if packageForItem[unit] != "" {
|
||||
unit = packageForItem[unit]
|
||||
}
|
||||
production := packageProduction[unit]
|
||||
// Aggregate pre-package decisions name their production dependencies.
|
||||
if len(production) == 0 {
|
||||
production = eventProduction[unit]
|
||||
}
|
||||
for _, key := range completionUnits(Event{TaskID: unit, Metric: "acceptance", ProductionUnits: production}) {
|
||||
add(root(item.RunID), "acceptance", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
return units
|
||||
}
|
||||
|
||||
// Missing historical dependency links are conservatively invalidated, never
|
||||
// treated as proof that downstream completion survived a return.
|
||||
func affectedProductionUnits(rejected, completed []string) bool {
|
||||
if len(rejected) == 0 || len(completed) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, a := range rejected {
|
||||
for _, b := range completed {
|
||||
if a == b {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Replacement packages complete the same production units; rejected historical
|
||||
// package IDs are not additional work that must somehow succeed later.
|
||||
func completionUnits(e Event) []string {
|
||||
if (e.Metric == "acceptance" || e.Metric == "delivered") && len(e.ProductionUnits) > 0 {
|
||||
return e.ProductionUnits
|
||||
}
|
||||
return []string{e.TaskID}
|
||||
}
|
||||
151
internal/productionstats/milestones_test.go
Normal file
151
internal/productionstats/milestones_test.go
Normal file
@ -0,0 +1,151 @@
|
||||
package productionstats
|
||||
|
||||
import (
|
||||
"droboticflow/internal/domain"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func multipartHistory() Snapshot {
|
||||
return Snapshot{Captures: []domain.CaptureRecord{{ID: "a", ProjectID: "p", Prefix: "source/part1", SourcePrefix: "source", RunID: "ra"}, {ID: "b", ProjectID: "p", Prefix: "source/part2", SourcePrefix: "source", RunID: "rb"}}, Runs: []domain.RunRecord{{ID: "ra", TaskID: "a", CreatedAt: "2026-09-20T00:00:00Z"}, {ID: "rb", TaskID: "b", CreatedAt: "2026-09-20T00:00:00Z"}}, Tasks: []domain.AnnotationTaskRecord{{ID: "ta", RunID: "ra"}, {ID: "tb", RunID: "rb"}}, Worklogs: []domain.AnnotationWorklogEventRecord{{ID: "ea", TaskID: "ta", SupplierID: "va", EventType: "combined_submitted", CreatedAt: "2026-09-21T01:00:00Z"}, {ID: "eb", TaskID: "tb", SupplierID: "vb", EventType: "combined_submitted", CreatedAt: "2026-09-22T01:00:00Z"}}}
|
||||
}
|
||||
func period(t *testing.T, date string) Query {
|
||||
t.Helper()
|
||||
q, err := ParseQuery("period", date, date, time.Now())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return q
|
||||
}
|
||||
func TestMultipartPeriodWaitsForAllParts(t *testing.T) {
|
||||
d := multipartHistory()
|
||||
r := Build(d)
|
||||
if got := Summarize(r, period(t, "2026-09-21")).Totals["submitted"]; got != 0 {
|
||||
t.Fatalf("partial source counted: %d", got)
|
||||
}
|
||||
q := period(t, "2026-09-22")
|
||||
got := Summarize(r, q)
|
||||
if got.Totals["submitted"] != 1 || !got.SupplierOverlap {
|
||||
t.Fatalf("whole-source completion missing: %+v", got)
|
||||
}
|
||||
q.SupplierID = "va"
|
||||
if got := Summarize(r, q).Totals["submitted"]; got != 1 {
|
||||
t.Fatal("first part contributor lost")
|
||||
}
|
||||
d.Worklogs = d.Worklogs[:1]
|
||||
if got := Summarize(Build(d), period(t, "2026-09-21")).Totals["submitted"]; got != 0 {
|
||||
t.Fatal("missing part counted as complete")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipartMilestoneDoesNotReuseSupersededAttempt(t *testing.T) {
|
||||
d := multipartHistory()
|
||||
d.Runs = append(d.Runs, domain.RunRecord{ID: "ra2", TaskID: "a", CreatedAt: "2026-09-21T12:00:00Z"})
|
||||
d.Tasks = append(d.Tasks, domain.AnnotationTaskRecord{ID: "ta2", RunID: "ra2"})
|
||||
d.Worklogs = append(d.Worklogs, domain.AnnotationWorklogEventRecord{ID: "late-old", TaskID: "ta", SupplierID: "va", EventType: "combined_submitted", CreatedAt: "2026-09-22T02:00:00Z"})
|
||||
if got := Summarize(Build(d), period(t, "2026-09-22")).Totals["submitted"]; got != 0 {
|
||||
t.Fatal("old attempt completed new source round")
|
||||
}
|
||||
d.Worklogs = append(d.Worklogs, domain.AnnotationWorklogEventRecord{ID: "new", TaskID: "ta2", SupplierID: "vc", EventType: "combined_submitted", CreatedAt: "2026-09-23T01:00:00Z"})
|
||||
r := Build(d)
|
||||
q := period(t, "2026-09-23")
|
||||
if got := Summarize(r, q).Totals["submitted"]; got != 1 {
|
||||
t.Fatal("new attempt not counted")
|
||||
}
|
||||
q.SupplierID = "va"
|
||||
if got := Summarize(r, q).Totals["submitted"]; got != 0 {
|
||||
t.Fatal("superseded owner counted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipartRejectionInvalidatesCompletionEvidence(t *testing.T) {
|
||||
d := multipartHistory()
|
||||
d.Worklogs = append(d.Worklogs, domain.AnnotationWorklogEventRecord{ID: "reject-b", TaskID: "tb", SupplierID: "vb", EventType: "quality_rejected", CreatedAt: "2026-09-23T01:00:00Z"}, domain.AnnotationWorklogEventRecord{ID: "repeat-a", TaskID: "ta", SupplierID: "va", EventType: "combined_submitted", CreatedAt: "2026-09-24T01:00:00Z"})
|
||||
r := Build(d)
|
||||
if got := Summarize(r, period(t, "2026-09-24")).Totals["submitted"]; got != 0 {
|
||||
t.Fatal("rejected part reused as complete")
|
||||
}
|
||||
if got := Summarize(r, period(t, "2026-09-23")).Totals["rejected"]; got != 1 {
|
||||
t.Fatal("rejection should remain an event count")
|
||||
}
|
||||
d.Worklogs = append(d.Worklogs, domain.AnnotationWorklogEventRecord{ID: "repeat-b", TaskID: "tb", SupplierID: "vb", EventType: "combined_submitted", CreatedAt: "2026-09-25T01:00:00Z"})
|
||||
if got := Summarize(Build(d), period(t, "2026-09-25")).Totals["submitted"]; got != 1 {
|
||||
t.Fatal("resubmission missing")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAcceptanceReturnPreservesSubmittedMilestone(t *testing.T) {
|
||||
d := multipartHistory()
|
||||
d.Worklogs = append(d.Worklogs, domain.AnnotationWorklogEventRecord{ID: "acceptance-return", TaskID: "ta", SupplierID: "va", EventType: "acceptance_rejected", CreatedAt: "2026-09-21T12:00:00Z"})
|
||||
if got := Summarize(Build(d), period(t, "2026-09-22")).Totals["submitted"]; got != 1 {
|
||||
t.Fatal("acceptance return to quality must not require re-annotation")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipartWaitsForEveryRequiredTaskWithinPart(t *testing.T) {
|
||||
d := multipartHistory()
|
||||
d.Tasks = append(d.Tasks, domain.AnnotationTaskRecord{ID: "ta-extra", RunID: "ra"})
|
||||
if got := Summarize(Build(d), period(t, "2026-09-22")).Totals["submitted"]; got != 0 {
|
||||
t.Fatal("unfinished task inside part counted as complete")
|
||||
}
|
||||
d.Worklogs = append(d.Worklogs, domain.AnnotationWorklogEventRecord{ID: "extra", TaskID: "ta-extra", SupplierID: "va", EventType: "combined_submitted", CreatedAt: "2026-09-23T01:00:00Z"})
|
||||
if got := Summarize(Build(d), period(t, "2026-09-23")).Totals["submitted"]; got != 1 {
|
||||
t.Fatal("all required tasks completed but source not counted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRejectionPreservesUnaffectedSiblingTask(t *testing.T) {
|
||||
d := multipartHistory()
|
||||
d.Tasks = append(d.Tasks, domain.AnnotationTaskRecord{ID: "ta2", RunID: "ra"})
|
||||
d.Worklogs = append(d.Worklogs, domain.AnnotationWorklogEventRecord{ID: "extra", TaskID: "ta2", SupplierID: "va", EventType: "combined_submitted", CreatedAt: "2026-09-21T02:00:00Z"}, domain.AnnotationWorklogEventRecord{ID: "reject-one", TaskID: "ta", SupplierID: "va", EventType: "quality_rejected", CreatedAt: "2026-09-21T03:00:00Z"}, domain.AnnotationWorklogEventRecord{ID: "resubmit-one", TaskID: "ta", SupplierID: "va", EventType: "combined_submitted", CreatedAt: "2026-09-23T00:00:00Z"})
|
||||
if got := Summarize(Build(d), period(t, "2026-09-23")).Totals["submitted"]; got != 1 {
|
||||
t.Fatal("unaffected sibling completion erased")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAggregateReturnOnlyInvalidatesReferencedProductionTasks(t *testing.T) {
|
||||
d := multipartHistory()
|
||||
d.Tasks = append(d.Tasks, domain.AnnotationTaskRecord{ID: "ta2", RunID: "ra"})
|
||||
d.Items = []domain.HumanItemRecord{{ID: "ia", RunID: "ra", LegacyTaskID: "ta"}, {ID: "ia2", RunID: "ra", LegacyTaskID: "ta2"}, {ID: "accept", RunID: "ra", CurrentStageID: "prepackage_acceptance"}}
|
||||
d.Worklogs = append(d.Worklogs, domain.AnnotationWorklogEventRecord{ID: "qa1", TaskID: "ta", SupplierID: "va", EventType: "quality_approved", CreatedAt: "2026-09-21T03:00:00Z"}, domain.AnnotationWorklogEventRecord{ID: "qa2", TaskID: "ta2", SupplierID: "va", EventType: "quality_approved", CreatedAt: "2026-09-21T04:00:00Z"}, domain.AnnotationWorklogEventRecord{ID: "reapprove", TaskID: "ta", SupplierID: "va", EventType: "quality_approved", CreatedAt: "2026-09-23T00:00:00Z"}, domain.AnnotationWorklogEventRecord{ID: "qb", TaskID: "tb", SupplierID: "vb", EventType: "quality_approved", CreatedAt: "2026-09-23T01:00:00Z"})
|
||||
d.Events = []domain.HumanEventRecord{{ID: "return", ItemID: "accept", StageID: "prepackage_acceptance", EventType: "rejected", CreatedAt: "2026-09-22T00:00:00Z", Payload: map[string]any{"sourceItemIds": []string{"ia"}}}}
|
||||
r := Build(d)
|
||||
q := period(t, "2026-09-23")
|
||||
if got := Summarize(r, q).Totals["quality"]; got != 1 {
|
||||
t.Fatal("aggregate return erased unrelated task")
|
||||
}
|
||||
rows := Details(r, q, "quality", "")
|
||||
if len(rows) != 1 {
|
||||
t.Fatal("missing detail")
|
||||
}
|
||||
found := false
|
||||
for _, e := range rows[0].Evidence {
|
||||
if e.TaskID == "ta2" {
|
||||
found = true
|
||||
if e.At != "2026-09-23T01:00:00Z" || e.EvidenceAt != "2026-09-21T04:00:00Z" {
|
||||
t.Fatalf("original evidence time lost: %+v", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatal("sibling evidence absent")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplacementPackageDoesNotRequireRejectedPackageSuccess(t *testing.T) {
|
||||
d := multipartHistory()
|
||||
d.Items = []domain.HumanItemRecord{{ID: "ia", RunID: "ra", LegacyTaskID: "ta"}, {ID: "ib", RunID: "rb", LegacyTaskID: "tb"}}
|
||||
d.Packages = []domain.DeliveryPackageRecord{
|
||||
{ID: "old", ParentRunID: "ra", ItemIDs: []string{"ia"}, SupplierID: "va", Status: domain.DeliveryPackageRejected, AcceptanceReviews: []domain.DeliveryPackageAcceptanceReview{{ID: "old-reject", Decision: domain.HumanDecisionRejected, CreatedAt: "2026-09-23T00:00:00Z"}}},
|
||||
{ID: "replacement", ParentRunID: "ra", ItemIDs: []string{"ia"}, SupplierID: "va", Status: domain.DeliveryPackageAccepted, FinalExportedAt: "2026-09-25T02:00:00Z", AcceptanceReviews: []domain.DeliveryPackageAcceptanceReview{{ID: "new-approve", Decision: domain.HumanDecisionApproved, CreatedAt: "2026-09-25T01:00:00Z"}}},
|
||||
{ID: "other", ParentRunID: "rb", ItemIDs: []string{"ib"}, SupplierID: "vb", Status: domain.DeliveryPackageAccepted, FinalExportedAt: "2026-09-24T02:00:00Z", AcceptanceReviews: []domain.DeliveryPackageAcceptanceReview{{ID: "other-approve", Decision: domain.HumanDecisionApproved, CreatedAt: "2026-09-24T01:00:00Z"}}},
|
||||
}
|
||||
r := Build(d)
|
||||
totals := Summarize(r, period(t, "2026-09-25")).Totals
|
||||
if totals["acceptance"] != 1 || totals["delivered"] != 1 {
|
||||
t.Fatalf("superseded package blocked replacement: %+v", totals)
|
||||
}
|
||||
if Summarize(r, period(t, "2026-09-23")).Totals["rejected"] != 1 {
|
||||
t.Fatal("rejection history lost")
|
||||
}
|
||||
}
|
||||
@ -43,6 +43,10 @@ type Source struct {
|
||||
type Event struct {
|
||||
ID, SourceID, SupplierID, Metric, At string
|
||||
RunID, WorkflowID, TaskID string
|
||||
EvidenceAt string
|
||||
AttemptID string
|
||||
InvalidateFrom string
|
||||
ProductionUnits []string
|
||||
}
|
||||
type RunReference struct {
|
||||
ID string `json:"id"`
|
||||
@ -50,6 +54,7 @@ type RunReference struct {
|
||||
Part string `json:"part"`
|
||||
}
|
||||
type Evidence struct {
|
||||
EvidenceAt string `json:"evidenceAt,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Metric string `json:"metric"`
|
||||
SupplierID string `json:"supplierId"`
|
||||
|
||||
@ -149,7 +149,7 @@ func Details(r Report, q Query, metric, search string) []Source {
|
||||
if q.View == "period" {
|
||||
for _, e := range r.Events {
|
||||
if (metric == "" || metric == e.Metric) && q.eventInRange(e) && (q.SupplierID == "" || q.SupplierID == e.SupplierID) {
|
||||
selected[e.SourceID] = append(selected[e.SourceID], Evidence{e.ID, e.Metric, e.SupplierID, e.At, e.RunID, e.WorkflowID, e.TaskID})
|
||||
selected[e.SourceID] = append(selected[e.SourceID], Evidence{ID: e.ID, Metric: e.Metric, SupplierID: e.SupplierID, At: e.At, RunID: e.RunID, WorkflowID: e.WorkflowID, TaskID: e.TaskID, EvidenceAt: e.EvidenceAt})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,3 +104,17 @@ func TestSupersededParentKeepsDiscoveryButNotCurrentStage(t *testing.T) {
|
||||
t.Fatalf("admitted parent lost: %+v", r.Sources)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCurrentProgressIgnoresReplacedRejectedPackage(t *testing.T) {
|
||||
d := Snapshot{Captures: []domain.CaptureRecord{{ID: "c", ProjectID: "p", Prefix: "c", RunID: "r"}}, Runs: []domain.RunRecord{{ID: "r", TaskID: "c"}}, Items: []domain.HumanItemRecord{{ID: "i", RunID: "r", Status: domain.HumanItemAccepted, ReleasePartitionID: "new"}}, Packages: []domain.DeliveryPackageRecord{{ID: "old", ParentRunID: "r", ReleasePartitionID: "old", ItemIDs: []string{"i"}, Status: domain.DeliveryPackageRejected}, {ID: "new", ParentRunID: "r", ReleasePartitionID: "new", ItemIDs: []string{"i"}, Status: domain.DeliveryPackageAccepted}}}
|
||||
d.Runs = append(d.Runs, domain.RunRecord{ID: "old-child", ParentRunID: "r", Trigger: domain.RunTriggerHumanRelease}, domain.RunRecord{ID: "new-child", ParentRunID: "r", Trigger: domain.RunTriggerHumanRelease})
|
||||
d.Packages[0].ChildRunID = "old-child"
|
||||
d.Packages[0].AcceptanceHumanItemID = "old-review"
|
||||
d.Packages[1].ChildRunID = "new-child"
|
||||
d.Packages[1].AcceptanceHumanItemID = "new-review"
|
||||
d.Items = append(d.Items, domain.HumanItemRecord{ID: "old-review", RunID: "old-child", CurrentStageID: "acceptance", Status: domain.HumanItemRejected}, domain.HumanItemRecord{ID: "new-review", RunID: "new-child", CurrentStageID: "acceptance", Status: domain.HumanItemAccepted})
|
||||
r := Build(d)
|
||||
if r.Sources[0].Stage != "delivered" || r.Sources[0].Exception {
|
||||
t.Fatalf("obsolete package still affects current progress: %+v", r.Sources)
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ func (s *MongoStore) LoadProductionStats(ctx context.Context, org string, projec
|
||||
if err := read(s.runs, runFilter, fields("id", "projectId", "workflowId", "taskId", "trigger", "mode", "parentRunId", "createdAt", "endedAt", "status", "deliveryOutcome"), &d.Runs); err != nil {
|
||||
return d, err
|
||||
}
|
||||
if err := read(s.humanItems, filter, fields("id", "projectId", "supplierId", "runId", "batchId", "legacyTaskId", "currentStageId", "status", "pendingCombinedSubmissionId", "processingJob.status"), &d.Items); err != nil {
|
||||
if err := read(s.humanItems, filter, fields("id", "projectId", "supplierId", "runId", "batchId", "legacyTaskId", "currentStageId", "status", "pendingCombinedSubmissionId", "releasePartitionId", "processingJob.status"), &d.Items); err != nil {
|
||||
return d, err
|
||||
}
|
||||
if err := read(s.humanBatches, filter, fields("id", "sourceBatchId", "stages"), &d.Batches); err != nil {
|
||||
@ -165,7 +165,7 @@ func (s *MongoStore) LoadProductionStats(ctx context.Context, org string, projec
|
||||
return d, err
|
||||
}
|
||||
}
|
||||
if err := read(s.deliveryPackages, filter, fields("id", "parentRunId", "childRunId", "supplierId", "mode", "temporary", "finalExportedAt", "status", "acceptanceReviews.id", "acceptanceReviews.decision", "acceptanceReviews.createdAt", "qualitySummary.prePackageAcceptance"), &d.Packages); err != nil {
|
||||
if err := read(s.deliveryPackages, filter, fields("id", "parentRunId", "childRunId", "supplierId", "mode", "temporary", "finalExportedAt", "status", "itemIds", "releasePartitionId", "acceptanceHumanItemId", "acceptanceReviews.id", "acceptanceReviews.decision", "acceptanceReviews.createdAt", "qualitySummary.prePackageAcceptance"), &d.Packages); err != nil {
|
||||
return d, err
|
||||
}
|
||||
return d, nil
|
||||
|
||||
@ -460,7 +460,11 @@ export function ProductionStatistics() {
|
||||
{s.evidence.map((e) => (
|
||||
<p key={e.id} className="my-2 text-xs">
|
||||
{metrics[e.metric]} · {names.get(e.supplierId) || e.supplierId} ·{" "}
|
||||
{e.evidenceAt ? "整源完成 " : ""}
|
||||
{new Date(e.at).toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" })}
|
||||
{e.evidenceAt && e.evidenceAt !== e.at
|
||||
? ` · 本 part 记录 ${new Date(e.evidenceAt).toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" })}`
|
||||
: ""}
|
||||
{e.runId && e.workflowId && (
|
||||
<Link
|
||||
className="ml-2 text-orange-600"
|
||||
|
||||
@ -19,6 +19,7 @@ export type ProductionSource = {
|
||||
metric: string;
|
||||
supplierId: string;
|
||||
at: string;
|
||||
evidenceAt?: string;
|
||||
runId?: string;
|
||||
workflowId?: string;
|
||||
taskId?: string;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user