def retrieve_campaign_rollups(): return run_safe_dict_query( connections['reporting'].cursor(), """ SELECT campaignrollups.campaign_id as root_id, campaigns.name, max(latest_activity) as latest_activity, min(first_activity) as first_activity, {} FROM campaignrollups JOIN campaigns using (campaign_id) JOIN ( select campaign_id, to_char(max(hour), 'YYYY-MM-DD') as latest_activity, to_char(min(hour), 'YYYY-MM-DD') as first_activity from campaignhourly group by campaign_id ) as timelookup using (campaign_id) WHERE campaigns.client_id = %s GROUP BY campaignrollups.campaign_id, campaigns.name ORDER BY campaignrollups.campaign_id desc """.format(metric_where_fragment()), (client.client_id,) )
def retrieve_client_rollups(): return run_safe_dict_query( connections['reporting'].cursor(), """ SELECT {} FROM clientrollups WHERE client_id = %s """.format(metric_where_fragment()), (client.client_id,) )
def retrieve_campaign_hourly(): return run_safe_dict_query( cursor, query, (campaign_pk,) )