Удалил всякое не нужное
This commit is contained in:
parent
ee7c78e1c8
commit
527b84554a
@ -0,0 +1,13 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
||||
|
||||
from database.database import Base
|
||||
|
||||
class CSVFile(Base):
|
||||
__tablename__ = "csv_files"
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
user_id: Mapped[int]
|
||||
file_path: Mapped[str]
|
||||
uploaded_at: Mapped[datetime] = mapped_column(default=datetime.utcnow)
|
@ -1,4 +1,6 @@
|
||||
from database.database import new_session, CSVFile
|
||||
from database.database import new_session
|
||||
from database.models.csv_file import CSVFile
|
||||
|
||||
|
||||
class CSVFileRepository:
|
||||
@staticmethod
|
||||
|
@ -1,8 +0,0 @@
|
||||
from database.database import new_session, H5Model
|
||||
class H5ModelRepository:
|
||||
@staticmethod
|
||||
async def add_model(user_id: int, model_path: str):
|
||||
async with new_session() as session:
|
||||
model = H5Model(user_id=user_id, model_path=model_path)
|
||||
session.add(model)
|
||||
await session.commit()
|
@ -1,11 +0,0 @@
|
||||
from database.database import new_session, ModelStatistics
|
||||
from schemas.model_statistics_create import ModelStatisticsCreate
|
||||
|
||||
|
||||
class ModelStatisticsRepository:
|
||||
@staticmethod
|
||||
async def add_statistics(data: ModelStatisticsCreate):
|
||||
async with new_session() as session:
|
||||
stats = ModelStatistics(**data.model_dump())
|
||||
session.add(stats)
|
||||
await session.commit()
|
@ -1,12 +0,0 @@
|
||||
from database.database import new_session, User
|
||||
from schemas.user_create import UserCreate
|
||||
|
||||
|
||||
class UserRepository:
|
||||
@staticmethod
|
||||
async def create_user(data: UserCreate):
|
||||
async with new_session() as session:
|
||||
user = User(username=data.username, password_hash=data.password)
|
||||
session.add(user)
|
||||
await session.commit()
|
||||
return user.id
|
36
fastapi-app-upload/routers/csv_router.py
Normal file
36
fastapi-app-upload/routers/csv_router.py
Normal file
@ -0,0 +1,36 @@
|
||||
import os
|
||||
from fastapi import APIRouter, UploadFile, File, Form, HTTPException
|
||||
from pathlib import Path
|
||||
from database.database import new_session
|
||||
import shutil
|
||||
import pandas as pd
|
||||
from sqlalchemy import select
|
||||
|
||||
from repositories.csv_file_repository import CSVFileRepository
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
UPLOAD_FOLDER_CSV = Path("uploads/csv")
|
||||
UPLOAD_FOLDER_CSV.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
UPLOAD_FOLDER_MODELS = "uploads/models"
|
||||
os.makedirs(UPLOAD_FOLDER_MODELS, exist_ok=True)
|
||||
|
||||
# Обновлённый метод для загрузки CSV файла
|
||||
@router.post("/upload/csv/")
|
||||
async def upload_csv(user_id: int = Form(...), file: UploadFile = File(...)):
|
||||
|
||||
# Формируем путь для сохранения
|
||||
user_folder = UPLOAD_FOLDER_CSV / str(user_id)
|
||||
user_folder.mkdir(parents=True, exist_ok=True)
|
||||
file_path = user_folder / file.filename
|
||||
|
||||
# Сохраняем файл
|
||||
with open(file_path, "wb") as buffer:
|
||||
shutil.copyfileobj(file.file, buffer)
|
||||
|
||||
# Сохраняем данные в БД, заменяя обратные слэши на прямые
|
||||
normalized_path = str(file_path).replace("\\", "/")
|
||||
await CSVFileRepository.upload_file(user_id=user_id, file_path=normalized_path)
|
||||
return {"message": "CSV файл загружен", "file_path": normalized_path}
|
||||
|
@ -1,7 +0,0 @@
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
# H5ModelCreate: для добавления модели
|
||||
class H5ModelCreate(BaseModel):
|
||||
path_model: str
|
@ -1,10 +0,0 @@
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
# ModelStatisticsCreate: для сохранения статистики модели
|
||||
class ModelStatisticsCreate(BaseModel):
|
||||
id_model: int
|
||||
accuracy: float
|
||||
loss: float
|
||||
created_at: Optional[datetime] = None
|
@ -1,8 +0,0 @@
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
# UserCreate: для создания пользователя
|
||||
class UserCreate(BaseModel):
|
||||
username: str
|
||||
password: str
|
Loading…
x
Reference in New Issue
Block a user