Guest User

Untitled

a guest
Jan 23rd, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. function doOrderCalculations(){
  2.  
  3. $.blockUI({message:"<h2>Calculating Programs...</h2>"}); // overlay to block input
  4. var temp = ""; // temp variable for various algorithms
  5. var totalCount = 0;
  6. var totalAvails = $("#order-stations").find(".program").length;
  7.  
  8. var offset = <? echo $weeks.";\r\n"; ?>
  9. <? for($a = 0;$a< $weeks;$a++){?>var week<? echo $a+6;?> = 0; // week <? echo $a+1; ?><? } ?>
  10. var totalweek = 0;
  11.  
  12. /**** loop through each station ****/
  13. $("#order-stations").find(".station").each(function(){
  14. var station = $(this).attr("id");
  15. /**** then loop through each program for the station ****/
  16. $("#order-stations").find("."+station).each(function(){
  17. var viewers = $(this).find("td:eq(0)>.demo").val(); // get number of views from demo
  18. var rtg = $(this).find(".rating").text()*1; //get rating value
  19. var unitprice = $(this).find(".units").text() * 1; // get unit price
  20.  
  21. /**** Obtain Ads per week ****/
  22. totalweek = 0;
  23. var unitx = 0;
  24. $(this).find("td").each(function(){
  25. var clss = $(this).attr("class");
  26. if(clss.match(/week/)){ // recurse week cells - qty of ads
  27. totalweek += $(this).html() * 1; //increment number of weeks
  28. temp = $(this).attr("class").replace(/programCell /,"");
  29. if ($(this).html() * 1 == 0){
  30. $(this).html("0"); // if is empty. make it 0
  31. }
  32. }
  33. });
  34.  
  35. /**** Target Population ****/
  36. targetPop = $(this).find("td:eq(0)>.pop").val() * 1;
  37. if(viewers == 0 || viewers == "undefined"){
  38. viewers = rtg / 100 * targetPop;
  39. }
  40. /**** Calculate Reach and Frequency :: function reachCalc(weeks,rating) ****/
  41. var data = reachCalc(totalweek,rtg);
  42. var rf = data.split("&");
  43. $(this).find(".rch").html(rf[0]); // display reach
  44. $(this).find(".freq").html(rf[1]); // display frequency
  45.  
  46. /**** GI ****/
  47. gi = totalweek * viewers;
  48. gi = gi.toFixed(1);
  49. $(this).find(".gi").html(gi); //display GI
  50.  
  51. /**** CPP ****/
  52. var cpp = unitprice / rtg; // calculate CPP
  53. cpp = cpp.toFixed(2);
  54. $(this).find(".cpp").html(cpp); // display CPP
  55.  
  56. /**** Total $ ****/
  57. var totd = totalweek * unitprice;
  58. totd = totd.toFixed(2);
  59. $(this).find(".totd").html(totd); // display total $
  60.  
  61. /**** Total Spots****/
  62. $(this).find(".tots").html(totalweek); // display total spots
  63.  
  64. /**** GRP ****/
  65. var grp = totalweek * rtg;
  66. grp = grp.toFixed(1);
  67. $(this).find(".grp").html(grp); // display GRP
  68. });
  69. });
  70. doOrderCalculationsTotals();
  71. }
  72.  
  73. function reachCalc(numAds,rating){
  74. var GRP = rating * numAds;
  75. var freq = (0.1909 * numAds ) + 0.8091;
  76. if(freq > 0){
  77. var rch = GRP / freq;
  78. } else {
  79. var rch = 0;
  80. }
  81. rch = rch.toFixed(2);
  82. freq = freq.toFixed(2)
  83. return rch.toString()+"&"+freq.toString();
  84. }
Add Comment
Please, Sign In to add comment