Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gadenbuie committed Oct 30, 2023
0 parents commit 9af0f92
Show file tree
Hide file tree
Showing 55 changed files with 25,890 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
source("renv/activate.R")

if (requireNamespace("later", quietly = TRUE)) {
later::later(function() {
qvm_v <- tryCatch(system("qvm -v", intern = TRUE), error = function(...) "")
if (nzchar(qvm_v)) {
qvm_path <- system("qvm path active", intern = TRUE)
if (nzchar(qvm_path)) {
quarto_path <- file.path(qvm_path, "quarto")
message("Setting QUARTO_PATH=", quarto_path)
Sys.setenv(QUARTO_PATH = quarto_path)
}
}
})
}
58 changes: 58 additions & 0 deletions .github/workflows/build-dash.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
on:
push:
branches:
- main
schedule:
- cron: "15 5,12,14 * * MON-FRI"
workflow_dispatch:

name: build-dash

jobs:
build-dash:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RENV_PATHS_ROOT: ~/.local/share/renv
steps:

- uses: actions/checkout@v3

- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
with:
version: pre-release

- uses: r-lib/actions/setup-r@v2

- name: Add Ubuntu dependencies
run: sudo apt-get install libglpk40

- uses: r-lib/actions/setup-renv@v2

- name: Cache targets data
uses: actions/cache@v3
with:
path: _targets
key: ${{ runner.os }}-targets-v1-${{ hashFiles('**/cache.log') }}
restore-keys: |
${{ runner.os }}-targets-v1-
- name: Build Pipeline and Dashboard
run: Rscript -e 'targets::tar_make()'

- name: Push Built Dashboard
run: |
git config --global user.name 'gha update bot'
git config --global user.email 'gadenbuie@users.noreply.github.com'
git add --all
git commit --allow-empty -m "[auto] Build Dashboard $(TZ=America/New_York date +'%Y-%m-%d %H:%M')"
git push
- name: Publish to Quarto Pub
uses: quarto-dev/quarto-actions/publish@v2
with:
target: quarto-pub
render: false
path: index.qmd
QUARTO_PUB_AUTH_TOKEN: ${{ secrets.QUARTO_PUB_AUTH_TOKEN }}
83 changes: 83 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
.Rproj.user
data-raw/*.csv
data-raw/*.parquet

# ---- Default .gitignore From grkmisc ----
.Rproj.user
.Rhistory
.RData
.DS_Store
README.html

# vscode
.history/

# Directories that start with _
_*/

