% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scores_nt_fitbit.R
\name{compute_fitbit_weekly_summary}
\alias{compute_fitbit_weekly_summary}
\title{Generates weekly summary tables}
\usage{
compute_fitbit_weekly_summary(
  df,
  wkdy_min = 3,
  wknd_min = 1,
  summarize_fn,
  filter_expr
)
}
\arguments{
\item{df}{tbl. Input daily-level dataset containing at minimum:
\code{participant_id}, \code{session_id}, \code{wk}, and \code{dt_wknd}.}

\item{wkdy_min}{numeric. Minimum number of weekday observations required
for a valid weekly weekday estimate.}

\item{wknd_min}{numeric. Minimum number of weekend observations required
for a valid weekly weekend estimate.}

\item{summarize_fn}{function. A user-defined function that takes a filtered
dataset and returns weekly summaries grouped by
\code{participant_id}, \code{session_id}, and \code{wk}.}

\item{filter_expr}{expression. Logical filtering condition applied to the
input dataset before summarization (e.g., QC thresholds).}
}
\value{
tbl. A combined weekly dataset containing three types of summaries:
\itemize{
\item \code{wk_type = 2}: Whole-week estimates (weekday + weekend combined)
\item \code{wk_type = 1}: Weekend-only estimates
\item \code{wk_type = 0}: Weekday-only estimates
}

Each row includes:
\itemize{
\item Weekly summary metrics from \code{summarize_fn}
\item Day count variables (\code{n_day}, \code{n_wkdy}, \code{n_wknd})
\item Quality control flag \code{qc_wk} indicating sufficient coverage
}
}
\description{
Generates weekly summary tables using a user-supplied summarization function,
with stratification by weekday, weekend, and full-week estimates.

This function standardizes weekly aggregation by:
(1) filtering valid records,
(2) computing day counts for quality control,
(3) applying a user-defined summarization function, and
(4) producing three parallel weekly summaries (whole week, weekday-only,
and weekend-only).
}
\details{
The function uses stratified counting to ensure that weekly estimates are
interpretable in the context of data completeness. The QC rule differs by
strata:
\itemize{
\item Whole week: requires both weekday and weekend minimum counts
\item Weekday/weekend: require minimum counts within their respective subsets
}

The \code{summarize_fn} argument allows flexible reuse across sleep and activity
pipelines while maintaining consistent weekly structure.
}
