fermentrack icon indicating copy to clipboard operation
fermentrack copied to clipboard

Cooling Duty / Heating Duty at 0%

Open goose-ws opened this issue 4 years ago • 6 comments

Hey folks.

I searched the docs, but couldn't find anything referencing these metrics. Frankly, I'm unsure of what they're supposed to be measuring. But whatever it is, they're at a constant 0% throughout cycles.

Any insight would be appreciated!

goose-ws avatar Oct 11 '20 21:10 goose-ws

I did see heating duty to change (I only have heater) before bounding gravity sensor to my fermentation device. After bounding the device both cooling and heating duty stay constantly at 0%. Seems there is a bug which puts both duties to 0% when gravity sensor is bound?

What I saw is that heating and cooling duty tells the activity percentage of both features. When you zoom the graph it eventually changes.

jaisoh avatar Oct 16 '20 14:10 jaisoh

Seems reproduced, as I do have a Tilt sensor bound.

goose-ws avatar Oct 17 '20 03:10 goose-ws

I have the same issue. Duty cycle is always 0%. I looked at the code in the dashboard template a bit but couldn't find anything.

uSlackr avatar Oct 25 '20 22:10 uSlackr

Same issue when binding an ispindel

peterruitenburg avatar Nov 15 '20 10:11 peterruitenburg

Seems an issue in the computeDutyCucles where row 6 is used. This row identifies the state (cooling / heating / other) however if you have a grafity device linked, this row 6 shows the grafity instead of the state (which then is in row 8). Function should be adapted to determine the correct value to use to identify sate.

const computeDutyCycles = () => { const [minDate, maxDate] = g2.xAxisRange(); const minIdx = g2.rawData_ .findIndex(([date]) => date > minDate) - 1; const maxIdxFromEnd = g2.rawData_ .slice(0) .reverse().findIndex(([date]) => date < maxDate);

const visibleData = g2.rawData_
    .slice(
        Math.max(0, minIdx),
        g2.rawData_.length -  maxIdxFromEnd
    );

const result = visibleData.reduce((acc, row, idx, arr) => {
    if (idx === 0) return acc;

    const currentStateName = stateToName(row[6])
    
    if (currentStateName === acc.lastState) {
        acc[currentStateName] += row[0] - arr[idx - 1][0];
        return acc;
    } else {
        acc.lastState = currentStateName;
        return acc;
    }
}, {
    heating: 0,
    cooling: 0,
    other: 0,
    lastState: stateToName(visibleData[0][6]),
});

peterruitenburg avatar Nov 15 '20 12:11 peterruitenburg

I've applied this to my local install to fix it. Ideally the data should be shuffled around so gravity is added after the state, but this might break more things.

diff --git a/app/templates/device_dashboard.html b/app/templates/device_dashboard.html
index 4890bf7..5d55d94 100644
--- a/app/templates/device_dashboard.html
+++ b/app/templates/device_dashboard.html
@@ -603,6 +603,15 @@ const stateToName = state => (({
     4: 'cooling',
 })[state] || 'other');

+// The index of the state in the record returned from the API can changes, depending on
+// whether a gravity device is enabled.  Ideally, the gravity data should be added to the
+// end of the record instead of before the state.
+{% if beer.gravity_enabled %}
+const stateIndex = 8;
+{% else %}
+const stateIndex = 6;
+{% endif %}
+
 const computeDutyCycles = () => {
     const [minDate, maxDate] = g2.xAxisRange();
     const minIdx = g2.rawData_
@@ -620,7 +629,7 @@ const computeDutyCycles = () => {
     const result = visibleData.reduce((acc, row, idx, arr) => {
         if (idx === 0) return acc;

-        const currentStateName = stateToName(row[6])
+        const currentStateName = stateToName(row[stateIndex])

         if (currentStateName === acc.lastState) {
             acc[currentStateName] += row[0] - arr[idx - 1][0];
@@ -633,7 +642,7 @@ const computeDutyCycles = () => {
         heating: 0,
         cooling: 0,
         other: 0,
-        lastState: stateToName(visibleData[0][6]),
+        lastState: stateToName(visibleData[0][stateIndex]),
     });

stix77 avatar Dec 03 '20 05:12 stix77