Skip to content

Commit

Permalink
Fixed rainRate reset. Updated gauge tile dayChange logic. GH-224
Browse files Browse the repository at this point in the history
  • Loading branch information
Daveiano committed Nov 14, 2023
1 parent 9c6ffb6 commit 81eb7f0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
3 changes: 2 additions & 1 deletion skins/weewx-wdc/includes/gauge-tile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
unit: "$get_unit_label($get_unit_for_obs($partial_obs, $partial_obs_key, $context))",
rounding: $get_rounding($partial_obs, $partial_obs_key),
properties: $get_gauge_diagram_props($partial_obs, $context),
label: "$obs.label[$partial_obs]"
label: "$obs.label[$partial_obs]",
dayChange: false,
}
</script>
<div class="diagram" data-value="$series_name"></div>
Expand Down
26 changes: 23 additions & 3 deletions skins/weewx-wdc/src/js/diagrams/d3/gauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,35 @@ export const D3GaugeDiagram: FunctionComponent<GaugeDiagramBaseProps> = (

// MQTT handling.
const gaugeData = (window as any)[props.seriesName];
// TODO: dayChange handling.
const gaugeProxy = new Proxy(gaugeData, {
set: function (target, key, value) {
console.log(`${String(key)} set to ${value}`);
//console.log(`${String(key)} set to ${value}`);
target[key] = value;

console.log(`Set ${String(key)} to ${value}`);

if (target.dayChange) {
console.log("dayChange gauge");
}

console.log(target);

if (String(key) === "current") {
setCurrent(parseFloat(value));
}

if (String(key) === "min" && parseFloat(value) < min) {
if (
String(key) === "min" &&
(parseFloat(value) < min || target.dayChange)
) {
setMin(parseFloat(value));
}

if (String(key) === "max" && parseFloat(value) > max) {
if (
String(key) === "max" &&
(parseFloat(value) > max || target.dayChange)
) {
setMax(parseFloat(value));
}

Expand Down Expand Up @@ -674,6 +689,11 @@ export const D3GaugeDiagram: FunctionComponent<GaugeDiagramBaseProps> = (
-gaugeContainerDimensions.y + margin
})`
);

console.log("obs", props.obs);
console.log("current", current);
console.log("min", min);
console.log("max", max);
}, [current, min, max, darkMode, dimensions]);

return (
Expand Down
29 changes: 22 additions & 7 deletions skins/weewx-wdc/src/js/live-updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ const _updateStatTile = (
`day${observation[0].toUpperCase()}${observation.slice(1)}_${unitMQTT}`
];

if (!sumValue) return;

statTile.querySelector(
".stat-title-obs-value .raw"
)!.innerHTML = `${parseFloat(sumValue).toFixed(rounding)}${unit}`;
if (sumValue) {
statTile.querySelector(
".stat-title-obs-value .raw"
)!.innerHTML = `${parseFloat(sumValue).toFixed(rounding)}${unit}`;
}
} else {
// Use the current value.
statTile.querySelector(
Expand Down Expand Up @@ -256,6 +256,11 @@ const _updateStatTile = (
rainRate = parseFloat(payLoad["rainRate_cm_per_hour"]);
}

// Ensure rainRate if reset in day change.
if (dayChange && rainRate === null) {
rainRate = 0;
}

if (rainRate === null) return;

const rainRateUnit = statTile.getAttribute("data-unit-rain-rate")!;
Expand Down Expand Up @@ -516,23 +521,33 @@ const onMessageArrived = (message: Message) => {
`.diagram-tile.gauge[data-observation="${observation}"]`
);

// TODO: Min/Max reset on day change not working.
if (gaugeTile) {
const gaugeTileSeriesName = gaugeTile.getAttribute("data-test")!;
(window as any)[gaugeTileSeriesName].current = payLoad[key];

// Respect day change.
if (dayChange) {
(window as any)[gaugeTileSeriesName].dayChange = true;
}

if (
payLoad[key] < (window as any)[gaugeTileSeriesName].min ||
parseFloat(payLoad[key]) <
parseFloat((window as any)[gaugeTileSeriesName].min) ||
dayChange
) {
(window as any)[gaugeTileSeriesName].min = payLoad[key];
}

if (
payLoad[key] > (window as any)[gaugeTileSeriesName].max ||
parseFloat(payLoad[key]) >
parseFloat((window as any)[gaugeTileSeriesName].max) ||
dayChange
) {
(window as any)[gaugeTileSeriesName].max = payLoad[key];
}

(window as any)[gaugeTileSeriesName].dayChange = false;
}

if (statTile) {
Expand Down

0 comments on commit 81eb7f0

Please sign in to comment.