1 | package de.uka.ipd.sdq.sensorframework.adapter; |
2 | |
3 | import java.util.HashMap; |
4 | |
5 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.AbstractPie; |
6 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.FrequencyFailurePie; |
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 | public class StateSensorToFrequencyFailurePieAdapter extends |
14 | StateSensorToPieAdapter { |
15 | |
16 | /** |
17 | * Initializes the adapter with the given StateSensor measurements. |
18 | * |
19 | * @param samInformation |
20 | * Information about the StateSensor and the measurements |
21 | */ |
22 | public StateSensorToFrequencyFailurePieAdapter( |
23 | final SensorAndMeasurements samInformation) { |
24 | super(samInformation); |
25 | } |
26 | |
27 | /* |
28 | * (non-Javadoc) |
29 | * |
30 | * @seede.uka.ipd.sdq.sensorframework.adapter.StateSensorToPieAdapter# |
31 | * calculateFractions(java.util.HashMap) |
32 | */ |
33 | protected double calculateFractions(final HashMap<String, Double> fractions) { |
34 | for (State state : ((StateSensor) samInformation.getSensor()) |
35 | .getSensorStates()) { |
36 | if (!state.getStateLiteral().equals("Success")) { |
37 | fractions.put(state.getStateLiteral(), 0.0); |
38 | } |
39 | } |
40 | int failureCounter = 0; |
41 | for (Measurement m : samInformation.getMeasurements()) { |
42 | StateMeasurement sm = (StateMeasurement) m; |
43 | if(sm.getSensorState().getStateLiteral().equals("Success")){ |
44 | continue; |
45 | } |
46 | failureCounter++; |
47 | double oldValue = fractions.get(sm.getSensorState().getStateLiteral()); |
48 | double newValue = oldValue + 1.0; |
49 | fractions.put(sm.getSensorState().getStateLiteral(), newValue); |
50 | } |
51 | return failureCounter; |
52 | } |
53 | |
54 | /* |
55 | * (non-Javadoc) |
56 | * |
57 | * @see |
58 | * de.uka.ipd.sdq.sensorframework.adapter.StateSensorToPieAdapter#instantiatePie |
59 | * (java.lang.String) |
60 | */ |
61 | protected AbstractPie instantiatePie(String sensorName) { |
62 | return new FrequencyFailurePie(sensorName); |
63 | } |
64 | |
65 | } |