|
- package models
-
- import (
- "fmt"
- "time"
-
- "code.gitea.io/gitea/modules/timeutil"
- )
-
- // RepoStatistic statistic info of all repository
- type RepoStatistic struct {
- ID int64 `xorm:"pk autoincr"`
- RepoID int64 `xorm:"unique(s) NOT NULL"`
- Name string `xorm:"INDEX"`
- IsPrivate bool
- Date string `xorm:"unique(s) NOT NULL"`
- NumWatches int64 `xorm:"NOT NULL DEFAULT 0"`
- NumWatchesAdded int64 `xorm:"NOT NULL DEFAULT 0"`
- NumStars int64 `xorm:"NOT NULL DEFAULT 0"`
- NumStarsAdded int64 `xorm:"NOT NULL DEFAULT 0"`
- NumForks int64 `xorm:"NOT NULL DEFAULT 0"`
- NumForksAdded int64 `xorm:"NOT NULL DEFAULT 0"`
- NumDownloads int64 `xorm:"NOT NULL DEFAULT 0"`
- NumDownloadsAdded int64 `xorm:"NOT NULL DEFAULT 0"`
- NumComments int64 `xorm:"NOT NULL DEFAULT 0"`
- NumCommentsAdded int64 `xorm:"NOT NULL DEFAULT 0"`
- NumVisits int64 `xorm:"NOT NULL DEFAULT 0"`
- NumClosedIssues int64 `xorm:"NOT NULL DEFAULT 0"`
- NumClosedIssuesAdded int64 `xorm:"NOT NULL DEFAULT 0"`
- NumVersions int64 `xorm:"NOT NULL DEFAULT 0"`
- NumDevMonths int64 `xorm:"NOT NULL DEFAULT 0"`
- RepoSize int64 `xorm:"NOT NULL DEFAULT 0"`
- DatasetSize int64 `xorm:"NOT NULL DEFAULT 0"`
- NumModels int64 `xorm:"NOT NULL DEFAULT 0"`
- NumWikiViews int64 `xorm:"NOT NULL DEFAULT 0"`
- NumCommits int64 `xorm:"NOT NULL DEFAULT 0"`
- NumCommitsAdded int64 `xorm:"NOT NULL DEFAULT 0"`
- NumIssues int64 `xorm:"NOT NULL DEFAULT 0"`
- NumIssuesAdded int64 `xorm:"NOT NULL DEFAULT 0"`
- NumPulls int64 `xorm:"NOT NULL DEFAULT 0"`
- NumPullsAdded int64 `xorm:"NOT NULL DEFAULT 0"`
- IssueFixedRate float32 `xorm:"NOT NULL"`
- NumContributor int64 `xorm:"NOT NULL DEFAULT 0"`
- NumContributorAdded int64 `xorm:"NOT NULL DEFAULT 0"`
- NumKeyContributor int64 `xorm:"NOT NULL DEFAULT 0"`
-
- NumContributorsGrowth int64 `xorm:"NOT NULL DEFAULT 0"`
- NumCommitsGrowth int64 `xorm:"NOT NULL DEFAULT 0"`
- NumCommitLinesGrowth int64 `xorm:"NOT NULL DEFAULT 0"`
- NumIssuesGrowth int64 `xorm:"NOT NULL DEFAULT 0"`
- NumCommentsGrowth int64 `xorm:"NOT NULL DEFAULT 0"`
-
- Impact float64 `xorm:"NOT NULL DEFAULT 0"`
- Completeness float64 `xorm:"NOT NULL DEFAULT 0"`
- Liveness float64 `xorm:"NOT NULL DEFAULT 0"`
- ProjectHealth float64 `xorm:"NOT NULL DEFAULT 0"`
- TeamHealth float64 `xorm:"NOT NULL DEFAULT 0"`
- Growth float64 `xorm:"NOT NULL DEFAULT 0"`
- RadarTotal float64 `xorm:"NOT NULL DEFAULT 0"`
- CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
- UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
- }
-
- func DeleteRepoStatDaily(date string) error {
- sess := xStatistic.NewSession()
- defer sess.Close()
- if err := sess.Begin(); err != nil {
- return fmt.Errorf("Begin: %v", err)
- }
-
- if _, err := sess.Where("date = ?", date).Delete(&RepoStatistic{}); err != nil {
- return fmt.Errorf("Delete: %v", err)
- }
-
- if err := sess.Commit(); err != nil {
- sess.Close()
- return fmt.Errorf("Commit: %v", err)
- }
-
- sess.Close()
- return nil
- }
-
- func GetRepoStatisticByDate(date string) ([]*RepoStatistic, error) {
- repoStatistics := make([]*RepoStatistic, 0)
- err := xStatistic.Where("date = ?", date).Find(&repoStatistics)
- return repoStatistics, err
-
- }
-
- func GetOneRepoStatisticBeforeTime(time time.Time) (*RepoStatistic, error) {
- repoStatistics := make([]*RepoStatistic, 0)
- err := xStatistic.Where("created_unix >= ?", time.Unix()).OrderBy("created_unix").Limit(1).Find(&repoStatistics)
- if err != nil {
- return nil, err
- } else {
- if len(repoStatistics) == 0 {
- return nil, fmt.Errorf("the repo statistic record count is 0")
- } else {
- return repoStatistics[0], nil
- }
- }
-
- }
-
- func InsertRepoStat(repoStat *RepoStatistic) (int64, error) {
- return xStatistic.Insert(repoStat)
- }
-
- func UpdateRepoStat(repoStat *RepoStatistic) error {
- sql := "update repo_statistic set impact=?,completeness=?,liveness=?,project_health=?,team_health=?,growth=?,radar_total=? where repo_id=? and date=?"
-
- _, err := xStatistic.Exec(sql, repoStat.Impact, repoStat.Completeness, repoStat.Liveness, repoStat.ProjectHealth, repoStat.TeamHealth, repoStat.Growth, repoStat.RadarTotal, repoStat.RepoID, repoStat.Date)
- return err
- }
|