Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.21.12.1
zouap 3 years ago
parent
commit
08bf463e99
3 changed files with 46 additions and 14 deletions
  1. +25
    -6
      models/user_business_analysis.go
  2. +1
    -0
      routers/private/tool.go
  3. +20
    -8
      routers/repo/user_data_analysis.go

+ 25
- 6
models/user_business_analysis.go View File

@@ -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()


+ 1
- 0
routers/private/tool.go View File

@@ -42,4 +42,5 @@ func RepoStatisticManually(ctx *macaron.Context) {
date := ctx.Query("date")
repo.RepoStatisticDaily(date)
repo.SummaryStatisticDaily(date)
repo.TimingCountDataByDate(date)
}

+ 20
- 8
routers/repo/user_data_analysis.go View File

@@ -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)
}

Loading…
Cancel
Save