Use doubles to generate random temperatures
This commit is contained in:
46
README.md
46
README.md
@@ -2,8 +2,22 @@
|
||||
|
||||
Une application Java et JavaFX pour gérer des capteurs de température.
|
||||
|
||||
## Usage
|
||||
|
||||
Sur la partie gauche de l'application figure l'arborescence des capteurs.
|
||||
|
||||
Un nouveau capteur peut être ajouté à la liste en saisissant son nom dans le champ de texte, son type et en appuyant sur le bouton *Create*.
|
||||
Il sera alors ajouté à la racine de l'arborescence et si le capteur qui était sélectionné est un capteur virtuel, il sera également ajouté comme source de ce dernier.
|
||||
|
||||
Une source de capteur virtuel peut être supprimée en sélectionnant le capteur virtuel puis en utilisant le menu contextuel sur la source à supprimer.
|
||||
|
||||
Les indicateurs liés à la génération automatique de température sont présentés en bas de l'application.
|
||||
Ils permettent d'activer ou non la génération automatique de température et de choisir la fréquence d'actualisation.
|
||||
|
||||
## Conception
|
||||
|
||||
*Note : les diagrammes UML présentés ci-dessous sont générés avec [Mermaid](https://mermaidjs.github.io/), et peuvent ne pas être rendus correctement sur CodeFirst. Les flèches d'héritage n'ont notamment pas la bonne forme.*
|
||||
|
||||
### Interfaces partagées
|
||||
|
||||
```mermaid
|
||||
@@ -128,3 +142,35 @@ Un capteur manuel ne fait qu'autoriser publiquement la modification de la tempé
|
||||
|
||||
Un capteur virtuel est composé de plusieurs sources de température.
|
||||
C'est une variante du patron de conception composite : chaque capteur virtuel contient une liste de capteurs et de poids associés avec des objets `DataSource`.
|
||||
|
||||
### Stratégies d'actualisation automatique
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
class AutoUpdateStrategy {
|
||||
+nextValue(s : AutoSensor)* double
|
||||
+getType()* AutoUpdateStrategyFactory
|
||||
}
|
||||
<<interface>> AutoUpdateStrategy
|
||||
class RandomUpdateStrategy {
|
||||
-random : Random
|
||||
-min : double
|
||||
-max : double
|
||||
+nextValue(s : AutoSensor) double
|
||||
+getType() AutoUpdateStrategyFactory
|
||||
}
|
||||
class RandomVariationStrategy {
|
||||
-random : Random
|
||||
-maxVariation : double
|
||||
+nextValue(s : AutoSensor) double
|
||||
+getType() AutoUpdateStrategyFactory
|
||||
}
|
||||
class CpuUpdateStrategy {
|
||||
+nextValue(s : AutoSensor) double
|
||||
+getType() AutoUpdateStrategyFactory
|
||||
}
|
||||
AutoUpdateStrategy <|.. CpuUpdateStrategy
|
||||
AutoUpdateStrategy <|.. RandomUpdateStrategy
|
||||
AutoUpdateStrategy <|.. RandomVariationStrategy
|
||||
|
||||
```
|
||||
|
@@ -9,14 +9,20 @@ import java.util.Random;
|
||||
public class RandomUpdateStrategy implements AutoUpdateStrategy {
|
||||
|
||||
private final Random random;
|
||||
private final int min;
|
||||
private final int max;
|
||||
private final double min;
|
||||
private final double max;
|
||||
|
||||
public RandomUpdateStrategy(int min, int max) {
|
||||
public RandomUpdateStrategy(double min, double max) {
|
||||
this(new Random(), min, max);
|
||||
}
|
||||
|
||||
public RandomUpdateStrategy(Random random, int min, int max) {
|
||||
public RandomUpdateStrategy(Random random, double min, double max) {
|
||||
if (min > max) {
|
||||
throw new IllegalArgumentException("min > max");
|
||||
}
|
||||
if (min < -273) {
|
||||
throw new IllegalArgumentException("min < 0K (-273°C)");
|
||||
}
|
||||
this.random = random;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
|
@@ -9,7 +9,7 @@ import java.util.Random;
|
||||
public class RandomVariationStrategy implements AutoUpdateStrategy {
|
||||
|
||||
private final Random random;
|
||||
private final int maxVariation;
|
||||
private final double maxVariation;
|
||||
|
||||
public RandomVariationStrategy(int maxVariation) {
|
||||
this(new Random(), maxVariation);
|
||||
@@ -22,7 +22,7 @@ public class RandomVariationStrategy implements AutoUpdateStrategy {
|
||||
|
||||
@Override
|
||||
public double nextValue(AutoSensor currentState) {
|
||||
return currentState.getTemperature() + random.nextInt(maxVariation * 2) - maxVariation;
|
||||
return currentState.getTemperature() + random.nextDouble(maxVariation * 2) - maxVariation;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user