TCPDashboard/utils/timeframe_utils.py
Vasily.onl dbe58e5cef Remove deprecated app_new.py and consolidate main application logic into main.py
- Deleted `app_new.py`, which was previously the main entry point for the dashboard application, to streamline the codebase.
- Consolidated the application initialization and callback registration logic into `main.py`, enhancing modularity and maintainability.
- Updated the logging and error handling practices in `main.py` to ensure consistent application behavior and improved debugging capabilities.

These changes simplify the application structure, aligning with project standards for modularity and maintainability.
2025-06-11 18:36:34 +08:00

63 lines
2.6 KiB
Python

import json
import os
import logging
logger = logging.getLogger(__name__)
def load_timeframe_options():
"""Loads timeframe options from a JSON file.
Returns:
list: A list of dictionaries, each representing a timeframe option.
"""
try:
# Construct path relative to the workspace root
# Assuming utils is at TCPDashboard/utils
# and config/options is at TCPDashboard/config/options
base_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
file_path = os.path.join(base_dir, 'config/options/timeframe_options.json')
with open(file_path, 'r', encoding='utf-8') as f:
return json.load(f)
except FileNotFoundError:
logger.error(f"Timeframe options file not found at {file_path}. Using default timeframes.")
return [
{'label': '1 Second', 'value': '1s'},
{'label': '5 Seconds', 'value': '5s'},
{'label': '15 Seconds', 'value': '15s'},
{'label': '30 Seconds', 'value': '30s'},
{'label': '1 Minute', 'value': '1m'},
{'label': '5 Minutes', 'value': '5m'},
{'label': '15 Minutes', 'value': '15m'},
{'label': '1 Hour', 'value': '1h'},
{'label': '4 Hours', 'value': '4h'},
{'label': '1 Day', 'value': '1d'},
]
except json.JSONDecodeError:
logger.error(f"Error decoding JSON from {file_path}. Using default timeframes.")
return [
{'label': '1 Second', 'value': '1s'},
{'label': '5 Seconds', 'value': '5s'},
{'label': '15 Seconds', 'value': '15s'},
{'label': '30 Seconds', 'value': '30s'},
{'label': '1 Minute', 'value': '1m'},
{'label': '5 Minutes', 'value': '5m'},
{'label': '15 Minutes', 'value': '15m'},
{'label': '1 Hour', 'value': '1h'},
{'label': '4 Hours', 'value': '4h'},
{'label': '1 Day', 'value': '1d'},
]
except Exception as e:
logger.error(f"An unexpected error occurred while loading timeframes: {e}. Using default timeframes.")
return [
{'label': '1 Second', 'value': '1s'},
{'label': '5 Seconds', 'value': '5s'},
{'label': '15 Seconds', 'value': '15s'},
{'label': '30 Seconds', 'value': '30s'},
{'label': '1 Minute', 'value': '1m'},
{'label': '5 Minutes', 'value': '5m'},
{'label': '15 Minutes', 'value': '15m'},
{'label': '1 Hour', 'value': '1h'},
{'label': '4 Hours', 'value': '4h'},
{'label': '1 Day', 'value': '1d'},
]