Files
DevOpsLab/app/api/v1/endpoints/stats.py
Сергей Антропов 1fbf9185a2 feat: добавлена пометка типа операции (Build/Push) в истории сборок Dockerfile
- Добавлена колонка 'Тип' во все таблицы истории сборок
- Для push операций отображается registry вместо платформ
- Сохранение пользователя при создании push лога
- Исправлена ошибка с logger в push_docker_image endpoint
- Улучшено отображение истории сборок с визуальными индикаторами
2026-02-15 22:59:02 +03:00

70 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
API endpoints для статистики
Автор: Сергей Антропов
Сайт: https://devops.org.ru
"""
from fastapi import APIRouter
from fastapi.responses import HTMLResponse
from pathlib import Path
from app.core.config import settings
router = APIRouter()
@router.get("/")
async def get_stats():
"""Общая статистика"""
roles_dir = settings.PROJECT_ROOT / "roles"
roles_count = 0
if roles_dir.exists():
roles = [d for d in roles_dir.iterdir()
if d.is_dir() and d.name != "deploy.yml"]
roles_count = len(roles)
return {
"roles": roles_count,
"tests": 0, # TODO: из БД
"success": 0, # TODO: из БД
"docker": 0 # TODO: из Docker API
}
@router.get("/roles", response_class=HTMLResponse)
async def get_roles_count():
"""Количество ролей"""
try:
roles_dir = settings.PROJECT_ROOT / "roles"
if not roles_dir.exists():
return "0"
# Подсчет ролей (исключая deploy.yml)
roles = [d for d in roles_dir.iterdir()
if d.is_dir() and d.name != "deploy.yml" and not d.name.startswith(".")]
return str(len(roles))
except Exception as e:
# В случае ошибки возвращаем 0
return "0"
@router.get("/tests", response_class=HTMLResponse)
async def get_tests_count():
"""Количество тестов"""
# TODO: Реализовать через БД
return "0"
@router.get("/success", response_class=HTMLResponse)
async def get_success_count():
"""Количество успешных тестов"""
# TODO: Реализовать через БД
return "0"
@router.get("/docker", response_class=HTMLResponse)
async def get_docker_count():
"""Количество Docker образов"""
# TODO: Реализовать через Docker API
return "0"