myio-js-library 0.1.579 → 0.1.580

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -989,7 +989,7 @@ module.exports = __toCommonJS(src_exports);
989
989
  // package.json
990
990
  var package_default = {
991
991
  name: "myio-js-library",
992
- version: "0.1.579",
992
+ version: "0.1.580",
993
993
  description: "A clean, standalone JS SDK for MYIO projects",
994
994
  license: "MIT",
995
995
  repository: "github:gh-myio/myio-js-library",
@@ -33874,12 +33874,26 @@ var DEFAULT_GRANULARITY_OPTIONS = [
33874
33874
  { value: "1h", title: "Hora" },
33875
33875
  { value: "1d", title: "Dia" }
33876
33876
  ];
33877
+ var TEMPERATURE_GRANULARITY_OPTIONS = [
33878
+ { value: "15m", title: "15 minutos" },
33879
+ { value: "30m", title: "30 minutos" },
33880
+ { value: "1h", title: "Hora" },
33881
+ { value: "1d", title: "Dia" }
33882
+ ];
33883
+ function granularityMinutes(g) {
33884
+ return g === "15m" ? 15 : g === "30m" ? 30 : g === "1h" ? 60 : 1440;
33885
+ }
33877
33886
 
33878
33887
  // src/components/granularity-selector/createGranularitySelector.ts
33879
33888
  var P = GRANULARITY_SELECTOR_CSS_PREFIX;
33880
- var DEFAULT_TITLES = { "1h": "Hora", "1d": "Dia" };
33889
+ var DEFAULT_TITLES = {
33890
+ "15m": "15 minutos",
33891
+ "30m": "30 minutos",
33892
+ "1h": "Hora",
33893
+ "1d": "Dia"
33894
+ };
33881
33895
  function isGranularity(v) {
33882
- return v === "1h" || v === "1d";
33896
+ return v === "15m" || v === "30m" || v === "1h" || v === "1d";
33883
33897
  }
33884
33898
  function createGranularitySelector(container, params = {}) {
33885
33899
  injectGranularitySelectorStyles();
@@ -35215,7 +35229,10 @@ var EnergyModalView = class {
35215
35229
  value: this.currentGranularity,
35216
35230
  themeMode: this.currentTheme
35217
35231
  },
35218
- onChange: (granularity) => this.setGranularity(granularity)
35232
+ // Opções default (1h | 1d) — 15m/30m só existem nos relatórios de temperatura
35233
+ onChange: (granularity) => {
35234
+ if (granularity === "1h" || granularity === "1d") this.setGranularity(granularity);
35235
+ }
35219
35236
  });
35220
35237
  dbg2("[EnergyModalView] [RFC-0097] Granularity selector initialized with:", this.currentGranularity);
35221
35238
  }
@@ -37527,7 +37544,7 @@ var DeviceReportModal = class {
37527
37544
  const domain = params.domain || "energy";
37528
37545
  this.domainConfig = DOMAIN_CONFIG[domain];
37529
37546
  this.granularity = params.granularity === "1h" ? "1h" : "1d";
37530
- this.energyFetcher = params.fetcher || createDefaultEnergyFetcher(params, () => this.granularity);
37547
+ this.energyFetcher = params.fetcher || createDefaultEnergyFetcher(params, () => this.apiGranularity);
37531
37548
  }
37532
37549
  modal;
37533
37550
  authClient;
