Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function doOrderCalculations(){
- $.blockUI({message:"<h2>Calculating Programs...</h2>"}); // overlay to block input
- var temp = ""; // temp variable for various algorithms
- var totalCount = 0;
- var totalAvails = $("#order-stations").find(".program").length;
- var offset = <? echo $weeks.";\r\n"; ?>
- <? for($a = 0;$a< $weeks;$a++){?>var week<? echo $a+6;?> = 0; // week <? echo $a+1; ?><? } ?>
- var totalweek = 0;
- /**** loop through each station ****/
- $("#order-stations").find(".station").each(function(){
- var station = $(this).attr("id");
- /**** then loop through each program for the station ****/
- $("#order-stations").find("."+station).each(function(){
- var viewers = $(this).find("td:eq(0)>.demo").val(); // get number of views from demo
- var rtg = $(this).find(".rating").text()*1; //get rating value
- var unitprice = $(this).find(".units").text() * 1; // get unit price
- /**** Obtain Ads per week ****/
- totalweek = 0;
- var unitx = 0;
- $(this).find("td").each(function(){
- var clss = $(this).attr("class");
- if(clss.match(/week/)){ // recurse week cells - qty of ads
- totalweek += $(this).html() * 1; //increment number of weeks
- temp = $(this).attr("class").replace(/programCell /,"");
- if ($(this).html() * 1 == 0){
- $(this).html("0"); // if is empty. make it 0
- }
- }
- });
- /**** Target Population ****/
- targetPop = $(this).find("td:eq(0)>.pop").val() * 1;
- if(viewers == 0 || viewers == "undefined"){
- viewers = rtg / 100 * targetPop;
- }
- /**** Calculate Reach and Frequency :: function reachCalc(weeks,rating) ****/
- var data = reachCalc(totalweek,rtg);
- var rf = data.split("&");
- $(this).find(".rch").html(rf[0]); // display reach
- $(this).find(".freq").html(rf[1]); // display frequency
- /**** GI ****/
- gi = totalweek * viewers;
- gi = gi.toFixed(1);
- $(this).find(".gi").html(gi); //display GI
- /**** CPP ****/
- var cpp = unitprice / rtg; // calculate CPP
- cpp = cpp.toFixed(2);
- $(this).find(".cpp").html(cpp); // display CPP
- /**** Total $ ****/
- var totd = totalweek * unitprice;
- totd = totd.toFixed(2);
- $(this).find(".totd").html(totd); // display total $
- /**** Total Spots****/
- $(this).find(".tots").html(totalweek); // display total spots
- /**** GRP ****/
- var grp = totalweek * rtg;
- grp = grp.toFixed(1);
- $(this).find(".grp").html(grp); // display GRP
- });
- });
- doOrderCalculationsTotals();
- }
- function reachCalc(numAds,rating){
- var GRP = rating * numAds;
- var freq = (0.1909 * numAds ) + 0.8091;
- if(freq > 0){
- var rch = GRP / freq;
- } else {
- var rch = 0;
- }
- rch = rch.toFixed(2);
- freq = freq.toFixed(2)
- return rch.toString()+"&"+freq.toString();
- }
Add Comment
Please, Sign In to add comment