Skip to content

Commit

Permalink
Merge pull request #77 from jhelvy/pingfan-ui-design
Browse files Browse the repository at this point in the history
rename "timestamp_" as "time_"
  • Loading branch information
pingfan-hu authored Aug 16, 2024
2 parents ce37ef6 + 61a13bd commit 31afdda
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions R/db.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ sd_database <- function(
#' Transform survey data for database storage
#'
#' @param question_vals List of question values
#' @param timestamp_vals List of timestamp values
#' @param time_vals List of timestamp values
#' @param session_id String representing the session ID
#' @param custom_vals List of custom values
#' @return A data frame with transformed survey data, including a UTC timestamp
Expand All @@ -124,9 +124,9 @@ sd_database <- function(
#' into a single data frame. The UTC timestamp is formatted as "YYYY-MM-DD HH:MM:SS UTC".
#' @importFrom stats setNames
#' @keywords internal
transform_data <- function(question_vals, timestamp_vals, session_id, custom_vals) {
transform_data <- function(question_vals, time_vals, session_id, custom_vals) {
# Create current timestamp in UTC with the desired format
current_timestamp <- format(Sys.time(), "%Y-%m-%d %H:%M:%S UTC", tz = "UTC")
current_time <- format(Sys.time(), "%Y-%m-%d %H:%M:%S UTC", tz = "UTC")

for (i in seq_len(length(question_vals))) {
val <- question_vals[[i]]
Expand All @@ -147,11 +147,11 @@ transform_data <- function(question_vals, timestamp_vals, session_id, custom_val

# Combine all data
data <- cbind(
timestamp = current_timestamp,
time_start = current_time,
session_id = session_id,
custom_df,
responses,
setNames(as.data.frame(timestamp_vals), paste0("timestamp_", names(timestamp_vals)))
setNames(as.data.frame(time_vals), names(time_vals))
)

return(data)
Expand Down Expand Up @@ -270,7 +270,7 @@ database_uploading <- function(df, db, table_name) {
}

# Ensure correct column order
correct_order <- c("timestamp", "session_id", setdiff(names(df), c("timestamp", "session_id")))
correct_order <- c("time_start", "session_id", setdiff(names(df), c("time_start", "session_id")))
df <- df[, correct_order]
}

Expand Down
4 changes: 2 additions & 2 deletions man/transform_data.Rd

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

0 comments on commit 31afdda

Please sign in to comment.