From 7eeab40ff9c0e27bfb2e546bbbdcb7e7852202f6 Mon Sep 17 00:00:00 2001 From: omenem Date: Tue, 26 May 2020 15:40:22 +0200 Subject: [PATCH] fix --- .../ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java | 2 +- .../usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java | 2 +- .../inf/sa4/sanmarinoes/smarthut/service/SensorService.java | 6 ++++-- .../sa4/sanmarinoes/smarthut/service/ThermostatService.java | 5 +++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java index 72f863a..7aee6c0 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Sensor.java @@ -49,7 +49,7 @@ public class Sensor extends InputDevice implements RangeTriggerable { private BigDecimal err = new BigDecimal(1); @Column(nullable = false, precision = 11, scale = 1) - private BigDecimal typical = new BigDecimal(17); + private BigDecimal typical = BigDecimal.valueOf(17); /** The type of this sensor */ @Column(nullable = false) @Enumerated(value = EnumType.STRING) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java index 4e69b01..7523a49 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java @@ -84,7 +84,7 @@ public class Thermostat extends Switchable implements BooleanTriggerable { private BigDecimal err = new BigDecimal(1); @Column(nullable = false, precision = 11, scale = 1) - private BigDecimal typical = new BigDecimal(17.0); + private BigDecimal typical = BigDecimal.valueOf(17); /** Creates a thermostat with a temperature sensor and its initial OFF state */ public Thermostat() { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/SensorService.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/SensorService.java index f2d8408..359220b 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/SensorService.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/service/SensorService.java @@ -19,14 +19,16 @@ public class SensorService { @Autowired private SensorSocketEndpoint endpoint; + private Random ran = new Random(); + private void randomJitter(Sensor sensor) { double x; - Random ran = new Random(); + x = (ran.nextInt(sensor.getTypical().intValue()) + sensor.getError().intValue()) * 0.975 + 1; - updateValueFromSensor(sensor, new BigDecimal(x)); + updateValueFromSensor(sensor, BigDecimal.valueOf(x)); } public void sensorFakeUpdate() { 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 20d7e32..0fea6b0 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 @@ -22,6 +22,8 @@ public class ThermostatService { private final ThermostatRepository thermostatRepository; + private Random ran = new Random(); + @Autowired public ThermostatService( SensorSocketEndpoint endpoint, @@ -37,12 +39,11 @@ public class ThermostatService { private void randomJitter(Thermostat thermostat) { double x; - Random ran = new Random(); x = (ran.nextInt(thermostat.getTypical().intValue()) + thermostat.getErr().intValue()) * 0.975 + 1; - updateValueForThermostat(thermostat, new BigDecimal(x)); + updateValueForThermostat(thermostat, BigDecimal.valueOf(x)); } private void updateValueForThermostat(Thermostat thermostat, BigDecimal value) {