ALL PLAY REPORT by Habman

Description:
This script details the All Play matchups in two table forms.

The first table summarizes the All Play record by week while the second table details the All Play record between two franchises.

Examples:
Click the All Play Report button on the following linked page:

    Sample Report
Implementation:
<style>

#habmanAllPlay {text-align:center}

#habmanAllPlay caption{display:table-caption!important;white-space:nowrap}

#habmanAllPlay_populating { font-style:italic; }

#habmanAllPlay_tableLegend {width:auto}

.habmanAllPlay_franchise {white-space:nowrap}

.habmanAllPlay_img {height:24px; width:auto; max-width:50px}

.habmanAllPlay_total {text-align:center}

.habmanAllPlay_week {text-align:center}

.habmanAllPlay_ptsScored {display:block;font-size:smaller}

.habmanAllPlay_record {display:block;white-space:nowrap}

.habmanAllPlay_record_total {display:block;font-weight:bold;white-space:nowrap}

.habmanAllPlay_hilite {background-color:khaki!important}

</style>
<div id="habmanAllPlay"></div>

<script>

//CUSTOM SETTINGS

var habmanAllPlay_weeks = 13; //weeks to include

var habmanAllPlay_precision = 1; //decimal places

var habmanAllPlay_buttonText = "All Play Report";



//LIST YOUR TEAM IDS THAT ARE TO BE INCLUDED; IF EMPTY THEN ALL FRANCHISES WILL BE INCLUDED

var habmanAllPlay_fid = new Array();



///////////////////////////////////////////////

//NO NEED TO EDIT BELOW THIS LINE

///////////////////////////////////////////////

if(habmanAllPlay_weeks==undefined) var habmanAllPlay_weeks = 13;

if(habmanAllPlay_precision==undefined) var habmanAllPlay_precision = 1;

if(habmanAllPlay_buttonText==undefined) var habmanAllPlay_buttonText = "All Play Report";

if(habmanAllPlay_fid==undefined) var habmanAllPlay_fid = new Array();



var habmanAllPlay_scoreAdjustment = new Array();

var habmanAllPlay_results = new Array();

var habmanAllPlay_resultsHTH = new Array();

var habmanAllPlay_scoreAdjustmentKey = new Array();

var habmanAllPlay_scoreAdjustmentHTML = '';

function habmanAllPlay_hilite(remove,rowFid,colFid){

	if(remove)

		$(".allPlayHilite").removeClass("habmanAllPlay_hilite");

	else {

		$(".allPlayHilite_row_"+rowFid).addClass("habmanAllPlay_hilite");

		$(".allPlayHilite_col_"+colFid).addClass("habmanAllPlay_hilite");

	}

}

function habmanAllPlay_doScoreAdjustmentKey(){

	var rowCount=0;

	var weekCount=-1;

	for (var i=0;i<habmanAllPlay_scoreAdjustment.length;i++){

		habmanAllPlay_scoreAdjustmentKey[habmanAllPlay_scoreAdjustment[i][0]+"_"+habmanAllPlay_scoreAdjustment[i][1]] = habmanAllPlay_scoreAdjustment[i][2];

		if(weekCount!=-1 && weekCount!=habmanAllPlay_scoreAdjustment[i][1])

			habmanAllPlay_scoreAdjustmentHTML=habmanAllPlay_scoreAdjustmentHTML.substring(0,habmanAllPlay_scoreAdjustmentHTML.length-2)+'</td></tr>';

		if(weekCount!=habmanAllPlay_scoreAdjustment[i][1]) {

			weekCount = habmanAllPlay_scoreAdjustment[i][1];

			if(rowCount%2)

				habmanAllPlay_scoreAdjustmentHTML+='<tr class="eventablerow"><td style="text-align:center">'+weekCount+'</td><td>';

			else

				habmanAllPlay_scoreAdjustmentHTML+='<tr class="oddtablerow"><td style="text-align:center">'+weekCount+'</td><td>';

			rowCount++;

		}

		habmanAllPlay_scoreAdjustmentHTML+= franchiseDatabase["fid_"+habmanAllPlay_scoreAdjustment[i][0]].name+' ('+habmanAllPlay_scoreAdjustment[i][2]+'), ';

		if(i==(habmanAllPlay_scoreAdjustment.length-1))

			habmanAllPlay_scoreAdjustmentHTML=habmanAllPlay_scoreAdjustmentHTML.substring(0,habmanAllPlay_scoreAdjustmentHTML.length-2)+'</td></tr>';

	}

	if(habmanAllPlay_scoreAdjustmentHTML!='')

		habmanAllPlay_scoreAdjustmentHTML='<br><br><div class="mobile-wrap" style="display:inline-block;float:left"><table align="center" cellspacing="1" class="homepagemodule report" id="habmanAllPlay_tableLegend"><caption><span>All Play Score Adjustments</span></caption><tr><th>Week #</th><th>Adjustment(s)</th></tr>'+habmanAllPlay_scoreAdjustmentHTML+'</table></div>';

}