@@ -37538,6 +37555,8 @@ var DeviceReportModal = class {
37538
37555
  dateRangePicker = null;
37539
37556
  sortState = { key: null, direction: "asc" };
37540
37557
  domainConfig;
37558
+ // Temperatura: 15m | 30m | 1h | 1d (15/30 min agregados no cliente a partir dos blocos de
37559
+ // 15 min que o Ingestion devolve com granularity=1h). Demais domínios: 1h | 1d.
37541
37560
  granularity = "1d";
37542
37561
  // Granularity selector (shared component — same pill 1h|1d as EnergyModal/AllReportModal).
37543
37562
  granularitySelector = null;
@@ -37549,6 +37568,25 @@ var DeviceReportModal = class {
37549
37568
  participationChart = null;
37550
37569
  // Período do último load — alimenta os headers dos exports PDF/XLS.
37551
37570
  exportPeriod = null;
37571
+ /** Linhas intradiárias (15 min, 30 min ou hora) — tudo que não é '1d' */
37572
+ get isIntraday() {
37573
+ return this.granularity !== "1d";
37574
+ }
37575
+ /** O Ingestion só aceita 1h|1d: 15/30 min buscam 1h (blocos de 15 min) e agregam aqui */
37576
+ get apiGranularity() {
37577
+ return this.isIntraday ? "1h" : "1d";
37578
+ }
37579
+ /** Rótulo da linha intradiária: "Hora" (1h) ou "Horário" (15/30 min) */
37580
+ get intradayLabel() {
37581
+ return this.granularity === "1h" ? "Hora" : "Hor\xE1rio";
37582
+ }
37583
+ /** Rótulo legível da granularidade (CSV/avisos) */
37584
+ get granularityText() {
37585
+ return { "15m": "15 minutos", "30m": "30 minutos", "1h": "Hora", "1d": "Dia" }[this.granularity];
37586
+ }
37587
+ get isTemperatureDomain() {
37588
+ return (this.params.domain || "energy") === "temperature";
37589
+ }
37552
37590
  // Header: "Relatório - <identifier> - <label>" + nome do device (sutil, com copiar).
37553
37591
  // O customer já aparece no footer premium. Texto escapado — o shell usa innerHTML no título.
37554
37592
  buildHeaderTitleHTML() {
@@ -37771,13 +37809,16 @@ var DeviceReportModal = class {
37771
37809
  // sem label interno (o form group acima já tem "Granularidade").
37772
37810
  label: "",
37773
37811
  themeMode: this.params.ui?.theme === "dark" ? "dark" : "light",
37812
+ // Temperatura: 15m | 30m | 1h | 1d; demais domínios: 1h | 1d (default do componente)
37813
+ ...this.isTemperatureDomain ? { options: TEMPERATURE_GRANULARITY_OPTIONS } : {},
37774
37814
  tooltip: {
37775
37815
  enabled: true,
37776
37816
  title: "Granularidade",
37777
- text: "Em <b>Dia</b>, a tabela traz uma linha por dia; em <b>Hora</b>, uma linha por hora e o seletor de per\xEDodo ganha hora/minuto. KPIs e gr\xE1fico recalculam conforme a granularidade."
37817
+ text: this.isTemperatureDomain ? "Em <b>Dia</b>, uma linha por dia (m\xE9dia do dia); em <b>15m</b>, <b>30m</b> e <b>1h</b>, uma linha por janela (m\xE9dia da janela) e o seletor de per\xEDodo ganha hora/minuto. KPIs e gr\xE1fico recalculam conforme a granularidade." : "Em <b>Dia</b>, a tabela traz uma linha por dia; em <b>Hora</b>, uma linha por hora e o seletor de per\xEDodo ganha hora/minuto. KPIs e gr\xE1fico recalculam conforme a granularidade."
37778
37818
  }
37779
37819
  },
37780
37820
  onChange: async (value) => {
37821
+ if (!this.isTemperatureDomain && value !== "1h" && value !== "1d") return;
37781
37822
  this.granularity = value;
37782
37823
  await this.rebuildDateRangePicker(dateRangeInput);
37783
37824
  this.resetAfterGranularityChange();
@@ -37796,7 +37837,7 @@ var DeviceReportModal = class {
37796
37837
  if (tableContainer) {
37797
37838
  tableContainer.innerHTML = `
37798
37839
  <div style="text-align: center; padding: 40px; color: var(--myio-text-muted);">
37799
- Granularidade alterada para <strong>${this.granularity}</strong>. Clique em "Carregar" para atualizar os dados.
37840
+ Granularidade alterada para <strong>${this.granularityText}</strong>. Clique em "Carregar" para atualizar os dados.
37800
37841
  </div>
37801
37842
  `;
37802
37843
  }
@@ -37840,7 +37881,7 @@ var DeviceReportModal = class {
37840
37881
  presetEnd,
37841
37882
  // Ciclo de rateio (dia D → dia D do mês seguinte) tem até 32 dias corridos (ex.: 15/08→15/09)
37842
37883
  maxRangeDays: 32,
37843
- includeTime: this.granularity === "1h",
37884
+ includeTime: this.isIntraday,
37844
37885
  timePrecision: "minute",
37845
37886
  parentEl: this.modal.element,
37846
37887
  onApply: ({ startISO, endISO }) => {
@@ -37859,7 +37900,7 @@ var DeviceReportModal = class {
37859
37900
  // Contrato do getDates(): hora LOCAL + offset (YYYY-MM-DDTHH:mm:ss±HH:MM) — os 10
37860
37901
  // primeiros caracteres são o dia exibido e os 6 últimos, o offset.
37861
37902
  resolveQueryWindow(range) {
37862
- if (this.granularity === "1h" || !range.startISO || !range.endISO) return range;
37903
+ if (this.isIntraday || !range.startISO || !range.endISO) return range;
37863
37904
  const day = (iso) => iso.slice(0, 10);
37864
37905
  const offset = (iso) => iso.slice(-6);
37865
37906
  return {
@@ -37899,7 +37940,8 @@ var DeviceReportModal = class {
37899
37940
  ingestionId: this.params.ingestionId,
37900
37941
  startISO,
37901
37942
  endISO,
37902
- granularity: this.granularity
37943
+ // API só conhece 1h|1d — 15/30 min vêm do 1h e são agregados em processApiResponse
37944
+ granularity: this.apiGranularity
37903
37945
  });
37904
37946
  this.data = this.processApiResponse(apiResponse, dateRange);
37905
37947
  this.renderSummary();
@@ -37925,7 +37967,7 @@ var DeviceReportModal = class {
37925
37967
  }
37926
37968
  processApiResponse(apiResponse, dateRange) {
37927
37969
  const dataArray = Array.isArray(apiResponse) ? apiResponse : apiResponse.data || [];
37928
- const isHourly = this.granularity === "1h";
37970
+ const isHourly = this.isIntraday;
37929
37971
  if (!Array.isArray(dataArray) || dataArray.length === 0) {
37930
37972
  console.warn("[DeviceReportModal] API returned empty or invalid response, zero-filling date range");
37931
37973
  if (isHourly) return [];
@@ -37950,7 +37992,7 @@ var DeviceReportModal = class {
37950
37992
  }
37951
37993
  if (isHourly) {
37952
37994
  const isAvg = this.domainConfig.summaryType === "average";
37953
- const HOUR = 3600 * 1e3;
37995
+ const HOUR = granularityMinutes(this.granularity) * 60 * 1e3;
37954
37996
  const byHour = /* @__PURE__ */ new Map();
37955
37997
  consumption.forEach((item) => {
37956
37998
  if (!item.timestamp || item.value == null) return;
@@ -38020,7 +38062,7 @@ var DeviceReportModal = class {
38020
38062
  computeKpis() {
38021
38063
  const fmt2 = this.domainConfig.formatter;
38022
38064
  const unit = this.domainConfig.unit;
38023
- const isHourly = this.granularity === "1h";
38065
+ const isHourly = this.isIntraday;
38024
38066
  const isTemperature = this.domainConfig.summaryType === "average";
38025
38067
  const total = this.calculateTotal();
38026
38068
  const rows = this.validRows;
@@ -38037,7 +38079,7 @@ var DeviceReportModal = class {
38037
38079
  null
38038
38080
  );
38039
38081
  const zeroCount = this.data.filter((r) => r.consumption <= 0).length;
38040
- const rowLabel = isHourly ? "Hora" : "Dia";
38082
+ const rowLabel = isHourly ? this.intradayLabel : "Dia";
38041
38083
  let perDay;
38042
38084
  if (isTemperature) {
38043
38085
  const byDay = /* @__PURE__ */ new Map();
@@ -38076,7 +38118,7 @@ var DeviceReportModal = class {
38076
38118
  kpis.push({ value: String(zeroCount), label: isHourly ? "Horas sem Consumo" : "Dias sem Consumo" });
38077
38119
  } else {
38078
38120
  const noData = this.data.length - rows.length;
38079
- if (noData > 0) kpis.push({ value: String(noData), label: isHourly ? "Horas sem Leitura" : "Dias sem Leitura" });
38121
+ if (noData > 0) kpis.push({ value: String(noData), label: isHourly ? `${this.intradayLabel}s sem Leitura` : "Dias sem Leitura" });
38080
38122
  }
38081
38123
  return kpis;
38082
38124
  }
@@ -38098,7 +38140,7 @@ var DeviceReportModal = class {
38098
38140
  // Temperatura (painel direito): ranking em barras — 1d = dias mais quentes (média do dia);
38099
38141
  // 1h = horas mais quentes (top 24). Escala comum + faixa ideal sombreada (padrão AllReport).
38100
38142
  renderTemperatureRanking(container) {
38101
- const isHourly = this.granularity === "1h";
38143
+ const isHourly = this.isIntraday;
38102
38144
  const valid = this.validRows;
38103
38145
  if (!valid.length) {
38104
38146
  container.innerHTML = `<div style="border:1px dashed var(--myio-border,#e5e7eb);border-radius:10px;padding:32px 16px;text-align:center;font-size:13px;color:var(--myio-text-muted,#6b7280);">Sem leituras no per\xEDodo</div>`;
@@ -38125,7 +38167,7 @@ var DeviceReportModal = class {
38125
38167
  <span style="text-align:right;font-variant-numeric:tabular-nums;font-weight:600;">${r ? this.domainConfig.formatter(r.consumption) : "\u2014"}</span>
38126
38168
  </div>`;
38127
38169
  const unit = this.domainConfig.unit;
38128
- const title = isHourly ? `${this.domainConfig.rankingHourTitle}${ranked.length > TOP_HOURS ? ` (top ${TOP_HOURS})` : ""}` : this.domainConfig.rankingDayTitle;
38170
+ const title = isHourly ? `${this.intradayRankingTitle()}${ranked.length > TOP_HOURS ? ` (top ${TOP_HOURS})` : ""}` : this.domainConfig.rankingDayTitle;
38129
38171
  container.innerHTML = `
38130
38172
  <div style="border:1px solid var(--myio-border,#e5e7eb);border-radius:10px;padding:12px 14px;max-height:620px;overflow-y:auto;">
38131
38173
  <div style="font-weight:700;font-size:14px;margin-bottom:2px;">${title}</div>
@@ -38136,6 +38178,12 @@ var DeviceReportModal = class {
38136
38178
  ${noData.map((r) => line(this.formatDate(r.date), null)).join("")}
38137
38179
  </div>`;
38138
38180
  }
38181
+ // "Horas mais quentes" (1h) / "Horários mais quentes (15 min)" (15/30 min)
38182
+ intradayRankingTitle() {
38183
+ const base = this.domainConfig.rankingHourTitle || "";
38184
+ if (this.granularity === "1h") return base;
38185
+ return `${base.replace(/^Horas/, "Hor\xE1rios")} (${this.granularityText})`;
38186
+ }
38139
38187
  updateDayChart() {
38140
38188
  const container = document.getElementById("participation-chart-container");
38141
38189
  if (!container) return;
@@ -38189,7 +38237,7 @@ var DeviceReportModal = class {
38189
38237
  <thead style="position: sticky; top: 0; background: var(--myio-bg); z-index: 1;">
38190
38238
  <tr>
38191
38239
  <th style="cursor: pointer;" data-sort="date">
38192
- ${this.granularity === "1h" ? "Data/Hora" : "Data"}
38240
+ ${this.isIntraday ? "Data/Hora" : "Data"}
38193
38241
  <span style="margin-left: 4px; opacity: ${this.sortState.key === "date" ? "1" : "0.5"};">${getSortIndicator("date")}</span>
38194
38242
  </th>
38195
38243
  <th style="cursor: pointer; text-align: right;" data-sort="consumption">
@@ -38272,16 +38320,16 @@ var DeviceReportModal = class {
38272
38320
  ...isTemp && off !== 0 ? [["Offset aplicado (\xB0C)", this.domainConfig.formatter(off), ""]] : [],
38273
38321
  ...this.resolveCustomerName() ? [["Cliente", this.resolveCustomerName(), ""]] : [],
38274
38322
  ...p?.startISO ? [["Per\xEDodo", `${fmtD(p.startISO)} \u2014 ${fmtD(p.endISO)}`, ""]] : [],
38275
- ["Granularidade", this.granularity === "1h" ? "Hora" : "Dia", ""],
38323
+ ["Granularidade", this.granularityText, ""],
38276
38324
  ["DATA EMISS\xC3O", timestamp, ""],
38277
38325
  [],
38278
38326
  ...this.computeKpis().map((k) => [k.label, k.value, k.sub || ""]),
38279
38327
  [],
38280
- [this.granularity === "1h" ? "Data/Hora" : "Data", this.domainConfig.label, ""],
38328
+ [this.isIntraday ? "Data/Hora" : "Data", this.domainConfig.label, ""],
38281
38329
  ...this.data.map((row) => [this.formatDate(row.date), row.noData ? "Sem leitura" : this.domainConfig.formatter(row.consumption)])
38282
38330
  ];
38283
38331
  const csvContent = toCsv(csvData);
38284
- const granSuffix = this.granularity === "1h" ? "-1h" : "";
38332
+ const granSuffix = this.isIntraday ? `-${this.granularity}` : "";
38285
38333
  this.downloadCSV(csvContent, `relatorio-${this.params.identifier || "dispositivo"}${granSuffix}-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}.csv`);
38286
38334
  }
38287
38335
  // Accent hex da paleta do dashboard (params.theme) para os exports — cai no
@@ -38322,18 +38370,18 @@ var DeviceReportModal = class {
38322
38370
  exportColumnOptions() {
38323
38371
  const isTemp = this.domainConfig.summaryType === "average";
38324
38372
  return {
38325
- nameLabel: this.granularity === "1h" ? "Data/Hora" : "Data",
38373
+ nameLabel: this.isIntraday ? "Data/Hora" : "Data",
38326
38374
  hideIdentifier: true,
38327
38375
  // Mesmo rótulo da coluna da tela (antes saía "Consumo (°C)" em temperatura)
38328
38376
  valueLabel: this.domainConfig.label,
38329
- countLabel: this.granularity === "1h" ? "hora(s)" : "dia(s)",
38377
+ countLabel: this.isIntraday ? this.granularity === "1h" ? "hora(s)" : "hor\xE1rio(s)" : "dia(s)",
38330
38378
  ...isTemp ? { hidePerc: true, emptyValueText: "Sem leitura", valueDecimals: 2 } : {}
38331
38379
  };
38332
38380
  }
38333
38381
  // Gráfico da página final do PDF = painel da direita da tela
38334
38382
  async buildExportChart() {
38335
38383
  if (this.domainConfig.summaryType === "average") {
38336
- const isHourly = this.granularity === "1h";
38384
+ const isHourly = this.isIntraday;
38337
38385
  const ranked = [...this.validRows].sort((a, b) => b.consumption - a.consumption);
38338
38386
  const shown = isHourly ? ranked.slice(0, 24) : ranked;
38339
38387
  const noData = isHourly ? [] : this.data.filter((r) => r.noData);
@@ -38346,7 +38394,7 @@ var DeviceReportModal = class {
38346
38394
  accent: this.resolveAccentHex(),
38347
38395
  unit: this.domainConfig.unit
38348
38396
  });
38349
- const title = isHourly ? `${this.domainConfig.rankingHourTitle}${ranked.length > 24 ? " (top 24)" : ""}` : this.domainConfig.rankingDayTitle;
38397
+ const title = isHourly ? `${this.intradayRankingTitle()}${ranked.length > 24 ? " (top 24)" : ""}` : this.domainConfig.rankingDayTitle;
38350
38398
  return png ? { ...png, title } : null;
38351
38399
  }
38352
38400
  const chartPng = await this.participationChart?.toPngDataUrl?.().catch(() => null);
@@ -40179,7 +40227,8 @@ var AllReportModal = class {
40179
40227
  debugEnabled;
40180
40228
  // Domain configuration
40181
40229
  domainConfig;
40182
- // Granularity: '1d' (daily) | '1h' (hourly)
40230
+ // Granularity: '1d' (daily) | '1h' (hourly). Temperatura também '15m' | '30m' — agregados
40231
+ // aqui a partir dos blocos de 15 min que o Ingestion devolve com granularity=1h.
40183
40232
  granularity = "1d";
40184
40233
  // Temperatura: estatísticas por sensor (key = ingestionId) da última carga
40185
40234
  temperatureStats = /* @__PURE__ */ new Map();
@@ -40590,13 +40639,16 @@ var AllReportModal = class {
40590
40639
  // Padrão FIEL ao EnergyModal: pill "1h | 1d" (opções default do componente),
40591
40640
  // sem label interno (o form group acima já tem "Granularidade").
40592
40641
  label: "",
40642
+ // Temperatura: 15m | 30m | 1h | 1d; demais domínios: 1h | 1d (default do componente)
40643
+ ...this.isTemperature ? { options: TEMPERATURE_GRANULARITY_OPTIONS } : {},
40593
40644
  tooltip: {
40594
40645
  enabled: true,
40595
40646
  title: "Granularidade",
40596
- text: this.isTemperature ? "A tabela mostra a <b>m\xE9dia do per\xEDodo</b> de cada sensor. Clique em \u25B8 no sensor para ver a s\xE9rie <b>por hora</b> ou <b>por dia</b>; o CSV segue a mesma granularidade." : "A tabela mostra os <b>totais do per\xEDodo</b>. Clique em \u25B8 no dispositivo para ver a s\xE9rie <b>por hora</b> ou <b>por dia</b>; em Hora, o CSV traz uma linha por dispositivo \xD7 hora."
40647
+ text: this.isTemperature ? "A tabela mostra a <b>m\xE9dia do per\xEDodo</b> de cada sensor. Clique em \u25B8 no sensor para ver a s\xE9rie <b>por 15 min</b>, <b>30 min</b>, <b>hora</b> ou <b>dia</b> (m\xE9dia da janela); o CSV segue a mesma granularidade." : "A tabela mostra os <b>totais do per\xEDodo</b>. Clique em \u25B8 no dispositivo para ver a s\xE9rie <b>por hora</b> ou <b>por dia</b>; em Hora, o CSV traz uma linha por dispositivo \xD7 hora."
40597
40648
  }
40598
40649
  },
40599
40650
  onChange: (value) => {
40651
+ if (!this.isTemperature && value !== "1h" && value !== "1d") return;
40600
40652
  this.granularity = value;
40601
40653
  this.hourlySeriesCache = null;
40602
40654
  if (this.data.length && this.expandedIds.size) this.renderTable();
@@ -40969,7 +41021,7 @@ var AllReportModal = class {
40969
41021
  renderRowHTML(row, grandTotal, showId) {
40970
41022
  const expandable = !!row.id;
40971
41023
  const expanded = expandable && this.expandedIds.has(row.id);
40972
- const expandBtn = expandable ? `<button type="button" class="rp-expand" data-expand-id="${row.id}" aria-expanded="${expanded}" title="Ver s\xE9rie por ${this.granularity === "1h" ? "hora" : "dia"}">\u25B8</button>` : "";
41024
+ const expandBtn = expandable ? `<button type="button" class="rp-expand" data-expand-id="${row.id}" aria-expanded="${expanded}" title="Ver s\xE9rie por ${this.granularityNoun(this.granularity)}">\u25B8</button>` : "";
40973
41025
  const idTd = showId ? `<td data-label="Identificador" style="font-family: monospace; font-weight: bold; text-transform: uppercase;">${row.identifier}</td>` : "";
40974
41026
  const off = this.isTemperature && row.id && !row.noData ? this.temperatureOffsetFor(row.id) : 0;
40975
41027
  const offsetTag = off ? ` <span class="rp-offset" title="Offset do sensor aplicado \xE0s leituras">offset ${off > 0 ? "+" : "\u2212"}${fmtPt(Math.abs(off))} \xB0C</span>` : "";
@@ -41059,14 +41111,15 @@ var AllReportModal = class {
41059
41111
  async fillSeries(id, box) {
41060
41112
  const row = this.data.find((r) => r.id === id);
41061
41113
  const gran = this.granularity;
41114
+ const intraday = gran !== "1d";
41062
41115
  try {
41063
41116
  const points = await this.getDeviceSeries(id, gran);
41064
41117
  if (!box.isConnected) return;
41065
41118
  if (!points.length) {
41066
- box.innerHTML = `<span class="rp-muted">Sem dados ${gran === "1h" ? "hor\xE1rios" : "di\xE1rios"} no per\xEDodo.</span>`;
41119
+ box.innerHTML = `<span class="rp-muted">Sem dados ${intraday ? "hor\xE1rios" : "di\xE1rios"} no per\xEDodo.</span>`;
41067
41120
  return;
41068
41121
  }
41069
- const fmtTs = (ts) => gran === "1h" ? new Date(ts).toLocaleString("pt-BR", {
41122
+ const fmtTs = (ts) => intraday ? new Date(ts).toLocaleString("pt-BR", {
41070
41123
  day: "2-digit",
41071
41124
  month: "2-digit",
41072
41125
  year: "numeric",
@@ -41074,15 +41127,16 @@ var AllReportModal = class {
41074
41127
  minute: "2-digit",
41075
41128
  timeZone: "America/Sao_Paulo"
41076
41129
  }) : new Date(ts).toLocaleDateString("pt-BR", { timeZone: "America/Sao_Paulo" });
41077
- const valueLabel = this.isTemperature ? gran === "1h" ? "Temperatura (\xB0C)" : "M\xE9dia do dia (\xB0C)" : this.domainConfig.label;
41078
- if (this.bucketMoney(id, points[0].timestamp, gran, points[0].value)) {
41079
- const money = points.map((p) => this.bucketMoney(id, p.timestamp, gran, p.value));
41130
+ const valueLabel = this.isTemperature ? intraday ? "Temperatura (\xB0C)" : "M\xE9dia do dia (\xB0C)" : this.domainConfig.label;
41131
+ const moneyGran = intraday ? "1h" : "1d";
41132
+ if (this.bucketMoney(id, points[0].timestamp, moneyGran, points[0].value)) {
41133
+ const money = points.map((p) => this.bucketMoney(id, p.timestamp, moneyGran, p.value));
41080
41134
  const cell = (m) => m && m.state === "complete" && m.amount ? formatBRL(m.amount) : `<span class="rp-muted" title="Sem custo estimado para este intervalo">\u2014</span>`;
41081
41135
  const sub = sumItemMoney(money);
41082
41136
  const subCell = sub.state === "complete" && sub.amount ? formatBRL(sub.amount) : `<span class="rp-muted">Cobertura incompleta (${sub.covered} de ${sub.total})</span>`;
41083
41137
  box.innerHTML = `
41084
41138
  <table>
41085
- <thead><tr><th>${gran === "1h" ? "Data/Hora" : "Dia"}</th><th class="num">${valueLabel}</th><th class="num">${this.moneyHeaderLabel()}</th></tr></thead>
41139
+ <thead><tr><th>${intraday ? "Data/Hora" : "Dia"}</th><th class="num">${valueLabel}</th><th class="num">${this.moneyHeaderLabel()}</th></tr></thead>
41086
41140
  <tbody>${points.map((p, i) => `<tr><td>${fmtTs(p.timestamp)}</td><td class="num">${fmtPt(p.value)}</td><td class="num" data-money-cell="1">${cell(money[i])}</td></tr>`).join("")}</tbody>
41087
41141
  <tfoot><tr><td><strong>Subtotal</strong></td><td class="num"><strong>${fmtPt(points.reduce((s, p) => s + p.value, 0))}</strong></td><td class="num" data-money-subtotal="1"><strong>${subCell}</strong></td></tr></tfoot>
41088
41142
  </table>`;
@@ -41090,7 +41144,7 @@ var AllReportModal = class {
41090
41144
  }
41091
41145
  box.innerHTML = `
41092
41146
  <table>
41093
- <thead><tr><th>${gran === "1h" ? "Data/Hora" : "Dia"}</th><th class="num">${valueLabel}</th></tr></thead>
41147
+ <thead><tr><th>${intraday ? "Data/Hora" : "Dia"}</th><th class="num">${valueLabel}</th></tr></thead>
41094
41148
  <tbody>${points.map((p) => `<tr><td>${fmtTs(p.timestamp)}</td><td class="num">${fmtPt(p.value)}</td></tr>`).join("")}</tbody>
41095
41149
  </table>`;
41096
41150
  } catch (err) {
@@ -41105,8 +41159,9 @@ var AllReportModal = class {
41105
41159
  async getDeviceSeries(id, gran) {
41106
41160
  if (this.isTemperature) {
41107
41161
  const raw = this.temperatureStats.get(id)?.series || [];
41108
- return gran === "1h" ? this.aggregateHourly(raw, "avg") : this.aggregateDaily(raw, "avg");
41162
+ return gran === "1d" ? this.aggregateDaily(raw, "avg") : this.aggregateHourly(raw, "avg", granularityMinutes(gran));
41109
41163
  }
41164
+ if (gran !== "1h" && gran !== "1d") gran = "1h";
41110
41165
  const key = `${gran}|${id}`;
41111
41166
  const cached = this.deviceSeriesCache.get(key);
41112
41167
  if (cached) return cached;
@@ -41130,10 +41185,10 @@ var AllReportModal = class {
41130
41185
  const ent = Array.isArray(body) ? body[0] : body;
41131
41186
  return (ent?.consumption || []).map((p) => ({ timestamp: new Date(p?.timestamp).getTime(), value: Number(p?.value) })).filter((p) => Number.isFinite(p.timestamp) && Number.isFinite(p.value)).sort((a, b) => a.timestamp - b.timestamp);
41132
41187
  }
41133
- // Consolida em HORA FECHADA (início da hora): média (temperatura) ou soma (consumo).
41134
- // Fusos inteiros → a hora UTC coincide com a hora de São Paulo.
41135
- aggregateHourly(points, mode) {
41136
- const HOUR = 3600 * 1e3;
41188
+ // Consolida em JANELA FECHADA de `minutes` (padrão 60 = hora; 15/30 em temperatura):
41189
+ // média (temperatura) ou soma (consumo). Fusos inteiros → alinha também em São Paulo.
41190
+ aggregateHourly(points, mode, minutes = 60) {
41191
+ const HOUR = minutes * 60 * 1e3;
41137
41192
  const byHour = /* @__PURE__ */ new Map();
41138
41193
  for (const p of points) {
41139
41194
  const h3 = Math.floor(p.timestamp / HOUR) * HOUR;
@@ -41144,6 +41199,10 @@ var AllReportModal = class {
41144
41199
  }
41145
41200
  return [...byHour.entries()].sort((a, b) => a[0] - b[0]).map(([h3, { sum: sum2, n }]) => ({ timestamp: h3, value: mode === "avg" ? sum2 / n : sum2 }));
41146
41201
  }
41202
+ // "hora" | "15 minutos" | "30 minutos" | "dia" — textos de ▸ e CSV
41203
+ granularityNoun(g) {
41204
+ return { "15m": "15 minutos", "30m": "30 minutos", "1h": "hora", "1d": "dia" }[g];
41205
+ }
41147
41206
  // Agrega série horária por dia civil (São Paulo): média (temperatura) ou soma (consumo)
41148
41207
  aggregateDaily(points, mode) {
41149
41208
  const byDay = /* @__PURE__ */ new Map();
@@ -41419,7 +41478,7 @@ var AllReportModal = class {
41419
41478
  ["Relat\xF3rio", this.resolveTitle()],
41420
41479
  ...this.params.customerName ? [["Cliente", this.params.customerName]] : [],
41421
41480
  ...p?.startISO ? [["Per\xEDodo", `${fmtD(p.startISO)} \u2014 ${fmtD(p.endISO)}`]] : [],
41422
- ["Granularidade", gran === "1h" ? "Hora" : "Dia"],
41481
+ ["Granularidade", { "15m": "15 minutos", "30m": "30 minutos", "1h": "Hora", "1d": "Dia" }[gran]],
41423
41482
  ["Gerado em", (/* @__PURE__ */ new Date()).toLocaleString("pt-BR")],
41424
41483
  [],
41425
41484
  ...this.computeKpis().map((k) => [k.label, k.value, k.sub || ""]),
@@ -41440,8 +41499,8 @@ var AllReportModal = class {
41440
41499
  String(r.discarded ?? "")
41441
41500
  ])
41442
41501
  ];
41443
- const series = [[...idHead, "Sensor", gran === "1h" ? "Data/Hora" : "Dia", "Temperatura (\xB0C)"]];
41444
- const fmtTs = (ts) => gran === "1h" ? new Date(ts).toLocaleString("pt-BR", {
41502
+ const series = [[...idHead, "Sensor", gran !== "1d" ? "Data/Hora" : "Dia", "Temperatura (\xB0C)"]];
41503
+ const fmtTs = (ts) => gran !== "1d" ? new Date(ts).toLocaleString("pt-BR", {
41445
41504
  day: "2-digit",
41446
41505
  month: "2-digit",
41447
41506
  year: "numeric",
@@ -41451,7 +41510,7 @@ var AllReportModal = class {
41451
41510
  }) : new Date(ts).toLocaleDateString("pt-BR", { timeZone: "America/Sao_Paulo" });
41452
41511
  for (const r of rows) {
41453
41512
  const raw = r.id && this.temperatureStats.get(r.id)?.series || [];
41454
- const pts = gran === "1h" ? this.aggregateHourly(raw, "avg") : this.aggregateDaily(raw, "avg");
41513
+ const pts = gran === "1d" ? this.aggregateDaily(raw, "avg") : this.aggregateHourly(raw, "avg", granularityMinutes(gran));
41455
41514
  for (const p2 of pts) series.push([...idCol(r), r.name, fmtTs(p2.timestamp), n2(p2.value)]);
41456
41515
  }
41457
41516
  const csvContent = toCsv([...meta, ...summary, [], ...series]);
package/dist/index.d.cts CHANGED
@@ -25516,7 +25516,8 @@ declare const EXPORT_BUTTON_CSS_PREFIX = "myio-export-btn";
25516
25516
  /** Injeta os estilos base (idempotente). Cores por kind/tema são inline (settings). */
25517
25517
  declare function injectExportButtonStyles(): void;
25518
25518
 
25519
- type Granularity = '1h' | '1d';
25519
+ /** 15m/30m: só onde houver opções explícitas (ex.: relatórios de temperatura) — default segue 1h|1d */
25520
+ type Granularity = '15m' | '30m' | '1h' | '1d';
25520
25521
  type GranularitySelectorThemeMode = 'light' | 'dark';
25521
25522
  interface GranularitySelectorOption {
25522
25523
  value: Granularity;
package/dist/index.d.ts CHANGED
@@ -25516,7 +25516,8 @@ declare const EXPORT_BUTTON_CSS_PREFIX = "myio-export-btn";
25516
25516
  /** Injeta os estilos base (idempotente). Cores por kind/tema são inline (settings). */
25517
25517
  declare function injectExportButtonStyles(): void;
25518
25518
 
25519
- type Granularity = '1h' | '1d';
25519
+ /** 15m/30m: só onde houver opções explícitas (ex.: relatórios de temperatura) — default segue 1h|1d */
25520
+ type Granularity = '15m' | '30m' | '1h' | '1d';
25520
25521
  type GranularitySelectorThemeMode = 'light' | 'dark';
25521
25522
  interface GranularitySelectorOption {
25522
25523
  value: Granularity;