Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.21.12.1^2
zouap 4 years ago
parent
commit
705862fcc5
2 changed files with 51 additions and 14 deletions
  1. +15
    -1
      models/ai_model_manage.go
  2. +36
    -13
      routers/repo/ai_model_manage.go

+ 15
- 1
models/ai_model_manage.go View File

@@ -22,7 +22,7 @@ type AiModelManage struct {
Path string `xorm:"varchar(400) NOT NULL"`
ConfigJson string `xorm:"text"`
DownloadCount int `xorm:"NOT NULL DEFAULT 0"`
Engine int `xorm:"NOT NULL DEFAULT 0"`
Engine int64 `xorm:"NOT NULL DEFAULT 0"`
Status int `xorm:"NOT NULL DEFAULT 0"`
Accuracy string `xorm:"varchar(1000)"`
AttachmentId string `xorm:"NULL"`
@@ -114,7 +114,21 @@ func ModifyModelNewProperty(id string, new int) error {
}
log.Info("success to update new property from db.re=" + fmt.Sprint((re)))
return nil
}

func ModifyModelDownloadCount(id string) error {
var sess *xorm.Session
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
if _, err := sess.Exec("UPDATE `ai_model_manage` SET download_count = download_count + 1 WHERE id = ?", id); err != nil {
return err
}
if err := sess.Commit(); err != nil {
return err
}
return nil
}

func QueryModelByName(name string, repoId int64) []*AiModelManage {


+ 36
- 13
routers/repo/ai_model_manage.go View File

@@ -2,6 +2,7 @@ package repo

import (
"archive/zip"
"encoding/json"
"errors"
"fmt"
"net/http"
@@ -56,20 +57,35 @@ func SaveModelByParameters(jobId string, name string, version string, label stri
return err
}
}

accuracy := make(map[string]string)
accuracy["F1"] = ""
accuracy["Recall"] = ""
accuracy["Accuracy"] = ""
accuracy["Precision"] = ""
accuracyJson, _ := json.Marshal(accuracy)
log.Info("accuracyJson=" + string(accuracyJson))
aiTaskJson, _ := json.Marshal(aiTask)

//taskConfigInfo,err := models.GetCloudbrainByJobIDAndVersionName(jobId,aiTask.VersionName)
model := &models.AiModelManage{
ID: id,
Version: version,
Label: label,
Name: name,
Description: description,
New: MODEL_LATEST,
Type: cloudType,
Path: modelPath,
Size: modelSize,
AttachmentId: aiTask.Uuid,
RepoId: aiTask.RepoID,
UserId: userId,
ID: id,
Version: version,
Label: label,
Name: name,
Description: description,
New: MODEL_LATEST,
Type: cloudType,
Path: modelPath,
Size: modelSize,
AttachmentId: aiTask.Uuid,
RepoId: aiTask.RepoID,
UserId: userId,
CodeBranch: "",
CodeCommitID: aiTask.CommitID,
Engine: aiTask.EngineID,
ConfigJson: "",
TrainTaskInfo: string(aiTaskJson),
Accuracy: string(accuracyJson),
}

models.SaveModelToDb(model)
@@ -190,6 +206,9 @@ func DownloadMultiModelFile(ctx *context.Context) {

allFile, err := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, path)
if err == nil {
//count++
models.ModifyModelDownloadCount(id)

returnFileName := task.Name + "_" + task.Version + ".zip"
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+returnFileName)
ctx.Resp.Header().Set("Content-Type", "application/octet-stream")
@@ -247,6 +266,8 @@ func DownloadSingleModelFile(ctx *context.Context) {
if err != nil {
log.Info("download error.")
} else {
//count++
models.ModifyModelDownloadCount(id)
defer body.Close()
ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+fileName)
ctx.Resp.Header().Set("Content-Type", "application/octet-stream")
@@ -272,6 +293,8 @@ func DownloadSingleModelFile(ctx *context.Context) {
ctx.ServerError("GetObsCreateSignedUrl", err)
return
}
//count++
models.ModifyModelDownloadCount(id)
http.Redirect(ctx.Resp, ctx.Req.Request, url, http.StatusMovedPermanently)
}
}


Loading…
Cancel
Save