| 1 | package de.uka.ipd.sdq.sensorframework.visualisation.rvisualisation.reportitems; |
| 2 | |
| 3 | import java.text.DecimalFormat; |
| 4 | |
| 5 | import org.rosuda.JRI.REXP; |
| 6 | |
| 7 | /**Summarizes the values stored in a R variable by displaying |
| 8 | * some statistical measures. |
| 9 | * These measures are Minimum, 1st Quartile, Median, Mean, |
| 10 | * 3rd Quartile, Maximum. |
| 11 | * @author groenda |
| 12 | */ |
| 13 | public class SummaryReportItem extends RCommandRReportItem { |
| 14 | |
| 15 | /**Initialized a new report item that summarizes the |
| 16 | * values stored in a R variable. |
| 17 | * @param rVariableName Name of the R variable in which the data is stored. |
| 18 | * @param displayName Name displayed when referring to the variable. |
| 19 | */ |
| 20 | public SummaryReportItem(final String rVariableName, |
| 21 | final String displayName) { |
| 22 | super("summary(" + rVariableName + ")", |
| 23 | "Summary of Sensor " + displayName); |
| 24 | } |
| 25 | |
| 26 | /** {@inheritDoc} |
| 27 | */ |
| 28 | @Override |
| 29 | public String getText() { |
| 30 | StringBuilder result = new StringBuilder(); |
| 31 | |
| 32 | result.append("<br/> <table border='1' cellspacing='3'><tr align='center'>"); |
| 33 | result.append("<th>Min.</th><th> 1st Quart.</th><th>Median</th><th>Mean</th><th>3rd Quart.</th><th>Max.</th></tr>"); |
| 34 | result.append("</tr><tr align='center'>"); |
| 35 | |
| 36 | if (returnedValue.rtype == REXP.REALSXP) { |
| 37 | double[] doubleArray = returnedValue.asDoubleArray(); |
| 38 | DecimalFormat df= new DecimalFormat(); |
| 39 | for (int measureNumber = 0; measureNumber < 6; measureNumber++) { |
| 40 | // fix the number of used decimals using different formatters |
| 41 | df.applyPattern("###.0"); |
| 42 | if (Math.abs(doubleArray[measureNumber])< 0.2) df.applyPattern("#0.0#E0#"); |
| 43 | if (Math.abs(doubleArray[measureNumber])>999) df.applyPattern("#0.0#E0#"); |
| 44 | df.format(doubleArray[measureNumber]); |
| 45 | result.append("<td>"+df.format(doubleArray[measureNumber])+"</td>"); |
| 46 | } |
| 47 | result.append("</tr></table>"); |
| 48 | return result.toString(); |
| 49 | } |
| 50 | |
| 51 | return "N/A"; |
| 52 | } |
| 53 | |
| 54 | } |