Parse what is actually present
Locate the statistics section of wearable CSV exports rather than assuming a fixed header position. Standardize identifiers and date fields.
CASE STUDY 02 / DATA ENGINEERING
Making wearable exports, sleep logs, and flight records agree on who, when, and which trip.
How can heterogeneous sleep records be converted into comparable trip-level features without losing timing context?
The data preparation work combines actigraphy exports, sleep logbooks, and flight records. Cross-midnight episodes, time zones, repeated trips, and inconsistent export headers make naive joins unreliable.
THE STORY IN PLAIN LANGUAGE
A sleep episode may cross midnight, belong to one of several trips, or only partly overlap an analysis window. Resolving those cases produces reusable features for downstream models—and demonstrates the engineering needed to turn research files into an analytical dataset.
The stack follows the analytical task: prepare the data, fit or apply the method, check the result, and communicate the output.
See how the libraries connect to the wider portfolio →THE PROJECT, STEP BY STEP
Locate the statistics section of wearable CSV exports rather than assuming a fixed header position. Standardize identifiers and date fields.
Match episodes using participant, route, and outbound-date context. Normalize timestamps before calculating overlap with flight-relative windows.
Calculate 24-, 48-, and 72-hour sleep summaries. Distinguish time in bed from estimated sleep time where wake-after-sleep-onset data is available.
THE TECHNICAL CASE
The analysis depends on a shared time axis. The difficult work is preserving the identity of a participant and trip while reconciling sleep episodes that cross midnight, time zones, and flight-relative windows.
The processing code locates the statistics section inside actigraphy exports instead of assuming one fixed header row. This is a practical defense against changes in export structure, but malformed files still require explicit handling and review.
Participant identifiers alone are insufficient when someone contributes several trips. Route and outbound-date context help associate an episode with the correct trip. Matching logic should distinguish no match, one match, and multiple candidates before aggregation.
Date parsing and time-zone interpretation precede duration calculations. A cross-midnight episode is an interval, not a negative clock-time difference. Flight-relative windows make the feature definition comparable across routes.
Time spent in a sleep episode or in bed is distinct from estimated total sleep time. The TST workflow incorporates wake after sleep onset where available and retains verification variants for comparison.
overlap = max(0, min(episode end, window end) − max(episode start, window start))
When total episode sleep is allocated in proportion to overlap, the estimate assumes sleep is distributed uniformly within the episode. It cannot recover minute-by-minute sleep states.
EXPLORE THE METHOD
Synthetic episodes show interval overlap and proportional allocation. Change the window to see which episodes contribute to the derived feature.
QUALITY OF THE EVIDENCE
Check an episode fully outside, fully inside, or partly overlapping a window, including equality at a boundary.
Reconcile unique trip keys before and after joins; review duplicated matches instead of silently summing them.
Review negative durations, implausibly long episodes, and sleep totals exceeding the available observation window.
Investigate missing windows and unexpected decreases between nested 24-, 48-, and 72-hour summaries.
FOR THE TECHNICAL CONVERSATION
A useful technical discussion is how to distinguish missing sleep data from zero sleep, test daylight-saving transitions, and quantify uncertainty introduced by proportional allocation.
WHAT IT DEMONSTRATES
The output is an analysis-ready set of trip-level sleep measures for downstream recovery and fatigue research.