Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Rezzie/eventdetector
base: b291afeb23
...
head fork: Rezzie/eventdetector
compare: 1916aefb27
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Sep 14, 2011
@Rezzie PEP8 fixes. 71fcc92
@Rezzie Default to stdout if --output omitted.
Fixed wrong filename printed with 'Parsing definitions...' message
aad7ad4
@Rezzie Merge branch 'master' of github.com:Rezzie/eventdetector 1916aef
Showing with 17 additions and 18 deletions.
  1. +17 −18 eventdetector.py
View
35 eventdetector.py
@@ -26,7 +26,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from playercpp import *
+from playercpp import PlayerClient, Position2dProxy
import json
import logging
@@ -34,12 +34,11 @@
import sys
from math import sqrt
from optparse import OptionParser
-from time import sleep
def DistBetweenPoints(point1, point2):
"""Returns the distance between two points."""
- return sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2)
+ return sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2)
def PointInCircle(point, centre, radius):
@@ -52,8 +51,8 @@ def PointInCircle(point, centre, radius):
def PointInPolygon(point, polygon):
"""Intersection test to see if a point lies within a polygon."""
- i = 0
- j = len(polygon) - 1
+ i = 0
+ j = len(polygon) - 1
inside = False
for i in xrange(0, len(polygon)):
@@ -82,7 +81,7 @@ def Inside(pos, bounds):
parser = OptionParser(usage="Usage: %prog [options] DEFINITIONS_FILE")
parser.add_option("--host", default="localhost", dest="hostname", help="hostname of player server [default: %default]", metavar="HOSTNAME")
parser.add_option("--port", default=6665, dest="port", help="port player server is listening to [default: %default]", metavar="PORT")
-parser.add_option("--output", default="events.log", dest="logfile", help="path to save log file (create/append) [default: %default]", metavar="FILE")
+parser.add_option("--output", default=None, dest="logfile", help="path to save log file (create/append) [default: stdout]", metavar="FILE")
parser.add_option("--log", default="INFO", dest="loglevel", help="verbosity of logging output [default: %default]", metavar="LEVEL")
(options, args) = parser.parse_args()
@@ -101,7 +100,7 @@ def Inside(pos, bounds):
datefmt='%Y-%m-%dT%H:%M:%SZ',
level=loglevel)
-logging.info("Parsing definitions from '%s'...", os.path.basename(options.logfile))
+logging.info("Parsing definitions from '%s'...", os.path.basename(args[0]))
definitions = json.load(open(args[0], 'r'))
logged_events = set(definitions['events'])
models = definitions['models']
@@ -122,9 +121,9 @@ def Inside(pos, bounds):
cache = {}
state = {}
for model in models.keys():
- state[model] = {'proximities': {}, # Current safety radius infractions {model: closest_approach}
- 'stalled': None, # Currently stalled or not
- 'zones': {}} # Current zone occupancies {zone: entry_time}
+ state[model] = {'proximities': {}, # Current safety radius infractions {model: closest_approach}
+ 'stalled': None, # Currently stalled or not
+ 'zones': {}} # Current zone occupancies {zone: entry_time}
logging.info("Starting client read loop...")
@@ -148,11 +147,11 @@ def Inside(pos, bounds):
cache[model] = {'time': None, 'pos': None, 'stall': None}
# Fetch the latest data from the proxy
- time = proxy.GetDataTime()
+ time = proxy.GetDataTime()
if (time != cache[model]['time']):
# Data is new; update the cache
- cache[model]['time'] = time
- cache[model]['pos'] = (proxy.GetXPos(), proxy.GetYPos(), proxy.GetYaw())
+ cache[model]['time'] = time
+ cache[model]['pos'] = (proxy.GetXPos(), proxy.GetYPos(), proxy.GetYaw())
cache[model]['stall'] = proxy.GetStall()
fresh_data = True
@@ -164,8 +163,8 @@ def Inside(pos, bounds):
for model, latest in cache.iteritems():
# Save some typing
- time = latest['time']
- pos = latest['pos']
+ time = latest['time']
+ pos = latest['pos']
stall = latest['stall']
if 'stall' in logged_events:
@@ -196,7 +195,7 @@ def Inside(pos, bounds):
continue
# Save some typing
- other_pos = cache[other]['pos']
+ other_pos = cache[other]['pos']
other_radius = models[other]['safety-radius']
if PointInCircle(pos, other_pos, other_radius):
@@ -218,8 +217,8 @@ def Inside(pos, bounds):
else:
if other in state[model]['proximities']:
# The model has just left the other's safety radius
- status = state[model]['proximities'][other]
- duration = time - status['time']
+ status = state[model]['proximities'][other]
+ duration = time - status['time']
closest_approach = status['closest_approach']
logging.info("[EVENT] '%s' left the safety radius of '%s' at (x: %f, y: %f, yaw: %f) at %fs after %fs (closest approach was %fm at %fs)", model, other, pos[0], pos[1], pos[2], time, duration, closest_approach['dist'], closest_approach['time'])
del state[model]['proximities'][other]

No commit comments for this range

Something went wrong with that request. Please try again.