TryGhost/Ghost

View on GitHub
ghost/tinybird/pipes/trend.pipe

Summary

Maintainability
Test Coverage

DESCRIPTION >
    Visits trend over time for the last 30 minutes, filling the blanks.
    Works great for the realtime chart.

TOKEN "dashboard" READ
TOKEN "stats page" READ

NODE timeseries
DESCRIPTION >
    Generate a timeseries for the last 30 minutes, so we call fill empty data points

SQL >
    with (now() - interval 30 minute) as start
    select addMinutes(toStartOfMinute(start), number) as t
    from (select arrayJoin(range(1, 31)) as number)

NODE visits
DESCRIPTION >
    Get last 30 minutes metrics gropued by minute

SQL >
    %
    select toStartOfMinute(timestamp) as t, uniq(session_id) as visits
    from analytics_hits
    where
        site_uuid = {{String(site_uuid, 'mock_site_uuid', description="Tenant ID", required=True)}}
         {% if defined(member_status) %}
            and member_status IN {{ Array(member_status,'String') }}
        {% end %}
        and timestamp >= (now() - interval 30 minute)
    group by toStartOfMinute(timestamp)
    order by toStartOfMinute(timestamp)

NODE endpoint
DESCRIPTION >
    Join and generate timeseries with metrics for the last 30 minutes

SQL >
    select a.t, b.visits from timeseries a left join visits b on a.t = b.t order by a.t