|
|
@@ -3,12 +3,15 @@ package models |
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"io/ioutil" |
|
|
|
"net/http" |
|
|
|
"sort" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
|
"xorm.io/builder" |
|
|
|
"xorm.io/xorm" |
|
|
@@ -785,7 +788,10 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS |
|
|
|
InvitationMap := queryUserInvitationCount(start_unix, end_unix) |
|
|
|
|
|
|
|
DataDate := currentTimeNow.Format("2006-01-02") + " 00:01" |
|
|
|
|
|
|
|
bonusMap := make(map[string]map[string]int) |
|
|
|
if tableName == "user_business_analysis_current_year" { |
|
|
|
bonusMap = getBonusMap() |
|
|
|
} |
|
|
|
cond := "type != 1 and is_active=true" |
|
|
|
count, err := sess.Where(cond).Count(new(User)) |
|
|
|
if err != nil { |
|
|
@@ -894,6 +900,7 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS |
|
|
|
dataSetInfo := getDataSetInfo(dateRecordAll.ID, CreatedDataset, dataSetDownloadMap, CommitDatasetNumMap, CollectedDataset) |
|
|
|
codeInfo := getCodeInfo(dateRecordAll) |
|
|
|
cloudBrainInfo := getCloudBrainInfo(dateRecordAll, CloudBrainTaskItemMap) |
|
|
|
playARoll := getPlayARoll(bonusMap, dateRecordAll.Name) |
|
|
|
re := &UserSummaryCurrentYear{ |
|
|
|
ID: dateRecordAll.ID, |
|
|
|
Name: dateRecordAll.Name, |
|
|
@@ -906,11 +913,9 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS |
|
|
|
DataSetInfo: dataSetInfo, |
|
|
|
CodeInfo: codeInfo, |
|
|
|
CloudBrainInfo: cloudBrainInfo, |
|
|
|
PlayARoll: playARoll, |
|
|
|
} |
|
|
|
statictisSess.Insert(re) |
|
|
|
//log.Info(fmt.Sprint(len(CommitCountMap))) |
|
|
|
//log.Info(fmt.Sprint(len(CommitCodeSizeMap))) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if len(dateRecordBatch) > 0 { |
|
|
@@ -940,15 +945,71 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS |
|
|
|
} |
|
|
|
log.Info("refresh data finished.tableName=" + tableName + " total record:" + fmt.Sprint(insertCount)) |
|
|
|
} |
|
|
|
|
|
|
|
func getBonusMap() map[string]map[string]int { |
|
|
|
bonusMap := make(map[string]map[string]int) |
|
|
|
url := setting.RecommentRepoAddr + "bonus/record.txt" |
|
|
|
content, err := GetContentFromPromote(url) |
|
|
|
if err == nil { |
|
|
|
filenames := strings.Split(content, "\n") |
|
|
|
for i := 0; i < len(filenames); i++ { |
|
|
|
url = setting.RecommentRepoAddr + "bonus/" + filenames[i] |
|
|
|
csvContent, err1 := GetContentFromPromote(url) |
|
|
|
if err1 == nil { |
|
|
|
//read csv |
|
|
|
lines := strings.Split(csvContent, "\n") |
|
|
|
for j := 1; j < len(lines); j++ { |
|
|
|
userName := lines[1] |
|
|
|
//email := lines[2] |
|
|
|
record, ok := bonusMap[userName] |
|
|
|
if !ok { |
|
|
|
record = make(map[string]int) |
|
|
|
} |
|
|
|
record["times"] = getMapKeyStringValue("times", record) + getIntValue(lines[3]) |
|
|
|
record["total_bonus"] = getMapKeyStringValue("total_bonus", record) + getIntValue(lines[4]) |
|
|
|
record["total_cardtime"] = getMapKeyStringValue("total_cardtime", record) + getIntValue(lines[5]) |
|
|
|
record["total_giveup"] = getMapKeyStringValue("total_giveup", record) + getIntValue(lines[6]) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return bonusMap |
|
|
|
} |
|
|
|
|
|
|
|
func getIntValue(val string) int { |
|
|
|
i, err := strconv.Atoi(val) |
|
|
|
if err == nil { |
|
|
|
return i |
|
|
|
} |
|
|
|
return 0 |
|
|
|
} |
|
|
|
|
|
|
|
func getPlayARoll(bonusMap map[string]map[string]int, userName string) string { |
|
|
|
bonusInfo := make(map[string]string) |
|
|
|
|
|
|
|
record, ok := bonusMap[userName] |
|
|
|
if ok { |
|
|
|
bonusInfo["times"] = fmt.Sprint(record["times"]) |
|
|
|
bonusInfo["total_bonus"] = fmt.Sprint(record["total_bonus"]) |
|
|
|
bonusInfo["total_cardtime"] = fmt.Sprint(record["total_cardtime"]) |
|
|
|
bonusInfo["total_giveup"] = fmt.Sprint(record["total_giveup"]) |
|
|
|
} |
|
|
|
bonusInfoJson, _ := json.Marshal(bonusInfo) |
|
|
|
return string(bonusInfoJson) |
|
|
|
} |
|
|
|
|
|
|
|
func getCloudBrainInfo(dateRecordAll UserBusinessAnalysisAll, CloudBrainTaskItemMap map[string]int) string { |
|
|
|
cloudBrainInfo := make(map[string]string) |
|
|
|
cloudBrainInfo["create_task_num"] = fmt.Sprint(dateRecordAll.CloudBrainTaskNum) |
|
|
|
cloudBrainInfo["debug_task_num"] = fmt.Sprint(dateRecordAll.GpuDebugJob + dateRecordAll.NpuDebugJob) |
|
|
|
cloudBrainInfo["train_task_num"] = fmt.Sprint(dateRecordAll.GpuTrainJob + dateRecordAll.NpuTrainJob) |
|
|
|
cloudBrainInfo["inference_task_num"] = fmt.Sprint(dateRecordAll.NpuInferenceJob + CloudBrainTaskItemMap["GpuInferenceJob"]) |
|
|
|
cloudBrainInfo["inference_task_num"] = fmt.Sprint(dateRecordAll.NpuInferenceJob + CloudBrainTaskItemMap[fmt.Sprint(dateRecordAll.ID)+"_GpuInferenceJob"]) |
|
|
|
cloudBrainInfo["card_runtime"] = fmt.Sprint(dateRecordAll.CloudBrainRunTime) |
|
|
|
cloudBrainInfo["card_runtime_money"] = fmt.Sprint(dateRecordAll.CloudBrainRunTime * 5) |
|
|
|
//todo |
|
|
|
cloudBrainInfo["CloudBrainOne"] = fmt.Sprint(CloudBrainTaskItemMap[fmt.Sprint(dateRecordAll.ID)+"_CloudBrainOne"]) |
|
|
|
cloudBrainInfo["CloudBrainTwo"] = fmt.Sprint(CloudBrainTaskItemMap[fmt.Sprint(dateRecordAll.ID)+"_CloudBrainTwo"]) |
|
|
|
cloudBrainInfo["C2Net"] = fmt.Sprint(CloudBrainTaskItemMap[fmt.Sprint(dateRecordAll.ID)+"_C2Net"]) |
|
|
|
|
|
|
|
cloudBrainInfoJson, _ := json.Marshal(cloudBrainInfo) |
|
|
|
return string(cloudBrainInfoJson) |
|
|
|
} |
|
|
@@ -2461,3 +2522,26 @@ func subMonth(t1, t2 time.Time) (month int) { |
|
|
|
} |
|
|
|
return month |
|
|
|
} |
|
|
|
|
|
|
|
func GetContentFromPromote(url string) (string, error) { |
|
|
|
defer func() { |
|
|
|
if err := recover(); err != nil { |
|
|
|
log.Info("not error.", err) |
|
|
|
return |
|
|
|
} |
|
|
|
}() |
|
|
|
resp, err := http.Get(url) |
|
|
|
if err != nil || resp.StatusCode != 200 { |
|
|
|
log.Info("Get organizations url error=" + err.Error()) |
|
|
|
return "", err |
|
|
|
} |
|
|
|
|
|
|
|
bytes, err := ioutil.ReadAll(resp.Body) |
|
|
|
resp.Body.Close() |
|
|
|
if err != nil { |
|
|
|
log.Info("Get organizations url error=" + err.Error()) |
|
|
|
return "", err |
|
|
|
} |
|
|
|
allLineStr := string(bytes) |
|
|
|
return allLineStr, nil |
|
|
|
} |