1 | package de.uka.ipd.sdq.sensorframework.adapter; |
2 | |
3 | import java.util.HashMap; |
4 | |
5 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.FrequencyPie; |
6 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.AbstractPie; |
7 | import de.uka.ipd.sdq.sensorframework.entities.Measurement; |
8 | import de.uka.ipd.sdq.sensorframework.entities.SensorAndMeasurements; |
9 | import de.uka.ipd.sdq.sensorframework.entities.State; |
10 | import de.uka.ipd.sdq.sensorframework.entities.StateMeasurement; |
11 | import de.uka.ipd.sdq.sensorframework.entities.StateSensor; |
12 | |
13 | /** |
14 | * This adapter provides a frequency-based calculation of the individual pie |
15 | * fractions. |
16 | * |
17 | * Used for execution result visualization (reliability-related). |
18 | * |
19 | * @author brosch |
20 | * |
21 | */ |
22 | public class StateSensorToFrequencyPieAdapter extends StateSensorToPieAdapter { |
23 | |
24 | /** |
25 | * Initializes the adapter with the given StateSensor measurements. |
26 | * |
27 | * @param samInformation |
28 | * Information about the StateSensor and the measurements |
29 | */ |
30 | public StateSensorToFrequencyPieAdapter( |
31 | final SensorAndMeasurements samInformation) { |
32 | super(samInformation); |
33 | } |
34 | |
35 | /* |
36 | * (non-Javadoc) |
37 | * @see de.uka.ipd.sdq.sensorframework.adapter.StateSensorToPieAdapter#calculateFractions(java.util.HashMap) |
38 | */ |
39 | protected double calculateFractions(final HashMap<String, Double> fractions) { |
40 | for (State state : ((StateSensor) samInformation.getSensor()) |
41 | .getSensorStates()) { |
42 | fractions.put(state.getStateLiteral(), 0.0); |
43 | } |
44 | for (Measurement m : samInformation.getMeasurements()) { |
45 | StateMeasurement sm = (StateMeasurement) m; |
46 | double oldValue = fractions.get(sm.getSensorState().getStateLiteral()); |
47 | double newValue = oldValue + 1.0; |
48 | fractions.put(sm.getSensorState().getStateLiteral(), newValue); |
49 | } |
50 | return samInformation.getMeasurements().size(); |
51 | } |
52 | |
53 | /* |
54 | * (non-Javadoc) |
55 | * @see de.uka.ipd.sdq.sensorframework.adapter.StateSensorToPieAdapter#instantiatePie(java.lang.String) |
56 | */ |
57 | protected AbstractPie instantiatePie(String sensorName) { |
58 | return new FrequencyPie(sensorName); |
59 | } |
60 | } |