-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateDataReport.java
More file actions
80 lines (73 loc) · 2.39 KB
/
generateDataReport.java
File metadata and controls
80 lines (73 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.*;
class Scratch
{
private static final List<String> dataTransferedON = new ArrayList<>();
private static final List<String> dataTransferedOFF = new ArrayList<>();
public static void main(final String[] args) throws InterruptedException
{
readSitesFromFile("target/AA_ON.txt", dataTransferedON);
readSitesFromFile("target/AA_OFF.txt", dataTransferedOFF);
int sum_AA_ON = getTotalSum(dataTransferedON);
int sum_AA_OFF = getTotalSum(dataTransferedOFF);
createReportFile("target/dataTranferedReport.txt", sum_AA_ON, sum_AA_OFF);
}
private static void readSitesFromFile(final String filePath, List<String> dataTransfered)
{
try
{
final FileReader reader = new FileReader(filePath);
final BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null)
{
dataTransfered.add(line.toString().split("DATA_RECEIVED:")[1]);
}
reader.close();
}
catch (final IOException e)
{
e.printStackTrace();
}
}
private static int getTotalSum(List<String> dataTransfered)
{
int total = 0;
for (final String dataT : dataTransfered)
{
try
{
int number = Integer.parseInt(dataT);
total = total + number;
}
catch (NumberFormatException ex)
{
ex.printStackTrace();
}
}
return total;
}
private static void createReportFile(final String filePath, final int sumON, final int sumOFF) throws InterruptedException
{
float percentGain = 100 - ((sumON * 100.0f) / sumOFF);
String formattedString = String.format("%.02f", percentGain);
int diference = sumON - sumOFF;
try
{
final File newTextFile = new File(filePath);
final FileWriter fw = new FileWriter(newTextFile);
fw.write("*********** DATA TRANSFERRED WITH AA ON AND AA OFF ***********" + "\n\n\n");
fw.write("TOTAL DATA TRANSFERRED FOR THE SAMPLED SITES WITH AA ON: " + sumON + "\n");
fw.write("TOTAL DATA TRANSFERRED FOR THE SAMPLED SITES WITH AA OFF: " + sumOFF + "\n\n\n");
fw.write("TOTAL DIFFERENCE: " + diference + "\n");
fw.write("PERCENTAGE GAIN WITH AA ON: " + formattedString + "\n");
fw.close();
}
catch (final IOException iox)
{
iox.printStackTrace();
}
}
}