Created
December 8, 2017 16:14
-
-
Save crova/abc1c854968e827cf02e61330661e66e to your computer and use it in GitHub Desktop.
orate and crate not being calculated
This file contains hidden or 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
| def update | |
| respond_to do |format| | |
| @single_shoot = DbCampaign.find_by_id(params[:id]) | |
| if @single_shoot.update(db_campaign_params) | |
| format.html { redirect_to @single_shoot, notice: 'Campaign was successfully updated.' } | |
| format.json { render :show, status: :ok, location: @single_shoot } | |
| calculate_kpi | |
| else | |
| format.html { render :edit } | |
| format.json { render json: @single_shoot.errors, status: :unprocessable_entity } | |
| end | |
| end | |
| end | |
| def calculate_kpi | |
| @single_shoot = DbCampaign.find_by_id(params[:id]) | |
| turnover = (@single_shoot.payout * @single_shoot.result) | |
| cost = (@single_shoot.sent * @single_shoot.cpm) / 1000 | |
| margin = (@single_shoot.turnover - @single_shoot.cost) | |
| ecpm = ((@single_shoot.turnover / @single_shoot.sent) * 1000) | |
| orate = (@single_shoot.unique_views / @single_shoot.sent) * 100 | |
| crate = (@single_shoot.clicker / @single_shoot.sent) * 100 | |
| @single_shoot.update_column(:turnover, turnover) | |
| @single_shoot.update_column(:cost, cost) | |
| @single_shoot.update_column(:margin, margin) | |
| @single_shoot.update_column(:ecpm, ecpm) | |
| @single_shoot.update_column(:orate, orate) | |
| @single_shoot.update_column(:crate, crate) | |
| end | |
| def db_campaign_params | |
| params.fetch(:db_campaign, {}).permit(:id, :campaign_id, :name, :payout, :ecpm, :turnover, :cost, :margin, :result, :roi, :segment, :deal, :partner, :cpm, :sender, :gender, :scenario, :theme, :orate, :crate) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment