-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdb_trip.py
45 lines (33 loc) · 1.38 KB
/
db_trip.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
# -*- coding: utf-8 -*-
"""
Contains the Trip class, which represents a single taxi trip.
This Trip class is an updated version of the old one which takes trip info from csv files. Instead, it receives trip info from database cursor. Its attributes are also expanded to include fare-related records.
Created on Tuesday Jan 13 12:56:56 2015
@author: Fangyu Wu ([email protected])
"""
import db_main
from traffic_estimation.Trip import Trip
#Fetch trips from database with pickup_datetime between two datetimes
def find_pickup_dt(dt1, dt2):
SQL = """SELECT * FROM trip
WHERE %s <= pickup_datetime
AND pickup_datetime <= %s
ORDER BY pickup_datetime, dropoff_datetime"""
cur = db_main.execute(SQL, (str(dt1), str(dt2)))
return [Trip(record) for record in cur]
#Fetch trips from database with dropoff_datetime between two datetimes
def find_dropoff_dt(dt1, dt2):
SQL = """SELECT * FROM trip
WHERE %s <= dropoff_datetime
AND dropoff_datetime <= %s
ORDER BY pickup_datetime, dropoff_datetime"""
cur = db_main.execute(SQL, (str(dt1), str(dt2)))
return [Trip(record) for record in cur]
#Fetch trips from database with day_of_week and hours_of_day of interest
def find_dow_hod(dow, hod):
SQL = """SELECT * FROM trip
WHERE day_of_week = %s
AND hours_of_day = %s
ORDER BY pickup_datetime, dropoff_datetime"""
cur = db_main.execute(SQL, (dow, hod))
return [Trip(record) for record in cur]