1 | package de.uka.ipd.sdq.pipesandfilters.framework.recorder.sensorframework.strategies; |
2 | |
3 | import java.util.HashMap; |
4 | |
5 | import javax.measure.Measure; |
6 | import javax.measure.quantity.Dimensionless; |
7 | import javax.measure.quantity.Duration; |
8 | import javax.measure.unit.SI; |
9 | |
10 | import de.uka.ipd.sdq.pipesandfilters.framework.MetaDataInit; |
11 | import de.uka.ipd.sdq.pipesandfilters.framework.PipeData; |
12 | import de.uka.ipd.sdq.pipesandfilters.framework.recorder.sensorframework.SensorHelper; |
13 | import de.uka.ipd.sdq.sensorframework.entities.Experiment; |
14 | import de.uka.ipd.sdq.sensorframework.entities.ExperimentRun; |
15 | import de.uka.ipd.sdq.sensorframework.entities.Sensor; |
16 | import de.uka.ipd.sdq.sensorframework.entities.State; |
17 | import de.uka.ipd.sdq.sensorframework.entities.StateSensor; |
18 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
19 | |
20 | public class OverallUtilisationWriteDataStrategy extends AbstractWriteDataStrategy { |
21 | |
22 | private State idleState; |
23 | |
24 | private State busyState; |
25 | |
26 | public OverallUtilisationWriteDataStrategy(IDAOFactory daoFactory, |
27 | Experiment experiment, ExperimentRun run) { |
28 | super(daoFactory, experiment, run); |
29 | } |
30 | |
31 | public void initialise(MetaDataInit metaData) { |
32 | String sensorId = metaData.getMeasurementName(); |
33 | this.idleState = SensorHelper.createOrReuseState(daoFactory, "Idle"); |
34 | this.busyState = SensorHelper.createOrReuseState(daoFactory, "Busy"); |
35 | sensor = SensorHelper.createOrReuseStateSensor(daoFactory, experiment, |
36 | sensorId, idleState); |
37 | if (!((StateSensor) sensor).getSensorStates().contains(idleState)) { |
38 | ((StateSensor) sensor).addSensorState(idleState); |
39 | } |
40 | ((StateSensor) sensor).addSensorState(busyState); |
41 | } |
42 | |
43 | @SuppressWarnings("unchecked") |
44 | @Override |
45 | public void writeData(PipeData data) { |
46 | Measure<Double, Duration> measurementTimeMeasure = (Measure<Double, Duration>) data |
47 | .getTupleElement(0); |
48 | double measurementTime = measurementTimeMeasure.doubleValue(SI.SECOND); |
49 | Measure<Integer, Dimensionless> numericStateMeasure = (Measure<Integer, Dimensionless>) data |
50 | .getTupleElement(1); |
51 | int numericState = numericStateMeasure.intValue(Dimensionless.UNIT); |
52 | State state = null; |
53 | if (numericState == 0) { |
54 | state = idleState; |
55 | } else { |
56 | state = busyState; |
57 | } |
58 | run.addStateMeasurement((StateSensor)sensor, state, measurementTime); |
59 | } |
60 | |
61 | } |