From e77dcc07cc8e615aba707c4c996e2952a2f81868 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 18 Nov 2021 10:05:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 17 ++++++++++------- options/locale/locale_en-US.ini | 4 ++-- options/locale/locale_zh-CN.ini | 1 + routers/repo/user_data_analysis.go | 28 ++++++++++++++++++++++------ 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index be22cc300..9e9bf7f3a 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -82,6 +82,7 @@ type UserBusinessAnalysisQueryOptions struct { SortType string StartTime int64 EndTime int64 + IsAll bool } type UserBusinessAnalysisList []*UserBusinessAnalysis @@ -162,7 +163,7 @@ func getLastCountDate() int64 { func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBusinessAnalysis, int64) { - log.Info("query startTime =" + fmt.Sprint(opts.StartTime) + " endTime=" + fmt.Sprint(opts.EndTime)) + log.Info("query startTime =" + fmt.Sprint(opts.StartTime) + " endTime=" + fmt.Sprint(opts.EndTime) + " isAll=" + fmt.Sprint(opts.IsAll)) statictisSess := xStatistic.NewSession() defer statictisSess.Close() @@ -219,12 +220,14 @@ func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBus newAndCond = newAndCond.And( newOrCond, ) - newAndCond = newAndCond.And( - builder.Gte{"count_date": opts.StartTime}, - ) - newAndCond = newAndCond.And( - builder.Lte{"count_date": opts.EndTime}, - ) + if !opts.IsAll { + newAndCond = newAndCond.And( + builder.Gte{"count_date": opts.StartTime}, + ) + newAndCond = newAndCond.And( + builder.Lte{"count_date": opts.EndTime}, + ) + } userBusinessAnalysisList = make([]*UserBusinessAnalysis, 0) if err := statictisSess.Table("user_business_analysis").Where(newAndCond). diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index cac2153bb..b54ca18f2 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -420,7 +420,7 @@ static.createrepocount=Create Repo Count static.openiindex=OpenI Index static.registdate=Regist Date static.countdate=Count Date - +static.all=All [settings] profile = Profile @@ -815,7 +815,7 @@ get_repo_stat_error=Can not get the statistics of the repository. get_repo_info_error=Can not get the information of the repository. generate_statistic_file_error=Fail to generate file. repo_stat_inspect=ProjectAnalysis -all=all +all=All modelarts.notebook=Debug Task modelarts.train_job=Train Task modelarts.train_job.new_debug= New Debug Task diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 9918d47e0..7da672c0d 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -423,6 +423,7 @@ static.createrepocount=创建项目数 static.openiindex=OpenI指数 static.registdate=用户注册时间 static.countdate=系统统计时间 +static.all=所有 [settings] profile=个人信息 account=账号 diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 666a3a342..168a6419b 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -40,12 +40,21 @@ func QueryUserStaticDataPage(ctx *context.Context) { } userName := ctx.Query("userName") IsReturnFile := ctx.QueryBool("IsReturnFile") - log.Info("startDate=" + startDate + " endDate=" + endDate + " userName=" + userName + " page=" + fmt.Sprint(page)) - startTime, _ := time.Parse("2006-01-02", startDate) - endTime, _ := time.Parse("2006-01-02", endDate) - endTime = endTime.AddDate(0, 0, 1) - log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix())) + var startTime time.Time + var endTime time.Time + var isAll bool + if startDate == "all" { + isAll = true + startTime = time.Now() + endTime = time.Now() + } else { + startTime, _ = time.Parse("2006-01-02", startDate) + endTime, _ = time.Parse("2006-01-02", endDate) + endTime = endTime.AddDate(0, 0, 1) + isAll = false + log.Info("startTime=" + fmt.Sprint(startTime.Unix()) + " endDate=" + fmt.Sprint(endTime.Unix())) + } if IsReturnFile { page = -1 @@ -60,6 +69,7 @@ func QueryUserStaticDataPage(ctx *context.Context) { UserName: userName, StartTime: startTime.Unix(), EndTime: endTime.Unix(), + IsAll: isAll, } mapInterface := make(map[string]interface{}) re, count := models.QueryUserStaticDataPage(pageOpts) @@ -120,7 +130,13 @@ func QueryUserStaticDataPage(ctx *context.Context) { //设置默认打开的表单 xlsx.SetActiveSheet(index) - filename := sheetName + "_" + strings.ReplaceAll(startDate, "-", "") + "_" + strings.ReplaceAll(endDate, "-", "") + ".xlsx" + var filename string + if isAll { + filename = sheetName + "_" + ctx.Tr("user.static.all") + ".xlsx" + } else { + filename = sheetName + "_" + strings.ReplaceAll(startDate, "-", "") + "_" + strings.ReplaceAll(endDate, "-", "") + ".xlsx" + } + if len(userName) > 0 { filename = sheetName + "_" + userName + "_" + strings.ReplaceAll(startDate, "-", "") + "_" + strings.ReplaceAll(endDate, "-", "") + ".xlsx" } From 28c97e1a8bf4f72274b5c58595acd8e28ee95a4c Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 18 Nov 2021 10:27:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?OpenI=E6=8C=87=E6=95=B0=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E4=B8=A4=E4=BD=8D=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/user_data_analysis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 168a6419b..a621289ae 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -123,7 +123,7 @@ func QueryUserStaticDataPage(ctx *context.Context) { xlsx.SetCellValue(sheetName, "L"+rows, userRecord.SolveIssueCount) xlsx.SetCellValue(sheetName, "M"+rows, userRecord.EncyclopediasCount) xlsx.SetCellValue(sheetName, "N"+rows, userRecord.CreateRepoCount) - xlsx.SetCellValue(sheetName, "O"+rows, userRecord.OpenIIndex) + xlsx.SetCellValue(sheetName, "O"+rows, fmt.Sprintf("%.2f", userRecord.OpenIIndex)) xlsx.SetCellValue(sheetName, "P"+rows, userRecord.RegistDate.Format("2006-01-02")) xlsx.SetCellValue(sheetName, "Q"+rows, time.Unix(userRecord.CountDate, 0).Format("2006-01-02")) }