Skip to content

Commit

Permalink
Merge branch 'main' into terraform-realtime
Browse files Browse the repository at this point in the history
  • Loading branch information
FarihaChoudhury authored Jul 26, 2024
2 parents 96a5e97 + 97c1830 commit 2121bc7
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .util/pylint_scores.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"avg_score": 9.853333333333333}
{"avg_score": 9.853333333333333}
33 changes: 8 additions & 25 deletions .util/pylint_scores.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ Your code has been rated at 10.00/10
------------------------------------
Your code has been rated at 10.00/10

************* Module db_connection
archive/db_connection.py:44:15: W0718: Catching too general exception Exception (broad-exception-caught)
archive/db_connection.py:52:15: W0718: Catching too general exception Exception (broad-exception-caught)

-----------------------------------
Your code has been rated at 9.26/10


------------------------------------
Your code has been rated at 10.00/10
Expand All @@ -41,23 +34,17 @@ Your code has been rated at 10.00/10
national_rail/sns_reporting.py:93:11: W0718: Catching too general exception Exception (broad-exception-caught)
national_rail/sns_reporting.py:97:0: R0913: Too many arguments (6/5) (too-many-arguments)
national_rail/sns_reporting.py:125:0: R0914: Too many local variables (19/15) (too-many-locals)
national_rail/sns_reporting.py:180:11: W0718: Catching too general exception Exception (broad-exception-caught)

-----------------------------------
Your code has been rated at 9.62/10
Your code has been rated at 9.71/10

************* Module load_national
national_rail/load_national.py:58:11: W0718: Catching too general exception Exception (broad-exception-caught)
national_rail/load_national.py:105:11: W0718: Catching too general exception Exception (broad-exception-caught)

-----------------------------------
Your code has been rated at 9.63/10
------------------------------------
Your code has been rated at 10.00/10

************* Module national_rail
national_rail/national_rail.py:42:11: W0718: Catching too general exception Exception (broad-exception-caught)

-----------------------------------
Your code has been rated at 9.60/10
------------------------------------
Your code has been rated at 10.00/10

************* Module extract_national
national_rail/extract_national.py:8:0: W0611: Unused load_dotenv imported from dotenv (unused-import)
Expand All @@ -73,20 +60,16 @@ Your code has been rated at 10.00/10
------------------------------------
Your code has been rated at 10.00/10

************* Module realtime_trains
realtime_trains/realtime_trains.py:36:11: W0718: Catching too general exception Exception (broad-exception-caught)

-----------------------------------
Your code has been rated at 9.52/10
------------------------------------
Your code has been rated at 10.00/10

************* Module load_real
realtime_trains/load_real.py:53:0: R0914: Too many local variables (24/15) (too-many-locals)
realtime_trains/load_real.py:136:11: W0718: Catching too general exception Exception (broad-exception-caught)
realtime_trains/load_real.py:240:0: R0913: Too many arguments (6/5) (too-many-arguments)
realtime_trains/load_real.py:265:15: W0718: Catching too general exception Exception (broad-exception-caught)

-----------------------------------
Your code has been rated at 9.67/10
Your code has been rated at 9.84/10


------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion .util/pytest_scores.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"passed": 65, "failed": 0, "total": 65, "passed_percentage": 100}
{"passed": 77, "failed": 0, "total": 77, "passed_percentage": 100}
18 changes: 10 additions & 8 deletions .util/pytest_scores.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
============================= test session starts ==============================
platform linux -- Python 3.12.4, pytest-8.3.2, pluggy-1.5.0
rootdir: /home/runner/work/Railway-Tracker/Railway-Tracker
collected 65 items
collected 77 items

national_rail/test_load_national.py ...... [ 9%]
national_rail/test_transform_national.py ................... [ 38%]
pdf_report/test_extract_pdf.py .. [ 41%]
pdf_report/test_load_pdf.py ...... [ 50%]
realtime_trains/test_extract_real.py ...... [ 60%]
realtime_trains/test_load_real.py ......... [ 73%]
archive/test_archive.py ........... [ 14%]
national_rail/test_load_national.py ...... [ 22%]
national_rail/test_transform_national.py ................... [ 46%]
pdf_report/test_extract_pdf.py ... [ 50%]
pdf_report/test_load_pdf.py ...... [ 58%]
realtime_trains/test_extract_real.py ...... [ 66%]
realtime_trains/test_load_real.py ......... [ 77%]
realtime_trains/test_transform_real.py ................. [100%]

============================== 65 passed in 0.44s ==============================
============================== 77 passed in 0.44s ==============================

8 changes: 4 additions & 4 deletions archive/clean_real_time_trains.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_month_old_waypoints(conn: connection, station_id: str) -> list[dict]:
query = """
SELECT *
FROM waypoint
WHERE run_date <= CURRENT_DATE - INTERVAL '1 month'
WHERE run_date <= CURRENT_DATE - INTERVAL '1 month'
AND station_id = %s;
"""

Expand All @@ -41,7 +41,7 @@ def compute_avg_delay_for_station(conn: connection, station_id: int) -> dict:
arrived/ departed over a month ago. """

query = """
SELECT
SELECT
station_id,
AVG((actual_arrival - booked_arrival)+(actual_departure - booked_departure))avg_overall_delay
FROM waypoint
Expand All @@ -62,7 +62,7 @@ def compute_cancellation_count_for_station(conn: connection, station_id: int) ->
query = """
SELECT COUNT(cancellation_id) AS cancellation_count
FROM waypoint w
JOIN cancellation c
JOIN cancellation c
ON c.waypoint_id = w.waypoint_id
WHERE w.station_id = %s
AND run_date <= CURRENT_DATE - INTERVAL '1 month';
Expand All @@ -78,7 +78,7 @@ def insert_performance_archive(conn: connection, archive_data: dict) -> None:
Creation date is date of inserting into archive. """

query = """
INSERT INTO performance_archive (station_id, avg_delay, cancellation_count, creation_date)
INSERT INTO performance_archive (station_id, avg_delay, cancellation_count, creation_date)
VALUES (%s, %s, %s, TIMEZONE('Europe/London', CURRENT_TIMESTAMP));
"""

Expand Down
5 changes: 2 additions & 3 deletions archive/db_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,21 @@ def execute(conn: connection, query: str, data: tuple) -> list[dict] | None:

with get_cursor(conn) as cur:
try:
cur = get_cursor(conn)
cur.execute(query, (data))
conn.commit()

logging.info("Clean: successful for %s, for %s.",
query_command, data)

except Exception as e:
except Exception as e: # pylint: disable=broad-exception-caught
conn.rollback()
logging.error("Clean: Error occurred for %s - %s.",
query_command, e)

try:
result = cur.fetchall()

except Exception:
except Exception: # pylint: disable=broad-exception-caught
result = None

return result
Loading

0 comments on commit 2121bc7

Please sign in to comment.