Skip to content

Commit

Permalink
Compute verse peaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lmullen committed Apr 16, 2021
1 parent bea6fbb commit 9896a86
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions scripts/verse-peaks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
library(jsonlite)
library(tidyverse)
library(DBI)
library(dbplyr)

db <- dbConnect(odbc::odbc(), "ResearchDB", timeout = 10)

top_verses <- tbl(db, in_schema("apb", "top_verses")) %>% collect()

get_peak <- function(verse) {
base_url <- "http://localhost:8090/apb/verse-trend?corpus=chronam"
verse_clean <- str_replace_all(verse, " ", "+")
url <- str_glue("{base_url}&ref={verse_clean}")
res <- jsonlite::read_json(url, simplifyVector = TRUE)
max_record <- res$trend %>%
filter(smoothed == max(smoothed)) %>%
slice(1)
max_record[[1, "year"]]
}

top_verses$peak <- top_verses$reference_id %>% map_int(get_peak)

top_verses <- top_verses %>% select(reference_id, year = peak)

dbWriteTable(db, "verse_peaks", top_verses)

0 comments on commit 9896a86

Please sign in to comment.