Skip to content

Commit

Permalink
lint with black
Browse files Browse the repository at this point in the history
  • Loading branch information
frankhereford committed Nov 27, 2023
1 parent d6fcef0 commit 39cf855
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions atd-etl/cris_import/lib/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# 🙏🏻 https://github.com/cityofaustin/atd-moped/blob/main/moped-toolbox/amd_milestones_backfill/utils.py#L18


def make_hasura_request(*, query, variables={}, endpoint, admin_secret):
print("Endpoint: ", endpoint)
headers = {"X-Hasura-Admin-Secret": admin_secret}
Expand Down
10 changes: 6 additions & 4 deletions atd-etl/cris_import/lib/helpers_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json
import datetime


def insert_crash_change_template(new_record_dict, differences, crash_id):
"""
Generates a crash insertion graphql query
Expand All @@ -18,8 +19,10 @@ def insert_crash_change_template(new_record_dict, differences, crash_id):
"""

new_record_crash_date = None
try:
new_record_crash_date = new_record_dict["crash_date"].strftime("%Y-%m-%d") #convert_date(new_record_dict["crash_date"])
try:
new_record_crash_date = new_record_dict["crash_date"].strftime(
"%Y-%m-%d"
) # convert_date(new_record_dict["crash_date"])
except:
print("Failed to convert crash_date")

Expand All @@ -30,7 +33,7 @@ def insert_crash_change_template(new_record_dict, differences, crash_id):
new_record_dict[key] = new_record_dict[key].strftime("%H:%M:%S")

# CRIS or the upstream ETL is representing this datum as a float, so cast it back
if key == "rpt_sec_speed_limit":
if key == "rpt_sec_speed_limit":
new_record_dict[key] = int(new_record_dict[key])

# Turn the dictionary into a character-escaped json string
Expand Down Expand Up @@ -78,4 +81,3 @@ def insert_crash_change_template(new_record_dict, differences, crash_id):
)
)
return output

19 changes: 17 additions & 2 deletions atd-etl/cris_import/lib/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import psycopg2.extras

import pprint

pp = pprint.PrettyPrinter(indent=4)

# This library is /not/ designed for reuse in other projects. It is designed to increase the
Expand All @@ -21,6 +22,7 @@ def get_pgfutter_path():
return "/root/pgfutter_x64"
return None


def invalidate_cr3(pg, crash_id):
invalidate_cr3_sql = f"""UPDATE public.atd_txdot_crashes
SET cr3_stored_flag = 'N', cr3_file_metadata = null, cr3_ocr_extraction_date = null
Expand Down Expand Up @@ -77,7 +79,14 @@ def get_column_operators(
column_aggregators.append(column_aggregator)

# fmt: on
return column_assignments, column_comparisons, column_aggregators, important_column_assignments, important_column_comparisons, important_column_aggregators
return (
column_assignments,
column_comparisons,
column_aggregators,
important_column_assignments,
important_column_comparisons,
important_column_aggregators,
)


def check_if_update_is_a_non_op(
Expand Down Expand Up @@ -200,7 +209,7 @@ def form_insert_statement(


def is_change_existing(pg, record_type, record_id):
#print(f"\b 🛎 is existing? {record_type}, {record_id}")
# print(f"\b 🛎 is existing? {record_type}, {record_id}")

sql = f"""
select count(*) as exists
Expand All @@ -216,6 +225,7 @@ def is_change_existing(pg, record_type, record_id):
else:
return False


def has_existing_temporary_record(pg, case_id):
sql = f"""
select count(*) as exists
Expand All @@ -231,6 +241,7 @@ def has_existing_temporary_record(pg, case_id):
else:
return False


def remove_existing_temporary_record(pg, case_id):
sql = f"""
delete from atd_txdot_crashes
Expand All @@ -241,6 +252,7 @@ def remove_existing_temporary_record(pg, case_id):
cursor.execute(sql)
return True


def try_statement(pg, output_map, table, public_key_sql, sql, dry_run):
if dry_run:
print("Dry run; skipping")
Expand Down Expand Up @@ -397,6 +409,7 @@ def get_input_column_type(pg, DB_IMPORT_SCHEMA, input_table, column):
input_column_type = cursor.fetchall()
return input_column_type


def get_input_tables_and_columns(pg, DB_IMPORT_SCHEMA):
sql = f"""
SELECT
Expand All @@ -416,6 +429,7 @@ def get_input_tables_and_columns(pg, DB_IMPORT_SCHEMA):
input_tables_and_columns = cursor.fetchall()
return input_tables_and_columns


def trim_trailing_carriage_returns(pg, DB_IMPORT_SCHEMA, column):
cursor = pg.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
sql = f"""
Expand All @@ -425,6 +439,7 @@ def trim_trailing_carriage_returns(pg, DB_IMPORT_SCHEMA, column):
cursor.execute(sql)
pg.commit()


def form_alter_statement_to_apply_column_typing(DB_IMPORT_SCHEMA, input_table, column):
# the `USING` hackery is due to the reality of the CSV null vs "" confusion
return f"""
Expand Down
31 changes: 15 additions & 16 deletions atd-etl/cris_import/lib/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
# usage: stick the "mess with in coming records" function in cris_import.py like
# so to make every record in the CRIS zip an update.

#trimmed_token = remove_trailing_carriage_returns(pgloader_command_files)
#typed_token = align_db_typing(trimmed_token)
#typed_token = mess_with_incoming_records_to_ensure_updates(
#typed_token,
#DB_BASTION_HOST_SSH_PRIVATE_KEY,
#DB_BASTION_HOST,
#DB_BASTION_HOST_SSH_USERNAME,
#DB_RDS_HOST,
#DB_USER,
#DB_PASS,
#DB_NAME,
#DB_SSL_REQUIREMENT,
#)
#align_records_token = align_records(typed_token)
#clean_up_import_schema(align_records_token)

# trimmed_token = remove_trailing_carriage_returns(pgloader_command_files)
# typed_token = align_db_typing(trimmed_token)
# typed_token = mess_with_incoming_records_to_ensure_updates(
# typed_token,
# DB_BASTION_HOST_SSH_PRIVATE_KEY,
# DB_BASTION_HOST,
# DB_BASTION_HOST_SSH_USERNAME,
# DB_RDS_HOST,
# DB_USER,
# DB_PASS,
# DB_NAME,
# DB_SSL_REQUIREMENT,
# )
# align_records_token = align_records(typed_token)
# clean_up_import_schema(align_records_token)


def mess_with_incoming_records_to_ensure_updates(
Expand Down

0 comments on commit 39cf855

Please sign in to comment.