Packages and Folders

# Install these packages if you don't have them yet
# if (!require("pacman")) install.packages("pacman")
# devtools::install_github("favstats/tidytemplate")

pacman::p_load(tidyverse, tidytemplate, stringi)

# Creates folders
# tidytemplate::data_dir()
# tidytemplate::images_dir()

Functions

Create AT Requestios

create_at_request <- function(x, type) {
  if (x %in% c("OMID", "AccessCode", "AssessmentVersion", "AssessmentsDone", paste0("D", 1:8))) {
    final_string <- glue::glue('"<<x>>" -> "{<<x>>}"', .open = "<<", .close = ">>")
    return(final_string)
  }
  if (type=="Pre") {
    if (str_detect(str_sub(x, -3), "Pre")) {
      final_string <- glue::glue('"<<x>>" -> "{<<x>>}"', .open = "<<", .close = ">>")
    }
    if (!str_detect(str_sub(x, -3), "Pre")) {
      final_string <- glue::glue('"<<x>>" -> "(not asked yet)"', .open = "<<", .close = ">>")
    }
    return(final_string)
  }
  if (type=="Post") {
    if (str_detect(x, "Post") | str_detect(str_sub(x, -3), "Pre")) {
      final_string <- glue::glue('"<<x>>" -> "{<<x>>}"', .open = "<<", .close = ">>")
    }
    if (!(str_detect(x, "Post") | str_detect(str_sub(x, -3), "Pre"))) {
      final_string <- glue::glue('"<<x>>" -> "(not asked yet)"', .open = "<<", .close = ">>")
    }
    return(final_string)
  }
  if (type=="Sep") {
    if (str_detect(x, "Sep")) {
      final_string <- glue::glue('"<<x>>" -> "{<<x>>}"', .open = "<<", .close = ">>")
    }
    if (!str_detect(x, "Sep")) {
      final_string <- glue::glue('"<<x>>" -> "(not asked yet)"', .open = "<<", .close = ">>")
    }
    return(final_string)
  }
  if (type=="Oct") {
    if (str_detect(x, "Sep|Oct")) {
      # x_internal <- str_remove(x, "Sep")
      final_string <- glue::glue('"<<x>>" -> "{<<x>>}"', .open = "<<", .close = ">>")
    }
    if (!str_detect(x, "Sep|Oct")) {
      final_string <- glue::glue('"<<x>>" -> "(not asked yet)"', .open = "<<", .close = ">>")
    }
    return(final_string)
  }
  if (type=="Nov") {
    if (str_detect(x, "Sep|Oct|Nov")) {
      # x_internal <- str_remove(x, "Sep")
      final_string <- glue::glue('"<<x>>" -> "{<<x>>}"', .open = "<<", .close = ">>")
    }
    if (!str_detect(x, "Sep|Oct|Nov")) {
      final_string <- glue::glue('"<<x>>" -> "(not asked yet)"', .open = "<<", .close = ">>")
    }
    return(final_string)
  }
  if (type %in% c("FollowUp", "Dec", "same")) {
    final_string <- glue::glue('"<<x>>" -> "{<<x>>}"', .open = "<<", .close = ">>")
    return(final_string)
  }
}

request_strings <- function(x) {
  glue::glue('*send: { "fields" -> { <<x>>  } }', .open = "<<", .close = ">>")
}

Create GT AT Vars

create_GT_AT_vars <- function(x){
  glue::glue('>>{x}=retrieved[1]["fields"]["{x}"]')
}
````

# AssessmentV6 Template Stuff

```r

dat.ass6 <- read_csv("data/AssessmentV6-Grid view.csv")

PreStrings <- dat.ass6 %>% 
  colnames() %>% 
  .[str_detect(., "Pre")] %>% 
  .[!str_detect(., "Post|FollowUp")]

FixStrings <- dat.ass6 %>% 
  colnames() %>% 
  .[!str_detect(., "Pre|Post|FollowUp")]

PostStrings <- PreStrings %>% 
  stri_replace_last_fixed(., "Pre", "Post")

FollowUpStrings <- PreStrings %>% 
  stri_replace_last_fixed(., "Pre", "FollowUp")

tibble(c(FixStrings, PreStrings, PostStrings, FollowUpStrings)) %>% 
  t() %>% 
  as.data.frame() %>% 
  mutate_all(as.character) -> Scribble

AssessmentTemplate <- bind_rows(Scribble, Scribble) %>% 
  janitor::row_to_names(1)

write_csv(AssessmentTemplate, path = "data/AssessmentTemplate.csv")

Create AT Request

Pre

colnames(AssessmentTemplate) %>% 
  map_chr(~create_at_request(.x, "Pre")) %>% 
  glue::glue_collapse(sep=", ") %>% 
  request_strings() %>% 
  cat()

Post

colnames(AssessmentTemplate) %>% 
  map_chr(~create_at_request(.x, "Post")) %>% 
  glue::glue_collapse(sep=", ") %>% 
  request_strings() %>% 
  cat()

FollowUp

colnames(AssessmentTemplate) %>% 
  map_chr(~create_at_request(.x, "FollowUp")) %>% 
  glue::glue_collapse(sep=", ") %>% 
  request_strings() %>% 
  cat()

Create GT AT Vars

Pre

PreStrings %>% 
  map_chr(~create_GT_AT_vars(.x)) %>% 
  glue::glue_collapse(sep="\n") %>% 
  cat()

Post

PostStrings %>% 
  map_chr(~create_GT_AT_vars(.x)) %>% 
  glue::glue_collapse(sep="\n") %>% 
  cat()

FollowUp

FollowUpStrings %>% 
  map_chr(~create_GT_AT_vars(.x)) %>% 
  glue::glue_collapse(sep="\n") %>% 
  cat()

AssessmentV6 DiD Template

PreStrings <- dat.ass6 %>% 
  colnames() %>% 
  .[str_detect(., "Pre")] %>% 
  .[!str_detect(., "Post|FollowUp")]

SepStrings <- dat.ass6 %>% 
  colnames() %>% 
  .[str_detect(., "Pre")] %>% 
  .[!str_detect(., "Post|FollowUp")] %>% 
  stri_replace_last_fixed(., "Pre", "Sep")

# stringi::stri_extract_last("PrepasdredPost", fixed = "Pre")
# 
# str_sub("PrepasdredPost",-6,-1)


OctStrings <- SepStrings %>% 
  stri_replace_last_fixed(., "Sep", "Oct")

NovStrings <- SepStrings %>% 
  stri_replace_last_fixed(., "Sep", "Nov")

DecStrings <- SepStrings %>% 
  stri_replace_last_fixed(., "Sep", "Dec")


tibble(c(FixStrings, SepStrings, OctStrings, NovStrings, DecStrings)) %>% 
  t() %>% 
  as.data.frame() %>% 
  mutate_all(as.character) -> Scribble

AssessmentTemplateDiD <- bind_rows(Scribble, Scribble) %>% 
  janitor::row_to_names(1)

write_csv(AssessmentTemplateDiD, path = "data/AssessmentTemplateDiD.csv")

Create AT Request

Sep

colnames(AssessmentTemplateDiD) %>% 
  map_chr(~create_at_request(.x, "Sep")) %>% 
  glue::glue_collapse(sep=", ") %>% 
  request_strings() %>% 
  cat()

Oct

colnames(AssessmentTemplateDiD) %>% 
  map_chr(~create_at_request(.x, "Oct")) %>% 
  glue::glue_collapse(sep=", ") %>% 
  request_strings() %>% 
  cat()

Nov

colnames(AssessmentTemplateDiD) %>% 
  map_chr(~create_at_request(.x, "Nov")) %>% 
  glue::glue_collapse(sep=", ") %>% 
  request_strings() %>% 
  cat()

Dec

colnames(AssessmentTemplateDiD) %>% 
  map_chr(~create_at_request(.x, "Dec")) %>% 
  glue::glue_collapse(sep=", ") %>% 
  request_strings() %>% 
  cat()

Create GT AT Vars

Sep

SepStrings %>% 
  map_chr(~create_GT_AT_vars(.x)) %>% 
  glue::glue_collapse(sep="\n") %>% 
  cat()

Oct

OctStrings %>% 
  map_chr(~create_GT_AT_vars(.x)) %>% 
  glue::glue_collapse(sep="\n") %>% 
  cat()

Nov

NovStrings %>% 
  map_chr(~create_GT_AT_vars(.x)) %>% 
  glue::glue_collapse(sep="\n") %>% 
  cat()

Dec

DecStrings %>% 
  map_chr(~create_GT_AT_vars(.x)) %>% 
  glue::glue_collapse(sep="\n") %>% 
  cat()


openmindplatform/GuidedTrackR documentation built on Nov. 4, 2019, 11:10 p.m.