Skip to content

Commit

Permalink
fix some bug metrics should not contain wont fix states
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey committed Sep 26, 2023
1 parent 04fe227 commit 362ac56
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 33 deletions.
30 changes: 18 additions & 12 deletions internal/apps/dop/providers/efficiency_measure/calculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ func (p *provider) calPersonalFields(personalInfo *PersonalPerformanceInfo) (*pe
if err != nil {
return nil, err
}
demandBugTotal, err := p.issueDB.GetBugCountByUserID(userID, projectID, wontfixStateIDS, []string{"demandDesign"}, nil, false, 0)
demandBugTotal, err := p.issueDB.GetBugCountByUserID(userID, projectID, wontfixStateIDS, p.Cfg.DemandStageList, nil, false, 0)
if err != nil {
return nil, err
}
fields.DemandDesignBugTotal = demandBugTotal

architectureDesignTotal, err := p.issueDB.GetBugCountByUserID(userID, projectID, wontfixStateIDS, []string{"architectureDesign"}, nil, false, 0)
architectureDesignTotal, err := p.issueDB.GetBugCountByUserID(userID, projectID, wontfixStateIDS, p.Cfg.ArchitectureStageList, nil, false, 0)
if err != nil {
return nil, err
}
Expand All @@ -83,7 +83,7 @@ func (p *provider) calPersonalFields(personalInfo *PersonalPerformanceInfo) (*pe
}
fields.ReopenBugTotal = reopenBugTotal

submitBugTotal, err := p.issueDB.GetBugCountByUserID(0, projectID, nil, nil, nil, false, userID)
submitBugTotal, err := p.issueDB.GetBugCountByUserID(0, projectID, wontfixStateIDS, nil, nil, false, userID)
if err != nil {
return nil, err
}
Expand All @@ -95,7 +95,7 @@ func (p *provider) calPersonalFields(personalInfo *PersonalPerformanceInfo) (*pe
}
fields.CreateTestCaseTotal = testCaseTotal

requirementTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeRequirement, nil)
requirementTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeRequirement, nil, wontfixStateIDS)
if err != nil {
return nil, err
}
Expand All @@ -109,49 +109,55 @@ func (p *provider) calPersonalFields(personalInfo *PersonalPerformanceInfo) (*pe
if err != nil {
return nil, err
}
workingRequirementTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeRequirement, workingStateIDS)
workingRequirementTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeRequirement, workingStateIDS, nil)
if err != nil {
return nil, err
}
fields.WorkingRequirementTotal = workingRequirementTotal

openRequirementTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeRequirement, openStateIDS)
openRequirementTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeRequirement, openStateIDS, nil)
if err != nil {
return nil, err
}
fields.PendingRequirementTotal = openRequirementTotal

bugTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeBug, nil)
bugTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeBug, nil, wontfixStateIDS)
if err != nil {
return nil, err
}
fields.BugTotal = bugTotal

workingBugTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeBug, workingStateIDS)
ownerBugTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(userID, 0, projectID, apistructs.IssueTypeBug, nil, wontfixStateIDS)
if err != nil {
return nil, err
}
fields.OwnerBugTotal = ownerBugTotal

workingBugTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeBug, workingStateIDS, nil)
if err != nil {
return nil, err
}
fields.WorkingBugTotal = workingBugTotal

pendingBugTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeBug, openStateIDS)
pendingBugTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeBug, openStateIDS, nil)
if err != nil {
return nil, err
}
fields.PendingBugTotal = pendingBugTotal

taskTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeTask, nil)
taskTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeTask, nil, wontfixStateIDS)
if err != nil {
return nil, err
}
fields.TaskTotal = taskTotal

workingTaskTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeTask, workingStateIDS)
workingTaskTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeTask, workingStateIDS, nil)
if err != nil {
return nil, err
}
fields.WorkingTaskTotal = workingTaskTotal

pendingTaskTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeTask, openStateIDS)
pendingTaskTotal, err := p.issueDB.GetIssueNumByStatesAndUserID(0, userID, projectID, apistructs.IssueTypeTask, openStateIDS, nil)
if err != nil {
return nil, err
}
Expand Down
36 changes: 20 additions & 16 deletions internal/apps/dop/providers/efficiency_measure/contributor_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,26 @@ import (
)

