fix
This commit is contained in:
@@ -270,6 +270,18 @@ export async function getSitePrices(siteId: number, date: string): Promise<SiteE
|
||||
return Array.isArray(data) ? data : []
|
||||
}
|
||||
|
||||
export async function getSitePricesSlotsRange(
|
||||
siteId: number,
|
||||
fromIso: string,
|
||||
toIso: string,
|
||||
): Promise<SiteEffectivePriceRowDto[]> {
|
||||
const { data } = await client.get<{ slots?: SiteEffectivePriceRowDto[] }>(
|
||||
`/sites/${siteId}/prices/slots`,
|
||||
{ params: { from: fromIso, to: toIso }, timeout: 60_000 },
|
||||
)
|
||||
return Array.isArray(data?.slots) ? data.slots : []
|
||||
}
|
||||
|
||||
export type ForecastPvIntervalRow = {
|
||||
interval_start: string
|
||||
power_w?: number | string | null
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||
import {
|
||||
getCurrentPlan,
|
||||
getForecastPvSlotsRangeCorrected,
|
||||
getSitePricesSlotsRange,
|
||||
} from '../api/backend'
|
||||
import { getJson } from '../api/postgrest'
|
||||
import {
|
||||
@@ -20,7 +21,6 @@ import type {
|
||||
HeatPumpLatestRow,
|
||||
ModeLogRecentRow,
|
||||
SiteStatusRow,
|
||||
SiteEffectivePriceRow,
|
||||
Telemetry15m7dRow,
|
||||
} from '../types/ems'
|
||||
import type { PlanningIntervalDto } from '../types/plan'
|
||||
@@ -220,15 +220,12 @@ export function useDashboardData(siteId: number | null) {
|
||||
limit: '200',
|
||||
}),
|
||||
getJson<HeatPumpLatestRow[]>('/vw_latest_heat_pump', { site_id: `eq.${siteId}` }),
|
||||
// Ceny bereme v jednom range dotazu přes PostgREST view (místo N× /api/v1/sites/{id}/prices?date=...).
|
||||
// Okno: [windowStart, windowStart + TOTAL_SLOTS) pro mapování na sloty.
|
||||
getJson<SiteEffectivePriceRow[]>('/vw_site_effective_price', {
|
||||
site_id: `eq.${siteId}`,
|
||||
interval_start: `gte.${new Date(windowStart).toISOString()}`,
|
||||
interval_end: `lt.${new Date(windowStart + TOTAL_SLOTS * SLOT_MS).toISOString()}`,
|
||||
order: 'interval_start.asc',
|
||||
limit: String(TOTAL_SLOTS + 32),
|
||||
}),
|
||||
// Ceny bereme přes FastAPI range endpoint (PostgREST /rest je u vás chráněné → 401).
|
||||
getSitePricesSlotsRange(
|
||||
siteId,
|
||||
new Date(windowStart).toISOString(),
|
||||
new Date(windowStart + TOTAL_SLOTS * SLOT_MS).toISOString(),
|
||||
),
|
||||
])
|
||||
|
||||
const status = Array.isArray(statusArr) && statusArr[0] ? statusArr[0]! : null
|
||||
@@ -242,7 +239,7 @@ export function useDashboardData(siteId: number | null) {
|
||||
}
|
||||
|
||||
const priceBySlot = new Map<string, { buy: number | null; sell: number | null }>()
|
||||
const flatPrices: SiteEffectivePriceRow[] = Array.isArray(priceRows) ? priceRows : []
|
||||
const flatPrices = Array.isArray(priceRows) ? priceRows : []
|
||||
for (const r of flatPrices) {
|
||||
const k = slotTimeKey(new Date(r.interval_start).getTime())
|
||||
priceBySlot.set(k, {
|
||||
|
||||
Reference in New Issue
Block a user