Skip to content
Merged
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
14 changes: 12 additions & 2 deletions tutorials/point-in-time/build-clock-report.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ build_report <- function(destination) {
length(xml2::xml_find_all(html, "//table/tbody/tr")) == row_count)
}
render("clock-report.Rmd", destination)
check_render(file.path(destination, "index.html"), "7 seconds of the 12-second window", nrow(csv))
# Add the public address after Pandoc makes the HTML self-contained. A reader's
# locally rendered report can use a different window and needs no canonical URL.
url <- "https://jacobiusmakes.github.io/parlayapiR/clock-report/"
published <- file.path(destination, "index.html")
lines <- readLines(published, warn = FALSE, encoding = "UTF-8")
close_head <- which(trimws(lines) == "</head>")
stopifnot(length(close_head) == 1L)
canonical <- sprintf('<link rel="canonical" href="%s" />', url)
writeLines(append(lines, canonical, after = close_head - 1L), published, useBytes = TRUE)
links <- xml2::xml_find_all(xml2::read_html(published), "//head/link[@rel='canonical']")
stopifnot(identical(xml2::xml_attr(links, "href"), url))
check_render(published, "7 seconds of the 12-second window", nrow(csv))
stage <- tempfile()
dir.create(stage)
on.exit(unlink(stage, recursive = TRUE), add = TRUE)
Expand All @@ -49,7 +60,6 @@ build_report <- function(destination) {

sitemap <- file.path(dirname(destination), "sitemap.xml")
xml <- xml2::read_xml(sitemap)
url <- "https://jacobiusmakes.github.io/parlayapiR/clock-report/"
locate <- function(x) xml2::xml_text(xml2::xml_find_all(x, "//*[local-name()='loc']"))
before <- locate(xml)
if (!url %in% before) {
Expand Down
4 changes: 2 additions & 2 deletions tutorials/point-in-time/clock-report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ output:
highlight: null
mathjax: null
self_contained: true
header-includes:
- '<link rel="canonical" href="https://jacobiusmakes.github.io/parlayapiR/clock-report/" />'
params:
start_second: 0
end_second: 12
Expand Down Expand Up @@ -72,6 +70,8 @@ Look at seconds 8–9 in the full log. The source withdrew the quote at second 8

## Reproduce the report

[Download the ten intervals as CSV](https://jacobiusmakes.github.io/parlayapiR/clock-report/decision-clock-intervals.csv) to inspect both prices and their UTC boundaries in a spreadsheet.

[Download the R Markdown project and the full twelve-second CSV](https://jacobiusmakes.github.io/parlayapiR/clock-report/project.zip). Extract the ZIP and open a terminal in that directory. Run `Rscript replay.R` with base R to see both clocks at eight selected decision times. Three of those eight decisions differ. The elapsed-time table counts how long each difference lasted.

To change the report window, run the following in R with **rmarkdown**, **knitr** and **Pandoc** installed. It renders a local HTML file. In the window from second 8 up to second 9, the two histories disagree for the entire second.
Expand Down
Loading