wip
This commit is contained in:
parent
74b32cea83
commit
44321fe153
2 changed files with 27 additions and 12 deletions
|
@ -1,3 +1,7 @@
|
||||||
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
|
||||||
|
|
||||||
public interface SensorRepository extends DeviceRepository<Sensor> {}
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface SensorRepository extends DeviceRepository<Sensor> {
|
||||||
|
List<Sensor> findAllBySensor(Sensor.SensorType sensor);
|
||||||
|
}
|
||||||
|
|
|
@ -2,11 +2,14 @@ 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;
|
||||||
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SensorRepository;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.SensorRepository;
|
||||||
|
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;
|
import ch.usi.inf.sa4.sanmarinoes.smarthut.socket.SensorSocketEndpoint;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
|
@ -15,23 +18,31 @@ public class SensorService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SensorRepository sensorRepository;
|
private SensorRepository sensorRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ThermostatRepository thermostatRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SensorSocketEndpoint endpoint;
|
private SensorSocketEndpoint endpoint;
|
||||||
|
|
||||||
public void sensorFakeUpdate() {
|
private void randomJitter(Sensor sensor) {
|
||||||
StreamSupport.stream(sensorRepository.findAll().spliterator(), true)
|
updateValueFromSensor(
|
||||||
.forEach(
|
sensor,
|
||||||
sensor ->
|
Sensor.TYPICAL_VALUES
|
||||||
updateValueFromSensor(
|
.get(sensor.getSensor())
|
||||||
sensor,
|
.multiply(
|
||||||
Sensor.TYPICAL_VALUES
|
BigDecimal.valueOf(0.9875 + Math.random() / 40)));
|
||||||
.get(sensor.getSensor())
|
|
||||||
.multiply(
|
|
||||||
BigDecimal.valueOf(0.9875 + Math.random() / 40))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void temperatureSensorFakeUpdate() {
|
public void sensorFakeUpdate() {
|
||||||
|
sensorRepository.findAllBySensor(Sensor.SensorType.HUMIDITY).forEach(this::randomJitter);
|
||||||
|
sensorRepository.findAllBySensor(Sensor.SensorType.LIGHT).forEach(this::randomJitter);
|
||||||
|
temperatureSensorFakeUpdate(sensorRepository.findAllBySensor(Sensor.SensorType.HUMIDITY));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void temperatureSensorFakeUpdate(List<Sensor> temperatureSensors) {
|
||||||
|
for (Sensor temperature : temperatureSensors) {
|
||||||
|
//Thermostat t = thermostatRepository.findByRoomId()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue