Implementation of CSVReader class
This commit is contained in:
parent
b3d75b9ad9
commit
1902b9374b
3 changed files with 117 additions and 6 deletions
93
app/src/main/java/com/ericsson/uecontrol/core/util/CSVReader.java
Executable file
93
app/src/main/java/com/ericsson/uecontrol/core/util/CSVReader.java
Executable file
|
|
@ -0,0 +1,93 @@
|
||||||
|
package com.ericsson.uecontrol.core.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.net.wifi.WifiInfo;
|
||||||
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.os.Environment;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.telephony.gsm.GsmCellLocation;
|
||||||
|
import com.ericsson.uecontrol.gui.MainActivity;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ezivkoc on 2014-07-30.
|
||||||
|
*/
|
||||||
|
public class CSVReader {
|
||||||
|
private static final Logger log = Logger.getLogger(CSVReader.class);
|
||||||
|
|
||||||
|
private File file;
|
||||||
|
private int size;
|
||||||
|
|
||||||
|
private ArrayList<Long> downThroughput;
|
||||||
|
private ArrayList<Long> upThroughput;
|
||||||
|
|
||||||
|
public CSVReader(File path){
|
||||||
|
file = path;
|
||||||
|
downThroughput = new ArrayList<Long>();
|
||||||
|
upThroughput = new ArrayList<Long>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void maxNoOfEntries(int n){
|
||||||
|
size = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Long> getDownThroughput() {
|
||||||
|
return downThroughput;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Long> getUpThroughput() {
|
||||||
|
return upThroughput;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void read() throws IOException {
|
||||||
|
int everyNLines = getNrOfLines(file) / size;
|
||||||
|
if(everyNLines <= 0) everyNLines = 1;
|
||||||
|
BufferedReader in = null;
|
||||||
|
try {
|
||||||
|
downThroughput.clear();
|
||||||
|
upThroughput.clear();
|
||||||
|
in = new BufferedReader(new FileReader(file));
|
||||||
|
in.readLine(); // Skip first line with headers
|
||||||
|
String line = null;
|
||||||
|
long x = 0, y = 0;
|
||||||
|
for (int i=0; (line = in.readLine()) != null; i++) {
|
||||||
|
String[] cols = line.split(CSVWriter.DELIMITER);
|
||||||
|
if(cols.length > 4) {
|
||||||
|
if (i % everyNLines == 0){
|
||||||
|
downThroughput.add(x);
|
||||||
|
upThroughput.add(y);
|
||||||
|
x = Long.parseLong(cols[2]);
|
||||||
|
y = Long.parseLong(cols[3]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
x = (x + Long.parseLong(cols[2])) / 2;
|
||||||
|
y = (y + Long.parseLong(cols[3])) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}finally {
|
||||||
|
if(in != null) in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getNrOfLines(File file) throws IOException {
|
||||||
|
LineNumberReader lnr = null;
|
||||||
|
try {
|
||||||
|
lnr = new LineNumberReader(new FileReader(file));
|
||||||
|
lnr.skip(Long.MAX_VALUE);
|
||||||
|
} finally {
|
||||||
|
// Finally, the LineNumberReader object should be closed to prevent resource leak
|
||||||
|
if (lnr != null) lnr.close();
|
||||||
|
}
|
||||||
|
return lnr.getLineNumber() + 1; //Add 1 because line index starts at 0
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -25,13 +25,13 @@ public class ThroughputCalculator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getByeThroughput(){
|
public double getByteThroughput(){
|
||||||
setHandledData(0); // Update throughput
|
setHandledData(0); // Update throughput
|
||||||
updated = false;
|
updated = false;
|
||||||
return throughput;
|
return throughput;
|
||||||
}
|
}
|
||||||
public double getBitThroughput(){
|
public double getBitThroughput(){
|
||||||
return getByeThroughput()*8;
|
return getByteThroughput()*8;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpdated(){
|
public boolean isUpdated(){
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import android.preference.PreferenceManager;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import com.ericsson.uecontrol.R;
|
import com.ericsson.uecontrol.R;
|
||||||
|
import com.ericsson.uecontrol.core.util.CSVReader;
|
||||||
import com.jjoe64.graphview.GraphView;
|
import com.jjoe64.graphview.GraphView;
|
||||||
import com.jjoe64.graphview.GraphViewSeries;
|
import com.jjoe64.graphview.GraphViewSeries;
|
||||||
import com.jjoe64.graphview.GraphViewStyle;
|
import com.jjoe64.graphview.GraphViewStyle;
|
||||||
|
|
@ -17,6 +18,7 @@ import com.jjoe64.graphview.LineGraphView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -24,6 +26,8 @@ import java.util.List;
|
||||||
public class HistoryActivity extends ListActivity {
|
public class HistoryActivity extends ListActivity {
|
||||||
private static final Logger log = Logger.getLogger(HistoryActivity.class);
|
private static final Logger log = Logger.getLogger(HistoryActivity.class);
|
||||||
|
|
||||||
|
private static final int GRAPH_LENGTH = 60;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
@ -77,18 +81,32 @@ public class HistoryActivity extends ListActivity {
|
||||||
TextView fileNameView = (TextView)view.findViewById(R.id.file_name);
|
TextView fileNameView = (TextView)view.findViewById(R.id.file_name);
|
||||||
fileNameView.setText(csvFile.getName());
|
fileNameView.setText(csvFile.getName());
|
||||||
|
|
||||||
|
// Read CSV File
|
||||||
|
CSVReader reader = new CSVReader(csvFile);
|
||||||
|
reader.maxNoOfEntries(GRAPH_LENGTH);
|
||||||
|
try{reader.read();}catch (IOException e){log.trace(null, e);}
|
||||||
|
GraphView.GraphViewData[] downThrp = new GraphView.GraphViewData[reader.getDownThroughput().size()];
|
||||||
|
GraphView.GraphViewData[] upThrp = new GraphView.GraphViewData[reader.getUpThroughput().size()];
|
||||||
|
for(int i=0; i<reader.getDownThroughput().size(); i++){
|
||||||
|
downThrp[i] = new GraphView.GraphViewData(
|
||||||
|
i, reader.getDownThroughput().get(i));
|
||||||
|
upThrp[i] = new GraphView.GraphViewData(
|
||||||
|
i, reader.getUpThroughput().get(i));
|
||||||
|
}
|
||||||
|
// Setup Graph
|
||||||
LineGraphView graphView = new LineGraphView(this.getContext(), "HistoryView");
|
LineGraphView graphView = new LineGraphView(this.getContext(), "HistoryView");
|
||||||
graphView.setLayoutParams(new LinearLayout.LayoutParams(
|
graphView.setLayoutParams(new LinearLayout.LayoutParams(
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||||
LinearLayout.LayoutParams.MATCH_PARENT));
|
LinearLayout.LayoutParams.MATCH_PARENT));
|
||||||
graphView.getGraphViewStyle().setGridStyle(GraphViewStyle.GridStyle.BOTH);
|
graphView.getGraphViewStyle().setGridStyle(GraphViewStyle.GridStyle.BOTH);
|
||||||
graphView.addSeries(new GraphViewSeries("Download Throughput", new GraphViewSeries.GraphViewSeriesStyle(Color.GREEN, 3),
|
graphView.addSeries(new GraphViewSeries("Download Throughput",
|
||||||
new GraphView.GraphViewData[]{new GraphView.GraphViewData(0, 0)}));
|
new GraphViewSeries.GraphViewSeriesStyle(Color.GREEN, 3), downThrp));
|
||||||
graphView.addSeries(new GraphViewSeries("Upload Throughput", new GraphViewSeries.GraphViewSeriesStyle(Color.RED, 3),
|
graphView.addSeries(new GraphViewSeries("Upload Throughput",
|
||||||
new GraphView.GraphViewData[]{new GraphView.GraphViewData(0, 0)}));
|
new GraphViewSeries.GraphViewSeriesStyle(Color.RED, 3), upThrp));
|
||||||
graphView.setShowVerticalLabels(false);
|
graphView.setShowVerticalLabels(false);
|
||||||
graphView.setShowHorizontalLabels(false);
|
graphView.setShowHorizontalLabels(false);
|
||||||
graphView.setDisableTouch(true);
|
graphView.setDisableTouch(true);
|
||||||
|
graphView.setDrawDataPoints(true);
|
||||||
LinearLayout graphLayout = (LinearLayout)view.findViewById(R.id.graph);
|
LinearLayout graphLayout = (LinearLayout)view.findViewById(R.id.graph);
|
||||||
graphLayout.addView(graphView);
|
graphLayout.addView(graphView);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue