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
24 changes: 24 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,27 @@
^pkgdown$
^\.github$
^vignettes/articles$
^database$
^database/.*$
^.*[.]duckdb$
^.*[.]parquet$
^data/db_overlay$
^data/raw$
^dashboard$
^dashboard/.*$
^dashboard/dashboard_cache$
^dashboard/_freeze$
^python$
^.*[.]RData$
^.*[.]rdx$
^\\.Rproj\\.user$
^\\.all-contributorsrc$
^\\.venv($|/)
^venv($|/)
^env($|/)
^.env($|/)
^__pycache__($|/)
^python/__pycache__($|/)
^\\.python-version$
^.*[.]ipynb$
^.*[.]ipynb_checkpoints($|/)
2 changes: 2 additions & 0 deletions .Renviron
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RETICULATE_PYTHON=D:/GitHub/OSMdashboard/.venv/Scripts/python.exe
DUCKDB_PATH=D:/GitHub/OSMdashboard/database/osm_changesets.duckdb
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,23 @@
.quarto
docs
inst/doc
database/
*.duckdb
*.parquet
data/db_overlay/
data/raw/
dashboard/dashboard_cache/
dashboard/_freeze/
dashboard/.quarto/
dashboard/site_libs/
.RData
.Rhistory
.Rproj.user/
.venv/
venv/
env/
.env/
__pycache__/
python/__pycache__/
*.ipynb
.ipynb_checkpoints/
7 changes: 6 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ Imports:
stringr,
tidyr,
tidyRSS,
WikipediR
WikipediR,
DBI,
duckdb,
readr,
sf,
reticulate
Suggests:
knitr,
rmarkdown,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(calc_stats_contributions_wiki)
export(categorise_keys)
export(connect_osm_db)
export(create_dashboard)
export(extract_and_combine_tags)
export(get_changesets_details)
Expand Down
33 changes: 33 additions & 0 deletions R/database.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#' Connect to the OSM DuckDB database
#'
#' @description Opens a DBI connection to the OSM Changesets DuckDB file.
#' It first checks the environment variable `DATABASE_URL` for a URL of the form
#' `duckdb:///path/to/osm_changesets.duckdb`. If not set, it falls back to
#' the environment variable `DUCKDB_PATH` (default:
#' `"database/osm_changesets.duckdb"`).
#'
#' @returns A DBI connection object (`DBI::DBIConnection`) to a DuckDB database.
#' You are responsible for closing it with `DBI::dbDisconnect(con)`.
#' @export
#'
#' @examples
#' \dontrun{
#' con <- connect_osm_db()
#' # ... use the connection ...
#' DBI::dbDisconnect(con)
#' }

#In the above example, dontrun is placed there as the database will not found on GitHub so these example
#checks will not execute
connect_osm_db <- function() {
url <- Sys.getenv("DATABASE_URL", "")
if (nzchar(url) && startsWith(url, "duckdb:///")) {
# DATABASE_URL like "duckdb:///absolute/or/relative/path/to/file.duckdb"
dbfile <- sub("^duckdb:///", "", url)
return(DBI::dbConnect(duckdb::duckdb(), dbfile))
}

# Fallback: environment variable DUCKDB_PATH
duck_path <- Sys.getenv("DUCKDB_PATH", "database/osm_changesets.duckdb")
DBI::dbConnect(duckdb::duckdb(), duck_path)
}
64 changes: 0 additions & 64 deletions R/summarise_groups.R

This file was deleted.

2 changes: 0 additions & 2 deletions R/user_contributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ get_contributions_osm_users <- function(users) {

for (user in users) {

print(user)

# Sanitise url
user_clean <- gsub(" ", "%20", user)

Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,25 @@ This package uses quarto, which is is already installed with RStudio and Positro

## Usage

## Usage WITHOUT database

1. Create the dashboard folder structure by calling `create_dashboard()`.
2. Edit the `data/group_info.csv` and `data/group_users.csv` files to add your groups and users.
3. Run `data_retrieval.R` to retrieve the data from OSM.
4. Render `dashboard.qmd` to generate the dashboard.
4. Render `dashboard.qmd` to generate the dashboard. Do this by running `quarto render dashboard.qmd`.

Refer to the `vignette("dashboard-group-contributions")` for more details.
## Usage WITH database

In your main directory, the database must be called `osm_changesets.duckdb` and must be stored in a subdirectory named `database`.

1. Create the dashboard folder structure by calling `create_dashboard()`.
2. Edit the `data/group_info.csv` and `data/group_users.csv` files to add your groups and users.
3. Run `data_retrieval.R` to retrieve the data from OSM.
4. Run `quarto render dashboard.qmd -P use_db_overlay:true`.

The `use_db_overlay:true` parameter ensures that all information within the database is loaded and used in place of information from APIs in the dashboard.

Refer to the `vignette("dashboard-group-contributions")` for more details.

## Contributors

Expand Down
Loading