fix telemtrie na dahsbaordu (15min misto 1h)
This commit is contained in:
@@ -22,7 +22,7 @@ import type {
|
||||
HeatPumpLatestRow,
|
||||
ModeLogRecentRow,
|
||||
SiteStatusRow,
|
||||
TelemetryHourly7dRow,
|
||||
Telemetry15m7dRow,
|
||||
} from '../types/ems'
|
||||
import type { PlanningIntervalDto } from '../types/plan'
|
||||
|
||||
@@ -56,13 +56,6 @@ function buildLiveMetrics(
|
||||
}
|
||||
}
|
||||
|
||||
function hourFloorUtcMs(ms: number): number {
|
||||
const d = new Date(ms)
|
||||
d.setUTCMinutes(0, 0, 0)
|
||||
d.setUTCSeconds(0, 0)
|
||||
return d.getTime()
|
||||
}
|
||||
|
||||
/** Klíč hodiny v Europe/Prague (pro shodu s vw_audit_today_hourly.hour_local). */
|
||||
function pragueHourKey(ms: number): string {
|
||||
return new Intl.DateTimeFormat('sv-SE', {
|
||||
@@ -198,7 +191,7 @@ export function useDashboardData(siteId: number | null) {
|
||||
const [
|
||||
planMaybe,
|
||||
statusArr,
|
||||
hourly7d,
|
||||
telemetry15m7d,
|
||||
auditHourly,
|
||||
modeLog,
|
||||
hpArr,
|
||||
@@ -211,10 +204,10 @@ export function useDashboardData(siteId: number | null) {
|
||||
throw e
|
||||
}),
|
||||
getJson<SiteStatusRow[]>('/vw_site_status', { site_id: `eq.${siteId}` }),
|
||||
getJson<TelemetryHourly7dRow[]>('/vw_telemetry_hourly_7d', {
|
||||
getJson<Telemetry15m7dRow[]>('/vw_telemetry_15m_7d', {
|
||||
site_id: `eq.${siteId}`,
|
||||
order: 'hour.asc',
|
||||
limit: '500',
|
||||
order: 'slot_start.asc',
|
||||
limit: '1000',
|
||||
}),
|
||||
getJson<AuditTodayHourlyRow[]>('/vw_audit_today_hourly', {
|
||||
site_id: `eq.${siteId}`,
|
||||
@@ -297,10 +290,10 @@ export function useDashboardData(siteId: number | null) {
|
||||
}
|
||||
setForecastWeek(forecastDays)
|
||||
|
||||
const hourlyMap = new Map<number, TelemetryHourly7dRow>()
|
||||
if (Array.isArray(hourly7d)) {
|
||||
for (const r of hourly7d) {
|
||||
hourlyMap.set(new Date(r.hour).getTime(), r)
|
||||
const telemetryBySlot = new Map<string, Telemetry15m7dRow>()
|
||||
if (Array.isArray(telemetry15m7d)) {
|
||||
for (const r of telemetry15m7d) {
|
||||
telemetryBySlot.set(slotTimeKey(new Date(r.slot_start).getTime()), r)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +314,7 @@ export function useDashboardData(siteId: number | null) {
|
||||
const base = emptySlot(iso)
|
||||
const k = slotTimeKey(startMs)
|
||||
|
||||
const tel = hourlyMap.get(hourFloorUtcMs(startMs))
|
||||
const tel = telemetryBySlot.get(k)
|
||||
if (tel) {
|
||||
base.pv_power_w = tel.avg_pv_w ?? base.pv_power_w
|
||||
base.battery_power_w = tel.avg_battery_w ?? base.battery_power_w
|
||||
@@ -373,6 +366,12 @@ export function useDashboardData(siteId: number | null) {
|
||||
})
|
||||
}
|
||||
|
||||
const liveSoc = parseNum(status?.battery_soc_percent)
|
||||
if (liveSoc != null && nIdx >= 0 && nIdx < built.length) {
|
||||
const cur = built[nIdx]!
|
||||
built[nIdx] = { ...cur, soc_actual_pct: liveSoc }
|
||||
}
|
||||
|
||||
const neg: NegPriceItem[] = []
|
||||
const nowMs = Date.now()
|
||||
for (const r of flatPrices) {
|
||||
|
||||
Reference in New Issue
Block a user