-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraffic_data.py
More file actions
54 lines (47 loc) · 1.61 KB
/
Copy pathtraffic_data.py
File metadata and controls
54 lines (47 loc) · 1.61 KB
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
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 23 12:50:09 2015
@author: ngreeney
"""
import numpy as np
import matplotlib.pyplot as plt
import mysql.connector
from datetime import datetime
import time
#connect to database
sql = mysql.connector.connect(user="admin",password="admin01",
host="sv-oryx",database="driving")
cursor = sql.cursor()
#locations
origin = "Dinosaur+Parking+Lots,+U.S.+40,+Golden,+CO"
destinations = np.array(["Breckenridge,+CO","Vail,+CO","Beaver+Creek,+CO"])
for dest in destinations:
# for day in xrange(0,7):
locVars = (
dest.replace("+"," "),
# day
)
#pull from database
# selectLine = ("SELECT round(time_to_sec(startTime)/(10*60)) as timekey, "
# "avg(duration) from times "
# "where hour(startTime) between 5 and 12 "
# "and endLoc = %s "
# "and weekday(startTime) = %s "
# "group by timekey")
selectLine = ("select startTime, avg(duration) from times "
"where hour(startTime) between 4 and 12 "
"and endLoc = %s "
# "and weekday(startTime) = %s "
"group by startTime;")
cursor.execute(selectLine,locVars)
data = np.array(cursor.fetchall())
data = data.transpose()
try:
print "day ",day
plt.plot(data[0],data[1]/60-60,label=dest[:-4])#+" "+np.str(day))
except Exception,e:
print np.str(e)
plt.legend()
print cursor.column_names
cursor.close()
sql.close()