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.

repo_statistic.go 2.0 kB

3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package models
  2. import (
  3. "code.gitea.io/gitea/modules/timeutil"
  4. "fmt"
  5. )
  6. // RepoStatistic statistic info of all repository
  7. type RepoStatistic struct {
  8. ID int64 `xorm:"pk autoincr"`
  9. RepoID int64 `xorm:"unique(s) NOT NULL"`
  10. Date string `xorm:"unique(s) NOT NULL"`
  11. NumWatches int64 `xorm:"NOT NULL DEFAULT 0"`
  12. NumStars int64 `xorm:"NOT NULL DEFAULT 0"`
  13. NumForks int64 `xorm:"NOT NULL DEFAULT 0"`
  14. NumDownloads int64 `xorm:"NOT NULL DEFAULT 0"`
  15. NumComments int64 `xorm:"NOT NULL DEFAULT 0"`
  16. NumVisits int64 `xorm:"NOT NULL DEFAULT 0"`
  17. NumClosedIssues int64 `xorm:"NOT NULL DEFAULT 0"`
  18. NumVersions int64 `xorm:"NOT NULL DEFAULT 0"`
  19. //develop months
  20. NumDevMonths int64 `xorm:"NOT NULL DEFAULT 0"`
  21. RepoSize int64 `xorm:"NOT NULL DEFAULT 0"`
  22. DatasetSize int64 `xorm:"NOT NULL DEFAULT 0"`
  23. NumModels int64 `xorm:"NOT NULL DEFAULT 0"`
  24. NumWikiViews int64 `xorm:"NOT NULL DEFAULT 0"`
  25. NumCommits int64 `xorm:"NOT NULL DEFAULT 0"`
  26. NumIssues int64 `xorm:"NOT NULL DEFAULT 0"`
  27. NumPulls int64 `xorm:"NOT NULL DEFAULT 0"`
  28. IssueFixedRate float32 `xorm:"NOT NULL"`
  29. NumContributor int64 `xorm:"NOT NULL DEFAULT 0"`
  30. NumKeyContributor int64 `xorm:"NOT NULL DEFAULT 0"`
  31. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  32. UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
  33. }
  34. func DeleteRepoStatDaily(date string) error {
  35. sess := xStatistic.NewSession()
  36. defer sess.Close()
  37. if err := sess.Begin(); err != nil {
  38. return fmt.Errorf("Begin: %v", err)
  39. }
  40. if _, err := sess.Where("date = ?", date).Delete(&RepoStatistic{}); err != nil {
  41. return fmt.Errorf("Delete: %v", err)
  42. }
  43. if err := sess.Commit(); err != nil {
  44. sess.Close()
  45. return fmt.Errorf("Commit: %v", err)
  46. }
  47. sess.Close()
  48. return nil
  49. }
  50. func InsertRepoStat(repoStat *RepoStatistic) (int64, error) {
  51. return xStatistic.Insert(repoStat)
  52. }