|
|
@@ -6,7 +6,6 @@ import ( |
|
|
|
"strconv" |
|
|
|
"time" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
|
"xorm.io/builder" |
|
|
@@ -353,7 +352,7 @@ func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBus |
|
|
|
return userBusinessAnalysisReturnList, count |
|
|
|
} |
|
|
|
|
|
|
|
func refreshUserStaticTable(wikiCountMap map[string]int, CommitCodeSizeMap map[string]*git.UserKPIStats, tableName string, pageStartTime time.Time, pageEndTime time.Time) { |
|
|
|
func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageStartTime time.Time, pageEndTime time.Time) { |
|
|
|
sess := x.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
|
|
|
@@ -379,7 +378,7 @@ func refreshUserStaticTable(wikiCountMap map[string]int, CommitCodeSizeMap map[s |
|
|
|
FocusRepoCountMap := queryWatch(start_unix, end_unix) |
|
|
|
StarRepoCountMap := queryStar(start_unix, end_unix) |
|
|
|
WatchedCountMap := queryFollow(start_unix, end_unix) |
|
|
|
|
|
|
|
CommitCodeSizeMap := queryCommitCodeSize(start_unix, end_unix) |
|
|
|
CommitDatasetSizeMap := queryDatasetSize(start_unix, end_unix) |
|
|
|
SolveIssueCountMap := querySolveIssue(start_unix, end_unix) |
|
|
|
CreateRepoCountMap := queryUserCreateRepo(start_unix, end_unix) |
|
|
@@ -455,10 +454,10 @@ func refreshUserStaticTable(wikiCountMap map[string]int, CommitCodeSizeMap map[s |
|
|
|
dateRecordAll.WatchedCount = WatchedCountMap[dateRecordAll.ID] |
|
|
|
} |
|
|
|
|
|
|
|
if _, ok := CommitCodeSizeMap[dateRecordAll.Email]; !ok { |
|
|
|
if _, ok := CommitCodeSizeMap[dateRecordAll.ID]; !ok { |
|
|
|
dateRecordAll.CommitCodeSize = 0 |
|
|
|
} else { |
|
|
|
dateRecordAll.CommitCodeSize = int(CommitCodeSizeMap[dateRecordAll.Email].CommitLines) |
|
|
|
dateRecordAll.CommitCodeSize = CommitCodeSizeMap[dateRecordAll.ID] |
|
|
|
} |
|
|
|
|
|
|
|
if _, ok := CommitDatasetSizeMap[dateRecordAll.ID]; !ok { |
|
|
@@ -546,36 +545,36 @@ func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, static |
|
|
|
statictisSess.Exec(insertBatchSql) |
|
|
|
} |
|
|
|
|
|
|
|
func RefreshUserStaticAllTabel(wikiCountMap map[string]int, CommitCodeSizeMap map[string]*git.UserKPIStats) { |
|
|
|
func RefreshUserStaticAllTabel(wikiCountMap map[string]int) { |
|
|
|
currentTimeNow := time.Now() |
|
|
|
pageStartTime := time.Date(2021, 11, 5, 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) |
|
|
|
refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_all", pageStartTime, pageEndTime) |
|
|
|
refreshUserStaticTable(wikiCountMap, "user_business_analysis_all", pageStartTime, pageEndTime) |
|
|
|
log.Info("refresh all data finished.") |
|
|
|
|
|
|
|
pageStartTime = time.Date(currentTimeNow.Year(), 1, 1, 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_current_year", pageStartTime, pageEndTime) |
|
|
|
refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_year", pageStartTime, pageEndTime) |
|
|
|
|
|
|
|
thisMonth := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location()) |
|
|
|
refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_current_month", thisMonth, pageEndTime) |
|
|
|
refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_month", thisMonth, pageEndTime) |
|
|
|
|
|
|
|
offset := int(time.Monday - currentTimeNow.Weekday()) |
|
|
|
if offset > 0 { |
|
|
|
offset = -6 |
|
|
|
} |
|
|
|
pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset) |
|
|
|
refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_current_week", pageStartTime, pageEndTime) |
|
|
|
refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_week", pageStartTime, pageEndTime) |
|
|
|
|
|
|
|
pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -30) |
|
|
|
refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_last30_day", pageStartTime, pageEndTime) |
|
|
|
refreshUserStaticTable(wikiCountMap, "user_business_analysis_last30_day", pageStartTime, pageEndTime) |
|
|
|
|
|
|
|
pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -1) |
|
|
|
pageEndTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1) |
|
|
|
refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_yesterday", pageStartTime, pageEndTime) |
|
|
|
refreshUserStaticTable(wikiCountMap, "user_business_analysis_yesterday", pageStartTime, pageEndTime) |
|
|
|
|
|
|
|
pageStartTime = thisMonth.AddDate(0, -1, 0) |
|
|
|
pageEndTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1) |
|
|
|
refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_last_month", pageStartTime, pageEndTime) |
|
|
|
refreshUserStaticTable(wikiCountMap, "user_business_analysis_last_month", pageStartTime, pageEndTime) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@@ -747,7 +746,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
RefreshUserStaticAllTabel(wikiCountMap, CommitCodeSizeMap) |
|
|
|
RefreshUserStaticAllTabel(wikiCountMap) |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
@@ -1212,6 +1211,40 @@ func queryLoginCount(start_unix int64, end_unix int64) map[int64]int { |
|
|
|
return resultMap |
|
|
|
} |
|
|
|
|
|
|
|
func queryCommitCodeSize(start_unix int64, end_unix int64) map[int64]int { |
|
|
|
statictisSess := xStatistic.NewSession() |
|
|
|
defer statictisSess.Close() |
|
|
|
|
|
|
|
resultMap := make(map[int64]int) |
|
|
|
cond := "count_date>=" + fmt.Sprint(start_unix) + " and count_date<=" + fmt.Sprint(end_unix) |
|
|
|
count, err := statictisSess.Where(cond).Count(new(UserBusinessAnalysis)) |
|
|
|
if err != nil { |
|
|
|
log.Info("query commit code size error. return.") |
|
|
|
return resultMap |
|
|
|
} |
|
|
|
var indexTotal int64 |
|
|
|
indexTotal = 0 |
|
|
|
for { |
|
|
|
statictisSess.Select("id,commit_code_size").Table("user_business_analysis").Where(cond).OrderBy("id asc").Limit(PAGE_SIZE, int(indexTotal)) |
|
|
|
userBusinessAnalysisList := make([]*UserBusinessAnalysis, 0) |
|
|
|
statictisSess.Find(&userBusinessAnalysisList) |
|
|
|
log.Info("query user login size=" + fmt.Sprint(len(userBusinessAnalysisList))) |
|
|
|
for _, analysisRecord := range userBusinessAnalysisList { |
|
|
|
if _, ok := resultMap[analysisRecord.ID]; !ok { |
|
|
|
resultMap[analysisRecord.ID] = analysisRecord.CommitCodeSize |
|
|
|
} else { |
|
|
|
resultMap[analysisRecord.ID] += analysisRecord.CommitCodeSize |
|
|
|
} |
|
|
|
} |
|
|
|
indexTotal += PAGE_SIZE |
|
|
|
if indexTotal >= count { |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
log.Info("user commit code size=" + fmt.Sprint(len(resultMap))) |
|
|
|
return resultMap |
|
|
|
} |
|
|
|
|
|
|
|
func subMonth(t1, t2 time.Time) (month int) { |
|
|
|
y1 := t1.Year() |
|
|
|
y2 := t2.Year() |
|
|
|