From 08bf463e998c9620763e82a3dd200dbdc8992ae5 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 28 Oct 2021 11:33:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=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 | 31 ++++++++++++++++++++++++------ routers/private/tool.go | 1 + routers/repo/user_data_analysis.go | 28 +++++++++++++++++++-------- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 406cc36f1..6f6abb1ff 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -114,7 +114,7 @@ func QueryUserStaticData(startTime int64, endTime int64) []*UserBusinessAnalysis return userBusinessAnalysisReturnList } -func CountData(wikiCountMap map[string]int) { +func CounDataByDate(wikiCountMap map[string]int, startTime time.Time, endTime time.Time) { log.Info("start to count other user info data") sess := x.NewSession() defer sess.Close() @@ -125,12 +125,12 @@ func CountData(wikiCountMap map[string]int) { currentTimeNow := time.Now() log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) - yesterday := currentTimeNow.AddDate(0, 0, -1) - startTime := time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location()) + //yesterday := currentTimeNow.AddDate(0, 0, -1) + //startTime := time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location()) start_unix := startTime.Unix() log.Info("DB query time:" + startTime.Format("2006-01-02 15:04:05")) - endTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) + //endTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) end_unix := endTime.Unix() CountDate := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 1, 0, 0, currentTimeNow.Location()) @@ -155,11 +155,17 @@ func CountData(wikiCountMap map[string]int) { CreateRepoCountMap := queryUserCreateRepo(start_unix, end_unix) LoginCountMap := queryLoginCount(start_unix, end_unix) + statictisSess := xStatistic.NewSession() + defer statictisSess.Close() + for i, userRecord := range userList { var dateRecord UserBusinessAnalysis dateRecord.ID = userRecord.ID log.Info("i=" + fmt.Sprint(i) + " userName=" + userRecord.Name) dateRecord.CountDate = CountDate.Unix() + + statictisSess.Delete(&dateRecord) + dateRecord.Email = userRecord.Email dateRecord.RegistDate = userRecord.CreatedUnix dateRecord.Name = userRecord.Name @@ -244,13 +250,26 @@ func CountData(wikiCountMap map[string]int) { dateRecord.CommitModelCount = 0 - statictisSess := xStatistic.NewSession() - defer statictisSess.Close() statictisSess.Insert(&dateRecord) } } +func CountData(wikiCountMap map[string]int) { + + currentTimeNow := time.Now() + log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) + + yesterday := currentTimeNow.AddDate(0, 0, -1) + startTime := time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location()) + + log.Info("DB query time:" + startTime.Format("2006-01-02 15:04:05")) + + endTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) + + CounDataByDate(wikiCountMap, startTime, endTime) +} + func querySolveIssue(start_unix int64, end_unix int64) map[int64]int { //select issue_assignees.* from issue_assignees,issue where issue.is_closed=true and issue.id=issue_assignees.issue_id sess := x.NewSession() diff --git a/routers/private/tool.go b/routers/private/tool.go index dcab8668e..b93f17090 100755 --- a/routers/private/tool.go +++ b/routers/private/tool.go @@ -42,4 +42,5 @@ func RepoStatisticManually(ctx *macaron.Context) { date := ctx.Query("date") repo.RepoStatisticDaily(date) repo.SummaryStatisticDaily(date) + repo.TimingCountDataByDate(date) } diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 3260780ac..7dc7af321 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -8,16 +8,17 @@ import ( "code.gitea.io/gitea/modules/log" ) -func TimingCountData() { +func TimingCountDataByDate(date string) { + + t, _ := time.Parse("2006-01-02", date) + startTime := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location()) + + endTime := time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, t.Location()) + //query wiki data log.Info("start to time count data") wikiMap := make(map[string]int) - currentTimeNow := time.Now() - log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) - - yesterday := currentTimeNow.AddDate(0, 0, -1) - repoList, err := models.GetAllRepositories() if err != nil { log.Error("query repo error.") @@ -29,7 +30,7 @@ func TimingCountData() { time, err := git.GetLatestCommitTime(wikiPath) if err == nil { log.Info("last commit time:" + time.Format("2006-01-02 15:04:05") + " wikiPath=" + wikiPath) - if time.After(yesterday) { + if time.After(startTime) { wikiRepo, _, err := FindWikiRepoCommitByWikiPath(wikiPath) if err != nil { log.Error("wiki not exist. wikiPath=" + wikiPath) @@ -55,5 +56,16 @@ func TimingCountData() { } } //other user info data - models.CountData(wikiMap) + models.CounDataByDate(wikiMap, startTime, endTime) + +} + +func TimingCountData() { + + log.Info("start to time count data") + currentTimeNow := time.Now() + log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) + startTime := currentTimeNow.AddDate(0, 0, -1).Format("2006-01-02") + + TimingCountDataByDate(startTime) } From d47b14737babc8c3abd03c5447f7b87970d88f43 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 28 Oct 2021 15:13:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 6f6abb1ff..bb6726a2c 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -255,21 +255,6 @@ func CounDataByDate(wikiCountMap map[string]int, startTime time.Time, endTime ti } -func CountData(wikiCountMap map[string]int) { - - currentTimeNow := time.Now() - log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05")) - - yesterday := currentTimeNow.AddDate(0, 0, -1) - startTime := time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location()) - - log.Info("DB query time:" + startTime.Format("2006-01-02 15:04:05")) - - endTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) - - CounDataByDate(wikiCountMap, startTime, endTime) -} - func querySolveIssue(start_unix int64, end_unix int64) map[int64]int { //select issue_assignees.* from issue_assignees,issue where issue.is_closed=true and issue.id=issue_assignees.issue_id sess := x.NewSession()