function habmanAllPlay_createHTML(){

	var html='';

	html+='<br><div class="mobile-wrap">';

	html+='<table align="center" cellspacing="1" class="homepagemodule report" id="habmanAllPlay_table"><caption><span>'+habmanAllPlay_buttonText+'</span></caption>';

	html+='<tr><th rowspan="2">Franchise</th><th rowspan="2">Season</th><th colspan="'+habmanAllPlay_weeks+'">Week #</th></tr>';

	html+='<tr>';

	for(var i=1;i<=habmanAllPlay_weeks;i++) html+='<th>'+i+'</th>';

	html+='</tr>';

	for(var i=0;i<habmanAllPlay_fid.length;i++){

		if(i%2)

			html+='<tr class="eventablerow">';

		else

			html+='<tr class="oddtablerow">';

		if(franchiseDatabase["fid_"+habmanAllPlay_fid[i]].icon!=undefined&&franchiseDatabase["fid_"+habmanAllPlay_fid[i]].icon!='') 

			var fIcon = '<img src="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].icon+'" title="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].name+'" class="habmanAllPlay_img" /> ';

		else if(franchiseDatabase["fid_"+habmanAllPlay_fid[i]].logo!=undefined&&franchiseDatabase["fid_"+habmanAllPlay_fid[i]].logo!='') 

			var fIcon = '<img src="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].logo+'" title="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].name+'" class="habmanAllPlay_img" /> ';

		else 

			var fIcon = '';

		var fName = '<a class="franchise_'+habmanAllPlay_fid[i]+'" href="'+baseURLDynamic+'/'+year+'/options?L='+league_id+'&F='+habmanAllPlay_fid[i]+'&O=01">'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].name+'</a>';

		

		html+='<td class="franchise_'+habmanAllPlay_fid[i]+' habmanAllPlay_franchise">'+fIcon+fName+'</td>';

		html+='<td class="habmanAllPlay_total"><span class="habmanAllPlay_record_total">'+habmanAllPlay_results[habmanAllPlay_fid[i]][0].totalWin+'-'+habmanAllPlay_results[habmanAllPlay_fid[i]][0].totalLoss+'-'+habmanAllPlay_results[habmanAllPlay_fid[i]][0].totalTie+'</span><span class="habmanAllPlay_ptsScored" title="Total Points Scored">('+habmanAllPlay_results[habmanAllPlay_fid[i]][0].totalScore.toFixed(habmanAllPlay_precision)+')</span></td>';

		if(completedWeek>habmanAllPlay_weeks) var toWeek = habmanAllPlay_weeks; else var toWeek = completedWeek;

		for(var j=1;j<=toWeek;j++) {

			html+='<td class="habmanAllPlay_week"><span class="habmanAllPlay_record">'+habmanAllPlay_results[habmanAllPlay_fid[i]][j].win+'-'+habmanAllPlay_results[habmanAllPlay_fid[i]][j].loss+'-'+habmanAllPlay_results[habmanAllPlay_fid[i]][j].tie+'</span><span class="habmanAllPlay_ptsScored" title="Weekly Points Scored">('+habmanAllPlay_results[habmanAllPlay_fid[i]][j].score.toFixed(habmanAllPlay_precision)+')</span></td>';

		}

		for(var j=completedWeek+1;j<=habmanAllPlay_weeks;j++) {

			html+='<td class="habmanAllPlay_week"></td>';

		}

		html+='</tr>';

	}

	html+='</table>';

	html+='</div>';

	html+='<br>';

	html+='<div class="mobile-wrap">';

	html+='<table align="center" cellspacing="1" class="homepagemodule report" id="habmanAllPlay_tableHTH"><caption><span>Head-to-Head '+habmanAllPlay_buttonText+'</span></caption>';

	html+='<tr><th rowspan="2">Franchise</th><th rowspan="2">Season</th><th colspan="'+habmanAllPlay_fid.length+'">Opponent</th></tr>';

	html+='<tr>';

	var fidStr = new Array();

	for(var i=0;i<habmanAllPlay_fid.length;i++) {

		fidStr[i] = '';

		if(franchiseDatabase["fid_"+habmanAllPlay_fid[i]].icon!=undefined&&franchiseDatabase["fid_"+habmanAllPlay_fid[i]].icon!='')

			var fIcon = '<img src="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].icon+'" title="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].name+'" class="habmanAllPlay_img" />';

		else if(franchiseDatabase["fid_"+habmanAllPlay_fid[i]].logo!=undefined&&franchiseDatabase["fid_"+habmanAllPlay_fid[i]].logo!='')

			var fIcon = '<img src="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].logo+'" title="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].name+'" class="habmanAllPlay_img" />';	

		else if(franchiseDatabase["fid_"+habmanAllPlay_fid[i]].abbrev!=undefined&&franchiseDatabase["fid_"+habmanAllPlay_fid[i]].abbrev!='')

			var fIcon = '<span title="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].name+'">'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].abbrev+'</span>';

		else {

			var fIcon = '<span title="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].name+'">'+habmanAllPlay_fid[i]+'</span>';

			fidStr[i] = ' ('+habmanAllPlay_fid[i]+')';

		}

		html+='<th class="allPlayHilite allPlayHilite_col_'+habmanAllPlay_fid[i]+'">'+fIcon+'</th>';

	}

	html+='</tr>';

	for(var i=0;i<habmanAllPlay_fid.length;i++){

		if(i%2)

			html+='<tr class="eventablerow allPlayHilite allPlayHilite_row_'+habmanAllPlay_fid[i]+'">';

		else

			html+='<tr class="oddtablerow allPlayHilite allPlayHilite_row_'+habmanAllPlay_fid[i]+'">';

			

		if(franchiseDatabase["fid_"+habmanAllPlay_fid[i]].icon!=undefined&&franchiseDatabase["fid_"+habmanAllPlay_fid[i]].icon!='')	

			var fIcon = '<img src="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].icon+'" title="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].name+'" class="habmanAllPlay_img" /> ';

		else if(franchiseDatabase["fid_"+habmanAllPlay_fid[i]].logo!=undefined&&franchiseDatabase["fid_"+habmanAllPlay_fid[i]].logo!='')	

			var fIcon = '<img src="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].logo+'" title="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].name+'" class="habmanAllPlay_img" /> ';

		else 

			var fIcon = '';

		var fName = '<a class="franchise_'+habmanAllPlay_fid[i]+'" href="'+baseURLDynamic+'/'+year+'/options?L='+league_id+'&F='+habmanAllPlay_fid[i]+'&O=01">'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].name+'</a>';

		

		html+='<td class="franchise_'+habmanAllPlay_fid[i]+' habmanAllPlay_franchise">'+fIcon+fName+fidStr[i]+'</td>';

		html+='<td class="habmanAllPlay_total"><span class="habmanAllPlay_record_total">'+habmanAllPlay_results[habmanAllPlay_fid[i]][0].totalWin+'-'+habmanAllPlay_results[habmanAllPlay_fid[i]][0].totalLoss+'-'+habmanAllPlay_results[habmanAllPlay_fid[i]][0].totalTie+'</span></td>';

		for(var j=0;j<habmanAllPlay_fid.length;j++){

			if(i==j)

				html+='<td class="habmanAllPlay_week habmanAllPlay_na allPlayHilite allPlayHilite_col_'+habmanAllPlay_fid[j]+'" onmouseover="habmanAllPlay_hilite(false,\''+habmanAllPlay_fid[i]+'\',\''+habmanAllPlay_fid[j]+'\')" onmouseout="habmanAllPlay_hilite(true)">X</td>';

			else

				html+='<td class="habmanAllPlay_week allPlayHilite allPlayHilite_col_'+habmanAllPlay_fid[j]+'" onmouseover="habmanAllPlay_hilite(false,\''+habmanAllPlay_fid[i]+'\',\''+habmanAllPlay_fid[j]+'\')" onmouseout="habmanAllPlay_hilite(true)"><span class="habmanAllPlay_record" title="'+franchiseDatabase["fid_"+habmanAllPlay_fid[i]].name+' vs '+franchiseDatabase["fid_"+habmanAllPlay_fid[j]].name+'">'+habmanAllPlay_resultsHTH[habmanAllPlay_fid[i]+"_"+habmanAllPlay_fid[j]].win+'-'+habmanAllPlay_resultsHTH[habmanAllPlay_fid[i]+"_"+habmanAllPlay_fid[j]].loss+'-'+habmanAllPlay_resultsHTH[habmanAllPlay_fid[i]+"_"+habmanAllPlay_fid[j]].tie+'</span></td>';

		}

		html+='</tr>';

	}

	html+='</table>';

	html+='</div>';

	

	$("#habmanAllPlay").html(html+habmanAllPlay_scoreAdjustmentHTML);

}

