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.TimeDeltaPie; |
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 time-delta-based calculation of the individual pie |
15 | * fractions. |
16 | * |
17 | * Used for resource utilization visualization. |
18 | * |
19 | * @author brosch |
20 | * |
21 | */ |
22 | public class StateSensorToTimeDeltaPieAdapter 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 StateSensorToTimeDeltaPieAdapter( |
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 | double lastChangeTime = 0.0; |
45 | State lastState = ((StateSensor) samInformation.getSensor()) |
46 | .getInitialState(); |
47 | double sum = 0; |
48 | for (Measurement m : samInformation.getMeasurements()) { |
49 | StateMeasurement sm = (StateMeasurement) m; |
50 | double oldValue = fractions.get(lastState.getStateLiteral()); |
51 | double diff = sm.getEventTime() - lastChangeTime; |
52 | double newValue = oldValue + diff; |
53 | sum += diff; |
54 | fractions.put(lastState.getStateLiteral(), newValue); |
55 | lastChangeTime = sm.getEventTime(); |
56 | lastState = sm.getSensorState(); |
57 | } |
58 | return sum; |
59 | } |
60 | |
61 | /* |
62 | * (non-Javadoc) |
63 | * @see de.uka.ipd.sdq.sensorframework.adapter.StateSensorToPieAdapter#instantiatePie(java.lang.String) |
64 | */ |
65 | protected AbstractPie instantiatePie(String sensorName) { |
66 | return new TimeDeltaPie(sensorName); |
67 | } |
68 | } |