1 | package de.uka.ipd.sdq.sensorframework.adapter; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.HashMap; |
5 | |
6 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.Histogram; |
7 | import de.uka.ipd.sdq.codegen.simudatavisualisation.datatypes.HistogramBucketInformation; |
8 | import de.uka.ipd.sdq.sensorframework.entities.Measurement; |
9 | import de.uka.ipd.sdq.sensorframework.entities.SensorAndMeasurements; |
10 | |
11 | /**Adapter for TimeSpanSensors to Histograms. |
12 | * @author groenda |
13 | */ |
14 | public class TimeSpanToThroughputHistogramAdapter extends DataAdapter { |
15 | |
16 | /** Width of the histogram classes. */ |
17 | public static final String HISTOGRAM_WIDTH = "HISTOGRAM_WIDTH"; |
18 | /** Width of the time span. */ |
19 | private static final String TIME_SPAN_WIDTH = "TIME_SPAN_WIDTH"; |
20 | /** Default width of the time span. */ |
21 | private static final double DEFAULT_TIME_SPAN_WIDTH = 10.0; |
22 | |
23 | /** Information about the TimeSpanSensor and the measurements. */ |
24 | private SensorAndMeasurements samInformation; |
25 | |
26 | /**Initializes the adapter with the provided TimeSpanSensor. |
27 | * @param samInformation Information about the TimeSpanSensor |
28 | * and the measurements. |
29 | */ |
30 | public TimeSpanToThroughputHistogramAdapter( |
31 | final SensorAndMeasurements samInformation) { |
32 | super(); |
33 | this.samInformation = samInformation; |
34 | this.adapterProperties.put(HISTOGRAM_WIDTH, Histogram.DEFAULT_BUCKET_WIDTH); |
35 | this.adapterProperties.put(TIME_SPAN_WIDTH, DEFAULT_TIME_SPAN_WIDTH); |
36 | } |
37 | |
38 | /** {@inheritDoc} |
39 | */ |
40 | public Object getAdaptedObject() { |
41 | throw new RuntimeException("Is not correctly implemented."); |
42 | |
43 | // int maxHistClass = 0; |
44 | // HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); |
45 | // double histWidth = (Double) adapterProperties.get(HISTOGRAM_WIDTH); |
46 | // double spanLenght = (Double) ( |
47 | // adapterProperties.get(TIME_SPAN_WIDTH) == null |
48 | // ? DEFAULT_TIME_SPAN_WIDTH |
49 | // : adapterProperties.get(TIME_SPAN_WIDTH)); |
50 | // if (histWidth == 0) { |
51 | // throw new RuntimeException("Histogram width must be > 0"); |
52 | // } |
53 | // Histogram hist = |
54 | // new Histogram(samInformation.getSensor().getSensorName()); |
55 | // ArrayList<Integer> count = new ArrayList<Integer>(); |
56 | // int currentCount = 0; |
57 | // double currentTime = 0; |
58 | // double nextLimit = spanLenght; |
59 | // boolean first = true; |
60 | // for (Measurement m : samInformation.getMeasurements()) { |
61 | // currentTime = m.getEventTime(); |
62 | // if (first) { |
63 | // nextLimit += currentTime; |
64 | // first = false; |
65 | // } |
66 | // if (currentTime < nextLimit) { |
67 | // currentCount++; |
68 | // } else { |
69 | // count.add(currentCount); |
70 | // currentCount = 1; |
71 | // nextLimit += spanLenght; |
72 | // } |
73 | // } |
74 | // for (Integer singleCount : count) { |
75 | // int histogramClass = (int) ((singleCount + histWidth / 2) |
76 | // / histWidth); |
77 | // Object o = map.get(histogramClass); |
78 | // if (o != null) { |
79 | // Integer oldValue = (Integer) o; |
80 | // map.put(histogramClass, oldValue + 1); |
81 | // } else { |
82 | // map.put(histogramClass, 1); |
83 | // } |
84 | // if (maxHistClass < histogramClass) { |
85 | // maxHistClass = histogramClass; |
86 | // } |
87 | // } |
88 | // boolean firstValueFound = false; |
89 | // for (int i = 0; i <= maxHistClass; i++) { |
90 | // Object o = map.get(i); |
91 | // if (o != null) { |
92 | // firstValueFound = true; |
93 | // hist.addEntity(new HistogramBucketInformation((Integer) o |
94 | // / (double) samInformation.getMeasurements().size(), |
95 | // i * histWidth)); |
96 | // } else { |
97 | // if (firstValueFound) { |
98 | // hist.addEntity(new HistogramBucketInformation(0.0, |
99 | // i * histWidth)); |
100 | // } |
101 | // } |
102 | // } |
103 | // return hist; |
104 | } |
105 | } |