|
- package repo
-
- import (
- "fmt"
- "net/http"
- "time"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/git"
- "code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/setting"
- )
-
- func QueryUserStaticData(ctx *context.Context) {
- startDate := ctx.Query("startDate")
- endDate := ctx.Query("endDate")
- log.Info("startDate=" + startDate + " endDate=" + endDate)
- startTime, _ := time.Parse("2006-01-02", startDate)
- endTime, _ := time.Parse("2006-01-02", endDate)
- log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix()))
- ctx.JSON(http.StatusOK, models.QueryUserStaticData(startTime.Unix(), endTime.Unix()))
- }
-
- func QueryUserStaticDataPage(ctx *context.Context) {
- startDate := ctx.Query("startDate")
- endDate := ctx.Query("endDate")
- page := ctx.QueryInt("page")
- if page <= 0 {
- page = 1
- }
- userName := ctx.Query("userName")
-
- 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)
- log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix()))
-
- pageOpts := &models.UserBusinessAnalysisQueryOptions{
- ListOptions: models.ListOptions{
- Page: page,
- PageSize: setting.UI.IssuePagingNum,
- },
- UserName: userName,
- StartTime: startTime.Unix(),
- EndTime: endTime.Unix(),
- }
- mapInterface := make(map[string]interface{})
- re, count := models.QueryUserStaticDataPage(pageOpts)
- mapInterface["data"] = re
- mapInterface["count"] = count
- ctx.JSON(http.StatusOK, mapInterface)
- }
-
- 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)
-
- repoList, err := models.GetAllRepositories()
- if err != nil {
- log.Error("query repo error.")
- return
- }
- log.Info("start to query wiki data")
- for _, repoRecord := range repoList {
- wikiPath := models.WikiPath(repoRecord.OwnerName, repoRecord.Name)
- 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(startTime) {
- wikiRepo, _, err := FindWikiRepoCommitByWikiPath(wikiPath)
- if err != nil {
- log.Error("wiki not exist. wikiPath=" + wikiPath)
- } else {
- log.Info("wiki exist, wikiPath=" + wikiPath)
- list, err := wikiRepo.GetCommitByPathAndDays(wikiPath, 1)
- if err != nil {
- log.Info("err,err=v%", err)
- } else {
- for logEntry := list.Front(); logEntry != nil; logEntry = logEntry.Next() {
- commit := logEntry.Value.(*git.Commit)
- log.Info("commit msg=" + commit.CommitMessage + " time=" + commit.Committer.When.Format("2006-01-02 15:04:05") + " user=" + commit.Committer.Name)
- if _, ok := wikiMap[commit.Committer.Name]; !ok {
- wikiMap[commit.Committer.Name] = 1
- } else {
- wikiMap[commit.Committer.Name] += 1
- }
- }
- }
-
- }
- }
- }
- }
- //other user info data
- 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)
- }
|