Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit only #106

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .github/workflows/build-Docker-image-triggers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
fail-fast: false
matrix:
config-name:
- audit_2022Q4
- audit_2023Q4
- audit_multiple_portfolio_files
- default_2022Q4
- default_2023Q4
- full_params_2022Q4
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: workflow.pacta
Title: Run PACTA
Version: 0.0.0.9013
Version: 0.0.0.9014
Authors@R:
c(person(given = "CJ",
family = "Yetman",
Expand Down
79 changes: 51 additions & 28 deletions R/run_pacta.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@
#' \item timeHorizon: Time horizon for analysis.
#' }
#' }
#' @param run_audit logical: Run the audit process
#' @param run_analysis logical: Run the analysis process
#' @param pacta_data_dir filepath: Directory with "pacta-data"
#' @param output_dir filepath: Directory to save outputs.
#' @param portfolio_dir filepath: Directory with portfolio files
#' @return No return value. Saves outputs to output_dir.
#' @export
run_pacta <- function(
params,
run_audit = TRUE,
run_analysis = TRUE,
pacta_data_dir = Sys.getenv("PACTA_DATA_DIR"),
output_dir = Sys.getenv("ANALYSIS_OUTPUT_DIR"),
portfolio_dir = Sys.getenv("PORTFOLIO_DIR")
Expand All @@ -44,35 +48,54 @@
}
log_info("Running PACTA")

audit_prechecks(
portfolio_files = params[["portfolio"]][["files"]],
pacta_data_dir = pacta_data_dir,
portfolio_dir = portfolio_dir,
output_dir = output_dir
)
analysis_prechecks(
pacta_data_dir = pacta_data_dir,
output_dir = output_dir,
check_portfolio = FALSE
)
audit_file_path <- file.path(output_dir, "audit_file.rds")

Check warning on line 51 in R/run_pacta.R

View check run for this annotation

Codecov / codecov/patch

R/run_pacta.R#L51

Added line #L51 was not covered by tests

run_audit(
portfolio_files = params[["portfolio"]][["files"]],
pacta_data_dir = pacta_data_dir,
portfolio_dir = portfolio_dir,
output_dir = output_dir
)
run_analysis(
pacta_data_dir = pacta_data_dir,
output_dir = output_dir,
equity_market_list = params[["analysis"]][["equityMarketList"]],
scenario_sources_list = params[["analysis"]][["scenarioSourcesList"]],
scenario_geographies_list =
params[["analysis"]][["scenarioGeographiesList"]],
sector_list = params[["analysis"]][["sectorList"]],
start_year = params[["analysis"]][["startYear"]],
time_horizon = params[["analysis"]][["timeHorizon"]]
)
if (!file.exists(audit_file_path)) {
log_warn("Audit file not found. Running audit.")
run_audit <- TRUE

Check warning on line 55 in R/run_pacta.R

View check run for this annotation

Codecov / codecov/patch

R/run_pacta.R#L53-L55

Added lines #L53 - L55 were not covered by tests
}

if (run_audit) {
audit_prechecks(
portfolio_files = params[["portfolio"]][["files"]],
pacta_data_dir = pacta_data_dir,
portfolio_dir = portfolio_dir,
output_dir = output_dir
)

Check warning on line 64 in R/run_pacta.R

View check run for this annotation

Codecov / codecov/patch

R/run_pacta.R#L58-L64

Added lines #L58 - L64 were not covered by tests
}

if (run_analysis) {
analysis_prechecks(
pacta_data_dir = pacta_data_dir,
output_dir = output_dir,
check_portfolio = FALSE
)

Check warning on line 72 in R/run_pacta.R

View check run for this annotation

Codecov / codecov/patch

R/run_pacta.R#L67-L72

Added lines #L67 - L72 were not covered by tests
}


if (run_audit) {
run_audit(
portfolio_files = params[["portfolio"]][["files"]],
pacta_data_dir = pacta_data_dir,
portfolio_dir = portfolio_dir,
output_dir = output_dir
)

Check warning on line 82 in R/run_pacta.R

View check run for this annotation

Codecov / codecov/patch

R/run_pacta.R#L76-L82

Added lines #L76 - L82 were not covered by tests
}


if (run_analysis) {
run_analysis(
pacta_data_dir = pacta_data_dir,
output_dir = output_dir,
equity_market_list = params[["analysis"]][["equityMarketList"]],
scenario_sources_list = params[["analysis"]][["scenarioSourcesList"]],
scenario_geographies_list =
params[["analysis"]][["scenarioGeographiesList"]],
sector_list = params[["analysis"]][["sectorList"]],
start_year = params[["analysis"]][["startYear"]],
time_horizon = params[["analysis"]][["timeHorizon"]]
)

Check warning on line 97 in R/run_pacta.R

View check run for this annotation

Codecov / codecov/patch

R/run_pacta.R#L86-L97

Added lines #L86 - L97 were not covered by tests
}

log_info("PACTA run complete.")
return(
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
services:
workflow.pacta:
# build: .
image: ghcr.io/rmi-pacta/workflow.pacta
build: .
# stdin_open: true
# tty: true
# entrypoint: ["R", "--args"]
Expand Down
4 changes: 4 additions & 0 deletions inst/extdata/parameters/analysis_default.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"commands": {
"audit": true,
"analysis": true
},
"analysis": {
"equityMarketList": [
"GlobalMarket",
Expand Down
2 changes: 1 addition & 1 deletion inst/extdata/schema/portfolioParameters.html

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions inst/extdata/schema/portfolioParameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
"$comment": "Created by Alex Axthelm, aaxthelm@rmi.org",
"type": "object",
"properties": {
"commands": {
"type": "object",
"description": "Commands to run.",
"properties": {
"audit": {
"type": "boolean",
"description": "Whether to run the audit."
},
"analysis": {
"type": "boolean",
"description": "Whether to run the analysis."
}
},
"required": [
"audit",
"analysis"
]
},
"portfolio": {
"$ref": "portfolio.json"
},
Expand Down Expand Up @@ -93,6 +111,7 @@
"allOf": [
{
"required": [
"commands",
"portfolio",
"analysis"
]
Expand Down
2 changes: 1 addition & 1 deletion inst/extdata/schema/rawParameters.html

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion inst/extdata/scripts/run_pacta.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ params <- pacta.workflow.utils::parse_raw_params(
force_array = c("portfolio", "files")
)

manifest_info <- workflow.pacta::run_pacta(params)
manifest_info <- workflow.pacta::run_pacta(
params = params,
run_audit = params[["commands"]][["audit"]],
run_analysis = params[["commands"]][["analysis"]]
)

pacta.workflow.utils::export_manifest(
input_files = manifest_info[["input_files"]],
Expand Down
6 changes: 6 additions & 0 deletions man/run_pacta.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions portfolios/default_params.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"commands": {
"audit": true,
"analysis": true
},
"portfolio": {
"holdingsDate": "2023-12-31",
"files":
Expand Down
17 changes: 17 additions & 0 deletions tests/config/audit_2022Q4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"holdingsDate": "2022Q4",
"pactaDataURL": "https://pactadatadev.file.core.windows.net/workflow-data-preparation-outputs/2022Q4_20240426T113151Z",
"parameters": {
"commands": {
"audit": true,
"analysis": false
},
"portfolio": {
"files": [
"default_portfolio.csv"
],
"holdingsDate": "2022-12-31"
},
"inherit": "analysis_2022Q4"
}
}
17 changes: 17 additions & 0 deletions tests/config/audit_2023Q4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"holdingsDate": "2023Q4",
"pactaDataURL": "https://pactadatadev.file.core.windows.net/workflow-data-preparation-outputs/2023Q4_20240424T120055Z",
"parameters": {
"commands": {
"audit": true,
"analysis": false
},
"portfolio": {
"files": [
"default_portfolio.csv"
],
"holdingsDate": "2023-12-31"
},
"inherit": "analysis_2023Q4"
}
}
18 changes: 18 additions & 0 deletions tests/config/audit_multiple_portfolio_files.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"holdingsDate": "2023Q4",
"pactaDataURL": "https://pactadatadev.file.core.windows.net/workflow-data-preparation-outputs/2023Q4_20240424T120055Z",
"parameters": {
"commands": {
"audit": true,
"analysis": false
},
"portfolio": {
"files": [
"section_1.csv",
"section_2.csv"
],
"holdingsDate": "2023-12-31"
},
"inherit": "analysis_2023Q4"
}
}
4 changes: 4 additions & 0 deletions tests/config/full_params_2022Q4.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"holdingsDate": "2022Q4",
"pactaDataURL": "https://pactadatadev.file.core.windows.net/workflow-data-preparation-outputs/2022Q4_20240426T113151Z",
"parameters": {
"commands": {
"audit": true,
"analysis": true
},
"portfolio": {
"holdingsDate": "2022-12-31",
"files": [
Expand Down
4 changes: 4 additions & 0 deletions tests/config/full_params_2023Q4.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"holdingsDate": "2023Q4",
"pactaDataURL": "https://pactadatadev.file.core.windows.net/workflow-data-preparation-outputs/2023Q4_20240424T120055Z",
"parameters": {
"commands": {
"audit": true,
"analysis": true
},
"portfolio": {
"holdingsDate": "2023-12-31",
"files": [
Expand Down
Loading