Added CSV logging

This commit is contained in:
Ziver Koc 2014-07-31 09:53:04 +02:00
parent 319f6023e9
commit d9fac2807a
25 changed files with 200 additions and 144 deletions

View file

@ -59,7 +59,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
</content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 15 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="GraphView-3.1.2" level="project" />
<orderEntry type="library" exported="" name="support-v4-19.1.0" level="project" />

View file

@ -1,15 +1,15 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
compileSdkVersion 15
buildToolsVersion '19.1.0'
defaultConfig {
applicationId "com.ericsson.uecontrol"
minSdkVersion 19
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
versionCode 3
versionName "1.0.2"
}
buildTypes {
release {

View file

@ -33,4 +33,7 @@
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

View file

@ -81,14 +81,14 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
public void handledIncomingData(long size) {
downloadSpeed.setHandledData(size);
if(throughputListener != null && downloadSpeed.isUpdated())
throughputListener.throughputUpdate(downloadSpeed.getThroughput(), uploadSpeed.getThroughput());
throughputListener.throughputUpdate(downloadSpeed.getBitThroughput(), uploadSpeed.getBitThroughput());
}
@Override
public void handledOutgoingData(long size) {
uploadSpeed.setHandledData(size);
if(throughputListener != null && uploadSpeed.isUpdated())
throughputListener.throughputUpdate(downloadSpeed.getThroughput(), uploadSpeed.getThroughput());
throughputListener.throughputUpdate(downloadSpeed.getBitThroughput(), uploadSpeed.getBitThroughput());
}
public void setThroughputListener(ThroughputListener listener){
@ -99,6 +99,9 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
return behaviours;
}
public UeBehaviour getRunningBehaviour(){
return currentlyActive;
}
public static interface ThroughputListener{
public void throughputUpdate(double downThroughput, double upThroughput);

View file

@ -1,34 +0,0 @@
package com.ericsson.uecontrol.core.behaviour;
import com.ericsson.uecontrol.core.UeBehaviour;
/**
* This behaviour simulates streaming data.
* E.g: video, music etc...
*
* Created by ezivkoc on 2014-07-15.
*/
public class UeBehaviourDownload extends UeBehaviour {
private long data_size;
public UeBehaviourDownload(long byte_amount){
data_size = byte_amount;
}
@Override
protected void execute() {
//TODO
}
@Override
public String getName() {
return "Download";
}
@Override
public String toString() {
return "Will download "+ data_size/1000 +"kB";
}
}

View file

@ -1,34 +0,0 @@
package com.ericsson.uecontrol.core.behaviour;
import com.ericsson.uecontrol.core.UeBehaviour;
/**
* This behaviour simulates streaming data.
* E.g: video, music etc...
*
* Created by ezivkoc on 2014-07-15.
*/
public class UeBehaviourUpload extends UeBehaviour {
private long data_size;
public UeBehaviourUpload(long byte_amount){
data_size = byte_amount;
}
@Override
protected void execute() {
//TODO
}
@Override
public String getName() {
return "Upload";
}
@Override
public String toString() {
return "Will Upload "+ data_size/1000 +"kB";
}
}

View file

@ -24,11 +24,14 @@ public class ThroughputCalculator {
}
}
public double getThroughput(){
public double getByeThroughput(){
setHandledData(0); // Update throughput
updated = false;
return throughput;
}
public double getBitThroughput(){
return getByeThroughput()*8;
}
public boolean isUpdated(){
return updated;
@ -36,12 +39,12 @@ public class ThroughputCalculator {
private static final String[] DATA_SIZE = new String[]{"b/s", "kbit/s", "Mbit/s", "Gbit/s"};
public static String getThroughputString(double bits){
public static String getBitThroughputString(double bitsPerSec){
int index = 0;
double value = bits;
double value = bitsPerSec;
for(; value > 1024 && index < DATA_SIZE.length ;index++) {
value /= 1024;
for(; value > 1000 && index < DATA_SIZE.length ;index++) {
value /= 1000;
}
value = (int)(value*10) / 10.0;

View file

@ -30,14 +30,8 @@ public class EditActivity extends ListActivity implements AdapterView.OnItemClic
setContentView(R.layout.activity_edit);
final List<UeBehaviour> list;
if(getIntent().hasExtra("executor")) {
int executorIndex = getIntent().getExtras().getInt("executor_index");
executor = MainActivity.getExecutor(executorIndex);
list = executor.getBehaviourList();
}
else
list = new ArrayList<UeBehaviour>();
executor = MainActivity.getExecutor();
list = executor.getBehaviourList();
adapter = new BehaviourListAdapter(this, list);
adapter.setEditable(true);

View file

@ -3,9 +3,10 @@ package com.ericsson.uecontrol.gui;
import android.app.ActionBar;
import android.app.FragmentManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.MenuItem;
@ -16,8 +17,7 @@ import com.ericsson.uecontrol.core.behaviour.UeBehaviourSurfing;
import com.ericsson.uecontrol.gui.fragments.BehaviourListFragment;
import com.ericsson.uecontrol.gui.fragments.NavigationDrawerFragment;
import com.ericsson.uecontrol.gui.fragments.StatusFragment;
import java.util.ArrayList;
import com.ericsson.uecontrol.gui.util.CSVWriter;
public class MainActivity extends FragmentActivity
@ -29,34 +29,31 @@ public class MainActivity extends FragmentActivity
private NavigationDrawerFragment navigationDrawerFragment;
private StatusFragment statusFragment;
private int currentExecutor;
private static UeControlExecutor currentExecutor;
private static CSVWriter logger;
private static ArrayList<UeControlExecutor> executors;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
navigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
//navigationDrawerFragment = (NavigationDrawerFragment)
// getFragmentManager().findFragmentById(R.id.navigation_drawer);
statusFragment = (StatusFragment)
getFragmentManager().findFragmentById(R.id.status_fragment);
// Set up the drawer.
navigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
//navigationDrawerFragment.setUp(
// R.id.navigation_drawer,
// (DrawerLayout) findViewById(R.id.drawer_layout));
executors = new ArrayList<UeControlExecutor>();
currentExecutor = 0;
UeControlExecutor exec = new UeControlExecutor();
exec.addBehaviour(new UeBehaviourSleep());
exec.addBehaviour(new UeBehaviourSurfing());
exec.addBehaviour(new UeBehaviourSleep(4000));
exec.setThroughputListener(statusFragment.getThroughputListener());
executors.add(exec);
currentExecutor = new UeControlExecutor();
currentExecutor.addBehaviour(new UeBehaviourSleep());
currentExecutor.addBehaviour(new UeBehaviourSurfing());
currentExecutor.addBehaviour(new UeBehaviourSleep(4000));
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
onNavigationDrawerItemSelected(0);
}
@Override
@ -64,13 +61,12 @@ public class MainActivity extends FragmentActivity
// update the main content by replacing fragments
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, BehaviourListFragment.newInstance(position)).commit();
currentExecutor = position;
.replace(R.id.container, BehaviourListFragment.newInstance()).commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (navigationDrawerFragment != null && !navigationDrawerFragment.isDrawerOpen()) {
if (navigationDrawerFragment == null || !navigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
@ -93,20 +89,23 @@ public class MainActivity extends FragmentActivity
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_execute) {
UeControlExecutor exec = executors.get(currentExecutor);
if(exec.isRunning()){
exec.terminate();
if(currentExecutor.isRunning()){
currentExecutor.terminate();
item.setTitle(R.string.action_run);
}
else {
exec.execute();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(prefs.getBoolean("logging", false))
logger = new CSVWriter(this);
else
logger = null;
currentExecutor.execute();
item.setTitle(R.string.action_stop);
}
return true;
}
if (id == R.id.action_edit) {
Intent intent = new Intent(this, EditActivity.class);
intent.putExtra("executor", currentExecutor);
startActivity(intent);
return true;
}
@ -117,9 +116,14 @@ public class MainActivity extends FragmentActivity
return super.onOptionsItemSelected(item);
}
public static UeControlExecutor getExecutor(int index) {
if(index >= executors.size())
return null;
return executors.get(index);
public static UeControlExecutor getExecutor() {
return currentExecutor;
}
public static void logThroughput(double downThroughput, double upThroughput) {
if(logger == null || currentExecutor == null || currentExecutor.getRunningBehaviour() == null)
return;
logger.write(currentExecutor.getRunningBehaviour().getName(), downThroughput, upThroughput);
}
}

View file

@ -32,12 +32,12 @@ public class BehaviourListFragment extends Fragment {
private BehaviourListAdapter adapter;
private UeControlExecutor executor;
public static BehaviourListFragment newInstance(int index) {
public static BehaviourListFragment newInstance() {
BehaviourListFragment f = new BehaviourListFragment();
// Supply index input as an argument.
Bundle args = new Bundle();
args.putInt("executor", index);
f.setArguments(args);
//Bundle args = new Bundle();
//args.putInt("executor", index);
//f.setArguments(args);
return f;
}
@ -46,11 +46,8 @@ public class BehaviourListFragment extends Fragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
int index = args.getInt("executor", 0);
if(MainActivity.getExecutor(index) != null) {
UeControlExecutor executor = MainActivity.getExecutor(index);
if(MainActivity.getExecutor() != null) {
UeControlExecutor executor = MainActivity.getExecutor();
adapter = new BehaviourListAdapter(getActivity(), executor.getBehaviourList());
}
else

View file

@ -60,8 +60,7 @@ public class NavigationDrawerFragment extends Fragment {
private boolean mFromSavedInstanceState;
private boolean mUserLearnedDrawer;
public NavigationDrawerFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {

View file

@ -1,8 +1,14 @@
package com.ericsson.uecontrol.gui.fragments;
import android.app.Fragment;
import android.content.Context;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -13,6 +19,8 @@ import android.widget.TextView;
import com.ericsson.uecontrol.R;
import com.ericsson.uecontrol.core.UeControlExecutor;
import com.ericsson.uecontrol.core.util.ThroughputCalculator;
import com.ericsson.uecontrol.gui.MainActivity;
import com.ericsson.uecontrol.gui.util.CSVWriter;
import com.jjoe64.graphview.GraphView.GraphViewData;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle;
@ -67,11 +75,13 @@ public class StatusFragment extends Fragment {
down_speed.post(new Runnable() {
@Override
public void run() {
down_speed.setText(ThroughputCalculator.getThroughputString(downThroughput));
up_speed.setText(ThroughputCalculator.getThroughputString(upThroughput));
down_speed.setText(ThroughputCalculator.getBitThroughputString(downThroughput));
up_speed.setText(ThroughputCalculator.getBitThroughputString(upThroughput));
downGraph.appendData(new GraphViewData(x, downThroughput), true, 120);
upGraph.appendData(new GraphViewData(x, upThroughput), true, 120);
x++;
MainActivity.logThroughput(downThroughput, upThroughput);
}
});
}

View file

@ -0,0 +1,108 @@
package com.ericsson.uecontrol.gui.util;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
/**
* Created by ezivkoc on 2014-07-30.
*/
public class CSVWriter {
public static final String[] HEADINGS = new String[]{
"Timestamp", "Behaviour", "RX Throughput(b/s)", "TX Throughput(b/s)", "RAT"
};
public static final String DELIMITER = ",";
protected static final SimpleDateFormat fileDateFormater = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
protected static final SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
private File file;
private NetworkInfo netInfo;
private WifiInfo wifiInfo;
private TelephonyManager telMan;
public CSVWriter(Context context){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
file = new File(
prefs.getString("logging_path", "/sdcard/uecontrol/"),
"log_"+fileDateFormater.format(System.currentTimeMillis())+".log");
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
netInfo = cm.getActiveNetworkInfo();
WifiManager wm = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
wifiInfo = wm.getConnectionInfo();
telMan = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
// Write Headings
StringBuilder line = new StringBuilder();
for(String header : HEADINGS){
line.append(header).append(DELIMITER);
}
file.delete();
file.getParentFile().mkdirs();
writeLine(line.toString());
}
public void write(String behaviour){
StringBuilder line = new StringBuilder();
line.append(getTime()).append(DELIMITER);
line.append(behaviour).append(DELIMITER);
line.append(DELIMITER);
line.append(DELIMITER);
line.append(getRat()).append(DELIMITER);
writeLine(line.toString());
}
public void write(String behaviour, double down, double up){
StringBuilder line = new StringBuilder();
line.append(getTime()).append(DELIMITER);
line.append(behaviour).append(DELIMITER);
line.append(down).append(DELIMITER);
line.append(up).append(DELIMITER);
line.append(getRat()).append(DELIMITER);
writeLine(line.toString());
}
protected void writeLine(String line){
try{
PrintWriter out = new PrintWriter(new FileOutputStream(file, true));
out.println(line);
out.close();
} catch(IOException e){
e.printStackTrace();
}
}
protected String getRat(){
if(netInfo.getType() == ConnectivityManager.TYPE_MOBILE){
switch(telMan.getNetworkType()){
case TelephonyManager.NETWORK_TYPE_GPRS: return "GPRS";
case TelephonyManager.NETWORK_TYPE_EDGE: return "EDGE";
case TelephonyManager.NETWORK_TYPE_UMTS: return "UMTS";
case TelephonyManager.NETWORK_TYPE_HSPA: return "HSPA";
case TelephonyManager.NETWORK_TYPE_LTE: return "LTE";
}
}
return netInfo.getTypeName();
}
protected String getTime(){
return dateFormater.format(System.currentTimeMillis());
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 660 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,004 B

View file

@ -34,11 +34,12 @@
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<!--
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.ericsson.uecontrol.gui.fragments.NavigationDrawerFragment"
tools:layout="@layout/fragment_navigation_drawer" />
-->
</android.support.v4.widget.DrawerLayout>

View file

@ -28,20 +28,19 @@
android:typeface="sans"
android:textSize="17dip"
android:textStyle="bold"
android:layout_toEndOf="@+id/draggable"
android:layout_alignParentTop="true" />
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/draggable" />
<!-- Behaviour description -->
<TextView
android:id="@+id/description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:textColor="#343434"
android:textSize="12dip"
android:layout_marginTop="1dip"
android:text="Description"
android:layout_toEndOf="@+id/draggable"/>
android:layout_below="@+id/title"
android:layout_toRightOf="@+id/draggable" />
<!-- Rightend -->
@ -64,7 +63,7 @@
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:visibility="invisible"
android:layout_toLeftOf="@+id/active"/>
android:layout_toLeftOf="@+id/active" />
<ProgressBar
android:id="@+id/progress"
@ -72,7 +71,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/description"
android:layout_alignParentStart="true"
android:visibility="invisible" />

View file

@ -12,7 +12,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:padding="10dp">
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp">
<ImageView
android:layout_width="wrap_content"
@ -55,8 +57,10 @@
<LinearLayout
android:id="@+id/graph"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>

View file

@ -13,7 +13,7 @@
android:key="logging_path"
android:title="@string/pref_logging_path"
android:summary="@string/pref_logging_path_summ"
android:defaultValue="/sdcard/uecontrol" />
android:defaultValue="/sdcard/uecontrol/" />
</PreferenceCategory>
<PreferenceCategory

BIN
app_icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

BIN
device-2014-07-29-112156.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

BIN
device-2014-07-29-112236.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB