Skip to content
Merged

Dev #76

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/unit_tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pip install -U pip
pip install .
pip install -r requirements.txt

python3 -m pytest tests/
12 changes: 4 additions & 8 deletions code/uqid_bug_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,11 @@ def post_correction_checks(


def add_unique_constraint():
constraint_query = text(
"""
constraint_query = text("""
ALTER TABLE question
ADD CONSTRAINT uq_question_uqid
UNIQUE (uqid, year)
"""
)
""")
with SQL_UTILS.engine.begin() as conn:
conn.execute(constraint_query)

Expand All @@ -175,15 +173,13 @@ def revert_or_drop_temp_table(revert: bool = False):
for column in QUESTION.c:
if not column.primary_key:
update_string.append(f"{column.name} = EXCLUDED.{column.name}")
query = text(
f"""
query = text(f"""
INSERT INTO question
SELECT *
FROM question_temp
ON CONFLICT ON CONSTRAINT pk_question DO UPDATE
SET {', '.join(update_string)}
"""
)
""")
queries.insert(0, query)

# Remove unique constraint.
Expand Down
Binary file modified documentation/PIR ERD.pptx
Binary file not shown.
25 changes: 18 additions & 7 deletions documentation/csv/PIR Data Dictionary.csv
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
table, column, column_proper, description
response, uid, Unique Program ID,"Uniquely identifies each program within a year. Hash of grant_number, program_number, and program_type."
response, question_id, Question ID,"Uniquely identifies questions within a year. Hash of question_number, and question_name."
response, year, Year, Year from which question is drawn.
response, answer, Answer, Response to present question.
response, year, Year,Year from which question is drawn.
response, answer, Answer,Response to present question.
question, question_id, Question ID,"Uniquely identifies questions within a year. Hash of question_number, and question_name."
question, year, Year, Year from which question is drawn.
question, uqid, Unique Question ID, Uniquely identifies a question across years.
question, year, Year,Year from which question is drawn.
question, uqid, Unique Question ID,Uniquely identifies a question across years.
question, category, Category, Category of question.
question, question_name, Question Name, Name of question.
question, question_number, Question Number, Number of question.
Expand Down Expand Up @@ -33,8 +33,19 @@ program, program_zip1, Zip 5, Five-digit zip code.
program, program_zip2, Zip 4, Additional four digits for nine-digit zip code.
program, region, Region, Region in which the program is located.
uqid_changelog, id, ID, Auto-incremented integer ID
uqid_changelog, question_id, Question ID, "Uniquely identifies questions within a year. Hash of question_number, and question_name."
uqid_changelog, original_uqid, Original Unique Question ID, "Original UQID, if any, of the target question"
uqid_changelog, new_uqid, New Unique Question ID, "New UQID, if any, of the target question"
uqid_changelog, question_id, Question ID, Uniquely identifies questions within a year. Hash of question_number and question_name.
uqid_changelog, original_uqid, Original Unique Question ID, Original UQID if any of the target question
uqid_changelog, new_uqid, New Unique Question ID, New UQID if any of the target question
uqid_changelog, timestamp, Timestamp, Auto-generated timestamp
uqid_changelog, complete_series_flag, Complete Series Flag, Indicator for whether this question should be marked as complete/confirmed
budget,region,Region,Region in which the program is located
budget,prg,Program,
budget,type,Type,
budget,program_state,Program State,State in which the program is located
budget,afm,Annual Funding Month,
budget,grant_number,Grant Number,Grant number.
budget,program_name,Program Name,Program name.
budget,year,Year,Fiscal year.
budget,quarter,Quarter,Fiscal quarter.
budget,metric,Metric,Reported metric.
budget,value,Value,Value of reported metric.
12 changes: 12 additions & 0 deletions documentation/csv/budget.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
field," type"
region,int
prg,varchar(2)
type,varchar(10)
program_state,varchar(10)
afm,varchar(3)
grant_number,varchar(20)
program_name,varchar(255)
year,int
quarter,int
metric,varchar(50)
value,numeric
38 changes: 19 additions & 19 deletions documentation/csv/program.csv
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
field, type
uid, varchar(255)
year, year
grantee_name, varchar(255)
grant_number, varchar(255)
program_address_line_1, varchar(255)
program_address_line_2, varchar(255)
program_agency_description, varchar(255)
program_agency_type, varchar(255)
program_city, varchar(255)
program_email, varchar(255)
program_name, varchar(255)
program_number, varchar(255)
program_phone, varchar(255)
program_type, varchar(255)
program_state, varchar(255)
program_zip1, varchar(255)
program_zip2, varchar(255)
region, int
field," type"
uid," varchar(255)"
year,int
grantee_name," varchar(255)"
grant_number," varchar(255)"
program_address_line_1," varchar(255)"
program_address_line_2," varchar(255)"
program_agency_description," varchar(255)"
program_agency_type," varchar(255)"
program_city," varchar(255)"
program_email," varchar(255)"
program_name," varchar(255)"
program_number," varchar(255)"
program_phone," varchar(255)"
program_type," varchar(255)"
program_state," varchar(255)"
program_zip1," varchar(255)"
program_zip2," varchar(255)"
region," int"
24 changes: 12 additions & 12 deletions documentation/csv/question.csv
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
field, type
question_id, varchar(255)
year, year
uqid, varchar(255)
category, varchar(255)
question_name, text
question_number, varchar(255)
question_order, float
question_text, text
question_type, varchar(255)
section, varchar(255)
subsection, varchar(255)
field," type"
question_id," varchar(255)"
year,int
uqid," varchar(255)"
category," varchar(255)"
question_name," text"
question_number," varchar(255)"
question_order,numeric
question_text," text"
question_type," varchar(255)"
section," varchar(255)"
subsection," varchar(255)"
10 changes: 5 additions & 5 deletions documentation/csv/response.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
field, type
uid, varchar(255)
question_id, varchar(255)
year, year
answer, text
field," type"
uid," varchar(255)"
question_id," varchar(255)"
year,int
answer," text"
7 changes: 7 additions & 0 deletions documentation/source/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ found in `workflow <https://hhs.github.io/ACF-pir-data/workflow.html>`__.
Tables
------

Budget
~~~~~~

.. csv-table::
:file: ../csv/budget.csv
:header-rows: 1

Question
~~~~~~~~

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ openpyxl==3.1.5
outcome==1.3.0.post0
packaging==25.0
pandas==2.2.3
-e git+https://github.com/HHS/ACF-pir-data.git@101d4d438bdd301fd96fd88c4c4580ff902b9705#egg=pir_pipeline
-e git+https://github.com/HHS/ACF-pir-data.git@0104f01060b03cdcbef74e0f8008782c8059cd32#egg=pir_pipeline
pluggy==1.5.0
psycopg==3.2.7
psycopg-binary==3.2.7
Expand Down Expand Up @@ -66,6 +66,7 @@ typing-inspection==0.4.0
typing_extensions==4.13.2
tzdata==2025.2
urllib3==2.4.0
waitress==3.0.2
websocket-client==1.8.0
Werkzeug==3.1.3
wsproto==1.2.0
Expand Down
6 changes: 2 additions & 4 deletions src/pir_pipeline/utils/SQLAlchemyUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,11 @@ def get_columns(self, table: str, where: str = "") -> list[str]:
elif self._dialect == "postgresql":
table_schema = "table_catalog"

query = text(
f"""
query = text(f"""
SELECT column_name
FROM information_schema.columns
WHERE table_name = :table AND {table_schema} = :schema {where}
"""
)
""")
with self._engine.connect() as conn:
result = conn.execute(
query, {"table": table, "schema": self._database, "where": where}
Expand Down
2 changes: 1 addition & 1 deletion tests/dashboard/test_review_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def count_modal_rows(table: str):
By.CSS_SELECTOR,
"tr#flashcard-matches-table-tr-10000 td[name='question_id']",
).get_attribute("textContent")
== "0e93c25d3a95604f40d3a64e2298093b4faed6f2"
== "d27e8217ba30000a78e5d92ea54f4d9a2e69cb54"
)

# Click the storeLink button in the first row
Expand Down
2 changes: 1 addition & 1 deletion tests/dashboard/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ def test_post_data(self, client):


if __name__ == "__main__":
pytest.main([__file__, "-sk", "test_post_data"])
pytest.main([__file__, "-s", "-vv", "-k", "test_post_data"])
6 changes: 3 additions & 3 deletions tests/dashboard/test_search_ui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time

import pytest
from selenium.common.exceptions import TimeoutException
Expand Down Expand Up @@ -65,8 +66,8 @@ def count_modal_rows(table: str):
edit_button = wait.until(
EC.element_to_be_clickable(
(
By.XPATH,
'//table[@id="search-results-table"]//button[@onclick="getFlashcardData(event)"]',
By.CSS_SELECTOR,
"tr[id='search-results-table-tr-10002'] button[onclick='getFlashcardData(event)']",
)
)
)
Expand Down Expand Up @@ -164,4 +165,3 @@ def count_modal_rows(table: str):

if __name__ == "__main__":
pytest.main([__file__, "-sk", "test_search_ui"])
pytest.main([__file__, "-sk", "test_search_ui"])
Loading