type PersonalContributorRow struct {
OrgID string `json:"orgID" ch:"orgID"`
UserEmail string `json:"userEmail" ch:"userEmail"`
ProjectName string `json:"projectName" ch:"projectName"`
CommitTotal float64 `json:"commitTotal" ch:"commitTotal"`
FileChangedTotal float64 `json:"fileChangedTotal" ch:"fileChangedTotal"`
AdditionTotal float64 `json:"additionTotal" ch:"additionTotal"`
DeletionTotal float64 `json:"deletionTotal" ch:"deletionTotal"`
OrgID string `json:"orgID" ch:"orgID"`
UserEmail string `json:"userEmail" ch:"userEmail"`
ProjectName string `json:"projectName" ch:"projectName"`
ProjectDisplayName string `json:"projectDisplayName" ch:"projectDisplayName"`
CommitTotal float64 `json:"commitTotal" ch:"commitTotal"`
FileChangedTotal float64 `json:"fileChangedTotal" ch:"fileChangedTotal"`
AdditionTotal float64 `json:"additionTotal" ch:"additionTotal"`
DeletionTotal float64 `json:"deletionTotal" ch:"deletionTotal"`
}

type PersonalActualMandayRow struct {
OrgID string `json:"orgID" ch:"orgID"`
OrgName string `json:"orgName" ch:"orgName"`
UserID string `json:"userID" ch:"userID"`
UserName string `json:"userName" ch:"userName"`
ProjectID string `json:"projectID" ch:"projectID"`
ProjectName string `json:"projectName" ch:"projectName"`
ProjectCode string `json:"projectCode" ch:"projectCode"`
ActualMandayTotal float64 `json:"actualMandayTotal" ch:"actualMandayTotal"`
OrgID string `json:"orgID" ch:"orgID"`
OrgName string `json:"orgName" ch:"orgName"`
UserID string `json:"userID" ch:"userID"`
UserName string `json:"userName" ch:"userName"`
ProjectID string `json:"projectID" ch:"projectID"`
ProjectName string `json:"projectName" ch:"projectName"`
ProjectDisplayName string `json:"projectDisplayName" ch:"projectDisplayName"`
ProjectCode string `json:"projectCode" ch:"projectCode"`
ActualMandayTotal float64 `json:"actualMandayTotal" ch:"actualMandayTotal"`
}

