Detecting My Sleeping Hours from Data

Between my Chrome browsing history and my Facebook Messenger message logs, I should be able to get a good estimate of when I’m awake and asleep.

Here’s a quick attempt using only Messenger data.

  (SELECT to_timestamp(timestamp / 1000), (timestamp - lag(timestamp) over (ORDER BY timestamp DESC)) / 1000 / 60 / 60 AS diff_hours
   FROM messenger WHERE = '1409114395' ORDER BY timestamp DESC LIMIT 100000) AS foo
WHERE diff_hours < -6;

Unfortunately, my late night and early morning Messenger usage doesn’t appear to be as consistent as I’d imagined, especially since COVID-19 induced shelter-in-place began. I’ll have to introduce additional sources of data if I want to infer good sleep time estimates.