code: def top_pages_by_time_period(self, interval='day'):
          
          date_trunc = fn.date_trunc(interval, PageView.timestamp)
          return (self.get_query()
                  .select(
                      PageView.url,
                      date_trunc.alias(interval),
                      fn.Count(PageView.id).alias('count'))
                  .group_by(PageView.url, date_trunc)
                  .order_by(
                      SQL(interval),
                      SQL('count').desc(),
                      PageView.url))
docs: Get a breakdown of top pages per interval, i.e.
  
          day         url     count
          2014-01-01  /blog/  11
          2014-01-02  /blog/  14
          2014-01-03  /blog/  9