wip
This commit is contained in:
parent
689e3b96a7
commit
0046143d82
7 changed files with 51 additions and 29 deletions
|
@ -44,8 +44,8 @@ public class SensorController {
|
||||||
newSensor.setName(s.getName());
|
newSensor.setName(s.getName());
|
||||||
newSensor.setRoomId(s.getRoomId());
|
newSensor.setRoomId(s.getRoomId());
|
||||||
newSensor.setValue(s.getValue());
|
newSensor.setValue(s.getValue());
|
||||||
newSensor.setError(s.getError());
|
// newSensor.setError(s.getError());
|
||||||
newSensor.setTypical(s.getTypical());
|
// newSensor.setTypical(s.getTypical());
|
||||||
|
|
||||||
return deviceService.saveAsOwner(newSensor, principal.getName());
|
return deviceService.saveAsOwner(newSensor, principal.getName());
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,21 @@ public class SensorController {
|
||||||
value);
|
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}")
|
@DeleteMapping("/{id}")
|
||||||
public void deleteById(@PathVariable("id") long id, final Principal principal)
|
public void deleteById(@PathVariable("id") long id, final Principal principal)
|
||||||
throws NotFoundException {
|
throws NotFoundException {
|
||||||
|
|
|
@ -30,8 +30,12 @@ public class ThermostatController {
|
||||||
newT.setRoomId(t.getRoomId());
|
newT.setRoomId(t.getRoomId());
|
||||||
newT.setUseExternalSensors(t.isUseExternalSensors());
|
newT.setUseExternalSensors(t.isUseExternalSensors());
|
||||||
newT.setOn(false);
|
newT.setOn(false);
|
||||||
|
if (t.getErr() != null) {
|
||||||
newT.setErr(t.getErr());
|
newT.setErr(t.getErr());
|
||||||
newT.setTypical(newT.getTypical());
|
}
|
||||||
|
if (t.getTypical() != null) {
|
||||||
|
newT.setTypical(t.getTypical());
|
||||||
|
}
|
||||||
|
|
||||||
thermostatService.populateMeasuredTemperature(newT);
|
thermostatService.populateMeasuredTemperature(newT);
|
||||||
newT = thermostatRepository.save(newT);
|
newT = thermostatRepository.save(newT);
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class SensorSaveRequest {
|
||||||
|
|
||||||
@NotNull private BigDecimal value;
|
@NotNull private BigDecimal value;
|
||||||
|
|
||||||
@NotNull private BigDecimal error = new BigDecimal(1);
|
private BigDecimal error;
|
||||||
|
|
||||||
private BigDecimal typical;
|
private BigDecimal typical;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class ThermostatSaveRequest {
|
||||||
@NotNull private boolean turnOn;
|
@NotNull private boolean turnOn;
|
||||||
|
|
||||||
/** The value of the error according to this value */
|
/** The value of the error according to this value */
|
||||||
@NotNull private BigDecimal err = new BigDecimal(1);
|
private BigDecimal err;
|
||||||
|
|
||||||
private BigDecimal typical;
|
private BigDecimal typical;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,11 +46,10 @@ public class Sensor extends InputDevice implements RangeTriggerable {
|
||||||
|
|
||||||
/** The value of the error according to this value */
|
/** The value of the error according to this value */
|
||||||
@Column(nullable = false, precision = 11, scale = 1)
|
@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;
|
|
||||||
|
|
||||||
|
@Column(nullable = false, precision = 11, scale = 1)
|
||||||
|
private BigDecimal typical = new BigDecimal(17);
|
||||||
/** The type of this sensor */
|
/** The type of this sensor */
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
|
|
@ -81,10 +81,10 @@ public class Thermostat extends Switchable implements BooleanTriggerable {
|
||||||
|
|
||||||
/** The value of the error according to this value */
|
/** The value of the error according to this value */
|
||||||
@Column(nullable = false, precision = 11, scale = 1)
|
@Column(nullable = false, precision = 11, scale = 1)
|
||||||
private BigDecimal err;
|
private BigDecimal err = new BigDecimal(1);
|
||||||
|
|
||||||
@Column(nullable = true, precision = 11, scale = 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 */
|
/** Creates a thermostat with a temperature sensor and its initial OFF state */
|
||||||
public Thermostat() {
|
public Thermostat() {
|
||||||
|
|
|
@ -22,20 +22,10 @@ public class SensorService {
|
||||||
private void randomJitter(Sensor sensor) {
|
private void randomJitter(Sensor sensor) {
|
||||||
|
|
||||||
double x;
|
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();
|
Random ran = new Random();
|
||||||
x =
|
x =
|
||||||
(ran.nextInt(sensor.getTypical().intValue()) + sensor.getError().intValue())
|
(ran.nextInt(sensor.getTypical().intValue()) + sensor.getError().intValue()) * 0.975
|
||||||
* 0.975
|
|
||||||
+ 1;
|
+ 1;
|
||||||
}
|
|
||||||
|
|
||||||
updateValueFromSensor(sensor, new BigDecimal(x));
|
updateValueFromSensor(sensor, new BigDecimal(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,11 +38,9 @@ public class SensorService {
|
||||||
* Updates the sensor with new measurement and propagates update through websocket
|
* Updates the sensor with new measurement and propagates update through websocket
|
||||||
*
|
*
|
||||||
* @param sensor the sensor to update
|
* @param sensor the sensor to update
|
||||||
* @param value the new measurement
|
|
||||||
* @return the updated sensor
|
* @return the updated sensor
|
||||||
*/
|
*/
|
||||||
public Sensor updateValueFromSensor(Sensor sensor, BigDecimal value) {
|
public Sensor update(Sensor sensor) {
|
||||||
sensor.setValue(value);
|
|
||||||
sensor =
|
sensor =
|
||||||
deviceService.saveAsOwner(
|
deviceService.saveAsOwner(
|
||||||
sensor, sensorRepository.findUser(sensor.getId()).getUsername());
|
sensor, sensorRepository.findUser(sensor.getId()).getUsername());
|
||||||
|
@ -60,4 +48,20 @@ public class SensorService {
|
||||||
sensor, sensorRepository.findUser(sensor.getId()), false, null, false);
|
sensor, sensorRepository.findUser(sensor.getId()), false, null, false);
|
||||||
return sensor;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue