def METHOD_NAME(engine, summary_date):
    PACKAGE_URL = u'/dataset/'
    # clear out existing data before adding new
    sql = u'''DELETE FROM tracking_summary
                WHERE tracking_date='%s'; ''' % summary_date
    engine.execute(sql)
    sql = u'''SELECT DISTINCT url, user_key,
                    CAST(access_timestamp AS Date) AS tracking_date,
                    tracking_type INTO tracking_tmp
                FROM tracking_raw
                WHERE CAST(access_timestamp as Date)=%s;
                INSERT INTO tracking_summary
                (url, count, tracking_date, tracking_type)
                SELECT url, count(user_key), tracking_date, tracking_type
                FROM tracking_tmp
                GROUP BY url, tracking_date, tracking_type;
                DROP TABLE tracking_tmp;
                COMMIT;'''
    engine.execute(sql, summary_date)
    # get ids for dataset urls
    sql = u'''UPDATE tracking_summary t
                SET package_id = COALESCE(
                    (SELECT id FROM package p
                    WHERE p.name = regexp_replace
                      (' ' || t.url, '^[ ]{1}(/\\w{2}){0,1}' || %s, ''))
                    ,'~~not~found~~')
                WHERE t.package_id IS NULL
                AND tracking_type = 'page';'''
    engine.execute(sql, PACKAGE_URL)
    # update summary totals for resources
    sql = u'''UPDATE tracking_summary t1
                SET running_total = (
                SELECT sum(count)
                FROM tracking_summary t2
                WHERE t1.url = t2.url
                AND t2.tracking_date <= t1.tracking_date
                )
                ,recent_views = (
                SELECT sum(count)
                FROM tracking_summary t2
                WHERE t1.url = t2.url
                AND t2.tracking_date <= t1.tracking_date
                AND t2.tracking_date >= t1.tracking_date - 14
                )
                WHERE t1.running_total = 0 AND tracking_type = 'resource';'''
    engine.execute(sql)
    # update summary totals for pages
    sql = u'''UPDATE tracking_summary t1
                SET running_total = (
                SELECT sum(count)
                FROM tracking_summary t2
                WHERE t1.package_id = t2.package_id
                AND t2.tracking_date <= t1.tracking_date
                )
                ,recent_views = (
                SELECT sum(count)
                FROM tracking_summary t2
                WHERE t1.package_id = t2.package_id
                AND t2.tracking_date <= t1.tracking_date
                AND t2.tracking_date >= t1.tracking_date - 14
                )
                WHERE t1.running_total = 0 AND tracking_type = 'page'
                AND t1.package_id IS NOT NULL
                AND t1.package_id != '~~not~found~~';'''
    engine.execute(sql)