Clover Coverage Report - WhatYouEat Coverage Report
Coverage timestamp: sab gen 3 2015 15:14:15 EST
../../../img/srcFileCovDistChart9.png 25% of files have more coverage
41   107   15   8,2
14   78   0,37   5
5     3  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  LoadDataFromTextFile       Line # 11 41 15 86,7% 0.8666667
 
No Tests
 
1    package co.harlequinmettle.healthfoodconcepts;
2   
3    import java.io.BufferedReader;
4    import java.io.IOException;
5    import java.io.InputStream;
6    import java.io.InputStreamReader;
7   
8    import android.content.Context;
9    import android.content.res.AssetManager;
10   
 
11    public class LoadDataFromTextFile implements Runnable {
12    Context context;
13    float[][] db;
14    static Integer lineCount = 0;
15    Boolean finished;
16    float threadTime = 0;
17   
 
18  1 toggle public LoadDataFromTextFile(Context context, float[][] db) {
19  1 this.context = context;
20  1 this.db = db;
21    }
22   
 
23  1 toggle public void run() {
24   
25  1 long start = System.currentTimeMillis();
26  131 for (int i = 0; i < db.length; i++)
27  1065350 for (int j = 0; j < db[i].length; j++)
28  1065220 db[i][j] = -1;
29   
30  1 AssetManager am = context.getAssets();
31  1 BufferedReader br = null;
32  1 try {
33  1 InputStream is = am.open("DATA__3.txt");
34  1 br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
35   
36  1 String holder = "";
37  ? while ((holder = br.readLine()) != null) {
38    // REMOVE INDEX4 - DO PER KAL CALC IN PROGRAM - ADD CAL/100G TO
39    // FOOD DEF
40    // 1573~6~2999~73~2999~70
41    // 1573~6~2999~73~70
42  578642 String[] values = holder.split("~");
43  578642 db[doInt(values[1])][doInt(values[0])] = (float) (doDouble(values[2]));
44   
45  578642 if (lineCount++ % 1000 == 10) {
46  579 WhatYouEat.mHandler.post(new Runnable() {
 
47  579 toggle public void run() {
48  579 int pgrs = (int) (100.0 * lineCount / 578642);
49  579 if (pgrs > 97)
50  11 pgrs = 100;
51  579 WhatYouEat.pb
52    .setProgress(pgrs);
53    }
54    });
55  579 Thread.yield();
56    }
57    }
58  1 br.close();
59    } catch (IOException e) {
60    // TODO Auto-generated catch block
61  0 e.printStackTrace();
62    }
63   
64  1 WhatYouEat.calculateHighlightNumbers();
65    //WhatYouEat.setNutrientStats();
66    //WhatYouEat.kCal = WhatYouEat.db[5];
67  1 WhatYouEat._loaded = true;
68  1 if(WhatYouEat.needToSetSearchFoods){
69  1 WhatYouEat.setFoodsIds();
70    }
71  1 threadTime = (float) ((System.currentTimeMillis() - start) / 1000.0);
72  1 lineCount = 0;
73  1 System.out.println("----------DATA BASE LOADED IN----------------->"
74    + threadTime);
75   
76    }
77   
78    /*
79    * returns the double value of a string and returns -1E-7 if the string
80    * could not be parsed as a double.
81    *
82    * @param value the string that gets converted into a double.
83    */
 
84  578642 toggle public static double doDouble(String value) {
85  578642 try {
86  578642 double val = Double.parseDouble(value);
87  578642 if (val == val)// only return value if its not NaN , NaN==NaN is
88    // false
89  578642 return val;
90    else
91  0 return -0.0000001;
92    } catch (Exception e) {
93    // System.out.println(" TEXT TO NUMBER ERR "+ value +" to -1e-7 ");
94  0 return -0.0000001;
95    }
96    }
97   
 
98  1157284 toggle public static int doInt(String value) {
99  1157284 try {
100  1157284 int val = Integer.parseInt(value);
101  1157284 return val;
102    } catch (Exception e) {
103  0 return -Integer.MAX_VALUE;
104    }
105    }
106   
107    }// END FILE LOAD THREAD