From b2ef4e090472267748fcf92275a890825f45a1c3 Mon Sep 17 00:00:00 2001 From: omenem Date: Wed, 27 May 2020 14:50:14 +0200 Subject: [PATCH] fix --- .../smarthut/service/ThermostatService.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatService.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatService.java index 0fea6b0..ad98717 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatService.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/ThermostatService.java @@ -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.utils.Utils; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.List; import java.util.Optional; import java.util.Random; @@ -38,12 +39,18 @@ public class ThermostatService { private void randomJitter(Thermostat thermostat) { - double x; - x = - (ran.nextInt(thermostat.getTypical().intValue()) + thermostat.getErr().intValue()) - * 0.975 - + 1; - updateValueForThermostat(thermostat, BigDecimal.valueOf(x)); + BigDecimal x = + thermostat + .getTypical() + .subtract( + thermostat + .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) {