View Javadoc

1   /*
2    * The contents of this file are subject to the terms 
3    * of the Common Development and Distribution License 
4    * (the "License").  You may not use this file except 
5    * in compliance with the License.
6    * 
7    * You can obtain a copy of the license at 
8    * http://www.sun.com/cddl/cddl.html. 
9    * See the License for the specific language governing 
10   * permissions and limitations under the License.
11   * 
12   * When distributing Covered Code, include this CDDL 
13   * HEADER in each file and include the License file at 
14   * license.txt.  If applicable, add the following below 
15   * this CDDL HEADER, with the fields enclosed by brackets 
16   * "[]" replaced with your own identifying information: 
17   * Portions Copyright [yyyy] [name of copyright owner]
18   * 
19   * Portions Copyright 2004 eBay, Inc.
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  			setQuery("select "
86  			        + "(select top 1 data from reportdata where reportid=" + numerator + " order by logtime desc)"
87  			        + "/"
88  			        + "(select top 1 data from reportdata where reportid=" + denominator + " order by logtime desc) * " + multiplier + " AS DATA");
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 }