SuperAI_Forecast / backend /catalog_utils.py
Thang6822
Update Kronos Platform v6.1.0: Complete backend refactor and frontend UI optimization
a721dfa
Raw
History Blame
1.72 kB
from __future__ import annotations
from typing import Any, Dict, Iterable, List, Mapping
def build_symbols_catalog(
symbols: Mapping[str, Any],
supported_intervals: List[str],
) -> Dict[str, Any]:
all_results = list(symbols.values())
grouped: Dict[str, List[Dict[str, Any]]] = {}
for symbol_config in all_results:
entry = {
"symbol": symbol_config.symbol,
"label": symbol_config.label,
"label_en": symbol_config.label_en,
"category": symbol_config.category,
"description": symbol_config.description,
"sources": list(symbol_config.mappings.keys()),
}
grouped.setdefault(symbol_config.category, []).append(entry)
return {
"total": len(all_results),
"categories": sorted(grouped.keys()),
"symbols": [
{
"symbol": symbol_config.symbol,
"label": symbol_config.label,
"label_en": symbol_config.label_en,
"category": symbol_config.category,
"sources": list(symbol_config.mappings.keys()),
}
for symbol_config in all_results
],
"symbols_by_category": grouped,
"supported_intervals": supported_intervals,
}
def filter_symbols_catalog(catalog: Dict[str, Any], category: str) -> Dict[str, Any]:
category_symbols = catalog["symbols_by_category"].get(category, [])
return {
"total": len(category_symbols),
"categories": catalog["categories"],
"symbols": category_symbols,
"symbols_by_category": {category: category_symbols},
"supported_intervals": catalog["supported_intervals"],
}