Created
April 20, 2010 19:06
-
-
Save jeremyevans/372907 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Metrics | |
def self.by_day(uid) | |
DB.synchronize do | |
DB.run "SET search_path TO rpt, dx" | |
return "The UUID is not valid, please try again." unless cid = DB[:dx_campaign].where(:object_uid => uid).get(:campaign_id) | |
DB["SELECT r.created_dt as \"date\", sum(clicks) as \"clicks\", sum(impressions) as \"impressions\", sum(actions) as \"actions\", sum(spend)/1000000 as \"spend\", sum(spend)/1000000 / sum(actions) as CPA FROM rpt.rpt_exchange_daily r WHERE campaign_id = #{cid} GROUP BY r.created_dt order by r.created_dt"].all | |
end | |
end | |
end | |
class CampaignsController < ApplicationController | |
def metrics_by_day | |
respond_to do |format| | |
format.json { render :json => Metrics.by_day(params[:uid]) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment