-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeraçao2.py
69 lines (57 loc) · 1.7 KB
/
geraçao2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import numpy as np
import matplotlib.pyplot as plt
import psycopg2
import math
from matplotlib.animation import FuncAnimation
import datetime
import csv
from postgis import Polygon,MultiPolygon
from postgis.psycopg import register
step = 10
conn = psycopg2.connect("dbname=postgres user=tiago")
register(conn)
cursor_psql = conn.cursor()
sql = """select distinct taxi from tracks order by 1"""
cursor_psql.execute(sql)
results = cursor_psql.fetchall()
taxis_x ={}
array_size = int(24*60*60/step)
for row in results:
taxis_x[int(row[0])] = np.zeros(array_size)
offsets = []
with open('offsets.csv', 'r') as csvFile:
reader = csv.reader(csvFile)
i = 0
for row in reader:
l = []
for j in row:
x,y = j.split()
x = float(x)
y= float(y)
l.append([x,y])
offsets.append(l)
offsets = np.array(offsets)
min_dist=50
count=0
#calculate distances
interactions=[]
for time in range(1000):
print(time)
time_i=[]
for t_i in range(len(offsets[0])):
interacts=[]
for t_j in range(t_i +1,len(offsets[0])):
coord_i , coord_j = offsets[time][t_i] , offsets[time][t_j]
if coord_i.all() != 0 and coord_j.all() != 0:
sql_d = """select st_distance(ST_GeomFromText('POINT(""" + str(coord_i[0])+ " " + str(coord_i[1]) + """)',3763),ST_GeomFromText('POINT(""" + str(coord_j[0])+ " " + str(coord_j[1]) + """)',3763));"""
cursor_psql.execute(sql_d)
results_d = cursor_psql.fetchall()
distance = int(results_d[0][0])
if distance <= min_dist:
interacts.append(t_j)
count+=1
time_i.append(interacts)
interactions.append(time_i)
interactions=np.array(interactions)
np.save('interactions', interactions, allow_pickle=True)
conn.close()