# HG changeset patch # User Nicolas Saunier # Date 1342556904 14400 # Node ID 583a2c4622f9f600efe7de1dfb0f570928762837 # Parent bd8ab323c198982c944c9af1c2d5568ad08fa744 created new module for algorithms with function to extract speeds diff -r bd8ab323c198 -r 583a2c4622f9 python/processing.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/processing.py Tue Jul 17 16:28:24 2012 -0400 @@ -0,0 +1,21 @@ +#! /usr/bin/env python +'''Algorithms to process trajectories and moving objects''' + +__metaclass__ = type + +import numpy as np + +import moving + +def extractSpeeds(objects, zone): + speeds = {} + objectsNotInZone = [] + import matplotlib.nxutils as nx + for o in objects: + inPolygon = nx.points_inside_poly(o.getPositions().asArray().T, zone.T) + if inPolygon.any(): + objspeeds = [o.getVelocityAt(i).norm2() for i in xrange(int(o.length()-1)) if inPolygon[i]] + speeds[o.num] = np.mean(objspeeds) # km/h + else: + objectsNotInZone.append(o) + return speeds.values(), speeds, objectsNotInZone diff -r bd8ab323c198 -r 583a2c4622f9 python/storage.py --- a/python/storage.py Tue Jul 17 13:25:34 2012 -0400 +++ b/python/storage.py Tue Jul 17 16:28:24 2012 -0400 @@ -71,6 +71,8 @@ can be positions or velocities returns a moving object''' + import sqlite3 + cursor = connection.cursor() try: