Skip to content

Commit

Permalink
fixed datetimes for tailoring
Browse files Browse the repository at this point in the history
  • Loading branch information
JuKo007 committed Apr 16, 2023
1 parent 57e1560 commit 65eb1da
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
13 changes: 7 additions & 6 deletions R/summarize_tokens_per_person.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
############ Function to return a summary for token count messages
summarize_tokens_per_person <- function(data,
names = "all",
starttime = anytime("1960-01-01 00:00"),
endtime = Sys.time(),
starttime = "1960-01-01 00:00",
endtime = as.character(Sys.time()),
exclude_sm = FALSE) {

# catching bad params
# start- and endtime are POSIXct
if (is(starttime, "POSIXct") == F) stop("starttime has to be of class POSIXct.")
if (is(endtime, "POSIXct") == F) stop("endtime has to be of class POSIXct.")
# start- and endtime are convertable to POSIXct
if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().")
if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().")
if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.")

# names in data or all names
if (!("all" %in% names) & any(!names %in% data$Sender)) stop("names has to either be \"all\" or a vector of names to include.")
Expand All @@ -32,7 +33,7 @@ summarize_tokens_per_person <- function(data,

# setting starttime
if (starttime == anytime("1960-01-01 00:00")) {
starttime <- min(data$DateTime)
starttime <- min(anytime(data$DateTime))
} else {
starttime <- anytime(starttime, asUTC = TRUE)
}
Expand Down
15 changes: 8 additions & 7 deletions R/tailor_chat.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
# Function to tailor dataframe with respect to time and author names
tailor_chat <- function(data,
names = "all",
starttime = anytime("1960-01-01 00:00"),
endtime = Sys.time(),
starttime = "1960-01-01 00:00",
endtime = as.character(Sys.time()),
exclude_sm = FALSE) {

# catching bad params
# start- and endtime are POSIXct
if (is(starttime, "POSIXct") == F) stop("starttime has to be of class POSIXct.")
if (is(endtime, "POSIXct") == F) stop("endtime has to be of class POSIXct.")
# start- and endtime are convertable to POSIXct
if (is.character(starttime) == FALSE | is.na(anytime(starttime))) stop("starttime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().")
if (is.character(endtime) == FALSE | is.na(anytime(endtime))) stop("endtime has to be a character string in the form of 'yyyy-mm-dd hh:mm' that can be converted by anytime().")
if (anytime(starttime) >= anytime(endtime)) stop("starttime has to be before endtime.")

# names in data or all names
if (!("all" %in% names) & any(!names %in% data$Sender)) stop("names has to either be \"all\" or a vector of names to include.")
Expand All @@ -32,14 +33,14 @@ tailor_chat <- function(data,

# setting starttime
if (starttime == anytime("1960-01-01 00:00")) {
starttime <- min(data$DateTime)
starttime <- min(anytime(data$DateTime))
} else {
starttime <- anytime(starttime)
}

# setting endtime
if (difftime(Sys.time(), endtime, units = "min") < 1) {
endtime <- max(data$DateTime)
endtime <- max(anytime(data$DateTime))
} else {
endtime <- anytime(endtime)
}
Expand Down
Binary file modified inst/TailoredData2.rds
Binary file not shown.
4 changes: 2 additions & 2 deletions man/summarize_tokens_per_person.Rd

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

4 changes: 2 additions & 2 deletions man/tailor_chat.Rd

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

16 changes: 8 additions & 8 deletions tests/testthat/test-WhatsR-tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,8 @@ test_that("tailoring function", {

tailored_data1 <- tailor_chat(data,
names = c("Mallory", "Alice"),
starttime = anytime("1976-01-01 00:00",asUTC = TRUE),
endtime = anytime("2022-01-01 00:00",asUTC = TRUE),
starttime = "1976-01-01 00:00",
endtime = "2022-01-01 00:00",
exclude_sm = TRUE
)

Expand All @@ -894,8 +894,8 @@ test_that("tailoring function", {

tailored_data2 <- tailor_chat(data,
names = "Dave",
starttime = anytime("2018-01-29 12:24:03",asUTC = TRUE),
endtime = anytime(" 2018-01-30 00:13:03",asUTC = TRUE),
starttime = "2018-01-29 12:24:03",
endtime = "2018-01-30 00:13:03",
exclude_sm = TRUE
)

Expand All @@ -907,8 +907,8 @@ test_that("tailoring function", {

tailored_data3 <- tailor_chat(data,
names = "Dave",
starttime = anytime(" 2018-01-29 12:24:03",asUTC = TRUE),
endtime = anytime(" 2018-01-30 00:13:03",asUTC = TRUE),
starttime = "2018-01-29 12:24:03",
endtime = "2018-01-30 00:13:03",
exclude_sm = TRUE
)

Expand All @@ -920,8 +920,8 @@ test_that("tailoring function", {

tailored_data4 <- tailor_chat(data,
names = "all",
starttime = anytime("2018-01-29 12:24:03",asUTC = TRUE),
endtime = Sys.time(),
starttime = "2018-01-29 12:24:03",
endtime = as.character(Sys.time()),
exclude_sm = TRUE
)

Expand Down

0 comments on commit 65eb1da

Please sign in to comment.