Browse Source

update

tags/v1.22.6.1^2
liuzx 3 years ago
parent
commit
3696ce23c4
6 changed files with 80 additions and 3 deletions
  1. +1
    -1
      models/cloudbrain_static.go
  2. +1
    -0
      models/models.go
  3. +1
    -0
      routers/api/v1/api.go
  4. +74
    -0
      routers/api/v1/repo/cloudbrain_dashboard.go
  5. +2
    -2
      routers/repo/cloudbrain_statistic.go
  6. +1
    -0
      routers/routes/routes.go

+ 1
- 1
models/cloudbrain_static.go View File

@@ -12,7 +12,7 @@ import (
// Cloudbrain statistic info of all CloudbrainTasks
type CloudbrainStatistic struct {
ID int64 `xorm:"pk autoincr" json:"-"`
Date string `xorm:"unique(s) NOT NULL" json:"date"`
Date string `xorm:"NOT NULL DEFAULT 0" json:"date"`
WhichHour int64 `xorm:"NOT NULL DEFAULT -1" json:"whichHour"`
NumDubugOne int64 `xorm:"NOT NULL DEFAULT 0" json:"numDubugOne"`
NumBenchmarkOne int64 `xorm:"NOT NULL DEFAULT 0" json:"numBenchmarkOne"`


+ 1
- 0
models/models.go View File

@@ -151,6 +151,7 @@ func init() {
new(UserBusinessAnalysisCurrentWeek),
new(UserBusinessAnalysisYesterday),
new(UserLoginLog),
new(CloudbrainStatistic),
)

gonicNames := []string{"SSL", "UID"}


+ 1
- 0
routers/api/v1/api.go View File

@@ -556,6 +556,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/query_user_all", operationReq, repo_ext.QueryUserStaticAll)
//cloudbrain board
m.Group("/cloudbrainboard", func() {
m.Get("/downloadtable", repo.ServeCloudbrainPeriodStatisticsFile)
m.Group("/cloudbrain", func() {
m.Get("", repo.GetAllCloudbrainsPeriodStatistics)
})


+ 74
- 0
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -2,10 +2,12 @@ package repo

import (
"net/http"
"net/url"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"github.com/360EntSecGroup-Skylar/excelize/v2"
)

type CloudbrainsPeriodData struct {
@@ -81,3 +83,75 @@ func GetAllCloudbrainsPeriodStatistics(ctx *context.Context) {
ctx.JSON(http.StatusOK, cloudbrainsPeriodData)

}
func ServeCloudbrainPeriodStatisticsFile(ctx *context.Context) {

recordBeginTime, err := getRecordBeginTime()
if err != nil {
log.Error("Can not get record begin time", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err"))
return
}
beginTime, endTime, err := getTimePeroid(ctx, recordBeginTime)
if err != nil {
log.Error("Parameter is wrong", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.parameter_is_wrong"))
return
}
q := ctx.QueryTrim("q")
page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
pageSize := 1000
orderBy := getOrderBy(ctx)

_, latestDate, err := models.GetRepoStatLastUpdatedTime()
if err != nil {
log.Error("Can not query the last updated time.", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.last_update_time_error"))
return
}

countSql := generateCountSql(beginTime, endTime, latestDate, q)
total, err := models.CountRepoStatByRawSql(countSql)
if err != nil {
log.Error("Can not query total count.", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.total_count_get_error"))
return
}
var projectAnalysis = ctx.Tr("repo.repo_stat_inspect")
fileName := getFileName(ctx, beginTime, endTime, projectAnalysis)

totalPage := getTotalPage(total, pageSize)

f := excelize.NewFile()

index := f.NewSheet(projectAnalysis)
f.DeleteSheet("Sheet1")

for k, v := range allProjectsPeroidHeader(ctx) {
f.SetCellValue(projectAnalysis, k, v)
}

var row = 2
for i := 0; i <= totalPage; i++ {

pageRecords := models.GetRepoStatisticByRawSql(generateSqlByType(ctx, beginTime, endTime, latestDate, q, orderBy, i+1, pageSize))
for _, record := range pageRecords {

for k, v := range allProjectsPeroidValues(row, record, ctx) {
f.SetCellValue(projectAnalysis, k, v)
}
row++

}

}
f.SetActiveSheet(index)

ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+url.QueryEscape(fileName))
ctx.Resp.Header().Set("Content-Type", "application/octet-stream")

f.WriteTo(ctx.Resp)

}

+ 2
- 2
routers/repo/cloudbrain_statistic.go View File

@@ -10,13 +10,13 @@ import (
)

func CloudbrainStatisticAuto() {
yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
yesterday := time.Now().AddDate(0, 0, 0).Format("2006-01-02")
CloudbrainStatisticDaily(yesterday)
}

func CloudbrainStatisticDaily(date string) {
log.Info("%s", date)
log.Info("begin Repo Statistic")
log.Info("begin Cloudbrain Statistic")
warnEmailMessage := "云脑任务统计信息入库失败,请尽快定位。"
if err := models.DeleteCloudbrainStatisticDaily(date); err != nil {
log.Error("DeleteCloudbrainStatisticDaily failed: %v", err.Error())


+ 1
- 0
routers/routes/routes.go View File

@@ -990,6 +990,7 @@ func RegisterRoutes(m *macaron.Macaron) {
}, context.RepoRef())

m.Group("/cloudbrain", func() {
m.Get("/test", repo.CloudbrainStatisticAuto)
m.Group("/:id", func() {
m.Get("", reqRepoCloudBrainReader, repo.CloudBrainShow)
m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.CloudBrainDebug)


Loading…
Cancel
Save