New endpoints: - GET /api/v1/version — returns VERSIONS.json (no auth required) For field engineers to check platform version from login page - GET /api/v1/kpi/solar — returns PR, self-consumption rate, equivalent utilization hours, and daily revenue Handles station-level vs device-level data deduplication Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import os
|
|
import json
|
|
from fastapi import APIRouter
|
|
|
|
router = APIRouter(prefix="/version", tags=["版本信息"])
|
|
|
|
|
|
@router.get("")
|
|
async def get_version():
|
|
"""Return platform version information for display on login/dashboard"""
|
|
# Read VERSIONS.json from project root (2 levels up from backend/)
|
|
backend_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
# Try multiple paths for VERSIONS.json
|
|
for path in [
|
|
os.path.join(backend_dir, "VERSIONS.json"), # standalone
|
|
os.path.join(backend_dir, "..", "VERSIONS.json"), # inside core/ subtree
|
|
os.path.join(backend_dir, "..", "..", "VERSIONS.json"), # customer project root
|
|
]:
|
|
if os.path.exists(path):
|
|
with open(path, 'r', encoding='utf-8') as f:
|
|
versions = json.load(f)
|
|
return versions
|
|
|
|
# Fallback: read VERSION file
|
|
version_file = os.path.join(backend_dir, "VERSION")
|
|
version = "unknown"
|
|
if os.path.exists(version_file):
|
|
with open(version_file, 'r') as f:
|
|
version = f.read().strip()
|
|
|
|
return {"project_version": version, "project": "ems-core"}
|