rewrite compute_filtration_time() using an abbacus
This commit is contained in:
parent
016d1cf5ce
commit
ca092a41c0
46
pool.js
46
pool.js
@ -28,27 +28,37 @@ let status = {
|
|||||||
tick_day: 0,
|
tick_day: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
// compute duration of filtration for a given max temperature
|
// temperature->duration chart
|
||||||
|
let filt_time = [
|
||||||
|
[ 5, 1.0 ], // at 5°C, 1 hour of filtering
|
||||||
|
[ 10, 2.0 ],
|
||||||
|
[ 12, 4.0 ],
|
||||||
|
[ 16, 6.0 ],
|
||||||
|
[ 24, 8.0 ],
|
||||||
|
[ 27, 12.0 ],
|
||||||
|
[ 30, 24.0 ]
|
||||||
|
];
|
||||||
|
|
||||||
|
// compute filtration time for a given max temperature
|
||||||
// duration is returned in float format (1.25 -> 1h 15mn)
|
// duration is returned in float format (1.25 -> 1h 15mn)
|
||||||
|
|
||||||
function compute_duration_filt(t) {
|
function compute_filtration_time(t) {
|
||||||
if (t < 5)
|
let len = filt_time.length;
|
||||||
return 1;
|
|
||||||
if (t < 10)
|
if (t < filt_time[0][0])
|
||||||
return (t/5); // 1 -> 2
|
return filt_time[0][1];
|
||||||
if (t < 12)
|
|
||||||
return (t-8); // 2 -> 4
|
for (let i = 0; i < len-1; i++) {
|
||||||
if (t < 16)
|
if (t >= filt_time[i][0] && t < filt_time[i+1][0]) {
|
||||||
return (t/2-2); // 4 -> 6
|
// linear interpolation between two points
|
||||||
if (t < 24)
|
return filt_time[i][1] + (filt_time[i+1][1] - filt_time[i][1]) / (filt_time[i+1][0] - filt_time[i][0]) * (t - filt_time[i][0]);
|
||||||
return (t/4+2); // 6 -> 8
|
}
|
||||||
if (t < 27)
|
}
|
||||||
return (t*4/3-24) // 8 -> 12
|
|
||||||
if (t < 30)
|
return filt_time[len-1][1];
|
||||||
return (t*4 - 96); // 12 -> 24
|
|
||||||
return 24;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// compute the pump schedule for a given duration
|
// compute the pump schedule for a given duration
|
||||||
// returns an array of start/stop times in float
|
// returns an array of start/stop times in float
|
||||||
// [ start1, stop1, start2, stop2, ... ]
|
// [ start1, stop1, start2, stop2, ... ]
|
||||||
@ -135,7 +145,7 @@ function update_pump(temp, max, time) {
|
|||||||
status.tick_pump++;
|
status.tick_pump++;
|
||||||
print("[POOL] update_pump", status.tick_pump, "- temp:", temp, "max:", max, "time:", time);
|
print("[POOL] update_pump", status.tick_pump, "- temp:", temp, "max:", max, "time:", time);
|
||||||
|
|
||||||
let duration = compute_duration_filt(max);
|
let duration = compute_filtration_time(max);
|
||||||
let schedule = compute_schedule_filt(duration);
|
let schedule = compute_schedule_filt(duration);
|
||||||
|
|
||||||
print("[POOL] update_pump - duration:", duration);
|
print("[POOL] update_pump - duration:", duration);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user