项目初次提交
This commit is contained in:
0
apps/business/train/__init__.py
Normal file
0
apps/business/train/__init__.py
Normal file
20
apps/business/train/crud.py
Normal file
20
apps/business/train/crud.py
Normal file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @version : 1.0
|
||||
# @Create Time : 2025/04/03 10:32
|
||||
# @File : crud.py
|
||||
# @IDE : PyCharm
|
||||
# @desc : 数据访问层
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from core.crud import DalBase
|
||||
from . import models, schemas
|
||||
|
||||
|
||||
class ProjectTrainDal(DalBase):
|
||||
|
||||
def __init__(self, db: AsyncSession):
|
||||
super(ProjectTrainDal, self).__init__()
|
||||
self.db = db
|
||||
self.model = models.ProjectTrain
|
||||
self.schema = schemas.ProjectTrainSimpleOut
|
0
apps/business/train/models/__init__.py
Normal file
0
apps/business/train/models/__init__.py
Normal file
24
apps/business/train/models/train.py
Normal file
24
apps/business/train/models/train.py
Normal file
@ -0,0 +1,24 @@
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy import String, Integer
|
||||
|
||||
from db.db_base import BaseModel
|
||||
|
||||
|
||||
class ProjectTrain(BaseModel):
|
||||
"""
|
||||
项目训练版本信息表
|
||||
"""
|
||||
__tablename__ = "project_train"
|
||||
__table_args__ = ({'comment': '项目训练版本信息表'})
|
||||
|
||||
project_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
||||
train_version: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
train_url: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
train_data: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
weights_id: Mapped[int] = mapped_column(Integer)
|
||||
weights_name: Mapped[str] = mapped_column(String(32))
|
||||
epochs: Mapped[int] = mapped_column(Integer)
|
||||
patience: Mapped[int] = mapped_column(Integer)
|
||||
best_pt: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
last_pt: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
user_id: Mapped[int] = mapped_column(Integer, nullable=False)
|
1
apps/business/train/params/__init__.py
Normal file
1
apps/business/train/params/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .project_train import ProjectTrainParams
|
15
apps/business/train/params/project_train.py
Normal file
15
apps/business/train/params/project_train.py
Normal file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @version : 1.0
|
||||
# @Create Time : 2025/04/03 10:32
|
||||
# @File : project_train.py
|
||||
# @IDE : PyCharm
|
||||
# @desc : 项目巡逻片信息
|
||||
|
||||
from fastapi import Depends
|
||||
from core.dependencies import Paging, QueryParams
|
||||
|
||||
|
||||
class ProjectTrainParams(QueryParams):
|
||||
def __init__(self, params: Paging = Depends()):
|
||||
super().__init__(params)
|
1
apps/business/train/schemas/__init__.py
Normal file
1
apps/business/train/schemas/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .project_train import ProjectTrain, ProjectTrainSimpleOut
|
32
apps/business/train/schemas/project_train.py
Normal file
32
apps/business/train/schemas/project_train.py
Normal file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @version : 1.0
|
||||
# @Create Time : 2025/04/03 10:32
|
||||
# @File : project_train.py
|
||||
# @IDE : PyCharm
|
||||
# @desc : pydantic 模型,用于数据库序列化操作
|
||||
|
||||
from pydantic import BaseModel, Field, ConfigDict
|
||||
from core.data_types import DatetimeStr
|
||||
|
||||
|
||||
class ProjectTrain(BaseModel):
|
||||
project_id: int = Field(..., title="None")
|
||||
train_version: str = Field(..., title="None")
|
||||
train_url: str = Field(..., title="None")
|
||||
train_data: str = Field(..., title="None")
|
||||
weights_id: int = Field(..., title="None")
|
||||
weights_name: str = Field(..., title="None")
|
||||
epochs: int = Field(..., title="None")
|
||||
patience: int = Field(..., title="None")
|
||||
best_pt: str = Field(..., title="None")
|
||||
last_pt: str = Field(..., title="None")
|
||||
user_id: int = Field(..., title="None")
|
||||
|
||||
|
||||
class ProjectTrainSimpleOut(ProjectTrain):
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int = Field(..., title="编号")
|
||||
create_datetime: DatetimeStr = Field(..., title="创建时间")
|
||||
update_datetime: DatetimeStr = Field(..., title="更新时间")
|
51
apps/business/train/views.py
Normal file
51
apps/business/train/views.py
Normal file
@ -0,0 +1,51 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# @version : 1.0
|
||||
# @Create Time : 2025/04/03 10:32
|
||||
# @File : views.py
|
||||
# @IDE : PyCharm
|
||||
# @desc : 路由,视图文件
|
||||
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from fastapi import APIRouter, Depends
|
||||
from . import models, schemas, crud, params
|
||||
from core.dependencies import IdList
|
||||
from apps.vadmin.auth.utils.current import AllUserAuth
|
||||
from utils.response import SuccessResponse
|
||||
from apps.vadmin.auth.utils.validation.auth import Auth
|
||||
from core.database import db_getter
|
||||
|
||||
|
||||
app = APIRouter()
|
||||
|
||||
|
||||
###########################################################
|
||||
# 项目巡逻片信息
|
||||
###########################################################
|
||||
@app.get("/project/train", summary="获取项目巡逻片信息列表", tags=["项目巡逻片信息"])
|
||||
async def get_project_train_list(p: params.ProjectTrainParams = Depends(), auth: Auth = Depends(AllUserAuth())):
|
||||
datas, count = await crud.ProjectTrainDal(auth.db).get_datas(**p.dict(), v_return_count=True)
|
||||
return SuccessResponse(datas, count=count)
|
||||
|
||||
|
||||
@app.post("/project/train", summary="创建项目巡逻片信息", tags=["项目巡逻片信息"])
|
||||
async def create_project_train(data: schemas.ProjectTrain, auth: Auth = Depends(AllUserAuth())):
|
||||
return SuccessResponse(await crud.ProjectTrainDal(auth.db).create_data(data=data))
|
||||
|
||||
|
||||
@app.delete("/project/train", summary="删除项目巡逻片信息", description="硬删除", tags=["项目巡逻片信息"])
|
||||
async def delete_project_train_list(ids: IdList = Depends(), auth: Auth = Depends(AllUserAuth())):
|
||||
await crud.ProjectTrainDal(auth.db).delete_datas(ids=ids.ids, v_soft=False)
|
||||
return SuccessResponse("删除成功")
|
||||
|
||||
|
||||
@app.put("/project/train/{data_id}", summary="更新项目巡逻片信息", tags=["项目巡逻片信息"])
|
||||
async def put_project_train(data_id: int, data: schemas.ProjectTrain, auth: Auth = Depends(AllUserAuth())):
|
||||
return SuccessResponse(await crud.ProjectTrainDal(auth.db).put_data(data_id, data))
|
||||
|
||||
|
||||
@app.get("/project/train/{data_id}", summary="获取项目巡逻片信息信息", tags=["项目巡逻片信息"])
|
||||
async def get_project_train(data_id: int, db: AsyncSession = Depends(db_getter)):
|
||||
schema = schemas.ProjectTrainSimpleOut
|
||||
return SuccessResponse(await crud.ProjectTrainDal(db).get_data(data_id, v_schema=schema))
|
||||
|
Reference in New Issue
Block a user