Skip to content
Open
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
37 changes: 36 additions & 1 deletion python/employment.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,29 @@ def _get_jobs_inputs(year: int) -> dict[str, pd.DataFrame]:
"year": year,
},
)
# Get military employment data and append to control_totals
with open(utils.SQL_FOLDER / "employment/get_military_employment.sql") as file:
jobs_inputs["military_emp"] = pd.read_sql_query(
sql=sql.text(file.read()),
con=con,
params={
"run_id": utils.RUN_ID,
"year": year,
},
)
Comment thread
bryce-sandag marked this conversation as resolved.

military_control_totals = (
jobs_inputs["military_emp"]
.groupby(["run_id", "year", "industry_code", "metric"], as_index=False)[
"value"
]
.sum()
)[["run_id", "year", "industry_code", "metric", "value"]]

jobs_inputs["control_totals"] = pd.concat(
[jobs_inputs["control_totals"], military_control_totals],
ignore_index=True,
)

return jobs_inputs

Expand Down Expand Up @@ -311,12 +334,20 @@ def _validate_jobs_inputs(jobs_inputs: dict[str, pd.DataFrame]) -> None:
null={},
)
tests.validate_data(
"QCEW control totals",
"Military employment data",
jobs_inputs["military_emp"],
row_count={"key_columns": {"mgra"}},
negative={},
null={},
)
tests.validate_data(
"Jobs control totals",
jobs_inputs["control_totals"],
row_count={"key_columns": {"industry_code"}},
negative={},
null={},
)



def _create_jobs_output(
Expand All @@ -341,6 +372,10 @@ def _create_jobs_output(
_distribute_self_emp_to_mgra(
jobs_inputs["B24080"], jobs_inputs["xref_bg_to_mgra"]
),
# Include military employment at MGRA level
jobs_inputs["military_emp"][
["run_id", "year", "mgra", "industry_code", "value"]
],
],
ignore_index=True,
).sort_values(by=["mgra", "industry_code"])
Expand Down
2 changes: 1 addition & 1 deletion python/tests.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added a comment regarding "SE" being added, should probably also add a comment regarding "MIL" being added.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# and 722 3-digit naics code. Self employment data does not natively have a
# naics code so it is therefore assigned to 'SE' as the naics codes are being
# treated as strings.
"industry_code": 22,
"industry_code": 23,
},
"series": {
15: {
Expand Down
38 changes: 38 additions & 0 deletions sql/employment/get_military_employment.sql
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need to update source once table is moved
may run into double-hop issue if the table is put into [EMPCORE]

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
This query grabs the Military Active Duty (Job) Data and assigns counts to MGRA15.
This will assign 0 to MGRAs where there is no Military Jobs
*/

-- Initialize parameters -----------------------------------------------------
DECLARE @run_id INTEGER = :run_id;
DECLARE @year INTEGER = :year;


-- Send error message if no data exists --------------------------------------
IF NOT EXISTS (
SELECT TOP (1) *
FROM [ws].[fact].[MILITARY_EMPLOYMENT]
WHERE [year] = @year
Comment thread
bryce-sandag marked this conversation as resolved.
)
BEGIN
THROW 50000, 'Military Active duty data does not exist.', 1;
Comment thread
bryce-sandag marked this conversation as resolved.
END
ELSE
BEGIN

-- Get MGRA Military Active Duty Counts -------------------------------------
SELECT
@run_id AS [run_id],
@year AS [year],
[mgra],
'MIL' AS [industry_code],
'jobs' AS [metric],
COALESCE(SUM([site_active_duty]), 0) AS [value]
FROM [inputs].[mgra]
LEFT OUTER JOIN [ws].[fact].[MILITARY_EMPLOYMENT]
ON [MILITARY_EMPLOYMENT].[shape].STWithin([mgra].[shape]) = 1
AND [run_id] = @run_id AND [year] = @year
WHERE [run_id] = @run_id
GROUP BY [mgra]
ORDER BY [mgra]
END