Reviewed-on: https://openi.pcl.ac.cn/OpenI/aiforge/pulls/3481 Reviewed-by: ychao_1983 <ychao_1983@sina.com>pull/3484/head
@@ -1,6 +1,7 @@ | |||
package models | |||
import ( | |||
"encoding/json" | |||
"fmt" | |||
"time" | |||
@@ -450,15 +451,30 @@ func QueryUserLoginInfo(userIds []int64) []*UserLoginLog { | |||
return loginList | |||
} | |||
var WeekBonusData = make(map[int64][]int) | |||
func QueryUserAnnualReport(userId int64) *UserSummaryCurrentYear { | |||
statictisSess := xStatistic.NewSession() | |||
defer statictisSess.Close() | |||
log.Info("userId=" + fmt.Sprint(userId)) | |||
if len(WeekBonusData) == 0 { | |||
WeekBonusData = getBonusWeekDataMap() | |||
} | |||
reList := make([]*UserSummaryCurrentYear, 0) | |||
err := statictisSess.Select("*").Table(new(UserSummaryCurrentYear)).Where("id=" + fmt.Sprint(userId)).Find(&reList) | |||
if err == nil { | |||
if len(reList) > 0 { | |||
record, ok := WeekBonusData[userId] | |||
if ok { | |||
bonusInfo := make(map[string]int) | |||
bonusInfo["order"] = record[0] | |||
bonusInfo["money"] = record[1] | |||
bonusInfo["week"] = record[2] | |||
bonusInfo["num"] = record[3] | |||
bonusInfoJson, _ := json.Marshal(bonusInfo) | |||
reList[0].WeekBonusData = string(bonusInfoJson) | |||
} | |||
return reList[0] | |||
} | |||
} else { | |||
@@ -880,6 +880,68 @@ func isUserYearData(tableName string) bool { | |||
return false | |||
} | |||
func getBonusWeekDataMap() map[int64][]int { | |||
bonusMap := make(map[int64][]int) | |||
url := setting.RecommentRepoAddr + "bonus/weekdata/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/weekdata/" + filenames[i] | |||
csvContent, err1 := GetContentFromPromote(url) | |||
if err1 == nil { | |||
//read csv | |||
lines := strings.Split(csvContent, "\n") | |||
for j := 1; j < len(lines); j++ { | |||
aLine := strings.Split(lines[j], ",") | |||
if len(aLine) < 4 { | |||
continue | |||
} | |||
userId := getInt64Value(aLine[0]) | |||
order := getIntValue(aLine[2]) | |||
money := getIntValue(aLine[3]) | |||
week, num := getWeekAndNum(filenames[i]) | |||
//email := lines[2] | |||
record, ok := bonusMap[userId] | |||
if !ok { | |||
record = make([]int, 4) | |||
record[0] = order | |||
record[1] = money | |||
record[2] = week | |||
record[3] = num | |||
bonusMap[userId] = record | |||
} else { | |||
if record[0] > order { | |||
record[0] = order | |||
record[1] = money | |||
record[2] = week | |||
record[3] = num | |||
} else { | |||
if record[0] == order && record[1] < money { | |||
record[1] = money | |||
record[2] = week | |||
record[3] = num | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
return bonusMap | |||
} | |||
func getWeekAndNum(name string) (int, int) { | |||
name = name[0 : len(name)-4] | |||
tmp := strings.Split(name, "_") | |||
if len(tmp) == 2 { | |||
week := getIntValue(tmp[0]) | |||
num := getIntValue(tmp[1]) | |||
return week, num | |||
} | |||
return 0, 0 | |||
} | |||
func getBonusMap() map[string]map[string]int { | |||
bonusMap := make(map[string]map[string]int) | |||
url := setting.RecommentRepoAddr + "bonus/record.txt" | |||
@@ -923,6 +985,14 @@ func getIntValue(val string) int { | |||
return 0 | |||
} | |||
func getInt64Value(val string) int64 { | |||
i, err := strconv.ParseInt(val, 10, 64) | |||
if err == nil { | |||
return i | |||
} | |||
return 0 | |||
} | |||
func getPlayARoll(bonusMap map[string]map[string]int, userName string, scoreMap map[string]float64) string { | |||
bonusInfo := make(map[string]string) | |||
record, ok := bonusMap[userName] | |||
@@ -18,9 +18,9 @@ type UserSummaryCurrentYear struct { | |||
CodeInfo string `xorm:"varchar(500)"` //代码提交次数,提交总代码行数,最晚的提交时间 | |||
CloudBrainInfo string `xorm:"varchar(1000)"` //,创建了XX 个云脑任务,调试任务XX 个,训练任务XX 个,推理任务XX 个,累计运行了XXXX 卡时,累计节省xxxxx 元 | |||
//这些免费的算力资源分别有,XX% 来自鹏城云脑1,XX% 来自鹏城云脑2,XX% 来自智算网络 | |||
PlayARoll string `xorm:"varchar(500)"` //你参加了XX 次“我为开源打榜狂”活动,累计上榜XX 次,总共获得了社区XXX 元的激励 | |||
Label string `xorm:"varchar(500)"` | |||
PlayARoll string `xorm:"varchar(500)"` //你参加了XX 次“我为开源打榜狂”活动,累计上榜XX 次,总共获得了社区XXX 元的激励 | |||
WeekBonusData string `xorm:"-"` | |||
Label string `xorm:"varchar(500)"` | |||
} | |||
type UserBusinessAnalysisCurrentYear struct { | |||
@@ -614,7 +614,7 @@ func ObsCreateObject(path string) error { | |||
return nil | |||
} | |||
func GetObsLogFileName(prefix string) (string, error) { | |||
func GetObsLogFileName(prefix string) ([]FileInfo, error) { | |||
input := &obs.ListObjectsInput{} | |||
input.Bucket = setting.Bucket | |||
input.Prefix = prefix | |||
@@ -622,10 +622,26 @@ func GetObsLogFileName(prefix string) (string, error) { | |||
output, err := ObsCli.ListObjects(input) | |||
if err != nil { | |||
log.Error("PutObject failed:", err.Error()) | |||
return "", err | |||
return nil, err | |||
} | |||
if output == nil || len(output.Contents) == 0 { | |||
return "", errors.New("obs log files not exist") | |||
return nil, errors.New("obs log files not exist") | |||
} | |||
fileInfos := make([]FileInfo, 0) | |||
for _, val := range output.Contents { | |||
//result[num] = c.Key | |||
if strings.HasSuffix(val.Key, ".log") { | |||
log.Info("log fileName=" + val.Key) | |||
fileInfo := FileInfo{ | |||
ModTime: val.LastModified.Local().Format("2006-01-02 15:04:05"), | |||
FileName: val.Key[len(prefix)-3:], //加上 job | |||
Size: val.Size, | |||
IsDir: false, | |||
ParenDir: prefix[0 : len(prefix)-3], | |||
} | |||
fileInfos = append(fileInfos, fileInfo) | |||
} | |||
} | |||
return output.Contents[0].Key, nil | |||
return fileInfos, nil | |||
} |
@@ -2893,15 +2893,19 @@ func TrainJobDownloadLogFile(ctx *context.Context) { | |||
ctx.ServerError("GetObsLogFileName", err) | |||
return | |||
} | |||
url, err := storage.GetObsCreateSignedUrlByBucketAndKey(setting.Bucket, key) | |||
if err != nil { | |||
log.Error("GetObsCreateSignedUrlByBucketAndKey failed: %v", err.Error(), ctx.Data["msgID"]) | |||
ctx.ServerError("GetObsCreateSignedUrlByBucketAndKey", err) | |||
return | |||
if len(key) > 1 { | |||
ObsDownloadManyFile(prefix[0:len(prefix)-3], ctx, task.DisplayJobName+".zip", key) | |||
} else { | |||
url, err := storage.GetObsCreateSignedUrlByBucketAndKey(setting.Bucket, key[0].ParenDir+key[0].FileName) | |||
if err != nil { | |||
log.Error("GetObsCreateSignedUrlByBucketAndKey failed: %v", err.Error(), ctx.Data["msgID"]) | |||
ctx.ServerError("GetObsCreateSignedUrlByBucketAndKey", err) | |||
return | |||
} | |||
ctx.Resp.Header().Set("Cache-Control", "max-age=0") | |||
http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusTemporaryRedirect) | |||
} | |||
ctx.Resp.Header().Set("Cache-Control", "max-age=0") | |||
http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusTemporaryRedirect) | |||
} | |||
func getDatasUrlListByUUIDS(uuidStr string) ([]models.Datasurl, string, string, bool, error) { | |||
var isMultiDataset bool | |||