You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

user_data_analysis.go 2.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package repo
  2. import (
  3. "fmt"
  4. "net/http"
  5. "time"
  6. "code.gitea.io/gitea/models"
  7. "code.gitea.io/gitea/modules/context"
  8. "code.gitea.io/gitea/modules/git"
  9. "code.gitea.io/gitea/modules/log"
  10. )
  11. func QueryUserStaticData(ctx *context.Context) {
  12. startDate := ctx.Query("startDate")
  13. endDate := ctx.Query("endDate")
  14. log.Info("startDate=" + startDate + " endDate=" + endDate)
  15. startTime, _ := time.Parse("2006-01-02", startDate)
  16. endTime, _ := time.Parse("2006-01-02", endDate)
  17. log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix()))
  18. ctx.JSON(http.StatusOK, models.QueryUserStaticData(startTime.Unix(), endTime.Unix()))
  19. }
  20. func TimingCountDataByDate(date string) {
  21. t, _ := time.Parse("2006-01-02", date)
  22. startTime := time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
  23. endTime := time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, t.Location())
  24. //query wiki data
  25. log.Info("start to time count data")
  26. wikiMap := make(map[string]int)
  27. repoList, err := models.GetAllRepositories()
  28. if err != nil {
  29. log.Error("query repo error.")
  30. return
  31. }
  32. log.Info("start to query wiki data")
  33. for _, repoRecord := range repoList {
  34. wikiPath := models.WikiPath(repoRecord.OwnerName, repoRecord.Name)
  35. time, err := git.GetLatestCommitTime(wikiPath)
  36. if err == nil {
  37. log.Info("last commit time:" + time.Format("2006-01-02 15:04:05") + " wikiPath=" + wikiPath)
  38. if time.After(startTime) {
  39. wikiRepo, _, err := FindWikiRepoCommitByWikiPath(wikiPath)
  40. if err != nil {
  41. log.Error("wiki not exist. wikiPath=" + wikiPath)
  42. } else {
  43. log.Info("wiki exist, wikiPath=" + wikiPath)
  44. list, err := wikiRepo.GetCommitByPathAndDays(wikiPath, 1)
  45. if err != nil {
  46. log.Info("err,err=v%", err)
  47. } else {
  48. for logEntry := list.Front(); logEntry != nil; logEntry = logEntry.Next() {
  49. commit := logEntry.Value.(*git.Commit)
  50. log.Info("commit msg=" + commit.CommitMessage + " time=" + commit.Committer.When.Format("2006-01-02 15:04:05") + " user=" + commit.Committer.Name)
  51. if _, ok := wikiMap[commit.Committer.Name]; !ok {
  52. wikiMap[commit.Committer.Name] = 1
  53. } else {
  54. wikiMap[commit.Committer.Name] += 1
  55. }
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. //other user info data
  63. models.CounDataByDate(wikiMap, startTime, endTime)
  64. }
  65. func TimingCountData() {
  66. log.Info("start to time count data")
  67. currentTimeNow := time.Now()
  68. log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05"))
  69. startTime := currentTimeNow.AddDate(0, 0, -1).Format("2006-01-02")
  70. TimingCountDataByDate(startTime)
  71. }