diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 4de0c6d1a..f53039ebd 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -233,19 +233,15 @@ func QueryMetricsPage(start int64, end int64, page int, pageSize int) ([]*UserMe statictisSess := xStatistic.NewSession() defer statictisSess.Close() cond := "count_date >" + fmt.Sprint(start) + " and count_date<" + fmt.Sprint(end) - allCount, err := statictisSess.Where(cond).Count(new(UserMetrics)) - if err != nil { - log.Info("query error." + err.Error()) - return nil, 0 - } + userMetricsList := make([]*UserMetrics, 0) //.Limit(pageSize, page*pageSize) if err := statictisSess.Table(new(UserMetrics)).Where(cond).OrderBy("count_date desc"). Find(&userMetricsList); err != nil { return nil, 0 } - postDeal(userMetricsList) - return userMetricsList, allCount + postUserMetricsList := postDeal(userMetricsList) + return postUserMetricsList, int64(len(postUserMetricsList)) } func QueryMetrics(start int64, end int64) ([]*UserMetrics, int) { @@ -256,16 +252,31 @@ func QueryMetrics(start int64, end int64) ([]*UserMetrics, int) { Find(&userMetricsList); err != nil { return nil, 0 } - postDeal(userMetricsList) - return userMetricsList, len(userMetricsList) + postUserMetricsList := postDeal(userMetricsList) + return postUserMetricsList, int(len(postUserMetricsList)) +} + +func duplicateRemoval(userMetricsList []*UserMetrics) []*UserMetrics { + userMetricsResult := make([]*UserMetrics, 0) + for i := 0; i < len(userMetricsList); i++ { + if i > 0 { + if userMetricsList[i].DataDate == userMetricsList[i-1].DataDate { + continue + } + } + userMetricsResult = append(userMetricsResult, userMetricsList[i]) + } + return userMetricsResult } -func postDeal(userMetricsList []*UserMetrics) { - for _, userMetrics := range userMetricsList { +func postDeal(userMetricsList []*UserMetrics) []*UserMetrics { + duplicateRemovalUserMetricsList := duplicateRemoval(userMetricsList) + for _, userMetrics := range duplicateRemovalUserMetricsList { userMetrics.DisplayDate = userMetrics.DataDate userMetrics.TotalRegistUser = userMetrics.ActivateRegistUser + userMetrics.NotActivateRegistUser userMetrics.TotalNotActivateRegistUser = userMetrics.TotalUser - userMetrics.TotalActivateRegistUser } + return duplicateRemovalUserMetricsList } func QueryMetricsForAll() []*UserMetrics { @@ -276,7 +287,8 @@ func QueryMetricsForAll() []*UserMetrics { Find(&userMetricsList); err != nil { return nil } - return makeResultForMonth(userMetricsList, len(userMetricsList)) + duplicateRemovalUserMetricsList := duplicateRemoval(userMetricsList) + return makeResultForMonth(duplicateRemovalUserMetricsList, len(duplicateRemovalUserMetricsList)) } func QueryMetricsForYear() []*UserMetrics { @@ -879,9 +891,9 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, //insert userMetrics table var useMetrics UserMetrics useMetrics.CountDate = CountDate.Unix() - useMetrics.DataDate = DataDate statictisSess.Delete(&useMetrics) + useMetrics.DataDate = DataDate useMetrics.ActivateRegistUser = getMapKeyStringValue("ActivateRegistUser", userMetrics) useMetrics.HasActivityUser = getMapKeyStringValue("HasActivityUser", userMetrics) useMetrics.RegistActivityUser = 0 diff --git a/modules/cloudbrain/cloudbrain.go b/modules/cloudbrain/cloudbrain.go index 3dee3a3fa..a71389741 100755 --- a/modules/cloudbrain/cloudbrain.go +++ b/modules/cloudbrain/cloudbrain.go @@ -1,11 +1,12 @@ package cloudbrain import ( - "code.gitea.io/gitea/modules/timeutil" "encoding/json" "errors" "strconv" + "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/models" @@ -186,7 +187,6 @@ func AdminOrImageCreaterRight(ctx *context.Context) { } - func GenerateTask(ctx *context.Context, displayJobName, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, brainScorePath, jobType, gpuQueue, description, branchName, bootFile, params string, benchmarkTypeID, benchmarkChildTypeID, resourceSpecId int) error { dataActualPath := setting.Attachment.Minio.RealPath + diff --git a/routers/private/internal.go b/routers/private/internal.go index a0c2843be..4731463b1 100755 --- a/routers/private/internal.go +++ b/routers/private/internal.go @@ -6,9 +6,10 @@ package private import ( - "code.gitea.io/gitea/routers/repo" "strings" + "code.gitea.io/gitea/routers/repo" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/private" "code.gitea.io/gitea/modules/setting" @@ -46,7 +47,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/manager/flush-queues", bind(private.FlushOptions{}), FlushQueues) m.Post("/tool/update_all_repo_commit_cnt", UpdateAllRepoCommitCnt) m.Post("/tool/repo_stat/:date", RepoStatisticManually) - + m.Post("/tool/user_stat/:date", UserStatisticManually) m.Get("/tool/org_stat", OrgStatisticManually) m.Post("/tool/update_repo_visit/:date", UpdateRepoVisit) m.Post("/task/history_handle/duration", repo.HandleTaskWithNoDuration) diff --git a/routers/private/tool.go b/routers/private/tool.go index 122a41afe..f8b1a2c3f 100755 --- a/routers/private/tool.go +++ b/routers/private/tool.go @@ -45,6 +45,11 @@ func RepoStatisticManually(ctx *macaron.Context) { repo.TimingCountDataByDate(date) } +func UserStatisticManually(ctx *macaron.Context) { + date := ctx.Params("date") + repo.TimingCountDataByDate(date) +} + func OrgStatisticManually() { models.UpdateOrgStatistics() } diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 2823f9c87..9707f8df2 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -247,6 +247,7 @@ func queryUserDataPage(ctx *context.Context, tableName string, queryObj interfac mapInterface := make(map[string]interface{}) mapInterface["data"] = re mapInterface["count"] = count + ctx.JSON(http.StatusOK, mapInterface) } } @@ -303,6 +304,15 @@ func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, e mapInterface := make(map[string]interface{}) mapInterface["data"] = result mapInterface["count"] = count + if tableName == "public.user_business_analysis_yesterday" { + mapInterface["datarecordbegintime"] = setting.RadarMap.GrowthBeginTime + if len(result) > 0 { + dateTime := time.Unix(result[0].CountDate, 0) + mapInterface["lastUpdatedTime"] = dateTime.Format("2006-01-02 15:04:05") + } else { + mapInterface["lastUpdatedTime"] = "" + } + } ctx.JSON(http.StatusOK, mapInterface) } diff --git a/web_src/js/components/UserTrend.vue b/web_src/js/components/UserTrend.vue index 489d65cbb..fcc4ede4b 100644 --- a/web_src/js/components/UserTrend.vue +++ b/web_src/js/components/UserTrend.vue @@ -257,10 +257,10 @@ return days; }, getUpdateTime(){ - this.$axios.get('../../api/v1/projectboard/project',{ + this.$axios.get('../../api/v1/query_metrics_yesterday',{ params:this.params_pro }).then((res)=>{ - this.recordBeginTime=res.data.recordBeginTime + this.recordBeginTime=res.data.datarecordbegintime this.lastUpdatedTime=res.data.lastUpdatedTime }) },