-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from jubilee2/report
add queryLogSummary
- Loading branch information
Showing
6 changed files
with
85 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: rcUtils | ||
Type: Package | ||
Title: REDCap Utility Functions | ||
Version: 0.3.0 | ||
Version: 0.4.0 | ||
Author: Jubilee | ||
Maintainer: Jubilee<[email protected]> | ||
Description: A collection of reusable functions to streamline and enhance the functionality of REDCap projects. This package includes functions for parsing logging strings, converting data types, and more. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
queryLogSummary <- function(logs) { | ||
# Function implementation | ||
o <- logDetailsParseDQ(logs$details) | ||
logs$Action <- sapply(o, function(x) if (is.null(x$Action)) NA else x$Action) | ||
logs$Record <- sapply(o, function(x) if (is.null(x$Record)) NA else x$Record) | ||
logs$Event <- sapply(o, function(x) if (is.null(x$Event)) NA else x$Event) | ||
logs$Field <- sapply(o, function(x) if (is.null(x$Field)) NA else x$Field) | ||
logs$Comment <- sapply(o, function(x) if (is.null(x$Comment)) NA else x$Comment) | ||
logs$`Data Quality Rule` <- sapply(o, function(x) if (is.null(x$`Data Quality Rule`)) NA else x$`Data Quality Rule`) | ||
|
||
selector <- sapply(o, length) > 0 | ||
logs[selector,c("timestamp", "username", "Action","Record","Event","Field","Data Quality Rule","Comment")] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
\name{queryLogSummary} | ||
\alias{queryLogSummary} | ||
\title{Summarize Data Query Logs} | ||
\description{ | ||
Summarize query logs by extracting relevant information from log details. | ||
} | ||
\usage{ | ||
queryLogSummary(logs) | ||
} | ||
\arguments{ | ||
\item{logs}{Data frame containing query logs with a 'timestamp', 'username', 'details' column.} | ||
} | ||
\value{ | ||
Data frame with summarized query log information. | ||
} | ||
\examples{ | ||
logs <- data.frame( | ||
timestamp = Sys.time(), | ||
username = "user123", | ||
details = c("Open data query", "Send data query back for further attention") | ||
) | ||
summary <- queryLogSummary(logs) | ||
print(summary) | ||
} | ||
\seealso{ | ||
\code{logDetailsParseDQ()} | ||
} | ||
\author{ | ||
Jubilee | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
test_that("queryLogSummary returns data frame", { | ||
logs <- data.frame(timestamp = Sys.time(), username = "user123", details = "Open data query") | ||
result <- queryLogSummary(logs) | ||
expect_s3_class(result, "data.frame") | ||
}) | ||
|
||
test_that("queryLogSummary has correct columns", { | ||
logs <- data.frame(timestamp = Sys.time(), username = "user123", details = "Open data query") | ||
result <- queryLogSummary(logs) | ||
expect_setequal(names(result), c("timestamp", "username", "Action", "Record", "Event", "Field", "Data Quality Rule", "Comment")) | ||
}) | ||
|
||
test_that("queryLogSummary handles empty logs", { | ||
logs <- data.frame(timestamp = Sys.time(), username = 'foo', details = '') | ||
result <- queryLogSummary(logs) | ||
expect_equal(nrow(result), 0) | ||
}) | ||
|
||
test_that("queryLogSummary handles NA details", { | ||
logs <- data.frame(timestamp = Sys.time(), username = "user123", details = NA) | ||
result <- queryLogSummary(logs) | ||
expect_equal(nrow(result), 0) | ||
}) |