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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 := models.QueryAllRepo()
  16. log.Info("start to query wiki data")
  17. for _, repoRecord := range repoList {
  18. wikiPath := models.WikiPath(repoRecord.OwnerName, repoRecord.Name)
  19. time, err := git.GetLatestCommitTime(wikiPath)
  20. if err == nil {
  21. log.Info("last commit time:" + time.Format("2006-01-02 15:04:05") + " wikiPath=" + wikiPath)
  22. if time.After(yesterday) {
  23. wikiRepo, _, err := FindWikiRepoCommitByWikiPath(wikiPath)
  24. if err != nil {
  25. log.Error("wiki not exist. wikiPath=" + wikiPath)
  26. } else {
  27. log.Info("wiki exist, wikiPath=" + wikiPath)
  28. list, err := wikiRepo.GetCommitByPathAndDays(wikiPath, 1)
  29. if err != nil {
  30. log.Info("err,err=v%", err)
  31. } else {
  32. for logEntry := list.Front(); logEntry != nil; logEntry = logEntry.Next() {
  33. commit := logEntry.Value.(*git.Commit)
  34. log.Info("commit msg=" + commit.CommitMessage + " time=" + commit.Committer.When.Format("2006-01-02 15:04:05") + " user=" + commit.Committer.Name)
  35. if _, ok := wikiMap[commit.Committer.Name]; !ok {
  36. wikiMap[commit.Committer.Name] = 1
  37. } else {
  38. wikiMap[commit.Committer.Name] += 1
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }
  45. }
  46. //other user info data
  47. models.CountData(wikiMap)
  48. }