Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.5.2
zouap 3 years ago
parent
commit
eac3bc9dbf
4 changed files with 35 additions and 13 deletions
  1. +1
    -1
      models/models.go
  2. +2
    -2
      models/repo_activity_custom.go
  3. +19
    -4
      models/user_business_analysis.go
  4. +13
    -6
      modules/git/repo_stats_custom.go

+ 1
- 1
models/models.go View File

@@ -157,7 +157,7 @@ func init() {
new(UserBusinessAnalysisCurrentMonth), new(UserBusinessAnalysisCurrentMonth),
new(UserBusinessAnalysisCurrentWeek), new(UserBusinessAnalysisCurrentWeek),
new(UserBusinessAnalysisYesterday), new(UserBusinessAnalysisYesterday),
//new(UserBusinessAnalysisLastWeek),
new(UserBusinessAnalysisLastWeek),
new(UserLoginLog), new(UserLoginLog),
new(UserMetrics), new(UserMetrics),
new(UserAnalysisPara), new(UserAnalysisPara),


+ 2
- 2
models/repo_activity_custom.go View File

@@ -211,7 +211,7 @@ func setKeyContributerDict(contributorDistinctDict map[string]int, email string,
} }
} }


func GetAllUserKPIStats() (map[string]*git.UserKPIStats, error) {
func GetAllUserKPIStats(startTime time.Time, endTime time.Time) (map[string]*git.UserKPIStats, error) {
authors := make(map[string]*git.UserKPIStats) authors := make(map[string]*git.UserKPIStats)
repositorys, err := GetAllRepositoriesByFilterCols("owner_name", "name") repositorys, err := GetAllRepositoriesByFilterCols("owner_name", "name")
if err != nil { if err != nil {
@@ -219,7 +219,7 @@ func GetAllUserKPIStats() (map[string]*git.UserKPIStats, error) {
} }


for _, repository := range repositorys { for _, repository := range repositorys {
authorsOneRepo, err1 := git.GetUserKPIStats(repository.RepoPath())
authorsOneRepo, err1 := git.GetUserKPIStats(repository.RepoPath(), startTime, endTime)
if err1 != nil { if err1 != nil {
log.Warn("get user kpi status err:"+repository.RepoPath(), err1.Error()) log.Warn("get user kpi status err:"+repository.RepoPath(), err1.Error())
continue continue


+ 19
- 4
models/user_business_analysis.go View File

@@ -429,7 +429,9 @@ func QueryUserStaticDataForUserDefine(opts *UserBusinessAnalysisQueryOptions, wi
StarRepoCountMap := queryStar(start_unix, end_unix) StarRepoCountMap := queryStar(start_unix, end_unix)
WatchedCountMap, WatchOtherMap := queryFollow(start_unix, end_unix) WatchedCountMap, WatchOtherMap := queryFollow(start_unix, end_unix)


CommitCodeSizeMap, err := GetAllUserKPIStats()
StartTime := time.Unix(start_unix, 0)
EndTime := time.Unix(end_unix, 0)
CommitCodeSizeMap, err := GetAllUserKPIStats(StartTime, EndTime)
if err != nil { if err != nil {
log.Info("query commit code errr.") log.Info("query commit code errr.")
} else { } else {
@@ -679,7 +681,15 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS
FocusRepoCountMap := queryWatch(start_unix, end_unix) FocusRepoCountMap := queryWatch(start_unix, end_unix)
StarRepoCountMap := queryStar(start_unix, end_unix) StarRepoCountMap := queryStar(start_unix, end_unix)
WatchedCountMap, WatchOtherMap := queryFollow(start_unix, end_unix) WatchedCountMap, WatchOtherMap := queryFollow(start_unix, end_unix)
CommitCodeSizeMap := queryCommitCodeSize(StartTimeNextDay.Unix(), EndTimeNextDay.Unix())
CommitCodeSizeMap, err := GetAllUserKPIStats(StartTimeNextDay, EndTimeNextDay)
if err != nil {
log.Info("query commit code errr.")
} else {
log.Info("query commit code size, len=" + fmt.Sprint(len(CommitCodeSizeMap)))
CommitCodeSizeMapJson, _ := json.Marshal(CommitCodeSizeMap)
log.Info("CommitCodeSizeMapJson=" + string(CommitCodeSizeMapJson))
}
//CommitCodeSizeMap := queryCommitCodeSize(StartTimeNextDay.Unix(), EndTimeNextDay.Unix())
CommitDatasetSizeMap, CommitDatasetNumMap := queryDatasetSize(start_unix, end_unix) CommitDatasetSizeMap, CommitDatasetNumMap := queryDatasetSize(start_unix, end_unix)
SolveIssueCountMap := querySolveIssue(start_unix, end_unix) SolveIssueCountMap := querySolveIssue(start_unix, end_unix)
CreateRepoCountMap := queryUserCreateRepo(start_unix, end_unix) CreateRepoCountMap := queryUserCreateRepo(start_unix, end_unix)
@@ -733,7 +743,12 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS
dateRecordAll.FocusOtherUser = getMapValue(dateRecordAll.ID, WatchOtherMap) dateRecordAll.FocusOtherUser = getMapValue(dateRecordAll.ID, WatchOtherMap)
dateRecordAll.StarRepoCount = getMapValue(dateRecordAll.ID, StarRepoCountMap) dateRecordAll.StarRepoCount = getMapValue(dateRecordAll.ID, StarRepoCountMap)
dateRecordAll.WatchedCount = getMapValue(dateRecordAll.ID, WatchedCountMap) dateRecordAll.WatchedCount = getMapValue(dateRecordAll.ID, WatchedCountMap)
dateRecordAll.CommitCodeSize = getMapValue(dateRecordAll.ID, CommitCodeSizeMap)
if _, ok := CommitCodeSizeMap[dateRecordAll.Email]; !ok {
dateRecordAll.CommitCodeSize = 0
} else {
dateRecordAll.CommitCodeSize = int(CommitCodeSizeMap[dateRecordAll.Email].CommitLines)
}
//dateRecordAll.CommitCodeSize = getMapValue(dateRecordAll.ID, CommitCodeSizeMap)
dateRecordAll.CommitDatasetSize = getMapValue(dateRecordAll.ID, CommitDatasetSizeMap) dateRecordAll.CommitDatasetSize = getMapValue(dateRecordAll.ID, CommitDatasetSizeMap)
dateRecordAll.CommitDatasetNum = getMapValue(dateRecordAll.ID, CommitDatasetNumMap) dateRecordAll.CommitDatasetNum = getMapValue(dateRecordAll.ID, CommitDatasetNumMap)
dateRecordAll.SolveIssueCount = getMapValue(dateRecordAll.ID, SolveIssueCountMap) dateRecordAll.SolveIssueCount = getMapValue(dateRecordAll.ID, SolveIssueCountMap)
@@ -907,7 +922,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time,
StarRepoCountMap := queryStar(start_unix, end_unix) StarRepoCountMap := queryStar(start_unix, end_unix)
WatchedCountMap, WatchOtherMap := queryFollow(start_unix, end_unix) WatchedCountMap, WatchOtherMap := queryFollow(start_unix, end_unix)


CommitCodeSizeMap, err := GetAllUserKPIStats()
CommitCodeSizeMap, err := GetAllUserKPIStats(startTime, endTime)
if err != nil { if err != nil {
log.Info("query commit code errr.") log.Info("query commit code errr.")
} else { } else {


+ 13
- 6
modules/git/repo_stats_custom.go View File

@@ -58,12 +58,11 @@ func SetDevelopAge(repoPath string, stats *RepoKPIStats, fromTime time.Time) err
return nil return nil
} }


//获取一天内的用户贡献指标
func GetUserKPIStats(repoPath string) (map[string]*UserKPIStats, error) {
timeUntil := time.Now()
oneDayAgo := timeUntil.AddDate(0, 0, -1)
since := oneDayAgo.Format(time.RFC3339)
args := []string{"log", "--numstat", "--no-merges", "--branches=*", "--pretty=format:---%n%h%n%an%n%ae%n", "--date=iso", fmt.Sprintf("--since='%s'", since)}
func GetUserKPIStats(repoPath string, startTime time.Time, endTime time.Time) (map[string]*UserKPIStats, error) {

after := startTime.Format(time.RFC3339)
until := endTime.Format(time.RFC3339)
args := []string{"log", "--numstat", "--no-merges", "--branches=*", "--pretty=format:---%n%h%n%an%n%ae%n", "--date=iso", fmt.Sprintf("--after='%s'", after), fmt.Sprintf("--until=='%s'", until)}
stdout, err := NewCommand(args...).RunInDirBytes(repoPath) stdout, err := NewCommand(args...).RunInDirBytes(repoPath)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -124,6 +123,14 @@ func GetUserKPIStats(repoPath string) (map[string]*UserKPIStats, error) {


} }


//获取一天内的用户贡献指标
func getUserKPIStats(repoPath string) (map[string]*UserKPIStats, error) {
timeUntil := time.Now()
oneDayAgo := timeUntil.AddDate(0, 0, -1)

return GetUserKPIStats(repoPath, oneDayAgo, oneDayAgo)
}

func SetRepoKPIStats(repoPath string, fromTime time.Time, stats *RepoKPIStats, newContributers map[string]struct{}) error { func SetRepoKPIStats(repoPath string, fromTime time.Time, stats *RepoKPIStats, newContributers map[string]struct{}) error {
since := fromTime.Format(time.RFC3339) since := fromTime.Format(time.RFC3339)
args := []string{"log", "--numstat", "--no-merges", "HEAD", "--pretty=format:---%n%h%n%an%n%ae%n", "--date=iso", fmt.Sprintf("--since='%s'", since)} args := []string{"log", "--numstat", "--no-merges", "HEAD", "--pretty=format:---%n%h%n%an%n%ae%n", "--date=iso", fmt.Sprintf("--since='%s'", since)}


Loading…
Cancel
Save