Clover Coverage Report - WhatYouEat Coverage Report
Coverage timestamp: sab gen 3 2015 15:14:15 EST
../../../img/srcFileCovDistChart6.png 85% of files have more coverage
103   280   30   6,87
16   189   0,29   15
15     2  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  HistogramView       Line # 14 103 30 58,2% 0.58208954
 
No Tests
 
1    package co.harlequinmettle.healthfoodconcepts;
2   
3    import java.util.ArrayList;
4    import java.util.Arrays;
5    import java.util.Collections;
6    import java.util.TreeMap;
7   
8    import android.content.Context;
9    import android.graphics.Canvas;
10    import android.graphics.Paint;
11    import android.graphics.RectF;
12    import android.widget.FrameLayout;
13   
 
14    public class HistogramView extends FrameLayout {
15   
16    int _nPaints = 10;
17    private Paint[] _paints = new Paint[_nPaints];
18    private double sum = 0, sumOfSquares = 0, mean, median, min, max, n, range;
19    private int size;
20    private float upperLim;
21    private int meanBar, pointBar;
22    public double standardDeviation;
23   
24    ArrayList<Float> _data = new ArrayList<Float>();
25    private int[] histogram;
26    // use keybord to change parameters
27    private int BAR_BUFFER = 2;
28    // private int categories = 30;
29    private RectF[] histoBars;
30    int frameW, frameH, barMax;
31    double barwidth;
32    double eMin_0, eMax_3rd;
33    String title, title2, title3, title4;
34    float nutrientPt;
35    float scale;
36    StatTool boiledDown;
37    int barcolor = 0xffcccccc;
38   
 
39  10 toggle public HistogramView(Context context, StatTool blDn, int sw, int sh,int bgcolor) {
40  10 super(context);
41  10 this.setWillNotDraw(false);
42  10 this.barcolor = bgcolor;
43  10 this.boiledDown = blDn;
44  10 this.frameW = (int) (sw * 2.3f);
45  10 this.frameH = sh;
46   
47  10 this.nutrientPt = WhatYouEat.db[SubScroll.currentNutrientID][SubScroll.currentFoodID];
48   
49  10 boolean useServingOK = true;
50   
51  10 switch (WhatYouEat.Nutrient_Measure) {
52  0 case WhatYouEat.USING_KCAL:
53  0 this.nutrientPt = WhatYouEat.getPer100KcalDataPoint(
54    SubScroll.currentFoodID, this.nutrientPt);
55   
56  0 break;
57  0 case WhatYouEat.USING_SERVING:
58  0 this.nutrientPt = WhatYouEat.getPerServingDataPoint(
59    SubScroll.currentFoodID, this.nutrientPt);
60  0 if (this.nutrientPt < 0) {
61  0 useServingOK = false;
62  0 this.nutrientPt =WhatYouEat.db[SubScroll.currentNutrientID][SubScroll.currentFoodID];
63    }
64  0 break;
65  10 case WhatYouEat.USING_GRAMS:
66   
67  10 break;
68    // ADD CASE ID_PER_SERVING:
69  0 default:
70   
71  0 break;
72    }
73   
74  10 this.title = "Distribution of "
75    + WhatYouEat.nutrients[SubScroll.currentNutrientID]
76    + " in all foods in: "+WhatYouEat.getFoodsSearchDescription();
77   
78  10 this.title2 = "["+WhatYouEat.foods[SubScroll.currentFoodID]+"]" + " contains ";
79  10 this.title3 = this.nutrientPt + " "
80    + WhatYouEat.units[SubScroll.currentNutrientID]+" of ["+ WhatYouEat.nutrients[SubScroll.currentNutrientID]+"]";
81   
82  10 switch (WhatYouEat.Nutrient_Measure) {
83  0 case WhatYouEat.USING_KCAL:
84  0 this.title3 += " per 100 kilocalories";
85  0 break;
86  10 case WhatYouEat.USING_GRAMS:
87  10 this.title3 += " per 100 grams";
88  10 break;
89  0 case WhatYouEat.USING_SERVING:
90   
91  0 if (useServingOK) {
92  0 this.title3 += " in "
93    + WhatYouEat.quantityFactor[SubScroll.currentFoodID][WhatYouEat.optimalServingId[SubScroll.currentFoodID]]
94    + " "
95    + WhatYouEat.oddUnits[SubScroll.currentFoodID][WhatYouEat.optimalServingId[SubScroll.currentFoodID]]
96    + " of " + WhatYouEat.foods[SubScroll.currentFoodID];
97    } else {
98  0 this.title3 += " per 100 gram serving";
99    }
100  0 break;
101   
102  0 default:
103   
104  0 break;
105    }
106   
107    // SET TITLE4 BASED ON WHATYOUEAT SETTINGS: USE ZERO USE NULL
108    // doStatsOnList(foodsToUse, currentNutrient);
109   
110  10 histogram = boiledDown.histogram;
111  10 sum = boiledDown.sum;
112  10 sumOfSquares = boiledDown.sumOfSquares;
113  10 mean = boiledDown.mean;
114  10 median = boiledDown.median;
115  10 min = boiledDown.min;
116  10 max = boiledDown.max;
117  10 n = boiledDown.n;
118  10 range = boiledDown.range;
119  10 standardDeviation = boiledDown.standardDeviation;
120  10 barwidth = (frameW - 30 - BAR_BUFFER * StatTool.nbars) / StatTool.nbars;
121  10 upperLim = (float) boiledDown.cutOffPoint;
122   
123  10 meanBar = (int) ((mean) / boiledDown.interval);
124  10 pointBar = (int) ((nutrientPt) / boiledDown.interval);
125   
126  10 if (false) {
127  0 int[] histoTemp = (int[]) histogram.clone();
128    // get third hights bar
129  0 Arrays.sort(histoTemp);
130  0 if (histoTemp.length > 3)
131  0 barMax = histoTemp[histoTemp.length - 4] + 1;
132    else
133  0 barMax = 1;
134    }
135  10 setUpBars(StatTool.nbars);
136  110 for (int i = 0; i < _nPaints; i++)
137  100 _paints[i] = new Paint();
138   
139  10 _paints[0].setARGB(255, 70, 120, 140);
140  10 _paints[1].setARGB(180, 230, 40, 50);
141  10 _paints[2].setColor(0xff000000 | barcolor);
142    //_paints[2].setARGB(200, 90, 100, 200);
143  10 _paints[3].setARGB(255, 200,200,200);
144  10 _paints[3].setTextSize(22);
145  10 _paints[4].setARGB(200, 250, 70, 170);
146  10 _paints[5].setARGB(200, 250, 70, 170);
147   
148    }
149   
 
150  10 toggle private void setUpBars(int nBars) {
151    // UPDATE FOR CONCURRENT HISTOGRAMS
152  10 histoBars = new RectF[nBars];
153  10 float scaleFactor = 2;
154    // scale = (frameH - 50) / barMax;
155  1010 for (int i = 0; i < nBars; i++) {
156  1000 int top = frameH - 50 - (int) (scaleFactor*histogram[i]);
157  1000 int left = 10 + BAR_BUFFER * i + ((int) barwidth) * i;
158  1000 int width = (int) (barwidth);
159  1000 int height = (int) (scaleFactor*histogram[i]);
160  1000 histoBars[i] = new RectF(left, top, left + width, top + height);
161   
162    }
163   
164    }
165   
 
166  10 toggle @Override
167    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
168    // TODO Auto-generated method stub
169  10 super.onMeasure(frameW, frameH);
170  10 setMeasuredDimension(frameW, frameH);
171    }
172   
173    // //////////////////////////
 
