Merge branch '96-fix-in-random-jitter-of-thermostat' into 'dev'

fix

Closes #96

See merge request sa4-2020/the-sanmarinoes/backend!205
This commit is contained in:
Matteo Omenetti 2020-05-27 14:54:37 +02:00
commit d62fe005a8

View file

@ -5,6 +5,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ThermostatRepository;
import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint; import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint;
import ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils; import ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Random; import java.util.Random;
@ -38,12 +39,18 @@ public class ThermostatService {
private void randomJitter(Thermostat thermostat) { private void randomJitter(Thermostat thermostat) {
double x; BigDecimal x =
x = thermostat
(ran.nextInt(thermostat.getTypical().intValue()) + thermostat.getErr().intValue()) .getTypical()
* 0.975 .subtract(
+ 1; thermostat
updateValueForThermostat(thermostat, BigDecimal.valueOf(x)); .getErr()
.divide(BigDecimal.valueOf(2), RoundingMode.CEILING))
.add(
BigDecimal.valueOf(
ran.nextDouble() * thermostat.getErr().doubleValue() * 2));
updateValueForThermostat(thermostat, x);
} }
private void updateValueForThermostat(Thermostat thermostat, BigDecimal value) { private void updateValueForThermostat(Thermostat thermostat, BigDecimal value) {