implemented user story 1 for thermmostat, a test is not passing

This commit is contained in:
omenem 2020-05-26 11:40:58 +02:00
parent 03ded14ed2
commit 689e3b96a7
4 changed files with 49 additions and 5 deletions

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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) {