/    Sign up×
Community /Pin to ProfileBookmark

Calculate places based on stats entered

It’s math so I know it can be done, I’m just not sure how.

You can see the script I have now here:
[URL=”http://volstatecup.bravehost.com/groupA.js”]http://volstatecup.bravehost.com/groupA.js[/URL]

Right now I would have to manually adjust the table rows so that each team is in the right spot. What I want my script to do is calculate the places for me.

First place is the team with the most points (pts#). If there is a tie, largest goal difference (gd#) wins. If there is still a tie, most goals for (gf#) wins.

Once I figure out how to rank the teams I’ll have the first place team info switched to A (e.g., var ptsA = pts2), and then I’ll change the vars in the output section.

I’m tired and I hope this makes sense to someone that’s willing to help.

Thanks in advance,
GTWeasel

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERMay 11.2007 — Did your script work as submitted?

It didn't work for me, but I changed it as follows.

NOTE: It still does not do what you asked, but at least you can see some results.


I will work on it some more, but in the meantime do you have any real test data.


I understand you plan on editing the numbers manually, but for testing it would be nice to see the data formatted with something other than zeros as in the final version.

[code=php]
<html>
<head>
<title>Team Stats Display</title>

<script type="text/javascript">
/* MANUALLY ENTERED STATS */

function Display_Stats() {
// Stats : { // to be put into separate file at a later time

var name1 = "Peabody F.C.";
var id1 = "229282";
var w1 = 0;
var l1 = 0;
var d1 = 0;
var gf1 = 0;
var ga1 = 0;

var name2 = "Erin Eagles";
var id2 = "72105";
var w2 = 0;
var l2 = 0;
var d2 = 0;
var gf2 = 0;
var ga2 = 0;

var name3 = "Pond";
var id3 = "230021";
var w3 = 0;
var l3 = 0;
var d3 = 0;
var gf3 = 0;
var ga3 = 0;

var name4 = "Spare";
var id4 = "spare";
var w4 = 0;
var l4 = 0;
var d4 = 0;
var gf4 = 0;
var ga4 = 0;

// }

/* FUNCTIONS FOR OTHER STATS */
var gp1 = w1 + l1 + d1;
var gd1 = gf1 - ga1;
var pts1 = (3 * w1) + d1;
var gp2 = w2 + l2 + d2;
var gd2 = gf2 - ga2;
var pts2 = (3 * w2) + d2;
var gp3 = w3 + l3 + d3;
var gd3 = gf3 - ga3;
var pts3 = (3 * w3) + d3;
var gp4 = w4 + l4 + d4;
var gd4 = gf4 - ga4;
var pts4 = (3 * w4) + d4;

common_site = 'http://www86.hattrick.org/Common/TeamDetails.asp?teamid=';

/* HEADER ROW */
document.write ('<table><tr class="groupTableHeader"><td width="34">&nbsp;</td>');
document.write ('<td width="236"><div align="left">&nbsp;GROUP A</div></td><td width="34">GP</td>');
document.write ('<td width="34">W</td><td width="34">L</td><td width="34">D</td><td width="34">GF</td>');
document.write ('<td width="34">GA</td><td width="34">+/-</td><td width="34">PTS</td></tr>');

/* FIRST PLACE ROW */
document.write ('<tr class="groupTable"><td>1</td>');

/* PEABODY F.C. */
document.write ('<td><div align="left">&nbsp;');
document.write ('<a href="' + common_site + id1 + '">');
document.write (name1 + '</a></div></td><td>' + gp1 + '</td>');
document.write ('<td>' + w1 + '</td><td>' + l1 + '</td><td>' + d1 + '</td><td>' + gf1 + '</td>');
document.write ('<td>' + ga1 + '</td><td>' + gd1 + '</td><td>' + pts1 + '</td></tr>');

/* SECOND PLACE ROW */
document.write ('<tr class="groupTable"><td>2</td>');

/* ERIN EAGLES */
document.write ('<td><div align="left">&nbsp;');
document.write ('<a href="' + common_site + id2 + '">');
document.write (name2 + '</a></div></td><td>' + gp2 + '</td>');
document.write ('<td>' + w2 + '</td><td>' + l2 + '</td><td>' + d2 + '</td><td>' + gf2 + '</td>');
document.write ('<td>' + ga2 + '</td><td>' + gd2 + '</td><td>' + pts2 + '</td></tr>')

/* THIRD PLACE ROW */
document.write ('<tr class="groupTable"><td>3</td>');

/* POND */
document.write ('<td><div align="left">&nbsp;');
document.write ('<a href="' + common_site + id3 + '">');
document.write (name3 + '</a></div></td><td>' + gp3 + '</td>');
document.write ('<td>' + w3 + '</td><td>' + l3 + '</td><td>' + d3 + '</td><td>' + gf3 + '</td>');
document.write ('<td>' + ga3 + '</td><td>' + gd3 + '</td><td>' + pts3 + '</td></tr>');

/* FOURTH PLACE ROW */
document.write ('<tr class="groupTable"><td>4</td>');

/* */
document.write ('<td><div align="left">&nbsp;');
document.write ('<a href="' + common_site + id4 + '">');
document.write (name4 + '</a></div></td><td>' + gp4 + '</td>');
document.write ('<td>' + w4 + '</td><td>' + l4 + '</td><td>' + d4 + '</td><td>' + gf4 + '</td>');
document.write ('<td>' + ga4 + '</td><td>' + gd4 + '</td><td>' + pts4 + '</td></tr>');

/* CLOSE TABLE */
document.write ('</table>');
}
</script>
</head>

<body onLoad="Display_Stats()">
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@JMRKERMay 12.2007 — Here's a major modification to your script.

The JSON portion can be put into a separate text file.

(I hope the teams don't get mad at me for the W,L,D values) :rolleyes:

Should automatically change order with stat changes.

Post your final product as it was an interesting challenge.

Good Luck!
[code=php]
<html>
<head>
<title>Team Stats Display</title>
<script type="text/javascript">

// MANUALLY ENTERED STATS
TS = { // to be put into separate file at a later time
place : [
// {'Team':'name','ids':'xxx', 'win':0, 'lose':0, 'draw':0, 'gf':0, 'ga':0, 'gp':0, 'gd':0, 'pts':0 },
{'Team':"Peabody F.C.",'ids':"229282", 'win':10, 'lose':8, 'draw':2, 'gf':0, 'ga':0, 'gp':0, 'gd':0, 'pts':0 },
{'Team':"Erin Eagles",'ids':"72105", 'win':12, 'lose':6, 'draw':1, 'gf':0, 'ga':0, 'gp':0, 'gd':0, 'pts':0 },
{'Team':"Pond", 'ids':"230021", 'win':14, 'lose':4, 'draw':1, 'gf':0, 'ga':0, 'gp':0, 'gd':0, 'pts':0 },
]
}
// note: no ',' at end of last entries
// STATS can be stored in external file
// and accessed with <script type="text/javascript" src="StatsFile.js"></script>

function sortNumber(a,b) { return b - a; } // reverse order number sort modification

function Display_Stats() {

var TS_Order = new Array();

// FUNCTIONS FOR OTHER STATS
for (var i=0; i<TS.place.length; i++) {
TS.place[i].gp = TS.place[i].win + TS.place[i].lose + TS.place[i].draw;
TS.place[i].gd = TS.place[i].gf - TS.place[i].ga;
TS.place[i].pts = (3 * TS.place[i].win) + TS.place[i].draw;
// want to use 'i' as pointer to correct 'place' element
TS_Order.push((TS.place[i].pts*1000)+i);

}
TS_Order = TS_Order.sort(sortNumber);

var common_site = 'http://www86.hattrick.org/Common/TeamDetails.asp?teamid=';

var tstr = '';
// HEADER ROW
tstr += '<table><tr class="groupTableHeader"><td width="34">&nbsp;</td>';
tstr += '<td width="136"><div align="left">&nbsp;GROUP A</div></td><td width="34">GP</td>';
tstr += '<td width="34">Win</td><td width="34">Lose</td><td width="34">Draw</td><td width="34">GF</td>';
tstr += '<td width="34">GA</td><td width="34">+/-</td><td width="34">PTS</td></tr>';

j = 0;
while (j<TS_Order.length) {
i = TS_Order[j] % 1000;

// PLACE ROWS
tstr += '<tr class="groupTable"><td>'+(j+1)+'</td>';

site = common_site + TS.place[i].ids;
tstr += '<td><div align="left">&nbsp;';
tstr += '<a href="' + site + '">';
tstr += TS.place[i].Team + '</a></div></td><td>' + TS.place[i].gp + '</td>';
tstr += '<td>' + TS.place[i].win + '</td><td>' + TS.place[i].lose + '</td>';
tstr += '<td>' + TS.place[i].draw + '</td><td>' +TS.place[i].gf + '</td>';
tstr += '<td>' + TS.place[i].ga + '</td><td>' + TS.place[i].gd + '</td>';
tstr += '<td>' + TS.place[i].pts + '</td></tr>';
j++;
}

// CLOSE TABLE
tstr += '</table>';
document.getElementById('StatTable').innerHTML = tstr;
}
</script>
</head>
<body onLoad="Display_Stats()">
<h1>Team Statistics</h1>
<div id="StatTable"></div>
</body>
</html>
[/code]
×

Success!

Help @GTWeasel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...