1、bug修复

2、提交采集数据接口
This commit is contained in:
wangjian 2023-06-09 17:43:08 +08:00
parent 53f9111046
commit e459922ebf
9 changed files with 153 additions and 4 deletions

View File

@ -89,7 +89,6 @@ Content-Type : application/json
{ {
"fileList": ["/home/data/bridge_capture/crack/0001.tif", "/home/data/bridge_capture/crack/0002.tif"], "fileList": ["/home/data/bridge_capture/crack/0001.tif", "/home/data/bridge_capture/crack/0002.tif"],
"labelStatus": true, "labelStatus": true,
"trainingSet": "5月10日隧道数据标注集",
"bizType": 3 "bizType": 3
} }
``` ```
@ -101,8 +100,48 @@ Content-Type : application/json
|-----|--------|-------|-------------------------------------| |-----|--------|-------|-------------------------------------|
| 1 | fileList | 字符串数组 | 文件的全路径组成的数组 | | 1 | fileList | 字符串数组 | 文件的全路径组成的数组 |
| 2 | labelStatus | 布尔值 | 标注状态true: 有病害; false: 无病害 | | 2 | labelStatus | 布尔值 | 标注状态true: 有病害; false: 无病害 |
| 3 | trainingSet | 字符串 | 训练集名称,上传到云端的训练集名称,如果云端已经存在,将合并训练集操作 | | 3 | bizType | 整型 | 1: 道路; 2: 桥梁; 3: 隧道; 4: 边坡; |
| 4 | bizType | 整型 | 1: 道路; 2: 桥梁; 3: 隧道; 4: 边坡; |
- 返回值
```
{
"code": 200,
"message": "成功",
"type": "OK"
}
```
### 提交标注数据
- 访问地址
```
POST /api/capture/submit
```
- 请求头参数
Content-Type : application/json
- 请求参数
```
{
"fileList": ["/home/data/bridge_capture/crack/0001.tif", "/home/data/bridge_capture/crack/0002.tif"],
"datasetName": "2023年06月09日17点40分数据集,
"bizType": 3
}
```
+ 说明
+ | 序号 | 字段名称 | 数据类型 | 说明 |
|-----|--------|-------|-----------------------------|
| 1 | fileList | 字符串数组 | 文件的全路径组成的数组 |
| 2 | datasetName | 字符串 | 数据集名称,如果不存在将会自动创建 |
| 3 | bizType | 整型 | 1: 道路; 2: 桥梁; 3: 隧道; 4: 边坡; |
- 返回值 - 返回值

View File

@ -24,4 +24,7 @@ functions:
mqType: 2 mqType: 2
- name: edge-cmd-response - name: edge-cmd-response
dataTag: 32 dataTag: 32
mqType: 1
- name: dataset-request
dataTag: 10
mqType: 1 mqType: 1

View File

@ -53,3 +53,14 @@ func (s HandlerService) LabelSubmit(c *gin.Context) (data interface{}, err error
data, err = repo.LabelSubmit(c, req) data, err = repo.LabelSubmit(c, req)
return return
} }
func (s HandlerService) CaptureSubmit(c *gin.Context) (data interface{}, err error) {
repo := service.NewEdgeService(s.Logger)
var req proto.CaptureRequest
err = c.ShouldBindJSON(&req)
if err != nil {
return nil, e.NewValidErr(err)
}
data, err = repo.CaptureSubmit(c, req)
return
}

View File

@ -8,6 +8,11 @@ type ListRequest struct {
type LabelRequest struct { type LabelRequest struct {
FileList []string `json:"fileList"` FileList []string `json:"fileList"`
LabelStatus bool `json:"labelStatus"` LabelStatus bool `json:"labelStatus"`
TrainingSet string `json:"trainingSet"` BizType int `json:"bizType"`
}
type CaptureRequest struct {
FileList []string `json:"fileList"`
DatasetName string `json:"datasetName"`
BizType int `json:"bizType"` BizType int `json:"bizType"`
} }

View File

@ -25,4 +25,16 @@ type FileContent struct {
FileBaseInfo FileBaseInfo
ContentBase string `json:"contentBase"` ContentBase string `json:"contentBase"`
LabelStatus int `json:"labelStatus"` //0:未标注;1:有病害;2:无病害 LabelStatus int `json:"labelStatus"` //0:未标注;1:有病害;2:无病害
BizType int `json:"bizType"`
}
type FileTransferInfo struct {
FileName string `json:"fileName"`
FilePath string `json:"filePath"`
DataType int `json:"dataType"`
DatasetName string `json:"datasetId"`
FileSize int64 `json:"fileSize"`
File string `json:"file"`
IsCompress bool `json:"isCompress"`
FileMd5 string `json:"fileMd5"`
} }

