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 1.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 TimeingCountData() {
  9. //query wiki data
  10. log.Info("start to time count data")
  11. wikiMap := make(map[string]int)
  12. currentTimeNow := time.Now()
  13. log.Info("current time:" + currentTimeNow.Format("2006-01-02 15:04:05"))
  14. yesterday := currentTimeNow.AddDate(0, 0, -1)
  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(yesterday) {
  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.CountData(wikiMap)
  52. }