From 2f05253bc15d7115242fd158ecbfbd5ad679679d Mon Sep 17 00:00:00 2001 From: omenem Date: Mon, 25 May 2020 18:41:30 +0200 Subject: [PATCH 1/6] implemented user story 1 for sensor --- .../smarthut/controller/SensorController.java | 2 ++ .../smarthut/dto/SensorSaveRequest.java | 4 +++ .../sanmarinoes/smarthut/models/Sensor.java | 27 +++++++++++++++++++ .../smarthut/service/SensorService.java | 23 ++++++++++++---- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java index 62581b3..a0b4f82 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java @@ -44,6 +44,8 @@ public class SensorController { newSensor.setName(s.getName()); newSensor.setRoomId(s.getRoomId()); newSensor.setValue(s.getValue()); + newSensor.setError(s.getError()); + newSensor.setTypical(s.getTypical()); return deviceService.saveAsOwner(newSensor, principal.getName()); } diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java index 59a089a..5ed77c9 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java @@ -20,6 +20,10 @@ public class SensorSaveRequest { @NotNull private BigDecimal value; + @NotNull private BigDecimal error = new BigDecimal(1); + + private BigDecimal typical; + /** * The room this device belongs in, as a foreign key id. To use when updating and inserting from * a REST call. 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 f4d444a..55bb074 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 @@ -44,6 +44,13 @@ public class Sensor extends InputDevice implements RangeTriggerable { @Column(nullable = false, precision = 11, scale = 1) private BigDecimal value; + /** The value of the error according to this value */ + @Column(nullable = false, precision = 11, scale = 1) + private BigDecimal err; + + @Column(nullable = true, precision = 11, scale = 1) + private BigDecimal typical; + /** The type of this sensor */ @Column(nullable = false) @Enumerated(value = EnumType.STRING) @@ -65,6 +72,26 @@ public class Sensor extends InputDevice implements RangeTriggerable { this.value = newValue; } + public BigDecimal getError() { + return err; + } + + public void setError(BigDecimal err) { + this.err = err; + } + + public BigDecimal getTypical() { + return typical; + } + + public void setTypical(BigDecimal typical) { + this.typical = typical; + } + + public void setTypicalNull() { + this.typical = null; + } + public Sensor() { super("sensor"); } 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 532442b..5029e21 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 @@ -4,6 +4,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SensorRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint; import java.math.BigDecimal; +import java.util.Random; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -19,11 +20,23 @@ public class SensorService { @Autowired private SensorSocketEndpoint endpoint; private void randomJitter(Sensor sensor) { - updateValueFromSensor( - sensor, - Sensor.TYPICAL_VALUES - .get(sensor.getSensor()) - .multiply(BigDecimal.valueOf(0.975 + Math.random() / 20))); + + double x; + if (sensor.getTypical() == null) { + BigDecimal typical = Sensor.TYPICAL_VALUES.get(sensor.getSensor()); + + Random ran = new Random(); + x = (ran.nextInt(typical.intValue()) + sensor.getError().intValue()) * 0.975 + 1; + + } else { + Random ran = new Random(); + x = + (ran.nextInt(sensor.getTypical().intValue()) + sensor.getError().intValue()) + * 0.975 + + 1; + } + + updateValueFromSensor(sensor, new BigDecimal(x)); } public void sensorFakeUpdate() { From 03ded14ed2e6d9b6ef72021dfa441dc2abca5db9 Mon Sep 17 00:00:00 2001 From: omenem Date: Tue, 26 May 2020 11:24:48 +0200 Subject: [PATCH 2/6] fix (wip) --- .../smarthut/controller/SensorControllerTests.java | 7 ++++++- .../sanmarinoes/smarthut/dto/SensorSaveRequestTests.java | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorControllerTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorControllerTests.java index bac53e0..484564f 100644 --- a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorControllerTests.java +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorControllerTests.java @@ -69,7 +69,12 @@ public class SensorControllerTests { final SensorSaveRequest toSend = new SensorSaveRequest( - Sensor.SensorType.TEMPERATURE, BigDecimal.ZERO, 42L, "Test sensor"); + Sensor.SensorType.TEMPERATURE, + BigDecimal.ZERO, + BigDecimal.ZERO, + BigDecimal.ZERO, + 42L, + "Test sensor"); final Sensor created = sensorController.create(toSend, mockPrincipal); checkSensorAgainstRequest(created, toSend); diff --git a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequestTests.java b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequestTests.java index 6c99297..2ca98e8 100644 --- a/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequestTests.java +++ b/src/test/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequestTests.java @@ -30,7 +30,13 @@ public class SensorSaveRequestTests { @DisplayName("test constructor") public void testConstructorNotEmpty() { SensorSaveRequest newSaveRequest = - new SensorSaveRequest(Sensor.SensorType.HUMIDITY, new BigDecimal(12), 12L, "name"); + new SensorSaveRequest( + Sensor.SensorType.HUMIDITY, + new BigDecimal(12), + BigDecimal.ZERO, + BigDecimal.ZERO, + 12L, + "name"); assertNotNull(newSaveRequest.getSensor()); assertNotNull(newSaveRequest.getName()); assertNotNull(newSaveRequest.getRoomId()); From 689e3b96a754aa69ad99aa32d44f6cc8a4a9e457 Mon Sep 17 00:00:00 2001 From: omenem Date: Tue, 26 May 2020 11:40:58 +0200 Subject: [PATCH 3/6] implemented user story 1 for thermmostat, a test is not passing --- .../controller/ThermostatController.java | 2 ++ .../smarthut/dto/ThermostatSaveRequest.java | 5 ++++ .../smarthut/models/Thermostat.java | 23 ++++++++++++++++++ .../smarthut/service/ThermostatService.java | 24 +++++++++++++++---- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java index d45ba96..5884a05 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java @@ -30,6 +30,8 @@ public class ThermostatController { newT.setRoomId(t.getRoomId()); newT.setUseExternalSensors(t.isUseExternalSensors()); newT.setOn(false); + newT.setErr(t.getErr()); + newT.setTypical(newT.getTypical()); thermostatService.populateMeasuredTemperature(newT); newT = thermostatRepository.save(newT); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ThermostatSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ThermostatSaveRequest.java index 6bbfbb8..ae1f87a 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ThermostatSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ThermostatSaveRequest.java @@ -26,4 +26,9 @@ public class ThermostatSaveRequest { /** State of this thermostat */ @NotNull private boolean turnOn; + + /** The value of the error according to this value */ + @NotNull private BigDecimal err = new BigDecimal(1); + + private BigDecimal typical; } 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 229f7f6..83ac603 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 @@ -79,6 +79,13 @@ public class Thermostat extends Switchable implements BooleanTriggerable { @Column private boolean useExternalSensors = false; + /** The value of the error according to this value */ + @Column(nullable = false, precision = 11, scale = 1) + private BigDecimal err; + + @Column(nullable = true, precision = 11, scale = 1) + private BigDecimal typical; + /** Creates a thermostat with a temperature sensor and its initial OFF state */ public Thermostat() { super("thermostat"); @@ -97,6 +104,22 @@ public class Thermostat extends Switchable implements BooleanTriggerable { return sb.toString(); } + public BigDecimal getErr() { + return err; + } + + public void setErr(BigDecimal err) { + this.err = err; + } + + public BigDecimal getTypical() { + return typical; + } + + public void setTypical(BigDecimal typical) { + this.typical = typical; + } + public void setMode(Mode state) { this.mode = state; } 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 9065826..54ae868 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 @@ -1,6 +1,7 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.service; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor; +import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor.SensorType; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ThermostatRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint; @@ -8,6 +9,7 @@ import ch.usi.inf.sa4.sanmarinoes.smarthut.utils.Utils; import java.math.BigDecimal; import java.util.List; import java.util.Optional; +import java.util.Random; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -35,11 +37,23 @@ public class ThermostatService { } private void randomJitter(Thermostat thermostat) { - updateValueForThermostat( - thermostat, - Sensor.TYPICAL_VALUES - .get(Sensor.SensorType.TEMPERATURE) - .multiply(BigDecimal.valueOf(0.975 + Math.random() / 20))); + + double x; + Random ran = new Random(); + ; + if (thermostat.getTypical() == null) { + BigDecimal typical = Sensor.TYPICAL_VALUES.get(SensorType.TEMPERATURE); + + x = (ran.nextInt(typical.intValue()) + thermostat.getErr().intValue()) * 0.975 + 1; + + } else { + x = + (ran.nextInt(thermostat.getTypical().intValue()) + + thermostat.getErr().intValue()) + * 0.975 + + 1; + } + updateValueForThermostat(thermostat, new BigDecimal(x)); } private void updateValueForThermostat(Thermostat thermostat, BigDecimal value) { From 0046143d82a4eca288a505294feb6c1b526944b5 Mon Sep 17 00:00:00 2001 From: omenem Date: Tue, 26 May 2020 12:05:42 +0200 Subject: [PATCH 4/6] wip --- .../smarthut/controller/SensorController.java | 19 +++++++++- .../controller/ThermostatController.java | 8 +++- .../smarthut/dto/SensorSaveRequest.java | 2 +- .../smarthut/dto/ThermostatSaveRequest.java | 2 +- .../sanmarinoes/smarthut/models/Sensor.java | 7 ++-- .../smarthut/models/Thermostat.java | 4 +- .../smarthut/service/SensorService.java | 38 ++++++++++--------- 7 files changed, 51 insertions(+), 29 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java index a0b4f82..d4accc3 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java @@ -44,8 +44,8 @@ public class SensorController { newSensor.setName(s.getName()); newSensor.setRoomId(s.getRoomId()); newSensor.setValue(s.getValue()); - newSensor.setError(s.getError()); - newSensor.setTypical(s.getTypical()); + // newSensor.setError(s.getError()); + // newSensor.setTypical(s.getTypical()); return deviceService.saveAsOwner(newSensor, principal.getName()); } @@ -63,6 +63,21 @@ public class SensorController { value); } + @PutMapping("/{id}/simulation") + public Sensor updateSimulation( + @PathVariable("id") Long sensorId, + @RequestParam("value") BigDecimal error, + @RequestParam("value") BigDecimal typical, + final Principal principal) + throws NotFoundException { + return sensorService.updateSimulationFromSensor( + sensorRepository + .findByIdAndUsername(sensorId, principal.getName()) + .orElseThrow(NotFoundException::new), + error, + typical); + } + @DeleteMapping("/{id}") public void deleteById(@PathVariable("id") long id, final Principal principal) throws NotFoundException { diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java index 5884a05..09b21cf 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ThermostatController.java @@ -30,8 +30,12 @@ public class ThermostatController { newT.setRoomId(t.getRoomId()); newT.setUseExternalSensors(t.isUseExternalSensors()); newT.setOn(false); - newT.setErr(t.getErr()); - newT.setTypical(newT.getTypical()); + if (t.getErr() != null) { + newT.setErr(t.getErr()); + } + if (t.getTypical() != null) { + newT.setTypical(t.getTypical()); + } thermostatService.populateMeasuredTemperature(newT); newT = thermostatRepository.save(newT); diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java index 5ed77c9..f5558c7 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/SensorSaveRequest.java @@ -20,7 +20,7 @@ public class SensorSaveRequest { @NotNull private BigDecimal value; - @NotNull private BigDecimal error = new BigDecimal(1); + private BigDecimal error; private BigDecimal typical; diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ThermostatSaveRequest.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ThermostatSaveRequest.java index ae1f87a..3734613 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ThermostatSaveRequest.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/dto/ThermostatSaveRequest.java @@ -28,7 +28,7 @@ public class ThermostatSaveRequest { @NotNull private boolean turnOn; /** The value of the error according to this value */ - @NotNull private BigDecimal err = new BigDecimal(1); + private BigDecimal err; private BigDecimal typical; } 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 55bb074..72f863a 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 @@ -46,11 +46,10 @@ public class Sensor extends InputDevice implements RangeTriggerable { /** The value of the error according to this value */ @Column(nullable = false, precision = 11, scale = 1) - private BigDecimal err; - - @Column(nullable = true, precision = 11, scale = 1) - private BigDecimal typical; + private BigDecimal err = new BigDecimal(1); + @Column(nullable = false, precision = 11, scale = 1) + private BigDecimal typical = new BigDecimal(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 83ac603..8dcd657 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 @@ -81,10 +81,10 @@ public class Thermostat extends Switchable implements BooleanTriggerable { /** The value of the error according to this value */ @Column(nullable = false, precision = 11, scale = 1) - private BigDecimal err; + private BigDecimal err = new BigDecimal(1); @Column(nullable = true, precision = 11, scale = 1) - private BigDecimal typical; + private BigDecimal typical = new BigDecimal(17.0);; /** 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 5029e21..f2d8408 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 @@ -22,20 +22,10 @@ public class SensorService { private void randomJitter(Sensor sensor) { double x; - if (sensor.getTypical() == null) { - BigDecimal typical = Sensor.TYPICAL_VALUES.get(sensor.getSensor()); - - Random ran = new Random(); - x = (ran.nextInt(typical.intValue()) + sensor.getError().intValue()) * 0.975 + 1; - - } else { - Random ran = new Random(); - x = - (ran.nextInt(sensor.getTypical().intValue()) + sensor.getError().intValue()) - * 0.975 - + 1; - } - + Random ran = new Random(); + x = + (ran.nextInt(sensor.getTypical().intValue()) + sensor.getError().intValue()) * 0.975 + + 1; updateValueFromSensor(sensor, new BigDecimal(x)); } @@ -48,11 +38,9 @@ public class SensorService { * Updates the sensor with new measurement and propagates update through websocket * * @param sensor the sensor to update - * @param value the new measurement * @return the updated sensor */ - public Sensor updateValueFromSensor(Sensor sensor, BigDecimal value) { - sensor.setValue(value); + public Sensor update(Sensor sensor) { sensor = deviceService.saveAsOwner( sensor, sensorRepository.findUser(sensor.getId()).getUsername()); @@ -60,4 +48,20 @@ public class SensorService { sensor, sensorRepository.findUser(sensor.getId()), false, null, false); return sensor; } + + public Sensor updateValueFromSensor(Sensor sensor, BigDecimal value) { + sensor.setValue(value); + return update(sensor); + } + + public Sensor updateSimulationFromSensor(Sensor sensor, BigDecimal error, BigDecimal typical) { + if (error != null) { + sensor.setError(error); + } + + if (typical != null) { + sensor.setTypical(typical); + } + return update(sensor); + } } From 5f12c0c813d7f665ab1409628ce3b511ed93e871 Mon Sep 17 00:00:00 2001 From: omenem Date: Tue, 26 May 2020 12:07:36 +0200 Subject: [PATCH 5/6] wip --- .../smarthut/service/ThermostatService.java | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 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 54ae868..20d7e32 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 @@ -1,7 +1,5 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.service; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor; -import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Sensor.SensorType; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.Thermostat; import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ThermostatRepository; import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint; @@ -40,19 +38,10 @@ public class ThermostatService { double x; Random ran = new Random(); - ; - if (thermostat.getTypical() == null) { - BigDecimal typical = Sensor.TYPICAL_VALUES.get(SensorType.TEMPERATURE); - - x = (ran.nextInt(typical.intValue()) + thermostat.getErr().intValue()) * 0.975 + 1; - - } else { - x = - (ran.nextInt(thermostat.getTypical().intValue()) - + thermostat.getErr().intValue()) - * 0.975 - + 1; - } + x = + (ran.nextInt(thermostat.getTypical().intValue()) + thermostat.getErr().intValue()) + * 0.975 + + 1; updateValueForThermostat(thermostat, new BigDecimal(x)); } From 77e7e9bd7b4003a9b822e070253812c82991e1e1 Mon Sep 17 00:00:00 2001 From: omenem Date: Tue, 26 May 2020 12:52:44 +0200 Subject: [PATCH 6/6] wip --- .../sa4/sanmarinoes/smarthut/controller/SensorController.java | 4 ++-- .../usi/inf/sa4/sanmarinoes/smarthut/models/Thermostat.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java index d4accc3..878bfe3 100644 --- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java @@ -66,8 +66,8 @@ public class SensorController { @PutMapping("/{id}/simulation") public Sensor updateSimulation( @PathVariable("id") Long sensorId, - @RequestParam("value") BigDecimal error, - @RequestParam("value") BigDecimal typical, + @RequestParam("error") BigDecimal error, + @RequestParam("typical") BigDecimal typical, final Principal principal) throws NotFoundException { return sensorService.updateSimulationFromSensor( 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 8dcd657..4e69b01 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 @@ -83,8 +83,8 @@ public class Thermostat extends Switchable implements BooleanTriggerable { @Column(nullable = false, precision = 11, scale = 1) private BigDecimal err = new BigDecimal(1); - @Column(nullable = true, precision = 11, scale = 1) - private BigDecimal typical = new BigDecimal(17.0);; + @Column(nullable = false, precision = 11, scale = 1) + private BigDecimal typical = new BigDecimal(17.0); /** Creates a thermostat with a temperature sensor and its initial OFF state */ public Thermostat() {