rewrite compute_filtration_time() using an abbacus
This commit is contained in:
parent
016d1cf5ce
commit
ca092a41c0
46
pool.js
46
pool.js
@ -28,26 +28,36 @@ let status = {
|
||||
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)
|
||||
|
||||
function compute_duration_filt(t) {
|
||||
if (t < 5)
|
||||
return 1;
|
||||
if (t < 10)
|
||||
return (t/5); // 1 -> 2
|
||||
if (t < 12)
|
||||
return (t-8); // 2 -> 4
|
||||
if (t < 16)
|
||||
return (t/2-2); // 4 -> 6
|
||||
if (t < 24)
|
||||
return (t/4+2); // 6 -> 8
|
||||
if (t < 27)
|
||||
return (t*4/3-24) // 8 -> 12
|
||||
if (t < 30)
|
||||
return (t*4 - 96); // 12 -> 24
|
||||
return 24;
|
||||
function compute_filtration_time(t) {
|
||||
let len = filt_time.length;
|
||||
|
||||
if (t < filt_time[0][0])
|
||||
return filt_time[0][1];
|
||||
|
||||
for (let i = 0; i < len-1; i++) {
|
||||
if (t >= filt_time[i][0] && t < filt_time[i+1][0]) {
|
||||
// linear interpolation between two points
|
||||
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 filt_time[len-1][1];
|
||||
}
|
||||
|
||||
|
||||
// compute the pump schedule for a given duration
|
||||
// returns an array of start/stop times in float
|
||||
@ -135,7 +145,7 @@ function update_pump(temp, max, time) {
|
||||
status.tick_pump++;
|
||||
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);
|
||||
|
||||
print("[POOL] update_pump - duration:", duration);
|
||||
|
Loading…
x
Reference in New Issue
Block a user