## https://github.com/github/gitignore/blob/master/R.gitignore
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
/*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# Shiny token, see https://shiny.rstudio.com/articles/shinyapps.html
rsconnect/

## https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
29 changes: 29 additions & 0 deletions R/formatting.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
`%||%` <- rlang::`%||%`

number <- scales::number_format(big.mark = ",")

new_change_with_caret_formatter <- function(caret_more = NULL, caret_less = NULL) {
caret_more <- format(caret_more %||% '<i class="bi bi-caret-up-fill"></i>')
caret_less <- format(caret_less %||% '<i class="bi bi-caret-down-fill"></i>')

function(then, now, ..., when = "yesterday", more = "more than", less = "less than") {
diff <- now - then
if (diff == 0) {
return(paste0("No change", ...))
}
ret <- paste0(
"<span>",
if (diff > 0) caret_more else caret_less,
" ",
scales::number(abs(diff), big.mark = ","),
if (diff > 0) paste0(" ", more),
if (diff < 0) paste0(" ", less),
if (!is.null(when)) paste0(" ", when),
...,
"</span>"
)
htmltools::HTML(ret)
}
}

change <- new_change_with_caret_formatter()
18 changes: 18 additions & 0 deletions R/get_my_norfolk_tickets.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

get_my_norfolk_tickets <- function() {
data_url <- "https://data.norfolk.gov/api/views/nbyu-xjez/rows.csv?accessType=DOWNLOAD&api_foundry=true"

tmpfile <- tempfile(fileext = ".csv")
download.file(data_url, tmpfile)

arrow::read_csv_arrow(tmpfile) |>
janitor::clean_names() |>
mutate(
across(contains("date"), mdy_hms),
is_resolved = status %in% c("Closed", "Cancelled"),
status = factor(status, c("Open", "In progress", "Cancelled", "Closed")),
resolved_date = if_else(is_resolved, modification_date, NA),
age_days = if_else(is.na(resolved_date), now(), resolved_date) - creation_date,
age_days = as.numeric(age_days) / 3600 / 24
)
}
3 changes: 3 additions & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pull_count <- function(x) {
x |> count(name = ".n") |> pull(.data$.n)
}
10 changes: 10 additions & 0 deletions R/plots_today.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plots_today <- function(norfolk, today) {
list(
top_new_requests =
plotly_top_requests(norfolk, creation_date >= today),
top_in_progress =
plotly_top_requests(norfolk, status == "In progress"),
top_closed =
plotly_top_requests(norfolk, status == "Closed", modification_date > today)
)
}
21 changes: 21 additions & 0 deletions R/plots_week.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
plots_week <- function(norfolk, week_this) {
list(
top_new_requests =
norfolk |>
plotly_top_requests(
creation_date >= week_this$start
),
top_in_progress =
norfolk |>
plotly_top_requests(
status == "In progress",
modification_date >= week_this$start
),
top_closed =
norfolk |>
plotly_top_requests(
status == "Closed",
modification_date >= week_this$start
)
)
}
55 changes: 55 additions & 0 deletions R/stats_today.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
stats_today <- function(norfolk, today, yesterday) {
opened_today <-
norfolk |> filter(creation_date >= today)

opened_yesterday <-
norfolk |> filter(between(creation_date, yesterday, today))

closed_today <-
norfolk |>
filter(status == "Closed", modification_date >= today)

closed_yesterday <-
norfolk |>
filter(
status == "Closed",
between(modification_date, yesterday, today)
)

cancelled_today <-
norfolk |>
filter(status == "Cancelled", modification_date >= today)

cancelled_yesterday <-
norfolk |>
filter(
status == "Cancelled",
between(modification_date, yesterday, today)
)

in_progress_total <-
norfolk |>
filter(status == "In progress")

in_progress_new <-
norfolk |>
filter(status == "In progress", modification_date >= today)

data <- list(
opened = opened_today,
closed = closed_today,
cancelled = cancelled_today,

opened_yesterday = opened_yesterday,
closed_yesterday = closed_yesterday,
cancelled_yesterday = cancelled_yesterday,

in_progress_total = in_progress_total,
in_progress_new = in_progress_new
)

counts <- lapply(data, pull_count)
names(counts) <- paste0("n_", names(data))

c(data, counts)
}
68 changes: 68 additions & 0 deletions R/stats_week.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
stats_week <- function(norfolk, week_this, week_prev) {
opened_this <-
norfolk |>
filter(between(creation_date, week_this$start, week_this$end))

opened_prev <-
norfolk |>
filter(between(creation_date, week_prev$start, week_prev$end))

started_this <-
norfolk |>
filter(
status == "In progress",
between(modification_date, week_this$start, week_this$end)
)

started_prev <-
norfolk |>
filter(
status == "In progress",
between(modification_date, week_prev$start, week_prev$end)
)

closed_this <-
norfolk |>
filter(
status == "Closed",
between(modification_date, week_this$start, week_this$end)
)

closed_prev <-
norfolk |>
filter(
status == "Closed",
between(modification_date, week_prev$start, week_prev$end)
)

cancelled_this <-
norfolk |>
filter(
status == "Cancelled",
between(modification_date, week_this$start, week_this$end)
)

cancelled_prev <-
norfolk |>
filter(
status == "Cancelled",
between(modification_date, week_prev$start, week_prev$end)
)

data <- list(
opened = opened_this,
closed = closed_this,
started = started_this,
cancelled = cancelled_this,

opened_prev = opened_prev,
closed_prev = closed_prev,
started_prev = started_prev,
cancelled_prev = cancelled_prev
)

counts <- lapply(data, pull_count)
names(counts) <- paste0("n_", names(data))

c(data, counts)
}
Loading

0 comments on commit 9af0f92

Please sign in to comment.