-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'update_trust' into public-view
# Conflicts: # R/app_server.R
- Loading branch information
Showing
19 changed files
with
264 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
--- | ||
title: "Write the predictions for all completed jobs to Database" | ||
author: "Experiences dashboard" | ||
date: 2023/11/14 | ||
format: | ||
html: | ||
embed-resources: true | ||
--- | ||
|
||
```{r} | ||
#| include: false | ||
library(DBI) | ||
library(odbc) | ||
library(dplyr) | ||
library(pins) | ||
``` | ||
|
||
|
||
|
||
## Intro | ||
|
||
Use this Script to manually write the prediction for all completed jobs that couldn't be auto written to the database by the scheduled API_url_tracker on Connect. | ||
This Script won't be needed if the [issue with the database upload](https://github.com/CDU-data-science-team/experiencesdashboard/issues/200) has been resolved. | ||
|
||
```{r} | ||
#| message: false | ||
conn <- odbc::dbConnect( | ||
drv = odbc::odbc(), | ||
driver = Sys.getenv("odbc_driver"), | ||
server = Sys.getenv("HOST_NAME"), | ||
UID = Sys.getenv("DB_USER"), | ||
PWD = Sys.getenv("MYSQL_PASSWORD"), | ||
database = "TEXT_MINING", | ||
Port = 3306, | ||
encoding = "UTF-8" | ||
) | ||
# connect to strategy unit Connect server | ||
board <- pins::board_connect() | ||
pending_jobs <- dplyr::tbl( | ||
conn, | ||
dbplyr::in_schema( | ||
"TEXT_MINING", | ||
"api_jobs" | ||
) | ||
) |> | ||
dplyr::filter(status == "completed") |> | ||
dplyr::collect() | ||
``` | ||
|
||
|
||
```{r} | ||
if (nrow(pending_jobs) > 0) { | ||
for (i in 1:nrow(pending_jobs)) { | ||
job <- pending_jobs[i, ] | ||
job_id <- as.character(job["job_id"]) | ||
trust_id <- as.character(job["trust_id"]) | ||
board_path <- as.character(job["pin_path"]) | ||
# get the prediction from the board | ||
prediction <- pins::pin_read(board, board_path) | ||
# update the main table on the database | ||
dplyr::rows_update( | ||
dplyr::tbl(conn, trust_id), | ||
prediction, | ||
by = "comment_id", | ||
unmatched = "ignore", | ||
copy = TRUE, | ||
in_place = TRUE | ||
) | ||
# update the job status as uploaded (successfully write prediction to main table) | ||
DBI::dbExecute(conn, paste("UPDATE api_jobs SET status='uploaded' WHERE job_id =", job_id)) | ||
# delete the prediction from the board | ||
pins::pin_delete(board, board_path) | ||
DBI::dbExecute( | ||
conn, | ||
sprintf("UPDATE api_jobs SET pin_path ='%s' WHERE job_id = %s", NA, job_id) | ||
) | ||
cat("Job", job_id, "prediction has been successfully written to database \n") | ||
} | ||
} else { | ||
cat("No uncompleted job") | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ header_links <- function() { | |
), | ||
tags$li( | ||
a( | ||
onclick = "onclick =window.open('mailto:[email protected][email protected]')", | ||
onclick = "onclick =window.open('mailto:[email protected]')", | ||
href = NULL, | ||
icon("envelope", prefer_type = "solid"), | ||
title = "Contact Project Team", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,13 +56,13 @@ experiencesdashboard | |
| Name | Link | Description | | ||
| ---- | ---- | ----------- | | ||
| .github/workflows | [[Link](/.github/workflows)] | Github Action workflow files that automate the `R CMD check` and `deployment` process | | ||
| app.R | [[Link](.)] | A `golem` file that contains the function to deploy the app on Posit platforms | | ||
| app.R | [[Link](.)] | A `golem` file that contains the set of functions needed to deploy the app on any platform such as Posit Connect, etc | | ||
| DESCRIPTION | [[Link](.)] | A standard `R` package file containing series of metadata about the package including the package dependencies required to run the app. It forms a key part of the dependency management | | ||
| NAMESPACE | [[Link](.)] | A standard `R` package file that contains functions to import and from which package and what functions to export | | ||
| R/ | [[Link](R/)] | Standard `R` package folder holding all the package functions. It contains the functions required for the app core functionality such as the Server function `app_server.R`, UI function `app_ui.R`, all the modules `mod_*` files and utilitarian/business logic functions `fct_*.R` or `*utils*.R`/ or other `.R` files. It also contains an important file, `run_app.R`, which in turn contains the [`run_app()`](R/run_app.R) function that is called to launch the app | | ||
| dev/ | [[Link](dev/)] | This folder contains utilitarian files used during development phase only and not core functionalities of the app. | | ||
| inst/ | [[Link](inst)] | It contains the [`golem-config.yml`](inst/golem-config.yml) file and [`inst/app/www/`](inst/app/www/) files. [`inst/app/www/`](inst/app/www/) contains all files that are made available at application run time, while [`golem-config.yml`](inst/golem-config.yml) is an important yaml file to configure the app. | | ||
| test/ | [[Link](test/)] | This folder contains the unit test infrastructure codes | | ||
| test/ | [[Link](tests/)] | This folder contains the codes for the unit test infrastructure | | ||
| data/ | [[Link](data/)] | Contains `.rda` data used by the app during runtime | | ||
| data-raw/ | [[Link](data-raw/)] | It contains scripts to prepare dataset in the `data` folder. We also store some data in there that are not required at runtime | | ||
| man/ | [[Link](man/)] | This is a standard `R` package folder containing automatically filled files for function documentations | | ||
|
@@ -123,7 +123,7 @@ Your data type must follow the schema in [Database table schema](data-raw/phase_ | |
i. You can safely ignore these columns without any modification: `'extra_variable_1', 'extra_variable_2', 'extra_variable_3'` | ||
|
||
ii. To ignore the following columns ` | ||
'location_2', 'location_3', 'sex', 'gender', 'age', 'ethnicity', 'sexuality', 'disability', 'religion',`, You need to set your configuration file accordingly. A sample configuation is this: | ||
'location_2', 'location_3', 'sex', 'gender', 'age', 'ethnicity', 'sexuality', 'disability', 'religion'`, You need to set your configuration file accordingly. A sample configuation is this: | ||
|
||
``` | ||
my_config: | ||
|
@@ -133,7 +133,7 @@ Your data type must follow the schema in [Database table schema](data-raw/phase_ | |
question_1: fft | ||
location_1: Division | ||
``` | ||
Please [get in touch](mailto:[email protected]) if you need additional help implementing this solution locally. | ||
Please [get in touch](mailto:[email protected]) if you need additional help implementing this solution locally. | ||
|
||
## Code of Conduct | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.