Advertisement
Advertisement
| 10.13.2008 at 02:39PM PDT, ID: 23810986 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: |
<?php
//BindEvents Method @1-D40060DD
function BindEvents()
{
global $CCSEvents;
$CCSEvents["BeforeShow"] = "Page_BeforeShow";
}
//End BindEvents Method
//Page_BeforeShow @1-8458E52C
function Page_BeforeShow(& $sender)
{
$Page_BeforeShow = true;
$Component = & $sender;
$Container = & CCGetParentContainer($sender);
global $calculation; //Compatibility
//End Page_BeforeShow
//Custom Code @60-2A29BDB7
// -------------------------
// Write your own code here.
//Start all calculations *********************************************************************
global $sel_cat;
global $weight;
global $sel_ins_cat;
global $pos_tot;
global $mod_check;
$db = new clsDBhockey_stats();
//Delete all records in the report:
$sql= "DELETE from report where user_id = ".CCGetUserID();
$db->query($sql);
//Get the stat_categories that the user has selected
$sql="SELECT lu_stat_categories.category, category_weights.weight FROM category_weights LEFT JOIN lu_stat_categories ON category_weights.stat_category_id = lu_stat_categories.ID
WHERE category_weights.yes_no=1 AND category_weights.user_id=".CCGetUserID();
$db->query($sql);
//Create an array of the user selected categories
while($db->next_record())
{
$sel_cat[]=$db->f("category");//store all cats in an array
$weight[]=$db->f("weight");//Store the weights for the calcs
}
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){
switch ($sel_cat[$i]) {
case "g":
$sel_ins_cat=$sel_cat[$i].",";
break;
case "a":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "p":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "plus_minus":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "pim":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "ppg":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "ppa":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "ppp":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "shg":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "sha":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "shp":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "sog":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "shot_perc":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "gwg":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "fw":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "hits":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "atoi":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
case "f_perc":
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
break;
$sel_ins_cat=$sel_ins_cat.$sel_cat[$i].",";
}
}
$sel_ins_cat = rtrim($sel_ins_cat,",");//Remove the last comma
//Routine Complete *********************************************************************
//Get the positions and total number for each position from league_info
$sql= "select * from league_info where user_id = ".CCGetUserID();
$db->query($sql);
while($db->next_record())
{
$pos_tot[]=$db->f("position")."|".$db->f("total_owned");//store all positions and tot number for each pos in an array
$position[]=$db->f("position");//Store the positions only for later calcs/
}
//Routine Complete *********************************************************************
//Get the annex for the specific group of stats that the user has chosen to complete the View name.
$sql= "select stats_used from league_setup WHERE user_id = ".CCGetUserID();
$db->query($sql);
$Result = $db->next_record();
$annex_used = $db->f("stats_used");
//Break down annex used to see if user-defined cats are being used i.e any _mod views
$mod_check = strrev($annex_used);
if (substr($mod_check,0,3) == "dom") {
$mod_check = true;}
else{
$mod_check = false;
}
//Start the insertion of data into the c_selected_players table.
for ($i=0;$i<=(sizeof($pos_tot)-1);$i++)
{
$pos1 = substr($pos_tot[$i],0,stripos($pos_tot[$i],"|"));//Extract the position from the string
$tot1 = substr($pos_tot[$i],stripos($pos_tot[$i],"|")+1);//Extract the tot number from the string
switch ($pos1) {
case 1://C
if ($mod_check == 1) {
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_c".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;
}
else
{
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_c".$annex_used." LIMIT 0,".$tot1;
}
$db->query($sql);
break;
case 2://LW
if ($mod_check == 1) {
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_lw".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;
}
else
{
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_lw".$annex_used." LIMIT 0,".$tot1;
}
$db->query($sql);
break;
case 3://RW
if ($mod_check == 1) {
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_rw".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;
}
else
{
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_rw".$annex_used." LIMIT 0,".$tot1;
}
$db->query($sql);
break;
case 4://F
if ($mod_check == 1) {
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_f".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;
}
else
{
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_f".$annex_used." LIMIT 0,".$tot1;
}
$db->query($sql);
//Update all the positions to 4.
$sql = "UPDATE c_selected_players SET c_selected_players.position_id = 4 where position_id IN (1,2,3)";
$db->query($sql);
break;
case 5://W
if ($mod_check == 1) {
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_w".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;
}
else
{
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_w".$annex_used." LIMIT 0,".$tot1;
}
$db->query($sql);
//Update all the positions to 5.
$sql = "UPDATE c_selected_players SET c_selected_players.position_id = 4 where position_id IN (2,3)";
$db->query($sql);
break;
case 6://D
if ($mod_check == 1) {
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_d".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;
}
else
{
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_d".$annex_used." LIMIT 0,".$tot1;
}
$db->query($sql);
break;
case 7://Bench
if ($mod_check == 1) {
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_b".$annex_used." WHERE user_id = ".CCGetUserID()." LIMIT 0,".$tot1;
}
else
{
$sql="INSERT INTO c_selected_players (player_id, position_id,".$sel_ins_cat.")
SELECT player_id, position_id,".$sel_ins_cat." FROM 1_b".$annex_used." LIMIT 0,".$tot1;
}
$db->query($sql);
break;
}
}
//Add user_id to the new records where it is NULL.
//Set the user_id
$sql = "UPDATE c_selected_players SET c_selected_players.user_id = " .CCGetUserID()." where user_id IS NULL";
$db->query($sql);
//Routine Complete *********************************************************************
//Create the average and Standard deviation for each position for each category the user has chosen
for ($i=0;$i<=(sizeof($position)-1);$i++)
{
switch ($position[$i]) {
case 1://C
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 1 group by position_id";
$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 1 group by position_id";
$db->query($sql);
break;
case 2://LW
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 2 group by position_id";
$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 2 group by position_id";
$db->query($sql);
break;
case 3://RW
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 3 group by position_id";
$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 3 group by position_id";
$db->query($sql);
break;
case 6://D
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 6 group by position_id";
$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 6 group by position_id";
$db->query($sql);
break;
case 7://Bench
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 7 group by position_id";
$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, position_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, position_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 7 group by position_id";
$db->query($sql);
break;
case 4://F
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 4 group by user_id";
$db->query($sql);
//Update the position ID
$sql = "UPDATE c_avg_at_pos SET c_avg_at_pos.position_id = 4 where position_id IS NULL";
$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 4 group by user_id";
$db->query($sql);
//Update the position ID
$sql = "UPDATE c_std_deviation SET c_std_deviation.position_id = 4 where position_id IS NULL";
$db->query($sql);
break;
case 5://W
//Calc Avg
$sql= "INSERT INTO c_avg_at_pos (user_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, avg(g), avg(a), avg(p), avg(plus_minus), avg(pim), avg(ppg), avg(ppa), avg(ppp), avg(shg), avg(sha), avg(shp), avg(sog), avg(shot_perc), avg(gwg), avg(fw), avg(f_perc), avg(hits), avg(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 5 group by user_id";
$db->query($sql);
//Update the position ID
$sql = "UPDATE c_avg_at_pos SET c_avg_at_pos.position_id = 5 where position_id IS NULL";
$db->query($sql);
//Calc Std Dev
$sql= "INSERT INTO c_std_deviation (user_id, g, a, p, plus_minus, pim, ppg, ppa, ppp, shg, sha, shp, sog, shot_perc, gwg, fw, f_perc, hits, atoi )
SELECT user_id, STDDEV_POP(g), STDDEV_POP(a), STDDEV_POP(p), STDDEV_POP(plus_minus), STDDEV_POP(pim), STDDEV_POP(ppg), STDDEV_POP(ppa), STDDEV_POP(ppp), STDDEV_POP(shg), STDDEV_POP(sha), STDDEV_POP(shp), STDDEV_POP(sog), STDDEV_POP(shot_perc), STDDEV_POP(gwg), STDDEV_POP(fw), STDDEV_POP(f_perc), STDDEV_POP(hits), STDDEV_POP(atoi) FROM c_selected_players WHERE user_id = ".CCGetUserID()." AND position_id = 5 group by user_id";
$db->query($sql);
//Update the position ID
$sql = "UPDATE c_std_deviation SET c_std_deviation.position_id = 5 where position_id IS NULL";
$db->query($sql);
}
}
//Routine Complete *********************************************************************
//Do the actual calculations.
global $avg;
global $std;
global $j;
global $player_stat;
//Start the main loop for Calculations +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$db1 = new clsDBhockey_stats();
//Copy Base data from c_selected_players into the c_values table.
$sql= "INSERT INTO c_values ( user_id, player_id, position_id) SELECT user_id, player_id, position_id FROM c_selected_players where user_id = ".CCGetUserID();
$db->query($sql);
//No start updating tha data in c_values with the calculation results.
$sql= "select * from c_selected_players where user_id = ".CCGetUserID();
$db->query($sql);
while($db->next_record())
{
for ($j=0;$j<=(sizeof($position)-1);$j++){
switch ($position[$j]) {
case 1://C
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 1";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 1";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 1";
$db1->query($sql);
}
}
break;
case 2://LW
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 2";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 2";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 2";
$db1->query($sql);
}
}
break;
case 3://RW
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 3";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 3";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 3";
$db1->query($sql);
}
}
break;
case 4://C,LW,RW
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 4";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 4";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 4";
$db1->query($sql);
}
}
break;
case 5://Lw,RW
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 5";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 5";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 5";
$db1->query($sql);
}
}
break;
case 6://D
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 6";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 6";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 6";
$db1->query($sql);
}
}
break;
case 7://Bench
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){//Loop to do the stat categories
$sql="select * from c_avg_at_pos where user_id = ".CCGetUserID(). " and position_id = 7";//Get the AVG for this position
$db1->query($sql);
$db1->next_record();
$avg=$db1->f($sel_cat[$i]);
$sql="select * from c_std_deviation where user_id = ".CCGetUserID()." and position_id = 7";//Get the STD for this position
$db1->query($sql);
$db1->next_record();
$std=$db1->f($sel_cat[$i]);
$sql="select * from c_selected_players where user_id = ".CCGetUserID()." and player_id = ".$db->f("player_id");//Get the Players Stat
$db1->query($sql);
$db1->next_record();
$player_stat=$db1->f($sel_cat[$i]);
//Update the rows
if ($std>0)//No players for this position
{
$res=(($player_stat - $avg) / $std) * $weight[$i];
$sql= "UPDATE c_values SET ".$sel_cat[$i]."= ".$res. " Where player_id = ".$db->f("player_id")." AND position_id = 7";
$db1->query($sql);
}
}
break;
}//Position
}//loop through categories
}//Loop through c_values
//Calculate the total_value field by removing all NULLS as sql returns NULL if any NULL in columns.
global $cols;
for ($i=0;$i<=(sizeof($sel_cat)-1);$i++){
$cols = $cols."+".$sel_cat[$i];
$cols = ltrim($cols,"+");//Remove the first +
}
$sql= "select * from c_values where user_id = ".CCGetUserID();
$db->query($sql);
while($db->next_record())
{
$sql= "UPDATE c_values SET total_value = ".$cols;
$db1->query($sql);
}
//Routine Complete *********************************************************************
//Save the results
$sql= "INSERT into report (user_id, player_id, position_id, value_calc) SELECT user_id, player_id, position_id, total_value from c_values WHERE user_id = ".CCGetUserID();
$db->query($sql);
//Clean up all the tables:
$sql= "DELETE from c_selected_players where user_id = ".CCGetUserID();
$db->query($sql);
$sql= "DELETE from c_std_deviation where user_id = ".CCGetUserID();
$db->query($sql);
$sql= "DELETE from c_avg_at_pos where user_id = ".CCGetUserID();
$db->query($sql);
$sql= "DELETE from c_values where user_id = ".CCGetUserID();
$db->query($sql);
//Close the connection.
$db->close();
$db1->close();
// -------------------------
global $Redirect;
$Redirect = "calculation_results.php";
//End Custom Code
//Close Page_BeforeShow @1-4BC230CD
return $Page_BeforeShow;
}
//End Close Page_BeforeShow
?>
|