Skip to content

Commit

Permalink
Autoreport: default-verdi på target leses fra config-fil (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnfinn authored Jan 20, 2025
1 parent 9748641 commit 905b1d4
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 44 deletions.
103 changes: 67 additions & 36 deletions R/autoReport.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,25 @@
#' @seealso \code{\link{deleteAutoReport}}
#' @export

createAutoReport <- function(synopsis, package, type = "subscription", fun,
paramNames, paramValues, owner, ownerName = "",
email, organization, runDayOfYear,
startDate = as.character(Sys.Date()),
terminateDate = NULL, interval = "",
intervalName = "", dryRun = FALSE,
target = "file") {
createAutoReport <- function(
synopsis,
package,
type = "subscription",
fun,
paramNames,
paramValues,
owner,
ownerName = "",
email,
organization,
runDayOfYear,
startDate = as.character(Sys.Date()),
terminateDate = NULL,
interval = "",
intervalName = "",
dryRun = FALSE,
target = getConfig("rapbaseConfig.yml")$r$autoReport$target
) {

# When NULL, set expiry date based on context
if (is.null(terminateDate)) {
Expand Down Expand Up @@ -110,7 +122,10 @@ createAutoReport <- function(synopsis, package, type = "subscription", fun,
#' @seealso \code{\link{createAutoReport}}
#' @export

deleteAutoReport <- function(autoReportId, target = "file") {
deleteAutoReport <- function(
autoReportId,
target = getConfig("rapbaseConfig.yml")$r$autoReport$target
) {
if (target == "file") {
rd <- readAutoReportData()
# just stop with an error if report does not exist
Expand Down Expand Up @@ -142,9 +157,11 @@ deleteAutoReport <- function(autoReportId, target = "file") {
#'
#' @examples
#' readAutoReportData()
readAutoReportData <- function(fileName = "autoReport.yml",
packageName = "rapbase",
target = "file") {
readAutoReportData <- function(
fileName = "autoReport.yml",
packageName = "rapbase",
target = getConfig("rapbaseConfig.yml")$r$autoReport$target
) {

if (target == "db") {
config <- getConfig(fileName = "rapbaseConfig.yml")
Expand Down Expand Up @@ -266,9 +283,11 @@ upgradeAutoReportData <- function(config) {
#' try(writeAutoReportData(config = config))
#' }
#'
writeAutoReportData <- function(fileName = "autoReport.yml", config,
packageName = "rapbase",
target = "file") {
writeAutoReportData <- function(
fileName = "autoReport.yml", config,
packageName = "rapbase",
target = getConfig("rapbaseConfig.yml")$r$autoReport$target
) {

if (target == "db") {
rc <- getConfig(fileName = "rapbaseConfig.yml")
Expand Down Expand Up @@ -389,7 +408,12 @@ writeAutoReportData <- function(fileName = "autoReport.yml", config,
#' ar <- list(ar1 = list(type = "A"), ar2 = list(type = "B"))
#' filterAutoRep(ar, "type", "B") # ar2
#'
filterAutoRep <- function(data, by, pass, target = "file") {
filterAutoRep <- function(
data,
by,
pass,
target = getConfig("rapbaseConfig.yml")$r$autoReport$target
) {
stopifnot(by %in% c("package", "type", "owner", "organization"))

if (length(data) == 0) {
Expand Down Expand Up @@ -527,11 +551,14 @@ getRegs <- function(config) {
#' }
#'

runAutoReport <- function(dayNumber = as.POSIXlt(Sys.Date())$yday + 1,
dato = Sys.Date(),
group = NULL,
type = c("subscription", "dispatchment"),
target = "file", dryRun = FALSE) {
runAutoReport <- function(
dayNumber = as.POSIXlt(Sys.Date())$yday + 1,
dato = Sys.Date(),
group = NULL,
type = c("subscription", "dispatchment"),
target = getConfig("rapbaseConfig.yml")$r$autoReport$target,
dryRun = FALSE
) {

# get report candidates
reps <- readAutoReportData(target = target) %>%
Expand Down Expand Up @@ -702,13 +729,15 @@ makeRunDayOfYearSequence <- function(startDay = Sys.Date(), interval) {
#' findNextRunDate(c(10, 20, 30), 20)
#' @export

findNextRunDate <- function(runDayOfYear,
baseDayNum = as.POSIXlt(Sys.Date())$yday + 1,
startDate = NULL,
terminateDate = NULL,
interval = NULL,
returnFormat = "%A %e. %B %Y",
target = "file") {
findNextRunDate <- function(
runDayOfYear,
baseDayNum = as.POSIXlt(Sys.Date())$yday + 1,
startDate = NULL,
terminateDate = NULL,
interval = NULL,
returnFormat = "%A %e. %B %Y",
target = getConfig("rapbaseConfig.yml")$r$autoReport$target
) {

if (target == "db") {
if (Sys.Date() < startDate) {
Expand Down Expand Up @@ -847,15 +876,17 @@ findNextRunDate <- function(runDayOfYear,
#' @export
# nolint end

makeAutoReportTab <- function(session,
namespace = character(),
user = rapbase::getUserName(session),
group = rapbase::getUserGroups(session),
orgId = rapbase::getUserReshId(session),
type = "subscription",
mapOrgId = NULL,
includeReportId = FALSE,
target = "file") {
makeAutoReportTab <- function(
session,
namespace = character(),
user = rapbase::getUserName(session),
group = rapbase::getUserGroups(session),
orgId = rapbase::getUserReshId(session),
type = "subscription",
mapOrgId = NULL,
includeReportId = FALSE,
target = getConfig("rapbaseConfig.yml")$r$autoReport$target
) {
stopifnot(type %in% c("subscription", "dispatchment", "bulletin"))

autoRep <- readAutoReportData(target = target) %>%
Expand Down
2 changes: 1 addition & 1 deletion man/createAutoReport.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/deleteAutoReport.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/filterAutoRep.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/findNextRunDate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/makeAutoReportTab.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/readAutoReportData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/runAutoReport.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/writeAutoReportData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 905b1d4

Please sign in to comment.