Skip to content
Snippets Groups Projects
Commit 18eb571f authored by Akrillo's avatar Akrillo
Browse files

1st bgt stop android impl

parent 10553cfd
Branches
No related tags found
No related merge requests found
Showing
with 23205 additions and 7 deletions
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="agg2graph/androidsrc/GPSEvaluator/gen"/>
<classpathentry kind="src" path="agg2graph/androidsrc/GPSEvaluator/src"/>
<classpathentry kind="src" path="agg2graph/src"/>
<classpathentry kind="src" path="agg2graph/unit-test"/>
<classpathentry kind="lib" path="agg2graph/agg2graph.jar"/>
<classpathentry kind="lib" path="agg2graph/androidsrc/GPSEvaluator/bin/dexedLibs/android-support-v4-a23537b079e86f2f8b0ba60bc0d723f2.jar"/>
<classpathentry kind="lib" path="agg2graph/androidsrc/GPSEvaluator/libs/android-support-v4.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/commons-jxpath-1.3.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/dom4j-1.6.1.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/frechet.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/hamcrest-all-1.3.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/jarjar-1.4.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/jaxen-1.1-beta-6.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/jcommon-1.0.17.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/jens.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/jfreechart-1.0.14.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/jmapviewer/JMapViewer.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/jscience/jscience.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/jsi-1.0b8.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/jts-1.8.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/junit-4.11.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/log4j-1.2.6.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/opencsv-2.3.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/processing.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/sqlitejdbc-v056.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/swingx-all-1.6.4.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/swingx-ws-1.0.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/trove-2.0.2.jar"/>
<classpathentry kind="lib" path="agg2graph/libs/weka.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="agg2graph/androidsrc/GPSEvaluator/bin/classes"/>
</classpath>
.project 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Projektseminar Datenverwaltung</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
......@@ -4,7 +4,7 @@
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk
android:minSdkVersion="16"
android:minSdkVersion="17"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
......
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>
\ No newline at end of file
......@@ -11,4 +11,5 @@
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-16
target=android-17
android.library=false
This diff is collapsed.
......@@ -8,11 +8,13 @@ import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import de.fub.agg2graph.gpseval.app.EasyNotification;
import de.fub.agg2graph.gpseval.app.GPSTracker;
import de.fub.agg2graph.gpseval.app.PushResponseReceiver;
import de.fub.agg2graph.gpseval.app.activity.MainActivity;
import de.fub.agg2graph.gpseval.evaluator.DecisionTree;
import de.fub.agg2graph.gpseval.evaluator.BvgStops;
import de.fub.agg2graph.gpseval.evaluator.DecisionTreeAndroid;
import android.app.IntentService;
import android.content.Context;
......@@ -35,6 +37,8 @@ public class DynamicDetectionService extends IntentService {
EasyNotification notification = new EasyNotification(this);
BvgStops bvgStops;
private TimerTask task_5s = new TimerTask() {
public void run() {
if(!lockDynamicDetection) {
......@@ -61,7 +65,7 @@ public class DynamicDetectionService extends IntentService {
} else {
String current_status = getCurrentStatus();
//sobald sich der algorithmus fr etwas anderes entscheidet dann stoppe den timeout
//sobald sich der algorithmus fr etwas anderes entscheidet dann stoppe den timeout
if (!current_status.equals(lastDynamicStatusDetection))
timeHelper = 0;
else
......@@ -87,6 +91,7 @@ public class DynamicDetectionService extends IntentService {
*/
public DynamicDetectionService() {
super("HelloIntentService");
bvgStops = new BvgStops(mContext);
}
/**
......@@ -154,7 +159,7 @@ public class DynamicDetectionService extends IntentService {
}
private void broadcastResult(String msg) {
// processing done here.
// processing done here.
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(PushResponseReceiver.ACTION_RESP);
broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
......@@ -188,11 +193,17 @@ public class DynamicDetectionService extends IntentService {
String j48 = MainActivity.settings.getString("decisionTree", "");
double averageSpeed = getAvarageFeature(30, 7);
double shortestDistance = bvgStops.getNearestStopDistance(getAvarageFeature(30, 3),getAvarageFeature(30, 2));
Log.d("DynamicDetectionService",
"Shortest distance of last 30s entrys: " + shortestDistance);
//just testing
Log.d("DynamicDetectionService",
"Average speed of last 30s entrys: " + averageSpeed);
DecisionTree tree = new DecisionTree(j48);
DecisionTreeAndroid tree = new DecisionTreeAndroid(j48);
String current_status = tree.getResult(averageSpeed);
return current_status;
......
package de.fub.agg2graph.gpseval.evaluator;
public class BvgRow {
int stop_id;
String stop_code;
String stop_name;
String stop_desc;
double stop_lat;
double stop_lon;
int location_type;
int parent_station;
public BvgRow(int stop_id, String stop_code, String stop_name,
String stop_desc, double stop_lat, double stop_lon,
int location_type, int parent_station) {
super();
this.stop_id = stop_id;
this.stop_code = stop_code;
this.stop_name = stop_name;
this.stop_desc = stop_desc;
this.stop_lat = stop_lat;
this.stop_lon = stop_lon;
this.location_type = location_type;
this.parent_station = parent_station;
}
public int getStop_id() {
return stop_id;
}
public void setStop_id(int stop_id) {
this.stop_id = stop_id;
}
public String getStop_code() {
return stop_code;
}
public void setStop_code(String stop_code) {
this.stop_code = stop_code;
}
public String getStop_name() {
return stop_name;
}
public void setStop_name(String stop_name) {
this.stop_name = stop_name;
}
public String getStop_desc() {
return stop_desc;
}
public void setStop_desc(String stop_desc) {
this.stop_desc = stop_desc;
}
public double getStop_lat() {
return stop_lat;
}
public void setStop_lat(double stop_lat) {
this.stop_lat = stop_lat;
}
public double getStop_lon() {
return stop_lon;
}
public void setStop_lon(double stop_lon) {
this.stop_lon = stop_lon;
}
public double getLocation_type() {
return location_type;
}
public void setLocation_type(int location_type) {
this.location_type = location_type;
}
public double getParent_station() {
return parent_station;
}
public void setParent_station(int parent_station) {
this.parent_station = parent_station;
}
public String toString() {
return stop_id + " " + stop_code + " " + stop_name + " " + stop_desc + " " + stop_lat + " " + stop_lon + " " + location_type + " " + parent_station;
}
}
package de.fub.agg2graph.gpseval.evaluator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import de.fub.agg2graph.gpseval.app.R;
import android.content.Context;
import android.content.res.AssetManager;
public class BvgStops {
List<BvgRow> data = new ArrayList<BvgRow>();
/**
* Read bvg stops file and save it to params
*/
public BvgStops(Context context) {
//read text from file
try {
String file = "res/raw/bvgstops.txt"; // res/raw/test.txt also work.
InputStream is = this.getClass().getClassLoader().getResourceAsStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
int lineNumber = 0;
String[] split ;
while ((line = br.readLine()) != null) {
//ignore 1st line
if(lineNumber++ != 0 ) {
split = line.split(",");
data.add(new BvgRow(Integer.parseInt(split[0]), clearQuotes(split[1]), clearQuotes(split[2]), clearQuotes(split[3]), Double.parseDouble(clearQuotes(split[4])), Double.parseDouble(clearQuotes(split[5])), Integer.parseInt(split[6]), Integer.parseInt(split[7])));
}
}
}catch (IOException e) {
e.printStackTrace();
}
}
private String clearQuotes(String in) {
if(in.charAt(0) == '"')
return in.substring(1, in.length()-2);
else
return in;
}
public double getNearestStopDistance(double lat, double lng) {
double distance = Double.MAX_VALUE;
double tmp_distance = -1;
for(int i = 0 ; i < data.size(); i++) {
tmp_distance = distFrom(lat,lng,data.get(i).getStop_lat(), data.get(i).getStop_lon());
if(tmp_distance < distance)
distance = tmp_distance;
}
return distance;
}
public static double distFrom(double lat1, double lng1, double lat2, double lng2) {
double earthRadius = 3958.75;
double dLat = Math.toRadians(lat2-lat1);
double dLng = Math.toRadians(lng2-lng1);
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
Math.sin(dLng/2) * Math.sin(dLng/2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
double dist = earthRadius * c;
int meterConversion = 1609;
return dist * meterConversion;
}
}
package de.fub.agg2graph.gpseval.evaluator;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class DecisionTreeAndroid {
GenericTreeNode<Object> root;
List<GenericTreeNode<Object>> nodelist;
public DecisionTreeAndroid(String graph) {
root = new GenericTreeNode<Object>();
root.number = 0;
nodelist
= new ArrayList<GenericTreeNode<Object>>();
String[] lines = graph.split(System.getProperty("line.separator"));
// collect nodes
for(String line: lines) {
if (line.startsWith("N")) {
String label = line.split("\"")[1];
int nodeNr = Integer.parseInt("" + line.charAt(1));
int toNodeNr = -1;
if (line.contains("->")) {
toNodeNr = Integer.parseInt("" + line.split("->")[1].split(" ")[0].charAt(1));
}
boolean found = false;
if (toNodeNr == -1) {
System.out.println("NODE " + line);
for (GenericTreeNode<Object> n: nodelist) {
if (n.number == nodeNr) {
found = true;
}
}
if (!found) {
GenericTreeNode<Object> newNode = new GenericTreeNode<Object>();
newNode.data = label;
newNode.number = nodeNr;
nodelist.add(newNode);
}
}
}
}
// collect edges and build tree
for(String line: lines) {
if (line.startsWith("N")) {
String label = line.split("\"")[1];
int nodeNr = Integer.parseInt("" + line.charAt(1));
int toNodeNr = -1;
if (line.contains("->")) {
toNodeNr = Integer.parseInt("" + line.split("->")[1].split(" ")[0].charAt(1));
}
if (toNodeNr >= 0) {
System.out.println("EDGE " + nodeNr + "->" + toNodeNr + " \"" + label + "\"");
for (GenericTreeNode<Object> n: nodelist) {
if (n.number == nodeNr) {
for (GenericTreeNode<Object> m: nodelist) {
if (m.number == toNodeNr) {
m.edgeLabel = label;
n.addChild(m);
}
}
}
}
}
}
}
}
public String getResult(double feature_maxspeed) {
String result = "not set";
//maxspeed
GenericTreeNode<Object> tree_maxspeed = nodelist.get(0);
//check edges for maxspeed decision values
for(GenericTreeNode<Object> n :tree_maxspeed.children) {
String[] split = n.edgeLabel.split(" ");
String op = split[0];
String value = split[1];
if(op.equals("<=")) {
if(feature_maxspeed <= Double.parseDouble(value)) {
result = n.data.toString();
}
} else if(op.equals(">")) {
if(feature_maxspeed > Double.parseDouble(value)) {
result = n.data.toString();
}
}
}
return result;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment