This function parses a standardised sleeptime dataframe into the full FIPS format, ready for simulation and modelling. The sleeptime format requires a sleep.id column (vector), a series of sleep times, and a series of corresponding wake times. This format is the simplest to work with for human-readable or human-generated dataframes. See parse_sleepwake_sequence for binary input methods.

parse_sleeptimes(
  sleeptimes,
  series.start,
  series.end,
  roundvalue = 5,
  sleep.start.col,
  sleep.end.col,
  sleep.id.col
)

sleeptimes_to_FIPSdf(
  sleeptimes,
  series.start,
  series.end,
  roundvalue = 5,
  sleep.start.col,
  sleep.end.col,
  sleep.id.col
)

Arguments

sleeptimes

A dataframe in the sleep time format (see help for more info)

series.start

A POSIXct object indicating the start datetime of the simulation (i.e., pre-first sleep waking duration)

series.end

A POSIXct object indicating the end datetime of the simulation

roundvalue

An whole numeric (integer) value to round the sleep times to in minutes (default = 5 minutes). Second precision not supported.

sleep.start.col

string The column in the dataframe containing the sleep start times

sleep.end.col

string The column name in the dataframe containing the sleep end times

sleep.id.col

string A column name specifying the sleep id sequence (i.e., 1:n())

Value

FIPS_df

Details

It is crucial that that following conditions are met for all arguments:

  • Ensure that all specified datetimes for all datetime arguments are in an identical timezone.

  • Ensure that the minimum sleep start time is >= series.start

  • Ensure that the maximum wake time (sleep end) is <= series.end

  • Ensure that each sleep start is < the corresponding sleep.end

See also

For binary input parsing see: parse_sleepwake_sequence

Examples


 my_sleeptimes = tibble::tribble(
   ~sleep.id,          ~sleep.start,            ~sleep.end,
   1L, "2018-05-21 01:00:00", "2018-05-21 07:00:00",
   2L, "2018-05-21 23:00:00", "2018-05-22 04:00:00",
   3L, "2018-05-23 01:00:00", "2018-05-23 09:00:00") %>%
   dplyr::mutate(
     sleep.start = lubridate::ymd_hms(sleep.start),
     sleep.end = lubridate::ymd_hms(sleep.end))

 my_simstart = lubridate::ymd_hms('2018-05-20 22:00:00')
 my_simend   = lubridate::ymd_hms('2018-05-23 10:00:00')

 my_FIPS_df = parse_sleeptimes(
   sleeptimes = my_sleeptimes,
   series.start = my_simstart,
   series.end = my_simend,
   sleep.start.col = "sleep.start",
   sleep.end.col = "sleep.end",
   sleep.id.col = "sleep.id",
   roundvalue = 5)