After Graduate Update
This commit is contained in:
parent
b92a91ab37
commit
c6917dd85e
69 changed files with 7540 additions and 0 deletions
43
ressult/app/routes/calculations.py
Normal file
43
ressult/app/routes/calculations.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# app/routes/calculations.py
|
||||
"""
|
||||
Маршруты API для расчетов
|
||||
Соответствует модулю 4 ТЗ по расчету материалов
|
||||
"""
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from app.models import MaterialCalculationRequest, MaterialCalculationResponse
|
||||
import math
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.post("/calculate-material", response_model=MaterialCalculationResponse)
|
||||
async def calculate_material(request: MaterialCalculationRequest):
|
||||
"""
|
||||
Расчет количества материала для производства продукции
|
||||
Соответствует модулю 4 ТЗ
|
||||
"""
|
||||
try:
|
||||
# Валидация входных параметров
|
||||
if (request.param1 <= 0 or request.param2 <= 0 or
|
||||
request.product_coeff <= 0 or request.defect_percent < 0):
|
||||
return MaterialCalculationResponse(
|
||||
material_quantity=-1,
|
||||
status="error: invalid parameters"
|
||||
)
|
||||
|
||||
# Расчет количества материала на одну единицу продукции
|
||||
material_per_unit = request.param1 * request.param2 * request.product_coeff
|
||||
|
||||
# Расчет общего количества материала с учетом брака
|
||||
total_material = material_per_unit * request.quantity
|
||||
total_material_with_defect = total_material * (1 + request.defect_percent / 100)
|
||||
|
||||
# Округление до целого числа в большую сторону
|
||||
material_quantity = math.ceil(total_material_with_defect)
|
||||
|
||||
return MaterialCalculationResponse(
|
||||
material_quantity=material_quantity,
|
||||
status="success"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
Loading…
Add table
Add a link
Reference in a new issue