Browse Source

init

master
Lennart Weller 6 years ago
commit
84a76c7ddf
11 changed files with 282 additions and 0 deletions
  1. +36
    -0
      .classpath
  2. +2
    -0
      .gitignore
  3. +23
    -0
      .project
  4. +17
    -0
      pom.xml
  5. +40
    -0
      src/main/java/de/ring0/lhw/footballesp/FootballEventProcessor.java
  6. +22
    -0
      src/main/java/de/ring0/lhw/footballesp/IdleDetectorBolt.java
  7. +69
    -0
      src/main/java/de/ring0/lhw/footballesp/SensorFileSpout.java
  8. +22
    -0
      src/main/java/de/ring0/lhw/footballesp/StdoutBolt.java
  9. +12
    -0
      src/main/java/de/ring0/lhw/footballesp/beans/Player.java
  10. +32
    -0
      src/main/java/de/ring0/lhw/footballesp/beans/SensorEvent.java
  11. +7
    -0
      src/main/java/de/ring0/lhw/footballesp/beans/Team.java

+ 36
- 0
.classpath View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
target
.settings

+ 23
- 0
.project View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>footballesp</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

+ 17
- 0
pom.xml View File

@@ -0,0 +1,17 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.ring0.lhw</groupId>
<artifactId>footballesp</artifactId>
<version>0.0.1</version>
<name>Football event parser</name>
<description>Parses event file with storm</description>

<dependencies>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>0.9.2-incubating</version>
</dependency>
</dependencies>
</project>

+ 40
- 0
src/main/java/de/ring0/lhw/footballesp/FootballEventProcessor.java View File

@@ -0,0 +1,40 @@
package de.ring0.lhw.footballesp;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.topology.TopologyBuilder;

public class FootballEventProcessor {
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Need input data as first argument");
return;
}

TopologyBuilder builder = new TopologyBuilder();

builder.setSpout("sensor-data", new SensorFileSpout(), 1);
builder.setBolt("idle-detector", new IdleDetectorBolt(), 1);
builder.setBolt("stdout", new StdoutBolt(), 1);

LocalCluster cluster = new LocalCluster();

Config conf = new Config();
conf.put("file", args[0]);

cluster.submitTopology("football", conf, builder.createTopology());

System.out.println("Press any key to exit");
try {
new BufferedReader(new InputStreamReader(System.in)).readLine();
} catch (IOException e) {
e.printStackTrace();
}
cluster.killTopology("football");
cluster.shutdown();
}
}

+ 22
- 0
src/main/java/de/ring0/lhw/footballesp/IdleDetectorBolt.java View File

@@ -0,0 +1,22 @@
package de.ring0.lhw.footballesp;

import backtype.storm.topology.BasicOutputCollector;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseBasicBolt;
import backtype.storm.tuple.Tuple;

public class IdleDetectorBolt extends BaseBasicBolt {

@Override
public void execute(Tuple arg0, BasicOutputCollector arg1) {
// TODO Auto-generated method stub

}

@Override
public void declareOutputFields(OutputFieldsDeclarer arg0) {
// TODO Auto-generated method stub

}

}

+ 69
- 0
src/main/java/de/ring0/lhw/footballesp/SensorFileSpout.java View File

@@ -0,0 +1,69 @@
package de.ring0.lhw.footballesp;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Map;

import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseRichSpout;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Values;
import de.ring0.lhw.footballesp.beans.SensorEvent;
import de.ring0.lhw.footballesp.beans.SensorEvent.SensorField;

public class SensorFileSpout extends BaseRichSpout {
private static final long serialVersionUID = -7030329478781805482L;
private SpoutOutputCollector collector;
private File csvFile;
private BufferedReader reader;
public void open(@SuppressWarnings("rawtypes") Map conf, TopologyContext context, SpoutOutputCollector collector) {
this.collector = collector;
csvFile = new File((String) conf.get("file"));
if (!csvFile.exists()) return;
try {
reader = new BufferedReader(new FileReader(csvFile));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

public void declareOutputFields(OutputFieldsDeclarer arg0) {
arg0.declare(new Fields("SensorEvent"));
}

public void nextTuple() {
try {
if (reader == null) {
Thread.sleep(1); //This is according to the JavaDoc
return;
}
String line;
while((line = reader.readLine()) != null) {
String[] eventValues = line.split(",");
SensorEvent event = new SensorEvent();
event.sid = Byte.parseByte(eventValues[SensorField.SID.ordinal()]);
event.ts = Long.parseLong(eventValues[SensorField.TS.ordinal()]);
event.x = Short.parseShort(eventValues[SensorField.X.ordinal()]);
event.y = Short.parseShort(eventValues[SensorField.Y.ordinal()]);
event.z = Short.parseShort(eventValues[SensorField.Z.ordinal()]);
event.v = Integer.parseInt(eventValues[SensorField.V.ordinal()]);
event.a = Integer.parseInt(eventValues[SensorField.A.ordinal()]);
event.vx = Short.parseShort(eventValues[SensorField.VX.ordinal()]);
event.vy = Short.parseShort(eventValues[SensorField.VY.ordinal()]);
event.vz = Short.parseShort(eventValues[SensorField.VZ.ordinal()]);
event.ax = Short.parseShort(eventValues[SensorField.AX.ordinal()]);
event.ay = Short.parseShort(eventValues[SensorField.AY.ordinal()]);
event.az = Short.parseShort(eventValues[SensorField.AZ.ordinal()]);
collector.emit(new Values(event));
}
} catch (InterruptedException | IOException e) {
e.printStackTrace();
}
}
}

+ 22
- 0
src/main/java/de/ring0/lhw/footballesp/StdoutBolt.java View File

@@ -0,0 +1,22 @@
package de.ring0.lhw.footballesp;

import backtype.storm.topology.BasicOutputCollector;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseBasicBolt;
import backtype.storm.tuple.Tuple;

public class StdoutBolt extends BaseBasicBolt {

@Override
public void execute(Tuple arg0, BasicOutputCollector arg1) {
// TODO Auto-generated method stub
}

@Override
public void declareOutputFields(OutputFieldsDeclarer arg0) {
// TODO Auto-generated method stub
}

}

+ 12
- 0
src/main/java/de/ring0/lhw/footballesp/beans/Player.java View File

@@ -0,0 +1,12 @@
package de.ring0.lhw.footballesp.beans;

public enum Player {
KEEPER,
PLAYER_1,
PLAYER_2,
PLAYER_3,
PLAYER_4,
PLAYER_5,
PLAYER_6,
PLAYER_7
}

+ 32
- 0
src/main/java/de/ring0/lhw/footballesp/beans/SensorEvent.java View File

@@ -0,0 +1,32 @@
package de.ring0.lhw.footballesp.beans;

public class SensorEvent {
public byte sid;
public long ts;
//position from (0,0) (mid-field)
public short x;
public short y;
public short z;
//absolute velocity and acceleration
public int v;
public int a;
//velocity
public short vx;
public short vy;
public short vz;
//acceleration
public short ax;
public short ay;
public short az;
public enum SensorField {
SID,TS,X,Y,Z,V,A,VX,VY,VZ,AX,AY,AZ
}
public enum SensorId {
LEFT_LEG,
RIGHT_LEG,
LEFT_ARM,
RIGHT_ARM
}
}

+ 7
- 0
src/main/java/de/ring0/lhw/footballesp/beans/Team.java View File

@@ -0,0 +1,7 @@
package de.ring0.lhw.footballesp.beans;

public enum Team {
TEAM_A,
TEAM_B,
TEAM_REFEREE
}

Loading…
Cancel
Save