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 |
|
import java.util.ArrayList; |
8 |
|
import java.util.Arrays; |
9 |
|
|
10 |
|
import android.content.res.AssetManager; |
11 |
|
|
|
|
| 95,3% |
Uncovered Elements: 3 (64) |
Complexity: 9 |
Complexity Density: 0,18 |
|
12 |
|
public class LoadWeightsConversion implements Runnable { |
13 |
|
|
14 |
|
|
15 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
16 |
1
|
public LoadWeightsConversion() {... |
17 |
|
|
18 |
|
} |
19 |
|
|
|
|
| 95,2% |
Uncovered Elements: 3 (62) |
Complexity: 8 |
Complexity Density: 0,16 |
|
20 |
1
|
public void run() {... |
21 |
|
|
22 |
1
|
ArrayList<ArrayList<String>> uns = new ArrayList<ArrayList<String>>(); |
23 |
1
|
ArrayList<ArrayList<Float>> quants = new ArrayList<ArrayList<Float>>(); |
24 |
1
|
ArrayList<ArrayList<Float>> grams = new ArrayList<ArrayList<Float>>(); |
25 |
|
|
26 |
8195
|
for (int i = 0; i < WhatYouEat.FOOD_COUNT; i++) { |
27 |
8194
|
uns.add(new ArrayList<String>()); |
28 |
8194
|
quants.add(new ArrayList<Float>()); |
29 |
8194
|
grams.add(new ArrayList<Float>()); |
30 |
|
} |
31 |
1
|
long start = System.currentTimeMillis(); |
32 |
1
|
int readCount = 0; |
33 |
1
|
AssetManager am = WhatYouEat.ctx.getAssets(); |
34 |
1
|
BufferedReader br = null; |
35 |
1
|
try { |
36 |
1
|
InputStream is = am.open("wt_con.txt"); |
37 |
1
|
br = new BufferedReader(new InputStreamReader(is, "UTF-8")); |
38 |
|
|
39 |
1
|
String holder = ""; |
40 |
?
|
while ((holder = br.readLine()) != null) { |
41 |
|
|
42 |
14162
|
String[] values = holder.split("~"); |
43 |
14162
|
int id = GeneralLoadingThread.doInt(values[0]); |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
14162
|
uns.get(id).add(values[2]); |
50 |
14162
|
quants.get(id).add( |
51 |
|
(float) GeneralLoadingThread.doDouble(values[1])); |
52 |
14162
|
grams.get(id).add( |
53 |
|
(float) GeneralLoadingThread.doDouble(values[3])); |
54 |
|
|
55 |
14162
|
if (readCount++ % 1000 == 10) { |
56 |
15
|
Thread.yield(); |
57 |
|
} |
58 |
|
} |
59 |
1
|
br.close(); |
60 |
|
} catch (IOException e) { |
61 |
|
|
62 |
0
|
e.printStackTrace(); |
63 |
|
} |
64 |
|
|
65 |
1
|
for (int i: WhatYouEat.HAS_SERVING_INFO) { |
66 |
7933
|
WhatYouEat.oddUnits[i] = new String[uns.get(i).size()]; |
67 |
7933
|
WhatYouEat.metricConversion[i] = new float[grams.get(i).size()]; |
68 |
7933
|
WhatYouEat.quantityFactor[i] = new float[quants.get(i).size()]; |
69 |
22095
|
for (int j = 0; j < uns.get(i).size(); j++) { |
70 |
14162
|
WhatYouEat.oddUnits[i][j] = uns.get(i).get(j); |
71 |
14162
|
WhatYouEat.metricConversion[i][j] = grams.get(i).get(j); |
72 |
14162
|
WhatYouEat.quantityFactor[i][j] = quants.get(i).get(j); |
73 |
|
} |
74 |
|
|
75 |
|
} |
76 |
|
|
77 |
1
|
for (int i: WhatYouEat.HAS_SERVING_INFO) { |
78 |
22095
|
for (int j = 0; j < uns.get(i).size(); j++) { |
79 |
14162
|
WhatYouEat.oddUnits[i][j] = uns.get(i).get(j); |
80 |
14162
|
WhatYouEat.metricConversion[i][j] = grams.get(i).get(j); |
81 |
14162
|
WhatYouEat.quantityFactor[i][j] = quants.get(i).get(j); |
82 |
|
} |
83 |
|
|
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
1
|
for (int id : WhatYouEat.WITH_SERVING_SIZE) { |
92 |
7933
|
int optimalServingSizeID = 0; |
93 |
7933
|
float smallestServing = 1000000; |
94 |
7933
|
int index = 0; |
95 |
7933
|
for (float weightOfServing : WhatYouEat.metricConversion[id]) { |
96 |
14162
|
if (weightOfServing < smallestServing) { |
97 |
10606
|
smallestServing = weightOfServing; |
98 |
10606
|
optimalServingSizeID = index; |
99 |
|
} |
100 |
14162
|
index++; |
101 |
|
} |
102 |
7933
|
WhatYouEat.optimalServingId[id] = optimalServingSizeID; |
103 |
|
} |
104 |
1
|
float threadTime = (float) ((System.currentTimeMillis() - start) / 1000.0); |
105 |
|
|
106 |
1
|
System.out.println("--------------------------->" + threadTime+"\n"+WhatYouEat.oddUnits[0].length); |
107 |
|
} |
108 |
|
} |