diff --git a/models/attachment.go b/models/attachment.go index 418d7c881..684a38b21 100755 --- a/models/attachment.go +++ b/models/attachment.go @@ -464,3 +464,12 @@ func CanDelAttachment(isSigned bool, user *User, attach *Attachment) bool { } return false } + +func GetAttachmentSizeByDatasetID(datasetID int64) (int64, error) { + total, err := x.Where("dataset_id = ?", datasetID).SumInt(&Attachment{}, "size") + if err != nil { + return 0, err + } + + return total, nil +} diff --git a/models/release.go b/models/release.go old mode 100644 new mode 100755 diff --git a/models/repo_statistic.go b/models/repo_statistic.go index afe32bcb9..6077f8c21 100755 --- a/models/repo_statistic.go +++ b/models/repo_statistic.go @@ -17,7 +17,7 @@ type RepoStatistic struct { NumForks int64 `xorm:"NOT NULL DEFAULT 0"` NumDownloads int64 `xorm:"NOT NULL DEFAULT 0"` NumComments int64 `xorm:"NOT NULL DEFAULT 0"` - NumViews int64 `xorm:"NOT NULL DEFAULT 0"` + NumVisits int64 `xorm:"NOT NULL DEFAULT 0"` NumClosedIssues int64 `xorm:"NOT NULL DEFAULT 0"` NumVersions int64 `xorm:"NOT NULL DEFAULT 0"` //develop months @@ -37,7 +37,6 @@ type RepoStatistic struct { UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` } - func DeleteRepoStatDaily(date time.Time) error { sess := xStatistic.NewSession() defer sess.Close() diff --git a/routers/repo/repo_statistic.go b/routers/repo/repo_statistic.go index ceb206218..982ec1c27 100755 --- a/routers/repo/repo_statistic.go +++ b/routers/repo/repo_statistic.go @@ -32,7 +32,25 @@ func RepoStatisticDaily() { log.Error("failed statistic: %s", repo.Name) continue } - log.Info("", repoGitStat.DevelopAge) + + var issueFixedRate float32 + if repo.NumIssues != 0 { + issueFixedRate = float32(repo.NumClosedIssues) / float32(repo.NumIssues) + } + + numVersions, err := models.GetReleaseCountByRepoID(repo.ID, models.FindReleasesOptions{}) + if err != nil { + log.Error("GetReleaseCountByRepoID failed: %s", repo.Name) + log.Error("failed statistic: %s", repo.Name) + continue + } + + datasetSize, err := getDatasetSize(repo) + if err != nil { + log.Error("getDatasetSize failed: %s", repo.Name) + log.Error("failed statistic: %s", repo.Name) + continue + } repoStat := models.RepoStatistic{ RepoID: repo.ID, @@ -41,18 +59,18 @@ func RepoStatisticDaily() { NumStars:int64(repo.NumStars), NumDownloads:repo.CloneCnt, NumComments:0, - NumViews:0, - NumClosedIssues:0, - NumVersions:0, + NumVisits:0, + NumClosedIssues:int64(repo.NumClosedIssues), + NumVersions:numVersions, NumDevMonths:repoGitStat.DevelopAge, - RepoSize:0, - DatasetSize:0, + RepoSize:repo.Size, + DatasetSize:datasetSize, NumModels:0, NumWikiViews:0, - NumCommits:0, - NumIssues:0, - NumPulls:0, - IssueFixedRate:0, + NumCommits:repo.NumCommit, + NumIssues:int64(repo.NumIssues), + NumPulls:int64(repo.NumPulls), + IssueFixedRate:issueFixedRate, NumContributor:repoGitStat.Contributors, NumKeyContributor:repoGitStat.KeyContributors, @@ -68,3 +86,12 @@ func RepoStatisticDaily() { } } + +func getDatasetSize(repo *models.Repository) (int64, error) { + dataset, err := models.GetDatasetByRepo(repo) + if err != nil { + return 0, err + } + + return models.GetAttachmentSizeByDatasetID(dataset.ID) +}