Skip to content

Commit

Permalink
add estimated metrics for task
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey committed Aug 30, 2023
1 parent 2c24969 commit 3a27b80
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 64 deletions.
19 changes: 11 additions & 8 deletions apistructs/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,14 +1167,17 @@ type IssuesStageRequest struct {
// IssueManHourSumResponse 事件下所有的任务总和响应
type IssueManHourSumResponse struct {
// Header
DesignManHour int64 `json:"designManHour"`
DevManHour int64 `json:"devManHour"`
TestManHour int64 `json:"testManHour"`
ImplementManHour int64 `json:"implementManHour"`
DeployManHour int64 `json:"deployManHour"`
OperatorManHour int64 `json:"operatorManHour"`
SumElapsedTime int64 `json:"sumElapsedTime"`
SumEstimateTime int64 `json:"sumEstimateTime"`
DesignManHour int64 `json:"designManHour"`
DevManHour int64 `json:"devManHour"`
TestManHour int64 `json:"testManHour"`
ImplementManHour int64 `json:"implementManHour"`
DeployManHour int64 `json:"deployManHour"`
OperatorManHour int64 `json:"operatorManHour"`
SumElapsedTime int64 `json:"sumElapsedTime"`
SumEstimateTime int64 `json:"sumEstimateTime"`
EstimateManDayGtOneDayNum int64 `json:"estimateManDayGtOneDayNum"`
EstimateManDayGtTwoDayNum int64 `json:"estimateManDayGtTwoDayNum"`
EstimateManDayGtThreeDayNum int64 `json:"estimateManDayGtThreeDayNum"`
}

// IssueBugPercentageResponse 缺陷率响应
Expand Down
45 changes: 33 additions & 12 deletions internal/apps/dop/providers/issue/dao/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import (
"github.com/erda-project/erda/pkg/strutil"
)

const (
// day = 8 * 60(minute)
day = 480
)

// Issue .
type Issue struct {
dbengine.BaseModel
Expand Down Expand Up @@ -531,10 +536,13 @@ func (client *DBClient) IssueStateCount2(issueIDs []uint64) ([]apistructs.Requir
// GetTaskIssueManHourSum get task mam hour sum
func (client *DBClient) GetTaskIssueManHourSum(req apistructs.IssuesStageRequest) (apistructs.IssueManHourSumResponse, error) {
var (
issues []Issue
ans = make(map[string]int64)
sumElapsedTime int64 = 0
sumEstimateTime int64 = 0
issues []Issue
ans = make(map[string]int64)
sumElapsedTime int64 = 0
sumEstimateTime int64 = 0
estimateDayGtOne int64 = 0
esitmateDayGtTwo int64 = 0
esitmateDayGtThree int64 = 0
)
sql := client.Table("dice_issues")
if len(req.StatisticRange) > 0 {
Expand Down Expand Up @@ -565,16 +573,29 @@ func (client *DBClient) GetTaskIssueManHourSum(req apistructs.IssuesStageRequest
ans[each.Stage] += ret.ElapsedTime
sumElapsedTime += ret.ElapsedTime
sumEstimateTime += ret.EstimateTime
estimateDay := float64(ret.EstimateTime) / day
if estimateDay > 1 {
estimateDayGtOne++
}
if estimateDay > 2 {
esitmateDayGtTwo++
}
if estimateDay > 3 {
esitmateDayGtThree++
}
}
return apistructs.IssueManHourSumResponse{
DesignManHour: ans["design"],
DevManHour: ans["dev"],
TestManHour: ans["test"],
ImplementManHour: ans["implement"],
DeployManHour: ans["deploy"],
OperatorManHour: ans["operator"],
SumElapsedTime: sumElapsedTime,
SumEstimateTime: sumEstimateTime,
DesignManHour: ans["design"],
DevManHour: ans["dev"],
TestManHour: ans["test"],
ImplementManHour: ans["implement"],
DeployManHour: ans["deploy"],
OperatorManHour: ans["operator"],
SumElapsedTime: sumElapsedTime,
SumEstimateTime: sumEstimateTime,
EstimateManDayGtOneDayNum: estimateDayGtOne,
EstimateManDayGtTwoDayNum: esitmateDayGtTwo,
EstimateManDayGtThreeDayNum: esitmateDayGtThree,
}, nil
}

Expand Down
10 changes: 10 additions & 0 deletions internal/apps/dop/providers/project_report/calculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
orgpb "github.com/erda-project/erda-proto-go/core/org/pb"
"github.com/erda-project/erda/apistructs"
"github.com/erda-project/erda/internal/apps/dop/dao"
"github.com/erda-project/erda/internal/apps/dop/providers/issue/core/query/issueexcel"
)

func (p *provider) refreshBasicIterations() error {
Expand Down Expand Up @@ -166,6 +167,12 @@ func (p *provider) calIterationFields(iter *IterationInfo) (*IterationMetricFiel
doneReqStateIDs = append(doneReqStateIDs, int64(doneReqStates[i].ID))
}

manHour, err := issueexcel.NewManhour(iter.Iteration.ManHour)
if err != nil {
return nil, err
}
fields.IterationEstimatedDayTotal = float64(manHour.EstimateTime) / 480

var doneTaskStateIDs []int64
doneTaskStates, err := p.issueDB.GetIssuesStatesByTypes(&apistructs.IssueStatesRequest{
ProjectID: iter.Iteration.ProjectID,
Expand Down Expand Up @@ -259,6 +266,9 @@ func (p *provider) calIterationFields(iter *IterationInfo) (*IterationMetricFiel
return nil, err
}
fields.TaskEstimatedMinute = uint64(totalTaskEstimateTime.SumEstimateTime)
fields.TaskEstimatedDayGtOneTotal = uint64(totalTaskEstimateTime.EstimateManDayGtOneDayNum)
fields.TaskEstimatedDayGtTwoTotal = uint64(totalTaskEstimateTime.EstimateManDayGtTwoDayNum)
fields.TaskEstimatedDayGtThreeTotal = uint64(totalTaskEstimateTime.EstimateManDayGtThreeDayNum)

if fields.RequirementTotal > 0 {
fields.RequirementCompleteSchedule = float64(iterationSummary.Requirement.Done) / float64(fields.RequirementTotal)
Expand Down
76 changes: 74 additions & 2 deletions internal/apps/dop/providers/project_report/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type IterationMetricFields struct {
TaskUnAssociatedTotal uint64
TaskAssociatedPercent float64
TaskWorkingTotal uint64
TaskEstimatedDayGtOneTotal uint64
TaskEstimatedDayGtTwoTotal uint64
TaskEstimatedDayGtThreeTotal uint64

// requirement-related metrics
RequirementTotal uint64
Expand All @@ -89,8 +92,9 @@ type IterationMetricFields struct {
BugWithWonfixTotal uint64

// iteration-related metrics
IterationAssigneeNum uint64
ProjectAssigneeNum uint64
IterationAssigneeNum uint64
IterationEstimatedDayTotal float64
ProjectAssigneeNum uint64
}

// IsValid returns true if the IterationMetricFields is valid.
Expand Down Expand Up @@ -237,6 +241,57 @@ var (
}
},
},
{
name: "iteration_task_estimated_day_gt_one_total",
help: "Cumulative estimated day greater than one of task type issue in iteration.",
valueType: prometheus.CounterValue,
getValues: func(iterationInfo *IterationInfo) metricValues {
var value float64
if iterationInfo.IterationMetricFields != nil {
value = float64(iterationInfo.IterationMetricFields.TaskEstimatedDayGtOneTotal)
}
return metricValues{
{
value: value,
timestamp: time.Now(),
},
}
},
},
{
name: "iteration_task_estimated_day_gt_two_total",
help: "Cumulative estimated day greater than two of task type issue in iteration.",
valueType: prometheus.CounterValue,
getValues: func(iterationInfo *IterationInfo) metricValues {
var value float64
if iterationInfo.IterationMetricFields != nil {
value = float64(iterationInfo.IterationMetricFields.TaskEstimatedDayGtTwoTotal)
}
return metricValues{
{
value: value,
timestamp: time.Now(),
},
}
},
},
{
name: "iteration_task_estimated_day_gt_three_total",
help: "Cumulative estimated day greater than three of task type issue in iteration.",
valueType: prometheus.CounterValue,
getValues: func(iterationInfo *IterationInfo) metricValues {
var value float64
if iterationInfo.IterationMetricFields != nil {
value = float64(iterationInfo.IterationMetricFields.TaskEstimatedDayGtThreeTotal)
}
return metricValues{
{
value: value,
timestamp: time.Now(),
},
}
},
},
{
name: "iteration_task_associated_percent",
help: "Accumulate the proportion of the number of requirements associated with the current task",
Expand Down Expand Up @@ -577,6 +632,23 @@ var (
}
},
},
{
name: "iteration_estimated_day_total",
help: "The total number estimated days of the iteration",
valueType: prometheus.CounterValue,
getValues: func(iterationInfo *IterationInfo) metricValues {
var value float64
if iterationInfo.IterationMetricFields != nil {
value = iterationInfo.IterationMetricFields.IterationEstimatedDayTotal
}
return metricValues{
{
value: value,
timestamp: time.Now(),
},
}
},
},
}
)

Expand Down
Loading

0 comments on commit 3a27b80

Please sign in to comment.