|
|
@@ -1,15 +1,17 @@ |
|
|
|
package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"time" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/services/mailer" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/normalization" |
|
|
|
"code.gitea.io/gitea/modules/repository" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
"code.gitea.io/gitea/services/mailer" |
|
|
|
|
|
|
|
"gitea.com/macaron/macaron" |
|
|
|
) |
|
|
|
|
|
|
|
func StatisticAuto() { |
|
|
@@ -48,7 +50,7 @@ func RepoStatisticDaily(date string) { |
|
|
|
var maxRepoRadar models.RepoStatistic |
|
|
|
|
|
|
|
for i, repo := range repos { |
|
|
|
log.Info("start statistic: %s", repo.Name) |
|
|
|
log.Info("start statistic: %s", getDistinctProjectName(repo)) |
|
|
|
var numDevMonths, numWikiViews, numContributor, numKeyContributor, numCommitsGrowth, numCommitLinesGrowth, numContributorsGrowth int64 |
|
|
|
repoGitStat, err := models.GetRepoKPIStats(repo) |
|
|
|
if err != nil { |
|
|
@@ -230,7 +232,7 @@ func RepoStatisticDaily(date string) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.Info("finish statistic: %s", repo.Name) |
|
|
|
log.Info("finish statistic: %s", getDistinctProjectName(repo)) |
|
|
|
} |
|
|
|
|
|
|
|
//radar map |
|
|
@@ -274,3 +276,29 @@ func getStatTime(timeStr string) (string, string) { |
|
|
|
|
|
|
|
return beginTime, endTime |
|
|
|
} |
|
|
|
|
|
|
|
func UpdateRepoVisits(ctx *macaron.Context, repo *models.Repository, date string) error { |
|
|
|
beginTime, endTime := getStatTime(date) |
|
|
|
var numVisits int |
|
|
|
numVisits, err := repository.AppointProjectView(repo.OwnerName, repo.Name, beginTime, endTime) |
|
|
|
if err != nil { |
|
|
|
log.Error("AppointProjectView failed(%s): %v", getDistinctProjectName(repo), err) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
repoStat, err := models.GetRepoStatisticByDate(date, repo.ID) |
|
|
|
if err != nil { |
|
|
|
log.Error("GetRepoStatisticByDate failed(%s): %v", getDistinctProjectName(repo), err) |
|
|
|
return err |
|
|
|
} else if len(repoStat) != 1 { |
|
|
|
log.Error("GetRepoStatisticByDate failed(%s): %v", getDistinctProjectName(repo), err) |
|
|
|
return errors.New("not find repo") |
|
|
|
} |
|
|
|
repoStat[0].NumVisits = int64(numVisits) |
|
|
|
|
|
|
|
if err = models.UpdateRepoStatVisits(repoStat[0]); err != nil { |
|
|
|
log.Error("UpdateRepoStatVisits failed(%s): %v", getDistinctProjectName(repo), err) |
|
|
|
return err |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |