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.1 kB

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