Skip to content

Commit

Permalink
upgrade psycopg from 2 to 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed Apr 23, 2024
1 parent 9048e39 commit 7e606dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion backend/app/db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from dotenv import load_dotenv
from psycopg2 import connect
from psycopg import connect

load_dotenv()

Expand Down
14 changes: 7 additions & 7 deletions backend/app/get_travel_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_
SUM(cn.unadjusted_tt) AS corr_hourly_daily_tt
FROM congestion.network_segments_daily AS cn
WHERE
cn.segment_id::integer IN %(seglist)s
cn.segment_id::integer = ANY(%(seglist)s)
AND cn.hr <@ %(time_range)s::numrange
AND date_part('ISODOW', cn.dt)::integer IN %(dow_list)s
AND date_part('ISODOW', cn.dt)::integer = ANY(%(dow_list)s)
AND cn.dt <@ %(date_range)s::daterange
{tt_holiday_clause}
GROUP BY
Expand Down Expand Up @@ -55,9 +55,9 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_
SELECT SUM( ((length / 1000.0) / mean) * sample_size ) AS probe_hours
FROM here.ta_path
WHERE
link_dir IN %(link_dir_list)s
link_dir = ANY(%(link_dir_list)s)
AND dt <@ %(date_range)s::daterange
AND EXTRACT(ISODOW FROM dt)::integer IN %(dow_list)s
AND EXTRACT(ISODOW FROM dt)::integer = ANY(%(dow_list)s)
AND EXTRACT(HOUR FROM tod)::numeric <@ %(time_range)s::numrange
{sample_holiday_clause}
"""
Expand All @@ -66,14 +66,14 @@ def get_travel_time(start_node, end_node, start_time, end_time, start_date, end_

query_params = {
"length_m": sum([link['length_m'] for link in links]),
"seglist": tuple(set([link['segment_id'] for link in links])),
"link_dir_list": tuple([link['link_dir'] for link in links]),
"seglist": list(set([link['segment_id'] for link in links])),
"link_dir_list": [link['link_dir'] for link in links],
"node_start": start_node,
"node_end": end_node,
# this is where we define that the end of the range is exclusive
"time_range": f"[{start_time},{end_time})", # ints
"date_range": f"[{start_date},{end_date})", # 'YYYY-MM-DD'
"dow_list": tuple(dow_list)
"dow_list": dow_list
}

connection = getConnection()
Expand Down
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ flask==2.2.2
flask_cors==3.0.10
gunicorn==20.1.0
packaging==20.7
psycopg2==2.9.6
psycopg==3.1.18
python-dotenv==0.15.0

0 comments on commit 7e606dc

Please sign in to comment.