In [1]:
from algorithms.db import getPositions, normalize, deletePositions
from algorithms.position import Position
from algorithms.dbscanner import dbscanner
import matplotlib

%pylab inline


Populating the interactive namespace from numpy and matplotlib

Nos conectamos a la base de datos:


In [3]:
dbname = "bahia"
recurso = "tetra:12082364"
limit = 2000
cmd = "SELECT id, recurso, latitud, longitud, velocidad, orientacion, UNIX_TIMESTAMP(fecha) FROM posicionesgps WHERE latitud <> 0 AND longitud <> 0 AND recurso='{0}' LIMIT {1};"

Conseguimos los datos:


In [4]:
data = getPositions(dbname, cmd, recurso, limit)
len(data)


Out[4]:
2000

Tipificamos las variables:


In [5]:
[normalData, normalLats, normalLongs] = normalize(data)

In [6]:
plt.figure(1, figsize=(15,10))
plt.subplot(111)
ax = plt.gca()
ax.grid(True)
plt.plot(normalLats, normalLongs, 'bo');


Utilizamos DBSCAN:


In [7]:
eps = 1
MinPts = 5

In [8]:
dataDBSCAN = []
for pos in normalData:
    dataDBSCAN.append([pos.lat, pos.lon, pos.date])

In [9]:
dbc = dbscanner()
dbc.dbscan(dataDBSCAN, eps, MinPts)



In [ ]: