metrumresearchgroup / review

helpful tools for organizing and performing quality control (QC) tasks
https://metrumresearchgroup.github.io/review/
2 stars 0 forks source link

create a tool to diff plots #70

Closed andersone1 closed 2 months ago

michaelmcd18 commented 5 months ago
svnInfo <- svnProjInfo()

tmp_loc <- tempfile(fileext = ".pdf")

svn_command <-
    glue::glue("svn export -r{svnInfo$rev} {svnInfo$url}/{file} {tmp_loc}")

Determine the checked out revision & export that version of the file. We will compare that version to the locally modified pdf. (Either side by side or some visual)

andersone1 commented 5 months ago

maybe we just open the and the old in the browser

andersone1 commented 5 months ago

This may be helpful at some pt:

https://search.r-project.org/CRAN/refmans/gdiff/html/samePDF.html

michaelmcd18 commented 5 months ago

Some promise to going with the gif approach - does work with multi page pdfs, although ordering is maybe not as useful

getOrigModify <- function(.file) {

  svnInfo <- svnProjInfo()

  .org_tmp_dir <- file.path(tempdir(), "reviewOrig")

  if(fs::dir_exists(.org_tmp_dir)){
    fs::dir_delete(.org_tmp_dir)
  }

  fs::dir_create(.org_tmp_dir)

  .orig_tmp_file <- 
    review:::svnExport(.file = .file,
                       .revision = svnInfo$rev,
                       .output_dir =.org_tmp_dir, 
                       .return_file = TRUE, 
                       .quiet = TRUE)

  list(
    orig = .orig_tmp_file,
    modify = .file
  )

}

diffPDF <- function(.file) {

  paths <- getOrigModify(.file)

  img_list <- lapply(paths, magick::image_read)

  ## join the images together
  img_joined <- magick::image_join(img_list)

  ## animate at 2 frames per second
  img_animated <- magick::image_animate(img_joined, fps = 1)

  ## view animated image
  img_animated
}

A couple areas for improvement:

michaelmcd18 commented 4 months ago
diffPDF <- function(.file, .fps = 1) {

  get_current_prev <-
    getPreviousCurrent(.file,
                       .previous_revision = svnProjInfo()[["rev"]],
                       .current_revision = NULL)

  paths <- list(previous = get_current_prev$.previous_revision_temp_file,
                current = get_current_prev$.current_revision_temp_file)

  img_list <- lapply(paths, magick::image_read)

  if(length(img_list[["previous"]]) != length(img_list[["current"]])){
    stop("must have same num pages")
  }

  img_list[["previous"]] <- magick::image_annotate(img_list[["previous"]], text = "OLD", gravity = "south", color = "red")
  img_list[["current"]]<- magick::image_annotate(img_list[["current"]], text = "NEW", gravity = "south", color = "blue")

  for(i in 1:length(img_list[["previous"]])){

    this_page.i <-
      image_join(
        img_list[["previous"]][i],
        img_list[["current"]][i]
      )

    img_list_all_pg <-
      if(i == 1){
        this_page.i
      } else {
        image_join(img_list_all_pg, this_page.i)
      }
  }

  img_animated <- magick::image_animate(image = img_list_all_pg, fps = .fps)

  img_animated
}
andersone1 commented 4 months ago
andersone1 commented 4 months ago

https://metrumresearchgroup.github.io/bbr/reference/model_diff.html