Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/2115 Reviewed-by: lewis <747342561@qq.com>tags/v1.22.5.1^2
| @@ -1,6 +1,7 @@ | |||
| package models | |||
| import ( | |||
| "encoding/json" | |||
| "fmt" | |||
| "sort" | |||
| "strconv" | |||
| @@ -228,7 +229,7 @@ func getLastCountDate() int64 { | |||
| return pageStartTime.Unix() | |||
| } | |||
| func QueryMetricsPage(start int64, end int64, page int, pageSize int) ([]*UserMetrics, int64) { | |||
| func QueryMetricsPage(start int64, end int64) ([]*UserMetrics, int64) { | |||
| statictisSess := xStatistic.NewSession() | |||
| defer statictisSess.Close() | |||
| @@ -652,7 +653,9 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS | |||
| dateRecordBatch = make([]UserBusinessAnalysisAll, 0) | |||
| } | |||
| if tableName == "user_business_analysis_all" { | |||
| if dateRecordAll.UserIndex > 0 || dateRecordAll.LoginCount > 0 { | |||
| tValue := getUserActivateAll(dateRecordAll) | |||
| if tValue > 0 { | |||
| log.Info("dateRecordAll name=" + dateRecordAll.Name + " value=" + fmt.Sprint(tValue)) | |||
| userMetrics["TotalHasActivityUser"] = getMapKeyStringValue("TotalHasActivityUser", userMetrics) + 1 | |||
| } | |||
| } | |||
| @@ -669,7 +672,9 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS | |||
| log.Info("insert all data failed." + err.Error()) | |||
| } | |||
| } | |||
| if tableName == "user_business_analysis_all" { | |||
| log.Info("TotalHasActivityUser=" + fmt.Sprint(userMetrics["TotalHasActivityUser"])) | |||
| } | |||
| //normalization | |||
| for k, v := range userIndexMap { | |||
| tmpResult := (v - minUserIndex) / (maxUserIndex - minUserIndex) | |||
| @@ -774,6 +779,8 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, | |||
| log.Info("query commit code errr.") | |||
| } else { | |||
| log.Info("query commit code size, len=" + fmt.Sprint(len(CommitCodeSizeMap))) | |||
| CommitCodeSizeMapJson, _ := json.Marshal(CommitCodeSizeMap) | |||
| log.Info("CommitCodeSizeMapJson=" + string(CommitCodeSizeMapJson)) | |||
| } | |||
| CommitDatasetSizeMap, CommitDatasetNumMap := queryDatasetSize(start_unix, end_unix) | |||
| SolveIssueCountMap := querySolveIssue(start_unix, end_unix) | |||
| @@ -868,6 +875,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, | |||
| dateRecord.UserIndexPrimitive = getUserIndex(dateRecord, ParaWeight) | |||
| setUserMetrics(userMetrics, userRecord, start_unix, end_unix, dateRecord) | |||
| if getUserActivate(dateRecord) > 0 { | |||
| log.Info("has activity." + userRecord.Name) | |||
| addUserToMap(userNewAddActivity, userRecord.CreatedUnix, dateRecord.ID) | |||
| } | |||
| if userRecord.IsActive { | |||
| @@ -1035,6 +1043,27 @@ func getUserIndexFromAnalysisAll(dateRecord UserBusinessAnalysisAll, ParaWeight | |||
| return result | |||
| } | |||
| func getUserActivateAll(dateRecord UserBusinessAnalysisAll) int { | |||
| var result int | |||
| result += dateRecord.CodeMergeCount | |||
| result += dateRecord.CommitCount | |||
| result += dateRecord.IssueCount | |||
| result += dateRecord.CommentCount | |||
| result += dateRecord.FocusRepoCount | |||
| result += dateRecord.StarRepoCount | |||
| result += dateRecord.SolveIssueCount | |||
| result += dateRecord.EncyclopediasCount | |||
| result += dateRecord.CreateRepoCount | |||
| result += dateRecord.CloudBrainTaskNum | |||
| result += dateRecord.CommitModelCount | |||
| result += dateRecord.CommitDatasetNum | |||
| result += dateRecord.FocusOtherUser | |||
| result += dateRecord.CollectDataset | |||
| result += dateRecord.CollectImage | |||
| result += dateRecord.CommitCodeSize | |||
| return result | |||
| } | |||
| func getUserActivate(dateRecord UserBusinessAnalysis) int { | |||
| var result int | |||
| result += dateRecord.CodeMergeCount | |||
| @@ -256,14 +256,6 @@ func queryUserDataPage(ctx *context.Context, tableName string, queryObj interfac | |||
| func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, endTime time.Time) { | |||
| page := ctx.QueryInt("page") | |||
| if page <= 0 { | |||
| page = 1 | |||
| } | |||
| pageSize := ctx.QueryInt("pageSize") | |||
| if pageSize <= 0 { | |||
| pageSize = setting.UI.IssuePagingNum | |||
| } | |||
| IsReturnFile := ctx.QueryBool("IsReturnFile") | |||
| var count int64 | |||
| @@ -275,7 +267,7 @@ func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, e | |||
| result = models.QueryMetricsForAll(startTime.Unix(), endTime.Unix()) | |||
| count = int64(len(result)) | |||
| } else { | |||
| result, count = models.QueryMetricsPage(startTime.Unix(), endTime.Unix(), page, pageSize) | |||
| result, count = models.QueryMetricsPage(startTime.Unix(), endTime.Unix()) | |||
| } | |||
| if IsReturnFile { | |||
| //writer exec file. | |||
| @@ -297,6 +289,9 @@ func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, e | |||
| //设置默认打开的表单 | |||
| xlsx.SetActiveSheet(index) | |||
| filename := sheetName + "_" + ctx.Tr("user.static."+tableName) + ".xlsx" | |||
| if tableName == "" { | |||
| filename = sheetName + "_" + getTimeFileName(startTime) + "_" + getTimeFileName(endTime) + ".xlsx" | |||
| } | |||
| ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+url.QueryEscape(filename)) | |||
| ctx.Resp.Header().Set("Content-Type", "application/octet-stream") | |||
| if _, err := xlsx.WriteTo(ctx.Resp); err != nil { | |||
| @@ -317,7 +312,10 @@ func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, e | |||
| } | |||
| ctx.JSON(http.StatusOK, mapInterface) | |||
| } | |||
| } | |||
| func getTimeFileName(t time.Time) string { | |||
| t = t.Local() | |||
| return t.Format("20060102") | |||
| } | |||
| func QueryRankingList(ctx *context.Context) { | |||
| @@ -345,8 +343,8 @@ func QueryUserStaticCurrentMonth(ctx *context.Context) { | |||
| } | |||
| func getStartTime(pageStartTime time.Time) time.Time { | |||
| t, _ := time.Parse("2006-01-02", setting.RadarMap.GrowthBeginTime) | |||
| t = time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 1, t.Location()) | |||
| t, _ := time.ParseInLocation("2006-01-02", setting.RadarMap.GrowthBeginTime, time.Local) | |||
| t = t.UTC() | |||
| if pageStartTime.Before(t) { | |||
| pageStartTime = t | |||
| } | |||
| @@ -423,22 +421,10 @@ func QueryUserMetricDataPage(ctx *context.Context) { | |||
| startDate := ctx.Query("startDate") | |||
| endDate := ctx.Query("endDate") | |||
| startTime, _ := time.ParseInLocation("2006-01-02", startDate, time.Local) | |||
| startTime = startTime.UTC() | |||
| endTime, _ := time.ParseInLocation("2006-01-02", endDate, time.Local) | |||
| page := ctx.QueryInt("page") | |||
| if page <= 0 { | |||
| page = 1 | |||
| } | |||
| pageSize := ctx.QueryInt("pageSize") | |||
| if pageSize <= 0 { | |||
| pageSize = setting.UI.IssuePagingNum | |||
| } | |||
| result, count := models.QueryMetricsPage(startTime.Unix(), endTime.Unix(), page, pageSize) | |||
| mapInterface := make(map[string]interface{}) | |||
| mapInterface["data"] = result | |||
| mapInterface["count"] = count | |||
| ctx.JSON(http.StatusOK, mapInterface) | |||
| startTime = getStartTime(startTime) | |||
| queryMetrics(ctx, "", startTime, endTime) | |||
| } | |||
| func QueryUserStaticDataPage(ctx *context.Context) { | |||
| @@ -13,7 +13,7 @@ | |||
| <span class="yesterday_blk yesterday_title" >昨日新增注册用户数 </span> | |||
| <span class="yesterday_blk yesterday_color1 yesterday_pdrt yesterday_text">未激活:<span class="bold_num">{{ tableDataYesterday.NotActivateRegistUser }}</span> 人 </span> | |||
| <span class="yesterday_blk yesterday_color2 yesterday_pdrt yesterday_text">已激活: <span class="bold_num">{{ tableDataYesterday.ActivateRegistUser }} </span>人</span> | |||
| <span class="yesterday_blk yesterday_pdrt yesterday_text">有贡献活动: <span class="bold_num">{{ tableDataYesterday.RegistActivityUser }} </span>人</span> | |||
| <span class="yesterday_blk yesterday_pdrt yesterday_text">有贡献活动: <span class="bold_num">{{ tableDataYesterday.HasActivityUser }} </span>人</span> | |||
| </el-col> | |||
| @@ -24,8 +24,8 @@ | |||
| </el-col> | |||
| <el-col :span="8" :style="{ height: '180px'}" v-if="ys_count>0"> | |||
| <span class="yesterday_blk yesterday_title" >注册用户数 </span> | |||
| <span class="yesterday_blk yesterday_color1 yesterday_pdrt yesterday_text">未激活:<span class="bold_num">{{ tableDataYesterday.TotalActivateRegistUser}} </span>人 </span> | |||
| <span class="yesterday_blk yesterday_color2 yesterday_pdrt yesterday_text">已激活:<span class="bold_num">{{ tableDataYesterday.TotalNotActivateRegistUser }} </span>人</span> | |||
| <span class="yesterday_blk yesterday_color2 yesterday_pdrt yesterday_text">未激活:<span class="bold_num">{{ tableDataYesterday.TotalNotActivateRegistUser }} </span>人</span> | |||
| <span class="yesterday_blk yesterday_color1 yesterday_pdrt yesterday_text">已激活:<span class="bold_num">{{ tableDataYesterday.TotalActivateRegistUser}} </span>人 </span> | |||
| <span class="yesterday_blk yesterday_pdrt yesterday_text">有贡献活动:<span class="bold_num"> {{ tableDataYesterday.TotalHasActivityUser}} </span>人</span> | |||
| </el-col> | |||
| @@ -114,7 +114,7 @@ | |||
| align="center"> | |||
| </el-table-column> | |||
| <el-table-column | |||
| prop="RegistActivityUser" | |||
| prop="HasActivityUser" | |||
| label="新增有贡献活动" | |||
| align="center"> | |||
| </el-table-column> | |||
| @@ -292,7 +292,7 @@ | |||
| switch(type_val){ | |||
| case "yesterday_usr":{ | |||
| this.value_time=[] | |||
| this.dataUrl = '../../api/v1/query_user_yesterday'; | |||
| this.dataUrl = '../../api/v1/query_metrics_yesterday'; | |||
| break | |||
| } | |||
| case "current_week_usr":{ | |||
| @@ -517,7 +517,7 @@ | |||
| xdata.push(this.tableData[this.tableData.length-1-i].DisplayDate); | |||
| ydata_TotalRegistUser.push(this.tableData[this.tableData.length-1-i].TotalRegistUser) | |||
| ydata_ActivateRegistUser.push(this.tableData[this.tableData.length-1-i].ActivateRegistUser) | |||
| ydata_RegistActivityUser.push(this.tableData[this.tableData.length-1-i].RegistActivityUser) | |||
| ydata_RegistActivityUser.push(this.tableData[this.tableData.length-1-i].HasActivityUser) | |||
| ydata_NotActivateRegistUser.push(this.tableData[this.tableData.length-1-i].NotActivateRegistUser) | |||
| ydata_TotalUser.push(this.tableData[this.tableData.length-1-i].TotalUser) | |||
| ydata_TotalActivateRegistUser.push(this.tableData[this.tableData.length-1-i].TotalActivateRegistUser) | |||