% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scores_nt_fitbit.R
\name{compute_sleep_ranges_waso_ext}
\alias{compute_sleep_ranges_waso_ext}
\title{Computes sleep timing and WASO metrics}
\usage{
compute_sleep_ranges_waso_ext(data_blocks, data_counts, bin_minutes)
}
\arguments{
\item{data_blocks}{tbl. Output from \code{add_sleep_flags()}, containing sleep
epoch data with block assignments and sleep stage information.}

\item{data_counts}{tbl. Output from \code{compute_block_counts()}, containing
the number of valid main sleep blocks per participant-night.}

\item{bin_minutes}{numeric. Number of minutes to bin data by.}
}
\value{
tbl. A participant-night level summary containing:
\itemize{
\item \code{dtt_start_slp}: Sleep onset time (if a single valid block exists).
\item \code{dtt_end_slp}: Sleep offset time (based on last wake transition or block end).
\item \code{dtt_start_bed}: Start of sleep recording interval.
\item \code{dtt_end_bed}: End of sleep recording interval.
\item \code{n_waso}: Number of wake-after-sleep-onset episodes (adjusted for block structure).
\item \code{min_waso}: Total wake-after-sleep-onset duration in minutes (30-sec epochs).
}
}
\description{
Computes sleep timing and WASO metrics at the sleep-block level,
incorporating block structure constraints to ensure sleep ranges are only
calculated when a single valid main sleep block is present.

This function extends \code{compute_sleep_ranges_waso()} by restricting sleep
range calculations to nights with exactly one valid sleep block, improving
robustness in fragmented sleep recordings.
}
\details{
Sleep metrics are only computed when exactly one valid main sleep block is
present for a given participant-night. If multiple blocks exist, sleep timing
variables are set to \code{NA} to avoid ambiguity.

Wake episodes are identified using run-length encoding of cleaned sleep
stages, where \code{"awake"} and \code{"wake"} are treated as wake states and missing
values are recoded as \code{"awake"}.
}
\keyword{internal}