function habmanAllPlay_week(week,_results){

	var results = _results;

	for (var i=0;i<habmanAllPlay_fid.length;i++){

		if(habmanAllPlay_scoreAdjustmentKey[habmanAllPlay_fid[i]+"_"+week]!==undefined)

			results[habmanAllPlay_fid[i]][week-1]+=habmanAllPlay_scoreAdjustmentKey[habmanAllPlay_fid[i]+"_"+week];

	}

	for (var i=0;i<habmanAllPlay_fid.length;i++){

		if(habmanAllPlay_results[habmanAllPlay_fid[i]]==undefined) habmanAllPlay_results[habmanAllPlay_fid[i]] = new Array();

		if(habmanAllPlay_results[habmanAllPlay_fid[i]].length==0) habmanAllPlay_results[habmanAllPlay_fid[i]][0] = ({ "totalScore":0 , "totalWin":0 , "totalLoss":0 , "totalTie":0 });

		if(habmanAllPlay_results[habmanAllPlay_fid[i]][week]==undefined) habmanAllPlay_results[habmanAllPlay_fid[i]][week] = ({ "score":0 , "win":0 , "loss":0 , "tie":0 });

		

		habmanAllPlay_results[habmanAllPlay_fid[i]][0].totalScore += results[habmanAllPlay_fid[i]][week-1];

		habmanAllPlay_results[habmanAllPlay_fid[i]][week].score = results[habmanAllPlay_fid[i]][week-1];

		for (var j=0;j<habmanAllPlay_fid.length;j++){

			if(i==j) continue;

			if( results[habmanAllPlay_fid[i]][week-1] > results[habmanAllPlay_fid[j]][week-1] ) {

				habmanAllPlay_results[habmanAllPlay_fid[i]][0].totalWin++;

				habmanAllPlay_results[habmanAllPlay_fid[i]][week].win++;

				habmanAllPlay_resultsHTH[habmanAllPlay_fid[i]+"_"+habmanAllPlay_fid[j]].win++;

			} else if( results[habmanAllPlay_fid[i]][week-1] < results[habmanAllPlay_fid[j]][week-1] ) {

				habmanAllPlay_results[habmanAllPlay_fid[i]][0].totalLoss++;

				habmanAllPlay_results[habmanAllPlay_fid[i]][week].loss++;

				habmanAllPlay_resultsHTH[habmanAllPlay_fid[i]+"_"+habmanAllPlay_fid[j]].loss++;

			} else {

				habmanAllPlay_results[habmanAllPlay_fid[i]][0].totalTie++;

				habmanAllPlay_results[habmanAllPlay_fid[i]][week].tie++;

				habmanAllPlay_resultsHTH[habmanAllPlay_fid[i]+"_"+habmanAllPlay_fid[j]].tie++;

			}

		}

	}

}