func (p *provider) queryPersonalContributors(rw http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -134,6 +136,7 @@ func (p *provider) makeContributorBasicSql(req *apistructs.PersonalContributionR
last_value(tag_values[indexOf(tag_keys,'app_name')]) as appName,
tag_values[indexOf(tag_keys,'app_id')] as appID,
last_value(tag_values[indexOf(tag_keys,'project_name')]) as projectName,
last_value(tag_values[indexOf(tag_keys,'project_display_name')]) as projectDisplayName,
tag_values[indexOf(tag_keys,'repo_id')] as repoID,
tag_values[indexOf(tag_keys,'project_id')] as projectID,
tag_values[indexOf(tag_keys,'org_id')] as orgID,
Expand Down Expand Up @@ -167,7 +170,7 @@ func (p *provider) makeContributorBasicSql(req *apistructs.PersonalContributionR
sum(dailyAdditionTotal) as additionTotal,
sum(dailyDeletionTotal) as deletionTotal`
if req.GroupByProject {
selectSql += ", last_value(projectName) as projectName"
selectSql += ", last_value(projectName) as projectName, last_value(projectDisplayName) as projectDisplayName"
}
tx = tx.Table(fmt.Sprintf("(%s)", dataSql)).
Select(selectSql).
Expand All @@ -187,6 +190,7 @@ func (p *provider) makeActualManDaySql(req *apistructs.PersonalContributionReque
Select(`last_value(tag_values[indexOf(tag_keys,'org_name')]) as orgName,
last_value(tag_values[indexOf(tag_keys,'user_name')]) as userName,
last_value(tag_values[indexOf(tag_keys,'project_name')]) as projectName,
last_value(tag_values[indexOf(tag_keys,'project_display_name')]) as projectDisplayName,
last_value(tag_values[indexOf(tag_keys,'emp_project_code')]) as projectCode,
tag_values[indexOf(tag_keys,'project_id')] as projectID,
tag_values[indexOf(tag_keys,'org_id')] as orgID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ type PersonalEfficiencyRow struct {
UserPositionLevel string `json:"userPositionLevel" ch:"userPositionLevel"`
JobStatus string `json:"jobStatus" ch:"jobStatus"`
ProjectName string `json:"projectName" ch:"projectName"`
ProjectDisplayName string `json:"projectDisplayName" ch:"projectDisplayName"`
RequirementTotal float64 `json:"requirementTotal" ch:"requirementTotal"`
WorkingRequirementTotal float64 `json:"workingRequirementTotal" ch:"workingRequirementTotal"`
PendingRequirementTotal float64 `json:"pendingRequirementTotal" ch:"pendingRequirementTotal"`
TaskTotal float64 `json:"taskTotal" ch:"taskTotal"`
WorkingTaskTotal float64 `json:"workingTaskTotal" ch:"workingTaskTotal"`
PendingTaskTotal float64 `json:"pendingTaskTotal" ch:"pendingTaskTotal"`
BugTotal float64 `json:"bugTotal" ch:"bugTotal"`
OwnerBugTotal float64 `json:"ownerBugTotal" ch:"ownerBugTotal"`
PendingBugTotal float64 `json:"pendingBugTotal" ch:"pendingBugTotal"`
WorkingBugTotal float64 `json:"workingBugTotal" ch:"workingBugTotal"`
DesignBugTotal float64 `json:"designBugTotal" ch:"designBugTotal"`
Expand Down Expand Up @@ -173,6 +175,7 @@ func (p *provider) makeEfficiencyBasicSql(req *apistructs.PersonalEfficiencyRequ
max(tag_values[indexOf(tag_keys,'emp_user_position_level')]) as userPositionLevel,
max(tag_values[indexOf(tag_keys,'emp_job_status')]) as jobStatus,
last_value(tag_values[indexOf(tag_keys,'project_name')]) as projectName,
last_value(tag_values[indexOf(tag_keys,'project_display_name')]) as projectDisplayName,
tag_values[indexOf(tag_keys,'org_id')] as orgID,
tag_values[indexOf(tag_keys,'user_id')] as userID,
tag_values[indexOf(tag_keys,'project_id')] as projectID,
Expand All @@ -183,6 +186,7 @@ func (p *provider) makeEfficiencyBasicSql(req *apistructs.PersonalEfficiencyRequ
last_value(number_field_values[indexOf(number_field_keys,'personal_working_task_total')]) as workingTaskTotal,
last_value(number_field_values[indexOf(number_field_keys,'personal_pending_task_total')]) as pendingTaskTotal,
last_value(number_field_values[indexOf(number_field_keys,'personal_bug_total')]) as bug_total,
last_value(number_field_values[indexOf(number_field_keys,'personal_owner_bug_total')]) as owner_bug_total,
last_value(number_field_values[indexOf(number_field_keys,'personal_pending_bug_total')]) as pendingBugTotal,
last_value(number_field_values[indexOf(number_field_keys,'personal_working_bug_total')]) as workingBugTotal,
last_value(number_field_values[indexOf(number_field_keys,'personal_demand_design_bug_total')]) as designBugTotal,
Expand Down Expand Up @@ -218,6 +222,7 @@ func (p *provider) makeEfficiencyBasicSql(req *apistructs.PersonalEfficiencyRequ
max(userPositionLevel) as userPositionLevel,
max(jobStatus) as jobStatus,
last_value(projectName) as projectName,
last_value(projectDisplayName) as projectDisplayName,
sum(requirementTotal) as requirementTotal,
sum(workingRequirementTotal) as workingRequirementTotal,
sum(pendingRequirementTotal) as pendingRequirementTotal,
Expand All @@ -233,6 +238,7 @@ func (p *provider) makeEfficiencyBasicSql(req *apistructs.PersonalEfficiencyRequ
sum(reopenBugTotal) as reopenBugTotal,
sum(submitBugTotal) as submitBugTotal,
sum(testCaseTotal) as testCaseTotal,
sum(owner_bug_total) as ownerBugTotal,
sum(fix_bug_elapsed_minute) as fixBugElapsedMinute,
sum(fix_bug_estimate_minute) as fixBugEstimateMinute,
sum(resolvedBugTotal) as resolvedBugTotal,
Expand All @@ -248,13 +254,13 @@ func (p *provider) makeEfficiencyBasicSql(req *apistructs.PersonalEfficiencyRequ
sum(actualMandayTotal) as actualMandayTotal,
sum(projectFuncPointsTotal) as projectFuncPointsTotal,
sum(productRequirementTotal) as productRequirementTotal,
if(bugTotal > 0, onlineBugTotal / bugTotal, 0) as onlineBugRatio,
if(bugTotal > 0, lowLevelBugTotal / bugTotal, 0) as lowLevelBugRatio,
if(ownerBugTotal > 0, onlineBugTotal / ownerBugTotal, 0) as onlineBugRatio,
if(ownerBugTotal > 0, lowLevelBugTotal / ownerBugTotal, 0) as lowLevelBugRatio,
if(projectFuncPointsTotal > 0, responsibleFuncPointsTotal / projectFuncPointsTotal, 0) as pointParticipationRatio,
if(demandFuncPointsTotal > 0, designBugTotal / demandFuncPointsTotal, 0) as requirementDefectDensity,
if(demandFuncPointsTotal > 0, architectureBugTotal / demandFuncPointsTotal, 0) as demandDefectDensity,
if(devFuncPointsTotal > 0, bugTotal / devFuncPointsTotal, 0) as devDefectDensity,
if(testFuncPointsTotal > 0, bugTotal / testFuncPointsTotal, 0) as bugDefectDensity,
if(testFuncPointsTotal > 0, onlineBugTotal / testFuncPointsTotal, 0) as bugDefectDensity,
if(demandFuncPointsTotal > 0, actualMandayTotal * 8 / demandFuncPointsTotal, 0) as demandProductPDR,
if(devFuncPointsTotal > 0, actualMandayTotal * 8 / devFuncPointsTotal, 0) as devProductPDR,
if(testFuncPointsTotal > 0, actualMandayTotal * 8 / testFuncPointsTotal, 0) as testProductPDR`).
Expand Down
18 changes: 18 additions & 0 deletions internal/apps/dop/providers/efficiency_measure/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,23 @@ var (
}
},
},
{
name: "personal_owner_bug_total",
help: "Total number of bug that owner is the user",
valueType: prometheus.CounterValue,
getValues: func(personalInfo *PersonalPerformanceInfo) metricValues {
var value float64
if personalInfo.metricFields != nil {
value = float64(personalInfo.metricFields.OwnerBugTotal)
}
return metricValues{
{
value: value,
timestamp: time.Now(),
},
}
},
},
{
name: "personal_pending_bug_total",
help: "Total number of pending bugs",
Expand Down Expand Up @@ -406,6 +423,7 @@ type personalMetricField struct {
WorkingRequirementTotal uint64
PendingRequirementTotal uint64
BugTotal uint64
OwnerBugTotal uint64
WorkingBugTotal uint64
PendingBugTotal uint64

Expand Down
2 changes: 2 additions & 0 deletions internal/apps/dop/providers/efficiency_measure/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type config struct {
RefreshCheckPerformanceNumberFiledDuration time.Duration `file:"refresh_check_performance_number_filed_duration" env:"REFRESH_CHECK_PERFORMANCE_NUMBER_FILED_DURATION" default:"20m"`
PerformanceMetricEtcdPrefixKey string `file:"performance_metric_etcd_prefix_key" env:"PERFORMANCE_METRIC_ETCD_PREFIX_KEY" default:"/devops/metrics/performance/"`
OrgWhiteList []string `file:"performance_measure_org_white_list" env:"PERFORMANCE_MEASURE_ORG_WHITE_LIST"`
DemandStageList []string `file:"demand_stage_list" env:"DEMAND_STAGE_LIST" default:"demandDesign,需求设计,架构设计,architectureDesign,需求调研"`
ArchitectureStageList []string `file:"architecture_stage_list" env:"ARCHITECTURE_STAGE_LIST" default:"代码研发,交互设计,技术设计"`
}

// +provider
Expand Down
7 changes: 5 additions & 2 deletions internal/apps/dop/providers/issue/dao/performance_measure.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Line struct {

func (client *DBClient) GetBugCountByUserID(userID uint64, projectID uint64, wontfixStateIDS []uint64, stages []string, severities []string, withReopened bool, creator uint64) (uint64, error) {
var lines []Line
cli := client.Table("dice_issues").Select("id").Where("type = ?", apistructs.IssueTypeBug)
cli := client.Table("dice_issues").Select("id").Where("deleted = 0").Where("type = ?", apistructs.IssueTypeBug)
if userID != 0 {
cli = cli.Where("owner = ?", userID)
}
Expand Down Expand Up @@ -52,7 +52,7 @@ func (client *DBClient) GetBugCountByUserID(userID uint64, projectID uint64, won
return uint64(len(lines)), nil
}

func (client *DBClient) GetIssueNumByStatesAndUserID(ownerID, assigneeID, projectID uint64, issueType apistructs.IssueType, states []uint64) (uint64, error) {
func (client *DBClient) GetIssueNumByStatesAndUserID(ownerID, assigneeID, projectID uint64, issueType apistructs.IssueType, states, statesNotIn []uint64) (uint64, error) {
var lines []Line
cli := client.Table("dice_issues").Where("deleted = 0").Select("id")
if ownerID != 0 {
Expand All @@ -70,6 +70,9 @@ func (client *DBClient) GetIssueNumByStatesAndUserID(ownerID, assigneeID, projec
if len(states) > 0 {
cli = cli.Where("state in (?)", states)
}
if len(statesNotIn) > 0 {
cli = cli.Where("state not in (?)", statesNotIn)
}
if err := cli.Find(&lines).Error; err != nil {
return 0, err
}
Expand Down

0 comments on commit 362ac56

Please sign in to comment.