You are currently not logged into ManagerLeague
If you wish to log in, click here.
If you wish to sign up and join us, click here.
MKManager79s BlogSee all entries in this blog
Calculate the total attribute points with Firebug (15/04/2013 15:36)

Firebug

Firebug is a plugin for Firefox. It adds several options to Firefox which can come in handy if you want to build your own website. It also enables you to execute leetcode in a console. This means you can change your view of the current webpage.

 

Code Example

The code example below calculates the sum of all attribute values for each of the team's players and shows the result in an additional column.

var rows = $(".tablelinereg");var agetds = [];var kptds = [];var tktds = [];var pstds = [];var shtds = [];var hetds = [];var sptds = [];var stt

var rows = $(".tablelinereg");

var agetds = [];

var kptds = [];

var tktds = [];

var pstds = [];

var shtds = [];

var hetds = [];

var sptds = [];

var sttds = [];

var gitds = [];

var bacds = [];

rows.each(function( indexRow ) {

  var tds = $(this).find('td');

  tds.each(function( indexCell ) {

    if (indexCell == 3) {

      kptds[indexRow] = $(this);

    }

    if (indexCell == 4) {

      tktds[indexRow] = $(this);

    }

    if (indexCell == 5) {

      pstds[indexRow] = $(this);

    }

    if (indexCell == 6) {

      shtds[indexRow] = $(this);

    }

    if (indexCell == 7) {

      hetds[indexRow] = $(this);

    }

    if (indexCell == 8) {

      sptds[indexRow] = $(this);

    }

    if (indexCell == 9) {

      sttds[indexRow] = $(this);

    }

    if (indexCell == 10) {

      gitds[indexRow] = $(this);

    }

    if (indexCell == 11) {

      bacds[indexRow] = $(this);

    }

    if (indexCell == 19) {

      agetds[indexRow] = $(this);

    }     

  });

});



$("div.overflow120").css('width',70);


if ($("td:contains('TotAttr')").length == 0) {

  $("td[width=25]:contains('Fit')").before("<td align='center'>TotAttr</td>");

}

if ($("td:contains('AgeAttr')").length == 0) {

  $("td[width=25]:contains('Fit')").before("<td align='center'>AgeAttr</td>");

}


var maxAttrTot = -1;

var maxAgeAttr = -1;


if ($("td.attrTotal").length == 0) {

  $(bacds).each(function( index ) {

    var agint = parseInt($(agetds[index]).html());

    var kpint = parseInt($(kptds[index]).html());

    var tkint = parseInt($(tktds[index]).html());

    var psint = parseInt($(pstds[index]).html());

    var shint = parseInt($(shtds[index]).html());

    var heint = parseInt($(hetds[index]).html());

    var spint = parseInt($(sptds[index]).html());

    var stint = parseInt($(sttds[index]).html());

    var giint = parseInt($(gitds[index]).html());

var bcint = parseInt($(bacds[index]).html());


    var total = kpint+tkint+psint+shint+heint+spint+stint+giint+bcint;

    

    if (total > maxAttrTot) {

      maxAttrTot = total;

    }

    

    var lfmult = agint;

    if (lfmult > 31) {

      lfmult = 31;

    }

    var attAge = total - 300 - lfmult * 12;

    

    if (attAge > maxAgeAttr) {

      maxAgeAttr = attAge;

    }

    

    $(this).after("<td class='AgeAttr'>"+attAge+"</td>");

    $(this).after("<td class='attrTotal'>"+total+"</td>");

    

  });

  

  $(".AgeAttr").each(function( index ) {

    var valint = parseInt($(this).html());

    var intensity = Math.round((255 * valint) / 192);

    var redintensity = 66;

    if (intensity < 0) {

      redintensity = 66 - intensity;

      intensity = 0;

      

    }

    $(this).css('background-color', 'rgb('+redintensity+','+intensity+','+intensity+')');

  });

  

  $(".attrTotal").each(function( index ) {

    var valint = parseInt($(this).html());

    if (valint < 0) {

      valint = 0;

    }    

    var intensity = Math.round((255 * (valint - 300)) / 492);

    $(this).css('background-color', 'rgb(33,'+intensity+',99)');

  });   

 

}

 

Note that two lines of code should be adjusted to your language:

  $("td[width=25]:contains('Fit')").before("<td align='center'>AgeAttr</td>");

  $("td[width=25]:contains('Fit')").before("<td align='center'>TotAttr</td>");

The 'Fit' should be the text of your Fitness column header.

 How do I use it?

Install Firefox and add the Firebug addon/plugin if you don't already have it. Go to Managerleague, log in and navigate to the team details screen. It will appear in a popup. Select the popup and push F12 to activate the Firebug console.

ml_firebug_console

Now copy/paste the code above in the console.

 ml_firebug_code

Now execute the code and two new columns should appear. The left column shows the sum of all attribute points for each player.

ml_firebug_myteam

The column to the right shows if a player will reach 672 attribute points by the age of 31 and above. A negative number means the player is lagging behind. A positive number means that if the player will have a net gain of 12 attributes each season he will have more than 672 attribute points by the age of 31.

You can change the code to your liking. This is just an example. 

Note: the code example relies heavily on the current html structure of the Managerleague Team Details page. Once the html structure changes the code will have to be adjusted. If you have knowledge of jQuery and html this is easy.

Below I have included a screenshot of one of the best teams in the dutch league with the additional attribute information.

ml_firebug_knudde

 Mini tutorial

In the old situation I wanted a 31 year old to have about 672 attribute points. I also wanted such a player to have a net gain of 12 attribute points per season. I came up with the following formula:

   var attAge = total - 300 - lfmult * 12;

Now suppose you want your players to have a total of at least 765 attribute points (about q99) by the time they are 31 years old and have a net gain of 18 attribute points each season.

In the new situation we change 12 to 18. Then we subtract 31 * 18 from 765. The remainder is 207. Thus we change 300 into 207. The resulting formula is:

   var attAge = total - 207 - lfmult * 18;

 

This means a 17 year old should have at least 513 attribute points and has to net gain at least 18 attribute points each season to finish at 765 or more attribute points at age 31.

Now we apply this new formula to one of the few teams in ML that actually has players with 750+ total attribute points. You can see the result below.

ml_firebug_darkness

 

 

 

 

Share on Facebook
This blogger owns the team JustinLaFieber. (TEAM:58384)
Post a comment
You must be logged in to post comments.
© 2003-2007 Fifth Season AS, Oslo, Norway. Privacy Policy. Rules and Code of Conduct. Sitemap.
Responsible Editor for ManagerLeague is Christian Lassem.