This commit is contained in:
HuangHai
2026-01-19 13:56:47 +08:00
parent 219cd5c220
commit b20b778f5d
10 changed files with 242 additions and 132 deletions

View File

@@ -174,7 +174,7 @@ def _set_column_widths(ws, widths: dict[int, float]):
ws.column_dimensions[get_column_letter(col_idx)].width = width
class DorisExcelExporter:
class DorisExcelExporter:
def __init__(self, db_url: str):
self.db = Db(db_url=db_url)
@@ -188,7 +188,7 @@ class DorisExcelExporter:
if getattr(self.db, "engine", None):
await self.db.engine.dispose()
async def fetch_current_station_rows(self, operator: str) -> List[Dict[str, Any]]:
async def fetch_current_station_rows(self, operator: str) -> List[Dict[str, Any]]:
sql = """
SELECT
p.station_hash,
@@ -214,7 +214,32 @@ class DorisExcelExporter:
WHERE p.is_current = 1 AND p.operator = :operator
ORDER BY p.station_name
"""
return await self.db.find(sql, {"operator": operator})
return await self.db.find(sql, {"operator": operator})
def extract_hourly_prices_from_schedule(schedule_json: Any) -> List[Optional[float]]:
items = _parse_schedule(schedule_json)
series: List[Optional[float]] = [None] * 24
if not items:
return series
for idx, item in enumerate(items):
if not isinstance(item, dict):
continue
price = _to_float(item.get("price_kwh") if "price_kwh" in item else item.get("price"))
if price is None:
continue
start = item.get("start") or item.get("begin") or item.get("start_time")
h = None
if isinstance(start, str) and ":" in start:
try:
h = int(start.split(":", 1)[0])
except Exception:
h = None
if h is None:
h = idx
if 0 <= h < 24:
series[h] = float(price)
return series
def _build_station_sheet(ws, row: Dict[str, Any]):

Binary file not shown.