1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.ebay.carad.os.vitalsigns.dataretrievers;
22
23 import com.ebay.carad.os.vitalsigns.DataPoint;
24 import com.ebay.carad.os.vitalsigns.IDashboardAgent;
25 import com.ebay.carad.os.vitalsigns.IDashboardReport;
26 import com.ebay.carad.os.vitalsigns.IDataRetriever;
27 import com.ebay.carad.os.vitalsigns.dao.IDataDAO;
28
29 /***
30 * <p>Takes in two report ID's and logs the ratio of their most recently logged values
31 * into its own report ID.</p>
32 *
33 * <p>The Report ID and sort order of the report this runs for needs to be higher
34 * than both numerator and denominator in order for it to run after the other reports.</p>
35 *
36 * <p>You can either supply an instance of IDataDAO to use, or this logger will utilized
37 * the default IDataDAO from the IDashboardAgent that invokes it (if you do not specify one).</p>
38 *
39 * @author Jeremy Kraybill
40 * @author Jeremy Thomerson
41 * @version $Id$
42 */
43 public class ReportRatioLogger implements IDataRetriever {
44
45 private IDashboardReport mNumerator = null;
46 private IDashboardReport mDenominator = null;
47 private double multiplier = 100;
48
49 private IDataDAO mDataDAO = null;
50
51 /***
52 * Set the numerator (top) report.
53 *
54 * @param numerator the numerator (top) report
55 */
56 public void setNumerator(IDashboardReport numerator) {
57 mNumerator = numerator;
58 }
59
60 /***
61 * Set the denominator (bottom) report.
62 *
63 * @param denominator the numerator (bottom) report
64 */
65 public void setDenominator(IDashboardReport denominator) {
66 mDenominator = denominator;
67 }
68
69 /***
70 * Set the multiplier for the result of numerator divided by denominator.
71 * Defaults to 100 if not specified.
72 *
73 * @param inMultiplier multiplier to use
74 */
75 public void setMultiplier(double inMultiplier) {
76 multiplier = inMultiplier;
77 }
78
79 public IDataDAO getDataDAO(IDashboardAgent agent) {
80 return mDataDAO == null ? agent.getDefaultDataDAO() : mDataDAO;
81 }
82
83 public Float getData(IDashboardAgent agent) {
84
85
86
87
88
89
90
91 DataPoint[] topPoints = getDataDAO(agent).getData(mNumerator);
92 DataPoint[] botPoints = getDataDAO(agent).getData(mDenominator);
93 if (topPoints == null || botPoints == null || topPoints.length == 0 || botPoints.length == 0) {
94 return IDataRetriever.ZERO;
95 }
96
97 float top = topPoints[0].getData();
98 float bottom = botPoints[0].getData();
99 return new Float((float) ((top / bottom) * multiplier));
100 }
101
102 public Object clone() throws CloneNotSupportedException {
103 return super.clone();
104 }
105 }