1 | package de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reports; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.Collection; |
5 | import java.util.Iterator; |
6 | |
7 | import de.uka.ipd.sdq.sensorframework.entities.SensorAndMeasurements; |
8 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems.CdfReportItem; |
9 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems.HistogramReportItem; |
10 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems.IReportItem; |
11 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems.PdfReportItem; |
12 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems.RCommandRReportItem; |
13 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems.StaticTextReportItem; |
14 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems.SummaryReportItem; |
15 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems.TimeSeriesReportItem; |
16 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.utils.RConnection; |
17 | import de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.utils.REngineHelper; |
18 | |
19 | /**View for a set of time series. |
20 | * Displays a Histogram, CDF, PDF, number of measurements, mean, |
21 | * and the standard deviation for the series. |
22 | * @author groenda, martens |
23 | */ |
24 | public class TimeSeriesReport extends RReport { |
25 | |
26 | /** {@inheritDoc} |
27 | */ |
28 | @Override |
29 | public ArrayList<IReportItem> prepareReportItems( |
30 | final Collection<SensorAndMeasurements> c, final RConnection t) { |
31 | ArrayList<IReportItem> items = new ArrayList<IReportItem>(); |
32 | items.add(new StaticTextReportItem("Time Series Report", true)); |
33 | |
34 | Iterator<SensorAndMeasurements> it = c.iterator(); |
35 | |
36 | HistogramReportItem hrt = new HistogramReportItem( |
37 | "Histogram", "Time"); |
38 | //hrt.setColumns(20); |
39 | items.add(hrt); |
40 | |
41 | CdfReportItem cdf = new CdfReportItem( |
42 | "Cumulative Distribution Function", "Time"); |
43 | items.add(cdf); |
44 | //cdf.setLegendPos(LegendPosition.right); |
45 | |
46 | PdfReportItem pdf = |
47 | new PdfReportItem("Probability Density Function", |
48 | "Time"); |
49 | items.add(pdf); |
50 | //pdf.setLegendPos(LegendPosition.right); |
51 | |
52 | TimeSeriesReportItem timeSeries = new TimeSeriesReportItem( |
53 | "Time Series", "Event Time"); |
54 | items.add(timeSeries); |
55 | //pdf.setLegendPos(LegendPosition.right); |
56 | |
57 | for (int i = 0; i < c.size(); i++) { |
58 | SensorAndMeasurements sm = it.next(); |
59 | |
60 | String sensorName = REngineHelper.storeMeasurementsInRVector(sm, i, |
61 | TimeseriesData.TIMESPAN, t); |
62 | |
63 | String sensorNameEventTime = REngineHelper.storeMeasurementsInRVector(sm, i, |
64 | TimeseriesData.EVENTTIME, t); |
65 | |
66 | items.add(new SummaryReportItem(sensorName, |
67 | sm.getSensor().getSensorName())); |
68 | hrt.addData("s" + i, sm.getSensor().getSensorName(), sensorName); |
69 | cdf.addData("s" + i, sm.getSensor().getSensorName(), sensorName); |
70 | pdf.addData("s" + i, sm.getSensor().getSensorName(), sensorName); |
71 | |
72 | timeSeries.addData("s" + i, sm.getSensor().getSensorName(), sensorName); |
73 | timeSeries.addData("s_ET_" + i, sm.getSensor().getSensorName()+"_ET", sensorNameEventTime); |
74 | |
75 | String rCommand = "length(" + sensorName + ")\n"; |
76 | items.add(new RCommandRReportItem(rCommand, |
77 | "Number of observations of Sensor " |
78 | + sm.getSensor().getSensorName())); |
79 | |
80 | rCommand = "mean(" + sensorName + ")\n"; |
81 | items.add(new RCommandRReportItem(rCommand, |
82 | "Mean of Sensor " + sm.getSensor().getSensorName())); |
83 | |
84 | rCommand = "sd(" + sensorName + ")\n"; |
85 | items.add(new RCommandRReportItem(rCommand, |
86 | "Standard-Deviation of Sensor " |
87 | + sm.getSensor().getSensorName())); |
88 | |
89 | rCommand = "max(" + sensorNameEventTime +") - min(" + sensorNameEventTime +")\n"; |
90 | items.add(new RCommandRReportItem(rCommand, |
91 | "Experiment duration (max(EventTimes) - min(EventTimes)) of Sensor " |
92 | + sm.getSensor().getSensorName())); |
93 | |
94 | rCommand = "length(" + sensorNameEventTime + ") / (max(" + sensorNameEventTime +") - min(" + sensorNameEventTime +"))\n"; |
95 | items.add(new RCommandRReportItem(rCommand, |
96 | "Throughput of Sensor " |
97 | + sm.getSensor().getSensorName())); |
98 | |
99 | |
100 | } |
101 | |
102 | return items; |
103 | } |
104 | |
105 | } |