Skip to main content
Macros are precomputed fields available in the Junction Sense DSL. Use them anywhere you would use a regular column expression. Reference a macro with the value_macro expression:

Available Sleep Macros

You can combine multiple sleep macros in a single query and mix them with standard aggregations or other select expressions.

Example query

Chronotype

Determine the chronotype of each sleep session. Chronotype categories are based on the sleep midpoint time:
  • lark if midpoint ≥ 17:00 or ≤ 03:30
  • third if midpoint ≤ 06:00
  • owl otherwise

Get last chronotype of the week

Sleep Score

Calculate a Sleep Score (0 to 100) for each sleep session.

Get mean sleep score of the week

Awake At / Asleep At

Pinpoint when a user first fell asleep and when they became fully awake during each sleep session. The asleep_at macro returns the bedtime start adjusted by the recorded sleep latency, while awake_at returns the bedtime start plus the offset of the final non-awake sleep segment.

Get mean asleep at and awake at of the week

Awakenings

Count the number of times a user transitioned from a sleeping phase (deep, light, or REM) to an awake phase during a sleep session. This is computed from sleep cycle hypnogram data.

Get average nightly awakenings per week