function habmanAllPlay_sortResults(){

	for(var i=0;i<habmanAllPlay_fid.length;i++){

		for(var j=0;j<(habmanAllPlay_fid.length - i -1);j++) {

			var currPts = habmanAllPlay_results[habmanAllPlay_fid[j]][0].totalWin*2+habmanAllPlay_results[habmanAllPlay_fid[j]][0].totalTie;

			var nextPts = habmanAllPlay_results[habmanAllPlay_fid[j+1]][0].totalWin*2+habmanAllPlay_results[habmanAllPlay_fid[j+1]][0].totalTie;

			if(currPts<nextPts) {

				var temp = habmanAllPlay_fid[j];

				habmanAllPlay_fid[j] = habmanAllPlay_fid[j+1];

				habmanAllPlay_fid[j+1] = temp;

			}

		}

	}

}

function habmanAllPlay_populate(){

	habmanAllPlay_doScoreAdjustmentKey();

	//initialize fid holder

	if(habmanAllPlay_fid.length==0) {

		for (key in franchiseDatabase) {

			if(franchiseDatabase.hasOwnProperty(key)&&parseInt(franchiseDatabase[key].id)>0) {

				habmanAllPlay_fid.push(franchiseDatabase[key].id);

			}

		}

	}

	//initialize head to head results

	for (var i=0;i<habmanAllPlay_fid.length;i++){

		for (var j=0;j<habmanAllPlay_fid.length;j++){

			if(i==j) continue;

			habmanAllPlay_resultsHTH[habmanAllPlay_fid[i]+"_"+habmanAllPlay_fid[j]] = ({ "win":0 , "loss":0 , "tie":0 });

		}

	}

	//get weekly scores

	var habmanAllPlay_weeklyResults = new Array();

	var habmanAllPlay_scores = new Array();

	if(completedWeek>habmanAllPlay_weeks) var toWeek = habmanAllPlay_weeks; else var toWeek = completedWeek;

	for (var i=1; i<=toWeek; i++) {

		var url = baseURLDynamic + "/" + year + "/export?TYPE=weeklyResults&L=" + league_id + "&W=" + i + "&JSON=1";

		jQuery.ajax({ 

			url: url, 

			success: function(data) { 

				habmanAllPlay_weeklyResults[i] = data; 

				try { //MULTI-GAME

					for (var j=0;j<habmanAllPlay_weeklyResults[i].weeklyResults.matchup.length;j++) {

						for (var k=0;k<habmanAllPlay_weeklyResults[i].weeklyResults.matchup[j].franchise.length;k++){

							var fid = habmanAllPlay_weeklyResults[i].weeklyResults.matchup[j].franchise[k].id;

							var score = parseFloat(habmanAllPlay_weeklyResults[i].weeklyResults.matchup[j].franchise[k].score);

							if(habmanAllPlay_scores[fid]==undefined) habmanAllPlay_scores[fid] = new Array();

							habmanAllPlay_scores[fid][i-1] = score;

						}

					}	

				} catch(er) {}

				try { //SINGLE GAME

					for (var k=0;k<habmanAllPlay_weeklyResults[i].weeklyResults.matchup.franchise.length;k++){

						var fid = habmanAllPlay_weeklyResults[i].weeklyResults.matchup.franchise[k].id;

						var score = parseFloat(habmanAllPlay_weeklyResults[i].weeklyResults.matchup.franchise[k].score);

						if(habmanAllPlay_scores[fid]==undefined) habmanAllPlay_scores[fid] = new Array();

						habmanAllPlay_scores[fid][i-1] = score;

					}

				} catch(er) {}

				try { //MULTI-SINGLE FRANCHISE

					for (var k=0;k<habmanAllPlay_weeklyResults[i].weeklyResults.franchise.length;k++){

						var fid = habmanAllPlay_weeklyResults[i].weeklyResults.franchise[k].id;

						var score = parseFloat(habmanAllPlay_weeklyResults[i].weeklyResults.franchise[k].score);

						if(habmanAllPlay_scores[fid]==undefined) habmanAllPlay_scores[fid] = new Array();

						habmanAllPlay_scores[fid][i-1] = score;

					}

				} catch(er) {}	

				try { //SINGLE FRANCHISE

					var fid = habmanAllPlay_weeklyResults[i].weeklyResults.franchise.id;

					var score = parseFloat(habmanAllPlay_weeklyResults[i].weeklyResults.franchise.score);

					if(habmanAllPlay_scores[fid]==undefined) habmanAllPlay_scores[fid] = new Array();

					habmanAllPlay_scores[fid][i-1] = score;

				} catch(er) {}

				//now loop through eligible franchises and assign weekly allplay win loss tie

				habmanAllPlay_week(i,habmanAllPlay_scores);

			}, 

			async: false 

		});

	}

	habmanAllPlay_sortResults();

	habmanAllPlay_createHTML();

}

function habmanAllPlay_initiate(){

	$("#habmanAllPlay").html('<span id="habmanAllPlay_populating">Populating . . . </i>');

	setTimeout("habmanAllPlay_populate()",250);

}

jQuery(document).ready(function(){

	$("#habmanAllPlay").html('<input id="triggerButton_habmanAllPlay" class="appButton" type="button" onclick="habmanAllPlay_initiate()" value="' + habmanAllPlay_buttonText + '" />');

});

</script>
Consider Donating:
These apps are all 100% free to use however if you want to show your appreciation for the time and effort it took to create then these apps then please consider donating.

Thank you.