|
|
@@ -1,25 +1,131 @@ |
|
|
|
package models |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"time" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
|
) |
|
|
|
|
|
|
|
type User_business_analysis struct { |
|
|
|
ID int64 `xorm:"pk"` |
|
|
|
countDate int64 `xorm:"pk"` |
|
|
|
|
|
|
|
codeMergeCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
commitCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
issueCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
commentCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
focusRepoCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
starRepoCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
watchedCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
giteaAgeMonth int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
commitCodeSize int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
commitDatasetSize int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
commitModelCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
solveIssueCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
encyclopediasCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
registDate timeutil.TimeStamp `xorm:"NOT NULL"` |
|
|
|
type UserBusinessAnalysis struct { |
|
|
|
ID int64 `xorm:"pk"` |
|
|
|
|
|
|
|
CountDate int64 `xorm:"pk"` |
|
|
|
|
|
|
|
//action :ActionMergePullRequest // 11 |
|
|
|
CodeMergeCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
//action :ActionCommitRepo // 5 |
|
|
|
CommitCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
//action :ActionCommentIssue // 10 |
|
|
|
IssueCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
//comment table current date |
|
|
|
CommentCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
//watch table current date |
|
|
|
FocusRepoCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
//star table current date |
|
|
|
StarRepoCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
//follow table |
|
|
|
WatchedCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
// user table |
|
|
|
GiteaAgeMonth int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
// |
|
|
|
CommitCodeSize int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
//attachement table |
|
|
|
CommitDatasetSize int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
//0 |
|
|
|
CommitModelCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
//issue, issueassignees |
|
|
|
SolveIssueCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
//baike |
|
|
|
EncyclopediasCount int `xorm:"NOT NULL DEFAULT 0"` |
|
|
|
|
|
|
|
//user |
|
|
|
RegistDate timeutil.TimeStamp `xorm:"NOT NULL"` |
|
|
|
|
|
|
|
//user |
|
|
|
Email string `xorm:"NOT NULL"` |
|
|
|
} |
|
|
|
|
|
|
|
func countData() { |
|
|
|
sess := x.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
sess.Select("`user`.*").Table("user") |
|
|
|
userList := make([]*User, 0) |
|
|
|
sess.Find(&userList) |
|
|
|
|
|
|
|
currentTimeNow := time.Now() |
|
|
|
yesterday := currentTimeNow.AddDate(0, 0, -1) |
|
|
|
startTime := time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location()) |
|
|
|
start_unix := startTime.Unix() |
|
|
|
log.Info("DB query time:" + startTime.Format("2000-01-01 10:10:10")) |
|
|
|
|
|
|
|
endTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
end_unix := endTime.Unix() |
|
|
|
|
|
|
|
//codeMergeCountMap := queryAction(start_unix,end_unix,11) |
|
|
|
|
|
|
|
CodeMergeCountMap := queryAction(start_unix, end_unix, 11) |
|
|
|
CommitCountMap := queryAction(start_unix, end_unix, 5) |
|
|
|
IssueCountMap := queryAction(start_unix, end_unix, 10) |
|
|
|
|
|
|
|
for i, userRecord := range userList { |
|
|
|
var dateRecord UserBusinessAnalysis |
|
|
|
dateRecord.ID = userRecord.ID |
|
|
|
log.Info("i=" + fmt.Sprint(i) + " userName=" + userRecord.Name) |
|
|
|
dateRecord.CountDate = time.Now().Unix() |
|
|
|
dateRecord.Email = userRecord.Email |
|
|
|
dateRecord.RegistDate = userRecord.CreatedUnix |
|
|
|
|
|
|
|
if _, ok := CodeMergeCountMap[dateRecord.ID]; !ok { |
|
|
|
dateRecord.CodeMergeCount = 0 |
|
|
|
} else { |
|
|
|
dateRecord.CodeMergeCount = CodeMergeCountMap[dateRecord.ID] |
|
|
|
} |
|
|
|
|
|
|
|
if _, ok := CommitCountMap[dateRecord.ID]; !ok { |
|
|
|
dateRecord.CommitCount = 0 |
|
|
|
} else { |
|
|
|
dateRecord.CommitCount = CommitCountMap[dateRecord.ID] |
|
|
|
} |
|
|
|
|
|
|
|
if _, ok := IssueCountMap[dateRecord.ID]; !ok { |
|
|
|
dateRecord.IssueCount = 0 |
|
|
|
} else { |
|
|
|
dateRecord.IssueCount = IssueCountMap[dateRecord.ID] |
|
|
|
} |
|
|
|
|
|
|
|
sess.Insert(&dateRecord) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func queryAction(start_unix int64, end_unix int64, actionType int64) map[int64]int { |
|
|
|
sess := x.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
sess.Select("id,user_id,op_type,act_user_id").Table("action").Where("op_type=" + fmt.Sprint(actionType) + " and create_unix>=" + fmt.Sprint(start_unix) + " and create_unix<=" + fmt.Sprint(end_unix)) |
|
|
|
actionList := make([]*Action, 0) |
|
|
|
sess.Find(&actionList) |
|
|
|
resultMap := make(map[int64]int) |
|
|
|
|
|
|
|
for _, actionRecord := range actionList { |
|
|
|
if _, ok := resultMap[actionRecord.UserID]; !ok { |
|
|
|
resultMap[actionRecord.UserID] = 1 |
|
|
|
} else { |
|
|
|
resultMap[actionRecord.UserID] += 1 |
|
|
|
} |
|
|
|
} |
|
|
|
return resultMap |
|
|
|
} |