Browse Source

Merge pull request '增加用户登录次数、用户创建项目、用户openi指数属性,目前只实现用户创建项目统计' (#540) from zouap into V20211018

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/540
Reviewed-by: lewis <747342561@qq.com>
tags/v1.21.12.1
lewis 4 years ago
parent
commit
89942bb7af
1 changed files with 35 additions and 0 deletions
  1. +35
    -0
      models/user_business_analysis.go

+ 35
- 0
models/user_business_analysis.go View File

@@ -55,6 +55,15 @@ type UserBusinessAnalysis struct {
//user
RegistDate timeutil.TimeStamp `xorm:"NOT NULL"`

//repo
CreateRepoCount int `xorm:"NOT NULL DEFAULT 0"`

//login count, from elk
LoginCount int `xorm:"NOT NULL DEFAULT 0"`

//openi index
OpenIIndex int `xorm:"NOT NULL DEFAULT 0"`

//user
Email string `xorm:"NOT NULL"`

@@ -100,6 +109,7 @@ func CountData(wikiCountMap map[string]int) {
}
CommitDatasetSizeMap := queryDatasetSize(start_unix, end_unix)
SolveIssueCountMap := querySolveIssue(start_unix, end_unix)
CreateRepoCountMap := queryUserCreateRepo(start_unix, end_unix)

for i, userRecord := range userList {
var dateRecord UserBusinessAnalysis
@@ -176,6 +186,12 @@ func CountData(wikiCountMap map[string]int) {
dateRecord.EncyclopediasCount = wikiCountMap[dateRecord.Name]
}

if _, ok := CreateRepoCountMap[dateRecord.ID]; !ok {
dateRecord.CreateRepoCount = 0
} else {
dateRecord.CreateRepoCount = CreateRepoCountMap[dateRecord.ID]
}

dateRecord.CommitModelCount = 0

statictisSess := xStatistic.NewSession()
@@ -322,6 +338,25 @@ func queryDatasetSize(start_unix int64, end_unix int64) map[int64]int {

}

func queryUserCreateRepo(start_unix int64, end_unix int64) map[int64]int {
sess := x.NewSession()
defer sess.Close()
sess.Select("id,owner_id,name").Table("repository").Where(" created_unix>=" + fmt.Sprint(start_unix) + " and created_unix<=" + fmt.Sprint(end_unix))
repoList := make([]*Repository, 0)
sess.Find(&repoList)
resultMap := make(map[int64]int)
log.Info("query Repository size=" + fmt.Sprint(len(repoList)))
for _, repoRecord := range repoList {
if _, ok := resultMap[repoRecord.OwnerID]; !ok {
resultMap[repoRecord.OwnerID] = 1
} else {
resultMap[repoRecord.OwnerID] += 1
}
}
return resultMap

}

func subMonth(t1, t2 time.Time) (month int) {
y1 := t1.Year()
y2 := t2.Year()


Loading…
Cancel
Save