174  1199 toggle protected void onDraw(Canvas c) {
175  1199 c.drawColor(0x00000000);
176    // c.save();
177    // c.scale(1, 3);
178  121099 for (int i = 0; i < histoBars.length; i++) {
179  119900 if (i == pointBar)
180  738 c.drawRect(histoBars[i], _paints[3]);
181  119162 else if (false && i == meanBar)
182  0 c.drawRect(histoBars[i], _paints[4]);
183    else
184   
185  119162 c.drawRect(histoBars[i], _paints[2]);
186    }
187    // c.restore();
188  1199 c.drawText(title, 50, 100, _paints[3]);
189  1199 c.drawText(title2, 50, 150, _paints[3]);
190  1199 c.drawText(title3, 50, 200, _paints[3]);
191  1199 c.drawText("0.0", 15, frameH - 20, _paints[3]);
192  1199 c.drawText(
193    " "
194    + Double.toString((double) ((int) (10000.0 * (upperLim))) / 10000.0),
195    frameW - 120, frameH - 20, _paints[3]);
196  1199 invalidate();
197    }
198   
199    /**
200    * @return the range
201    */
 
202  0 toggle public double getRange() {
203  0 return range;
204    }
205   
206    /*
207    * (non-Javadoc)
208    *
209    * @see java.lang.Object#toString()
210    */
 
211  0 toggle @Override
212    public String toString() {
213   
214  0 return "\nactual size: " + n + "\nmin: " + min + "\nmax: " + max
215    + "\nmean: " + mean + "\nmedian: " + median
216   
217    + "\nstandard deviation: " + standardDeviation;
218    }
219   
 
220  0 toggle public double getEffectiveRange() {
221  0 return 4 * standardDeviation;
222    }
223   
224    /**
225    * @return the sum
226    */
 
227  0 toggle public double getSum() {
228  0 return sum;
229    }
230   
231    /**
232    * @return the sumOfSquares
233    */
 
234  0 toggle public double getSumOfSquares() {
235  0 return sumOfSquares;
236    }
237   
238    /**
239    * @return the mean
240    */
 
241  0 toggle public double getMean() {
242  0 return mean;
243    }
244   
245    /**
246    * @return the median
247    */
 
248  0 toggle public double getMedian() {
249  0 return median;
250    }
251   
252    /**
253    * @return the min
254    */
 
255  0 toggle public double getMin() {
256  0 return min;
257    }
258   
259    /**
260    * @return the max
261    */
 
262  0 toggle public double getMax() {
263  0 return max;
264    }
265   
266    /**
267    * @return the n
268    */
 
269  0 toggle public double getN() {
270  0 return n;
271    }
272   
273    /**
274    * @return the standardDeviation
275    */
 
276  0 toggle public double getStandardDeviation() {
277  0 return standardDeviation;
278    }
279   
280    }