Skip to content

Commit

Permalink
Erarr dev (#36)
Browse files Browse the repository at this point in the history
v. 0.1.3

* fixed naming bug

* tweaked milestone plot width

* fixed milestoneplot function

---------

Co-authored-by: Michael Dougherty <[email protected]>
  • Loading branch information
bchileen and mpdougherty authored Oct 30, 2024
1 parent f9cb82b commit 3dfd72b
Show file tree
Hide file tree
Showing 26 changed files with 1,313 additions and 198 deletions.
1 change: 1 addition & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
source("renv/activate.R")
6 changes: 2 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: erarr
Title: A package to support the Enterprise Risk Analysis Reporting
Application
Version: 0.1.2
Version: 0.1.3
Authors@R: c(
person("Barrie", "Chileen Martinez", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-6960-8167")),
Expand Down Expand Up @@ -38,9 +38,7 @@ Imports:
shinyalert,
shinyjs,
stringr,
tidyr,
webshot,
usethis
tidyr
Suggests:
htmlwidgets,
spelling,
Expand Down
7 changes: 0 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ export(proj_pieprep)
export(proj_tableprep)
export(run_app)
export(update_data)
import(english)
import(ggplot2)
import(ggrepel)
import(rlang)
import(shiny)
import(webshot)
importFrom(DT,DTOutput)
importFrom(DT,datatable)
importFrom(DT,renderDT)
Expand All @@ -40,7 +35,6 @@ importFrom(dplyr,slice_head)
importFrom(dplyr,slice_max)
importFrom(dplyr,summarise)
importFrom(dplyr,summarize)
importFrom(english,english)
importFrom(forcats,fct_inorder)
importFrom(formattable,currency)
importFrom(ggplot2,aes)
Expand All @@ -63,7 +57,6 @@ importFrom(golem,with_golem_options)
importFrom(kableExtra,kable_styling)
importFrom(kableExtra,kbl)
importFrom(knitr,include_graphics)
importFrom(knitr,kable)
importFrom(plotly,add_pie)
importFrom(plotly,layout)
importFrom(plotly,plot_ly)
Expand Down
2 changes: 1 addition & 1 deletion R/milestoneplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mileplot <- ggplot(projphases,
shape = 21, stroke = .75) +
geom_point(aes(x = riskitem$PROJECTMILESTONEID, y = 0.1),
colour = "#1F78B4", fill = "#1F78B4", shape = 16, size = 4) +
geom_text(aes(label = str_wrap(riskitem$MILESTONE, width=14)),
geom_text(aes(label = str_wrap(MILESTONE, width=14)),

position = position_nudge(y = -0.55), size = 3) +
scale_y_continuous(limits = c(-1, 1), expand = c(0, 0)) +
Expand Down
20 changes: 20 additions & 0 deletions R/report_project_Top4s.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#' @title Project Top 4 Risks Report
#'
#' @description Creates a report of top 4 risks.
#'
#' @details All package reports are stored in the folder: `./inst/app/rmd/`
#'
#' @name ProjectTop4s
#'
#' @param projID character; erisk Project identifier
#' @param p2ID numeric; USACE P2 number
#' @param p2sub numeric; P2 sub identifier
#'
#'
#'
#' @importFrom readr read_csv
#' @importFrom dplyr select mutate filter arrange slice_head
#' @importFrom formattable currency
#' @importFrom kableExtra kbl kable_styling
#'
NULL
9 changes: 1 addition & 8 deletions R/report_project_all_risks.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@
#' @param p2sub numeric; P2 sub identifier
#'
#' @importFrom readr read_csv
#' @importFrom dplyr left_join select filter mutate arrange slice_head
#' case_when
#' @importFrom dplyr select filter arrange mutate
#' @importFrom tidyr separate
#' @importFrom formattable currency
#' @importFrom kableExtra kbl kable_styling
#' @import rlang
#' @import ggplot2
#' @import ggrepel
#' @import english
#' @import webshot
#'
NULL
5 changes: 2 additions & 3 deletions R/report_risk_item.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
#' @param projID character; erisk Project identifier
#' @param p2ID numeric; USACE P2 number
#'
#' @importFrom dplyr left_join mutate select filter case_when slice_max
#' @importFrom knitr include_graphics kable
#' @importFrom dplyr mutate select filter left_join case_when slice_max
#' @importFrom knitr include_graphics
#' @importFrom kableExtra kable_styling
#' @importFrom formattable currency
#' @importFrom english english
#' @importFrom stringr str_to_title
#' @importFrom plotly plot_ly add_pie layout
#' @importFrom stringr str_trim
Expand Down
1 change: 0 additions & 1 deletion R/wrangle_riskitem_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ create_risk_proj <- function(risk, project, archive){

readr::write_csv(risk_item_db,
paste0(output_path, "erisk_project_riskitem.csv"))
usethis::use_data(risk_item_db, overwrite = TRUE)

return(risk_item_db)
}
2 changes: 1 addition & 1 deletion R/wrangle_riskprogram_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ create_risk_prog <- function(erisk_orgs, erisk_dist, erisk_msc, risk_item_db){
dplyr::select(MSC, MSC_DESCRIPT, DISTRICT_CODE), by=dplyr::join_by(DISTRICT_CODE), keep=FALSE)

readr::write_csv(risk_program_db, paste0(output_path, "erisk_program_riskitem.csv"))
usethis::use_data(risk_program_db, overwrite = TRUE)
return(risk_program_db)
}

5 changes: 3 additions & 2 deletions data-raw/Data_Update.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Update Risk Analysis Report Test Data
date: "`r Sys.Date()`"
title: "Update Risk Analysis Report Test Data"
date: `r Sys.Date()`
---

# Introduction
Expand Down Expand Up @@ -82,6 +82,7 @@ readr::write_csv(erisk_dist,"C:/workspace/erarr/inst/app/data/erisk_dist.csv")
readr::write_csv(erisk_msc,"C:/workspace/erarr/inst/app/data/erisk_msc.csv")
readr::write_csv(erisk_modeled,"C:/workspace/erarr/inst/app/data/erisk_modeled.csv")
erisk_item_db <- risk_item_db
usethis::use_data(erisk_project,
erisk_phase_milestone,
erisk_item,
Expand Down
Binary file added data/erisk_item_db.rda
Binary file not shown.
Binary file added data/erisk_phase_milestone.rda
Binary file not shown.
Binary file added data/erisk_program_db.rda
Binary file not shown.
Binary file removed data/phase_milestone.rda
Binary file not shown.
Binary file removed data/risk_item_db.rda
Binary file not shown.
Binary file removed data/risk_program_db.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion dev/01_start.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ golem::use_recommended_tests()
## Favicon ----
# If you want to change the favicon (default is golem's one)
golem::remove_favicon()
golem::use_favicon(path="inst/app/www/erarr.png")
golem::use_favicon(path="inst/app/www/castle.png")


## Add helper functions ----
Expand Down
2 changes: 2 additions & 0 deletions dev/02_dev.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ usethis::use_data(erisk_project,
erisk_dist,
erisk_msc,
erisk_modeled,
erisk_program_riskitem,
erisk_project_riskitem,
overwrite = TRUE)

## Tests ----
Expand Down
41 changes: 17 additions & 24 deletions inst/app/rmd/ProjectAllRiskReport.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,8 @@ body {-webkit-print-color-adjust: exact;}
```{r echo=FALSE, message=FALSE, warning=FALSE, include=FALSE}
library(readr)
library(dplyr)
library(magrittr)
library(tidyr)
library(rlang)
library(formattable)
library(plotly)
library(ggplot2)
library(ggrepel)
library(kableExtra)
library(english)
```

```{r echo=FALSE, message=FALSE, warning=FALSE, include=FALSE}
Expand All @@ -56,7 +49,7 @@ risk_item_db<-readr::read_csv("../data/erisk_program_riskitem.csv",
show_col_types = FALSE)
RiskDeets <- risk_item_db |>
select("PROJECT_ID", "P2_NUMBER", "RISK_IDENTIFIER", "P2_SUB_IDENTIFIER",
dplyr::select("PROJECT_ID", "P2_NUMBER", "RISK_IDENTIFIER", "P2_SUB_IDENTIFIER",
"PROJECT_NAME", "RISK_NAME", "RISKCATEGORY", "RISK_STATEMENT",
"LIFECYCLEPHASENAME", "MILESTONE", "LIKELIHOOD", "DISCIPLINE",
"PERFORMANCEIMPACT", "PERFORMANCE_RANK_DESC",
Expand All @@ -69,8 +62,8 @@ RiskDeets <- risk_item_db |>

```{r echo=FALSE, eval = params$projID != ""}
Risk_List_Proj <- RiskDeets |>
filter(RiskDeets$PROJECT_NAME == params$projID)
proj_risks <- filter(Risk_List_Proj,
dplyr::filter(RiskDeets$PROJECT_NAME == params$projID)
proj_risks <- dplyr::filter(Risk_List_Proj,
Risk_List_Proj$PROJECT_NAME == params$projID)
proj_risk_item <- slice_head(Risk_List_Proj)
header <- paste("Project:", proj_risk_item$PROJECT_NAME)
Expand All @@ -79,28 +72,28 @@ header2 <- if (params$p2sub != "") {paste("SubID:", params$p2sub)}
```

```{r echo=FALSE, eval = params$p2ID != ""}
Risk_List_Proj <- filter(RiskDeets, RiskDeets$P2_NUMBER == params$p2ID)
Risk_List_Proj <- dplyr::filter(RiskDeets, RiskDeets$P2_NUMBER == params$p2ID)
proj_risks <- filter(Risk_List_Proj, Risk_List_Proj$P2_NUMBER == params$p2ID)
proj_risk_item <- slice_head(Risk_List_Proj)
proj_risks <- dplyr::filter(Risk_List_Proj, Risk_List_Proj$P2_NUMBER == params$p2ID)
proj_risk_item <- dplyr::slice_head(Risk_List_Proj)
header <- paste("P2 Number:", proj_risk_item$P2_NUMBER)
header2 <- if (params$p2sub != "") {paste("SubID:", params$p2sub)}
```

```{r echo=FALSE, eval = params$p2sub != ""}
Risk_List_Proj<-filter(Risk_List_Proj,
Risk_List_Proj<-dplyr::filter(Risk_List_Proj,
Risk_List_Proj$P2_SUB_IDENTIFIER == params$p2sub)
proj_risks <- filter(proj_risks,
proj_risks <- dplyr::filter(proj_risks,
proj_risks$P2_SUB_IDENTIFIER == params$p2sub)
header2 <- if (params$p2sub != "") {paste("SubID:", params$p2sub)}
```

```{r echo=FALSE, message=FALSE, warning=FALSE, include=FALSE}
proj_risks <- proj_risks %>%
mutate(
dplyr::mutate(
'costcolor' = case_when(
COST_RANK_DESC == "No Risk" ~ "#FFFFFF",
COST_RANK_DESC == "Opportunity" ~ 'rgb(31,120,180)',
Expand All @@ -109,7 +102,7 @@ proj_risks <- proj_risks %>%
COST_RANK_DESC == 'High' ~ 'rgb(227,26,28)'
)
) |>
mutate(
dplyr::mutate(
'schedulecolor' = case_when(
SCHEDULE_RANK_DESC == "No Risk" ~ "#FFFFFF",
SCHEDULE_RANK_DESC == "Opportunity" ~ 'rgb(31,120,180)',
Expand All @@ -118,7 +111,7 @@ proj_risks <- proj_risks %>%
SCHEDULE_RANK_DESC == 'High' ~ 'rgb(227,26,28)'
)
) |>
mutate(
dplyr::mutate(
'performancecolor' = case_when(
PERFORMANCE_RANK_DESC == "No Risk" ~ '#FFFFFF',
PERFORMANCE_RANK_DESC == "Opportunity" ~ 'rgb(31,120,180)',
Expand Down Expand Up @@ -152,12 +145,12 @@ erarr::pie_plots(cost_pie, schedule_pie, perform_pie)

```{r proj risk log, echo = FALSE, warning=FALSE}
risk_log_tables <- proj_risks |>
select(RISK_IDENTIFIER, RISK_NAME, COST_RISK_RANKING, SCHEDULE_RISK_RANKING,
dplyr::select(RISK_IDENTIFIER, RISK_NAME, COST_RISK_RANKING, SCHEDULE_RISK_RANKING,
PERFORMANCEIMPACT_RISK_RANKING, costcolor, schedulecolor,
performancecolor)
risk_log_tables |>
mutate(
dplyr::mutate(
COST_RISK_RANKING = cell_spec(COST_RISK_RANKING,
color = costcolor,
align = 'c',
Expand All @@ -171,11 +164,11 @@ risk_log_tables |>
align = 'c',
background = performancecolor)
) |>
select(RISK_IDENTIFIER, RISK_NAME,COST_RISK_RANKING, SCHEDULE_RISK_RANKING,
dplyr::select(RISK_IDENTIFIER, RISK_NAME,COST_RISK_RANKING, SCHEDULE_RISK_RANKING,
PERFORMANCEIMPACT_RISK_RANKING) |>
separate(RISK_IDENTIFIER, c("code", "rnkorder"), sep = "-", remove = FALSE) |>
arrange(code, as.numeric(rnkorder)) |>
select(RISK_IDENTIFIER, RISK_NAME, COST_RISK_RANKING, SCHEDULE_RISK_RANKING,
tidyr::separate(RISK_IDENTIFIER, c("code", "rnkorder"), sep = "-", remove = FALSE) |>
dplyr::arrange(code, as.numeric(rnkorder)) |>
dplyr::select(RISK_IDENTIFIER, RISK_NAME, COST_RISK_RANKING, SCHEDULE_RISK_RANKING,
PERFORMANCEIMPACT_RISK_RANKING) |>
kbl(format = "html",
escape = F,
Expand Down
22 changes: 11 additions & 11 deletions inst/app/rmd/ProjectTop4s.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ title: ""
runtime: shiny
output: html_document
params:
projID: ""
p2ID: 479265
projID: Lee County Conservation Board CAP Sec 204
p2ID: ""
p2sub: ""
---

Expand Down Expand Up @@ -65,12 +65,12 @@ Risk_List_Proj <- RiskDeets
# Apply filters based on available parameters
if (params$projID != "") {
proj_risks <- dplyr::filter(Risk_List_Proj, PROJECT_NAME == params$projID)
header <- paste("Project:", Risk_List_Proj$PROJECT_NAME[1])
header <- paste("Project:", params$projID)
}
if (params$p2ID != "") {
proj_risks<- dplyr::filter(Risk_List_Proj, P2_NUMBER == params$p2ID)
header <- paste("P2 Number:", Risk_List_Proj$P2_NUMBER[1])
header <- paste("P2 Number:", params$p2ID)
}
if (params$p2sub != "") {
Expand All @@ -85,7 +85,7 @@ header2 <- if (params$p2sub != "") {
""
}
proj_risk_item<- dplyr::slice_head(Risk_List_Proj)
proj_risk_item<- dplyr::slice_head(proj_risks)
```

###### Report Created On: `r format(Sys.time(), '%d %B, %Y')`
Expand Down Expand Up @@ -113,11 +113,11 @@ cat("###",header,header2)
#### Top 4 Cost Impacts (All Phases)
``` {r cost risk log, echo = FALSE, warning=FALSE}
cost_top4s<-proj_risks |>
mutate(MAX_COST = pmax(COST_IMPACT_LOWEST, COST_MEAN, COST_IMPACT_HIGHEST))|>
arrange(desc(COST_RISK_RANKING), desc(MAX_COST), desc(PROB_OCCURRENCE))|>
dplyr::mutate(MAX_COST = pmax(COST_IMPACT_LOWEST, COST_MEAN, COST_IMPACT_HIGHEST))|>
dplyr::arrange(desc(COST_RISK_RANKING), desc(MAX_COST), desc(PROB_OCCURRENCE))|>
dplyr::select(RISK_IDENTIFIER, RISK_NAME, RISKCATEGORY , MILESTONE , LIKELIHOOD, MAX_COST) |>
dplyr::slice_head(n=4)|>
mutate(MAX_COST = as.character(formattable::currency(MAX_COST)))|>
dplyr::mutate(MAX_COST = as.character(formattable::currency(MAX_COST)))|>
kableExtra::kbl(format = "html", escape = F, col.names =c("Risk ID","Risk Name","Risk Category","Project Milestone","Likelihood", "Mean Cost Impact"), align="clcccc", row.names = FALSE)|>
kableExtra::kable_styling(bootstrap_options = c( "hover", "condensed", "responsive"))
Expand All @@ -127,8 +127,8 @@ cost_top4s
#### Top 4 Schedule Impacts (All Phases)
``` {r schedule risk log, echo = FALSE, warning=FALSE}
schedule_top4s<-proj_risks |>
mutate(MAX_SCHED = pmax(SCHEDULE_IMPACT_LOWEST, SCHEDULE_MEAN, SCHEDULE_IMPACT_HIGHEST))|>
arrange(desc(SCHEDULE_RISK_RANKING), desc(MAX_SCHED), desc(PROB_OCCURRENCE))|>
dplyr::mutate(MAX_SCHED = pmax(SCHEDULE_IMPACT_LOWEST, SCHEDULE_MEAN, SCHEDULE_IMPACT_HIGHEST))|>
dplyr::arrange(desc(SCHEDULE_RISK_RANKING), desc(MAX_SCHED), desc(PROB_OCCURRENCE))|>
dplyr::select(RISK_IDENTIFIER, RISK_NAME, RISKCATEGORY , MILESTONE , LIKELIHOOD, MAX_SCHED) |>
dplyr::slice_head(n=4)|>
kableExtra::kbl(format = "html", escape = F, col.names =c("Risk ID","Risk Name","Risk Category","Project Milestone","Likelihood", "Mean Schedule Impact (Days)"), align="clcccc", row.names = FALSE)|>
Expand All @@ -141,7 +141,7 @@ schedule_top4s
#### Top 4 Performance Impacts (All Phases)
``` {r perform risk log, echo = FALSE, warning=FALSE}
perform_log_table<-proj_risks |>
arrange(desc(PERFORMANCEIMPACT_RISK_RANKING), desc(PERFORMANCEIMPACT_IMPCT), desc(PROB_OCCURRENCE))|>
dplyr::arrange(desc(PERFORMANCEIMPACT_RISK_RANKING), desc(PERFORMANCEIMPACT_IMPCT), desc(PROB_OCCURRENCE))|>
dplyr::select(RISK_IDENTIFIER, RISK_NAME, RISKCATEGORY , MILESTONE , LIKELIHOOD, PERFORMANCE_RANK_DESC) |>
dplyr::slice_head(n=4)|>
kableExtra::kbl(format = "html", escape = F, col.names =c("Risk ID","Risk Name","Risk Category","Project Milestone","Likelihood", "Performance Impact"), align="clcccc", row.names = FALSE)|>
Expand Down
Loading

0 comments on commit 3dfd72b

Please sign in to comment.