View File

@ -28,6 +28,10 @@ func InitRouter(cfg *config.WebConfig, logger *logging.Logger) *gin.Engine {
{ {
label.POST("/submit", e.ErrorWrapper(hs.LabelSubmit)) label.POST("/submit", e.ErrorWrapper(hs.LabelSubmit))
} }
capture := r.Group("/capture")
{
capture.POST("/submit", e.ErrorWrapper(hs.CaptureSubmit))
}
} }
return root return root
} }

View File

@ -45,6 +45,7 @@ type EdgeService interface {
GetList(ctx context.Context, req proto.ListRequest) (rsp *proto.BaseResponse, err error) GetList(ctx context.Context, req proto.ListRequest) (rsp *proto.BaseResponse, err error)
GetInfo(ctx context.Context, req proto.ListRequest) (rsp *proto.BaseResponse, err error) GetInfo(ctx context.Context, req proto.ListRequest) (rsp *proto.BaseResponse, err error)
LabelSubmit(ctx context.Context, req proto.LabelRequest) (rsp *proto.BaseResponse, err error) LabelSubmit(ctx context.Context, req proto.LabelRequest) (rsp *proto.BaseResponse, err error)
CaptureSubmit(ctx context.Context, req proto.CaptureRequest) (rsp *proto.BaseResponse, err error)
} }
func NewEdgeService(logger *logging.Logger) EdgeService { func NewEdgeService(logger *logging.Logger) EdgeService {
@ -205,6 +206,7 @@ func (rp *repo) LabelSubmit(ctx context.Context, req proto.LabelRequest) (rsp *p
}, },
ContentBase: base64.StdEncoding.EncodeToString(dstContent), ContentBase: base64.StdEncoding.EncodeToString(dstContent),
LabelStatus: status, LabelStatus: status,
BizType: req.BizType,
} }
} }
go mq.SendLabelData(list, rp.logger) go mq.SendLabelData(list, rp.logger)
@ -222,3 +224,55 @@ func (rp *repo) LabelSubmit(ctx context.Context, req proto.LabelRequest) (rsp *p
return rsp, err return rsp, err
} }
} }
func (rp *repo) CaptureSubmit(ctx context.Context, req proto.CaptureRequest) (rsp *proto.BaseResponse, err error) {
rsp = new(proto.BaseResponse)
select {
case <-ctx.Done():
err = fmt.Errorf("超时/取消")
rsp.Code = http.StatusInternalServerError
rsp.Status = http.StatusText(http.StatusInternalServerError)
rsp.Message = "超时/取消"
rsp.Err = ctx.Err()
return rsp, ctx.Err()
default:
list := make([]proto.FileTransferInfo, len(req.FileList))
var (
fileInfo os.FileInfo
)
for k, v := range req.FileList {
fileInfo, err = os.Stat(v)
if err != nil {
goto ReturnPoint
}
buff := utils.ReadFile(v)
dstContent := store.Compress(buff)
list[k] = proto.FileTransferInfo{
FileName: fileInfo.Name(),
FilePath: v,
DatasetName: req.DatasetName,
DataType: req.BizType,
FileSize: fileInfo.Size(),
File: base64.StdEncoding.EncodeToString(dstContent),
IsCompress: true,
FileMd5: utils.GetFileMd5(buff),
}
}
go mq.SubmitFileData(list, rp.logger)
rsp.Code = http.StatusOK
rsp.Status = http.StatusText(http.StatusOK)
rsp.Message = "成功"
rsp.Err = err
}
ReturnPoint:
if err != nil {
rsp.Code = http.StatusInternalServerError
rsp.Status = http.StatusText(http.StatusInternalServerError)
rsp.Err = err
rsp.Message = "失败"
}
return rsp, err
}

View File

@ -197,3 +197,23 @@ func SendLabelData(list []proto.FileContent, logger *logging.Logger) {
} }
} }
} }
func SubmitFileData(list []proto.FileTransferInfo, logger *logging.Logger) {
cli := GetMqClient("dataset-request", 1)
if cli != nil {
for _, v := range list {
payload := InstructionReq{
Command: DatasetRequest,
Payload: v,
}
s, _ := json.Marshal(payload)
err := GenerateAndSendData(cli.EndPoint.(hpds_node.AccessPoint), s, logger)
if err != nil {
logger.With(
zap.String("文件名称", v.FileName),
zap.String("存储路径", v.FilePath),
).Error("文件传输", zap.Error(err))
}
}
}
}

View File

@ -1,6 +1,7 @@
package mq package mq
const ( const (
DatasetRequest = iota + 10
DataLabelRequest = iota + 12 DataLabelRequest = iota + 12
DataLabelResponse DataLabelResponse
) )