Browse Source

Merge pull request '#2234 数字看板-活动分析】用户总数与增长趋势分析页面的注册用户数据不一致' (#2273) from zouap_fix into V20220616

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/2273
Reviewed-by: lewis <747342561@qq.com>
pull/2290/head
lewis 3 years ago
parent
commit
aabad1f4bc
1 changed files with 16 additions and 13 deletions
  1. +16
    -13
      models/user_business_analysis.go

+ 16
- 13
models/user_business_analysis.go View File

@@ -719,12 +719,11 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS
userIndexMap := make(map[int64]float64, 0) userIndexMap := make(map[int64]float64, 0)
maxUserIndex := 0.0 maxUserIndex := 0.0
minUserIndex := 100000000.0 minUserIndex := 100000000.0
dateRecordBatch := make([]UserBusinessAnalysisAll, 0)
for { for {
sess.Select("`user`.*").Table("user").Where(cond).OrderBy("id asc").Limit(PAGE_SIZE, int(indexTotal)) sess.Select("`user`.*").Table("user").Where(cond).OrderBy("id asc").Limit(PAGE_SIZE, int(indexTotal))
userList := make([]*User, 0) userList := make([]*User, 0)
sess.Find(&userList) sess.Find(&userList)
dateRecordBatch := make([]UserBusinessAnalysisAll, 0)
for _, userRecord := range userList { for _, userRecord := range userList {
var dateRecordAll UserBusinessAnalysisAll var dateRecordAll UserBusinessAnalysisAll
dateRecordAll.ID = userRecord.ID dateRecordAll.ID = userRecord.ID
@@ -789,7 +788,7 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS


dateRecordBatch = append(dateRecordBatch, dateRecordAll) dateRecordBatch = append(dateRecordBatch, dateRecordAll)
if len(dateRecordBatch) >= BATCH_INSERT_SIZE { if len(dateRecordBatch) >= BATCH_INSERT_SIZE {
insertTable(dateRecordBatch, tableName, statictisSess)
err := insertTable(dateRecordBatch, tableName, statictisSess)
insertCount += BATCH_INSERT_SIZE insertCount += BATCH_INSERT_SIZE
if err != nil { if err != nil {
log.Info("insert all data failed." + err.Error()) log.Info("insert all data failed." + err.Error())
@@ -804,18 +803,19 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS
} }
} }
} }
if len(dateRecordBatch) > 0 {
err := insertTable(dateRecordBatch, tableName, statictisSess)
insertCount += len(dateRecordBatch)
if err != nil {
log.Info("insert all data failed." + err.Error())
}
}
indexTotal += PAGE_SIZE indexTotal += PAGE_SIZE
if indexTotal >= count { if indexTotal >= count {
break break
} }
} }
if len(dateRecordBatch) > 0 {
insertTable(dateRecordBatch, tableName, statictisSess)
insertCount += len(dateRecordBatch)
if err != nil {
log.Info("insert all data failed." + err.Error())
}
}

if tableName == "user_business_analysis_all" { if tableName == "user_business_analysis_all" {
log.Info("TotalHasActivityUser=" + fmt.Sprint(userMetrics["TotalHasActivityUser"])) log.Info("TotalHasActivityUser=" + fmt.Sprint(userMetrics["TotalHasActivityUser"]))
} }
@@ -835,7 +835,7 @@ func updateUserIndex(tableName string, statictisSess *xorm.Session, userId int64
statictisSess.Exec(updateSql) statictisSess.Exec(updateSql)
} }


func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, statictisSess *xorm.Session) {
func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, statictisSess *xorm.Session) error {


insertBatchSql := "INSERT INTO public." + tableName + insertBatchSql := "INSERT INTO public." + tableName +
"(id, count_date, code_merge_count, commit_count, issue_count, comment_count, focus_repo_count, star_repo_count, watched_count, gitea_age_month, commit_code_size, commit_dataset_size, " + "(id, count_date, code_merge_count, commit_count, issue_count, comment_count, focus_repo_count, star_repo_count, watched_count, gitea_age_month, commit_code_size, commit_dataset_size, " +
@@ -854,7 +854,8 @@ func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, static
} }
} }


statictisSess.Exec(insertBatchSql)
_, err := statictisSess.Exec(insertBatchSql)
return err
} }


func RefreshUserStaticAllTabel(wikiCountMap map[string]int, userMetrics map[string]int) { func RefreshUserStaticAllTabel(wikiCountMap map[string]int, userMetrics map[string]int) {
@@ -2057,7 +2058,9 @@ func queryCloudBrainTask(start_unix int64, end_unix int64) (map[int64]int, map[s
} else { } else {
resultMap[cloudTaskRecord.UserID] += 1 resultMap[cloudTaskRecord.UserID] += 1
} }
setMapKey("CloudBrainRunTime", cloudTaskRecord.UserID, int(cloudTaskRecord.Duration), resultItemMap)
if cloudTaskRecord.Duration < 100000000 && cloudTaskRecord.Duration > 0 {
setMapKey("CloudBrainRunTime", cloudTaskRecord.UserID, int(cloudTaskRecord.Duration), resultItemMap)
}
if cloudTaskRecord.Type == 1 { //npu if cloudTaskRecord.Type == 1 { //npu
if cloudTaskRecord.JobType == "TRAIN" { if cloudTaskRecord.JobType == "TRAIN" {
setMapKey("NpuTrainJob", cloudTaskRecord.UserID, 1, resultItemMap) setMapKey("NpuTrainJob", cloudTaskRecord.UserID, 1, resultItemMap)


Loading…
Cancel
Save