This commit is contained in:
Claudio Maggioni (maggicl) 2020-04-15 14:10:40 +02:00
parent 74b32cea83
commit 44321fe153
2 changed files with 27 additions and 12 deletions

View file

@ -1,3 +1,7 @@
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);
}

View file

@ -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.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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.StreamSupport;
@Component
@ -15,23 +18,31 @@ public class SensorService {
@Autowired
private SensorRepository sensorRepository;
@Autowired
private ThermostatRepository thermostatRepository;
@Autowired
private SensorSocketEndpoint endpoint;
public void sensorFakeUpdate() {
StreamSupport.stream(sensorRepository.findAll().spliterator(), true)
.forEach(
sensor ->
updateValueFromSensor(
sensor,
Sensor.TYPICAL_VALUES
.get(sensor.getSensor())
.multiply(
BigDecimal.valueOf(0.9875 + Math.random() / 40))));
private void randomJitter(Sensor sensor) {
updateValueFromSensor(
sensor,
Sensor.TYPICAL_VALUES
.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()
}
}
/**