From 034707c725b7951c9c8e1ab8c34331f085a3760d Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 16 Nov 2021 09:30:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 11 +++++++---- routers/repo/user_data_analysis.go | 2 ++ routers/routes/routes.go | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index f0bdbc950..7c734a0f5 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -73,6 +73,8 @@ type UserBusinessAnalysis struct { //user Name string `xorm:"NOT NULL"` + + DataDate string `xorm:"NOT NULL"` } type UserBusinessAnalysisQueryOptions struct { @@ -263,7 +265,7 @@ func CounDataByDate(wikiCountMap map[string]int, startTime time.Time, endTime ti end_unix := endTime.Unix() CountDate := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 1, 0, 0, currentTimeNow.Location()) - + DataDate := startTime.Format("2006-01-02") CodeMergeCountMap := queryPullRequest(start_unix, end_unix) CommitCountMap := queryAction(start_unix, end_unix, 5) IssueCountMap := queryAction(start_unix, end_unix, 10) @@ -300,6 +302,7 @@ func CounDataByDate(wikiCountMap map[string]int, startTime time.Time, endTime ti dateRecord.RegistDate = userRecord.CreatedUnix dateRecord.Name = userRecord.Name dateRecord.GiteaAgeMonth = subMonth(currentTimeNow, userRecord.CreatedUnix.AsTime()) + dateRecord.DataDate = DataDate if _, ok := CodeMergeCountMap[dateRecord.ID]; !ok { dateRecord.CodeMergeCount = 0 } else { @@ -522,10 +525,10 @@ func queryFollow(start_unix int64, end_unix int64) map[int64]int { resultMap := make(map[int64]int) log.Info("query Follow size=" + fmt.Sprint(len(followList))) for _, followRecord := range followList { - if _, ok := resultMap[followRecord.UserID]; !ok { - resultMap[followRecord.UserID] = 1 + if _, ok := resultMap[followRecord.FollowID]; !ok { + resultMap[followRecord.FollowID] = 1 } else { - resultMap[followRecord.UserID] += 1 + resultMap[followRecord.FollowID] += 1 } } return resultMap diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 2737116bf..3742cf67c 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -18,6 +18,7 @@ func QueryUserStaticData(ctx *context.Context) { log.Info("startDate=" + startDate + " endDate=" + endDate) startTime, _ := time.Parse("2006-01-02", startDate) endTime, _ := time.Parse("2006-01-02", endDate) + endTime = endTime.AddDate(0, 0, 1) log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix())) ctx.JSON(http.StatusOK, models.QueryUserStaticData(startTime.Unix(), endTime.Unix())) } @@ -38,6 +39,7 @@ func QueryUserStaticDataPage(ctx *context.Context) { log.Info("startDate=" + startDate + " endDate=" + endDate + " userName=" + userName + " page=" + fmt.Sprint(page)) startTime, _ := time.Parse("2006-01-02", startDate) endTime, _ := time.Parse("2006-01-02", endDate) + endTime = endTime.AddDate(0, 0, 1) log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix())) pageOpts := &models.UserBusinessAnalysisQueryOptions{ diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 0ce670c17..c28e76a47 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -792,8 +792,8 @@ func RegisterRoutes(m *macaron.Macaron) { }, reqSignIn, context.RepoAssignment(), context.UnitTypes(), reqRepoAdmin, context.RepoRef()) m.Post("/:username/:reponame/action/:action", reqSignIn, context.RepoAssignment(), context.UnitTypes(), repo.Action) - m.Get("/tool/query_user_static", repo.QueryUserStaticData) - m.Get("/tool/query_user_static_page", repo.QueryUserStaticDataPage) + m.Get("/tool/query_user_static", adminReq, repo.QueryUserStaticData) + m.Get("/tool/query_user_static_page", adminReq, repo.QueryUserStaticDataPage) // Grouping for those endpoints not requiring authentication m.Group("/:username/:reponame", func() { m.Get("/contributors", repo.Contributors)