Added CSV logging
This commit is contained in:
parent
319f6023e9
commit
d9fac2807a
25 changed files with 200 additions and 144 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue