(project_id, incremental:bool=True, cursor=None)
Add review summary information to the summary table. Create hourly
    aggregates in UTC time. These aggregates can still be moved in other
    timezones with good enough precision for our purpose. By default, this
    happens in an incremental manner, but can optionally be fone for all data
    from scratch (overriding existing statistics).
Add review summary information to the summary table. Create hourly
    aggregates in UTC time. These aggregates can still be moved in other
    timezones with good enough precision for our purpose. By default, this
    happens in an incremental manner, but can optionally be fone for all data
    from scratch (overriding existing statistics).
Add review summary information to the summary table . Create hourly aggregates in UTC time . These aggregates can still be moved in other timezones with good enough precision for our purpose . By default this happens in an incremental manner but can optionally be fone for all data from scratch ( overriding existing statistics ) .
def populate_review_stats_summary(project_id, incremental:bool=True, cursor=None) -> None:
    """Add review summary information to the summary table. Create hourly
    aggregates in UTC time. These aggregates can still be moved in other
    timezones with good enough precision for our purpose. By default, this
    happens in an incremental manner, but can optionally be fone for all data
    from scratch (overriding existing statistics).
    """
    if not cursor:
        cursor = connection.cursor()

    # Add reviewer info
    cursor.execute("""
        WITH last_precomputation AS (
            SELECT CASE WHEN %(incremental)s = FALSE THEN '-infinity'
                ELSE COALESCE(date_trunc('hour', MAX(date)) - interval '1 hour',
                    '-infinity') END AS max_date
            FROM catmaid_stats_summary
            WHERE project_id=%(project_id)s
                AND n_reviewed_nodes > 0
        ),
        review_info AS (
            SELECT r.reviewer_id AS user_id,
                date_trunc('hour', r.review_time) AS date,
                count(*) AS n_reviewed_nodes
            FROM review r, last_precomputation
            WHERE r.project_id = %(project_id)s
            AND r.review_time > last_precomputation.max_date
            AND r.review_time < date_trunc('hour', CURRENT_TIMESTAMP)
            GROUP BY r.reviewer_id, date
        )
        INSERT INTO catmaid_stats_summary (project_id, user_id, date,
                n_reviewed_nodes)
        SELECT %(project_id)s, ri.user_id, ri.date, ri.n_reviewed_nodes
        FROM review_info ri
        ON CONFLICT (project_id, user_id, date) DO UPDATE
        SET n_reviewed_nodes = EXCLUDED.n_reviewed_nodes;
    """, dict(project_id=project_id, incremental=incremental))
def populate_review_stats_summary ( project_id , incremental : bool = True , cursor = None ) -> None : if not cursor : cursor = connection . cursor ( ) # Add reviewer info cursor . execute ( """
        WITH last_precomputation AS (
            SELECT CASE WHEN %(incremental)s = FALSE THEN '-infinity'
                ELSE COALESCE(date_trunc('hour', MAX(date)) - interval '1 hour',
                    '-infinity') END AS max_date
            FROM catmaid_stats_summary
            WHERE project_id=%(project_id)s
                AND n_reviewed_nodes > 0
        ),
        review_info AS (
            SELECT r.reviewer_id AS user_id,
                date_trunc('hour', r.review_time) AS date,
                count(*) AS n_reviewed_nodes
            FROM review r, last_precomputation
            WHERE r.project_id = %(project_id)s
            AND r.review_time > last_precomputation.max_date
            AND r.review_time < date_trunc('hour', CURRENT_TIMESTAMP)
            GROUP BY r.reviewer_id, date
        )
        INSERT INTO catmaid_stats_summary (project_id, user_id, date,
                n_reviewed_nodes)
        SELECT %(project_id)s, ri.user_id, ri.date, ri.n_reviewed_nodes
        FROM review_info ri
        ON CONFLICT (project_id, user_id, date) DO UPDATE
        SET n_reviewed_nodes = EXCLUDED.n_reviewed_nodes;
    """ , dict ( project_id = project_id , incremental = incremental ) )