parent
659fb26862
commit
204d26a7e7
@ -0,0 +1,27 @@
|
||||
package fr.uca.iut.clfreville2.model.sensor.auto;
|
||||
|
||||
import fr.uca.iut.clfreville2.model.sensor.AutoSensor;
|
||||
import fr.uca.iut.clfreville2.model.sensor.auto.provider.AutoUpdateStrategyProvider;
|
||||
import fr.uca.iut.clfreville2.model.sensor.auto.provider.StandardUpdateStrategyProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class CpuUpdateStrategy implements AutoUpdateStrategy {
|
||||
|
||||
@Override
|
||||
public double nextValue(AutoSensor currentState) {
|
||||
try {
|
||||
//return Integer.parseInt(Files.readString(Path.of("/sys/devices/pci0000:00/0000:00:18.3/hwmon/hwmon1/temp1_input")).trim()) / 1000D;
|
||||
return Integer.parseInt(Files.readString(Path.of("/sys/class/thermal/thermal_zone0/temp")).trim()) / 1000D;
|
||||
} catch (IOException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoUpdateStrategyProvider getType() {
|
||||
return StandardUpdateStrategyProvider.CPU;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package fr.uca.iut.clfreville2.model.sensor.auto;
|
||||
|
||||
import fr.uca.iut.clfreville2.model.sensor.AutoSensor;
|
||||
import fr.uca.iut.clfreville2.model.sensor.auto.provider.AutoUpdateStrategyProvider;
|
||||
import fr.uca.iut.clfreville2.model.sensor.auto.provider.StandardUpdateStrategyProvider;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomUpdateStrategy implements AutoUpdateStrategy {
|
||||
|
||||
private final Random random;
|
||||
private final int min;
|
||||
private final int max;
|
||||
|
||||
public RandomUpdateStrategy(int min, int max) {
|
||||
this(new Random(), min, max);
|
||||
}
|
||||
|
||||
public RandomUpdateStrategy(Random random, int min, int max) {
|
||||
this.random = random;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double nextValue(AutoSensor currentState) {
|
||||
return random.nextDouble(min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AutoUpdateStrategyProvider getType() {
|
||||
return StandardUpdateStrategyProvider.RANDOM_UPDATE;
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package fr.uca.iut.clfreville2.model.sensor.auto.provider;
|
||||
|
||||
import fr.uca.iut.clfreville2.model.sensor.auto.AutoUpdateStrategy;
|
||||
import fr.uca.iut.clfreville2.model.shared.Nameable;
|
||||
|
||||
public interface AutoUpdateStrategyProvider extends Nameable {
|
||||
|
||||
AutoUpdateStrategy create();
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package fr.uca.iut.clfreville2.model.sensor.auto.provider;
|
||||
|
||||
import fr.uca.iut.clfreville2.model.sensor.auto.AutoUpdateStrategy;
|
||||
import fr.uca.iut.clfreville2.model.sensor.auto.CpuUpdateStrategy;
|
||||
import fr.uca.iut.clfreville2.model.sensor.auto.RandomUpdateStrategy;
|
||||
import fr.uca.iut.clfreville2.model.sensor.auto.RandomVariationStrategy;
|
||||
|
||||
/**
|
||||
* Provide common update strategies.
|
||||
* <p>
|
||||
* This enum ensures that the same strategy is always returned with the same identity.
|
||||
*/
|
||||
public enum StandardUpdateStrategyProvider implements AutoUpdateStrategyProvider {
|
||||
RANDOM_UPDATE {
|
||||
@Override
|
||||
public AutoUpdateStrategy create() {
|
||||
return new RandomUpdateStrategy(-10, 40);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Random";
|
||||
}
|
||||
},
|
||||
RANDOM_VARIATION {
|
||||
@Override
|
||||
public AutoUpdateStrategy create() {
|
||||
return new RandomVariationStrategy(5);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Random variation";
|
||||
}
|
||||
},
|
||||
CPU {
|
||||
@Override
|
||||
public AutoUpdateStrategy create() {
|
||||
return new CpuUpdateStrategy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "CPU";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue