World Baseball Association

General Category => General WBA Discussion => Topic started by: Huckleberry on April 24, 2015, 12:13:39 AM

Title: WBA Tools
Post by: Huckleberry on April 24, 2015, 12:13:39 AM
There is a new menu at the top called WBA Tools.  It's not just a description of the IBL owners (man I make myself laugh sometimes), it's also where you can go for:

Title: Re: WBA Tools
Post by: captaincoop17 on April 24, 2015, 06:18:50 AM
How did you make all of these?
Title: Re: WBA Tools
Post by: Huckleberry on April 24, 2015, 07:15:04 AM
Wrote PHP scripts to read the csv files (except for #3 which pulls data on the team export files and the league file).  Same way the financial information pages run.

The upload form is just another PHP script that checks to make sure you're uploading a *.ootp file and that it's not too huge.
Title: Re: WBA Tools
Post by: captaincoop17 on April 24, 2015, 07:49:59 AM
You think you could walk me through the contract one? It would be really useful for the league I run.
Title: Re: WBA Tools
Post by: Huckleberry on April 24, 2015, 08:02:16 AM
I can do better than walk you through it.

Code: [Select]
<?php

if (($handle fopen('PATH TO CSV DIRECTORY GOES HERE/players.csv''r')) === false) {
    die(
'Error opening file');
}

$headers fgetcsv($handle);
$pl_array = array();

while (
$row fgetcsv($handle)) {
$pl_array[$row[0]] = array_combine($headers$row);
}

fclose($handle);

/*  SETTING PLAYERS AND THEIR ORGANIZATIONS (ORG NUMBERS) ARRAY */

$plys_array2 = array();
$cnt=0;

foreach(
$pl_array as $plkey => $plkeyval) {
    if(
$plkeyval['organization_id'] != 0) {
        foreach(
$plkeyval as $key2 => $val2) {
            if(
substr($key209) == 'player_id' || substr($key2010) == 'first_name' || substr($key209) == 'last_name' || substr($key2015) == 'organization_id') {
                
$plys_array2[$plkey][$key2] = $val2;
            }
        }
        
$cnt++;
    }
}

unset(
$pl_array);

/*  ADDING ORGANIZATION MAJOR LEAGUE TEAM NAME TO ARRAY */

if (($handle fopen('PATH TO CSV DIRECTORY GOES HERE/teams.csv''r')) === false) {
    die(
'Error opening file');
}

$headers fgetcsv($handle);
$tm_arrayi = array();

while (
$row fgetcsv($handle)) {
$tm_arrayi[$row[0]] = array_combine($headers$row);
}

fclose($handle);

foreach(
$plys_array2 as $plkey => $plkeyval) {
    
$plys_array2[$plkey]['team_name'] = $tm_arrayi[$plys_array2[$plkey]['organization_id']]['name']." ".$tm_arrayi[$plys_array2[$plkey]['organization_id']]['nickname'];
    
$plys_array2[$plkey]['player_name'] = $plys_array2[$plkey]['first_name']." ".$plys_array2[$plkey]['last_name'];
}

unset(
$tm_arrayi);

foreach(
$plys_array2 as $plkey => $plkeyval) {
    unset(
$plys_array2[$plkey]['organization_id']);
    unset(
$plys_array2[$plkey]['first_name']);
    unset(
$plys_array2[$plkey]['last_name']);
}

/* SET PLAYER, TEAM NAME, CONTRACT YEARS, AND SALARIES ARRAY */

if (($handle fopen('PATH TO CSV DIRECTORY GOES HERE/players_contract.csv''r')) === false) {
    die(
'Error opening file');
}

$headers fgetcsv($handle);
$pls_array = array();
$pc_arrayi = array();

while (
$row fgetcsv($handle)) {
$pc_arrayi[$row[0]] = array_combine($headers$row);
}

fclose($handle);

foreach(
$plys_array2 as $plkey => $plkeyval) {
    foreach(
$plkeyval as $key2 => $val2) {
            if(
substr($key209) == 'player_id') {
$pls_array[$plkey] = $val2;
}
}
}

foreach(
$pc_arrayi as $pckey => $pckeyval) {
    if(
in_array($pckeyval['player_id'], $pls_array)) {
        foreach(
$pckeyval as $key2 => $val2) {
            if(
substr($key206) == 'salary') {
                
$plys_array2[$pckey][$key2] = $val2;
            }
        }
    }
}

unset(
$pc_arrayi);

/* SET ILLEGAL CONTRACT VALUE TO 0 */

foreach($pls_array as $plkey => $plkeyval) {
    
$plys_array2[$plkey]['i_c'] = 0;
}

/* SET EXTENSION YEARS AND SALARIES INTO ARRAY */

if (($handle fopen('PATH TO CSV DIRECTORY GOES HERE/players_contract_extension.csv''r')) === false) {
    die(
'Error opening file');
}

$headers fgetcsv($handle);
$pce_arrayi = array();

while (
$row fgetcsv($handle)) {
$pce_arrayi[$row[0]] = array_combine($headers$row);
}

fclose($handle);

foreach(
$pce_arrayi as $pckey => $pckeyval) {
    if(
in_array($pckeyval['player_id'], $pls_array)) {
        foreach(
$pckeyval as $key2 => $val2) {
            if(
substr($key206) == 'salary') {
                
$plys_array2[$pckey]['e_'.$key2] = $val2;
            }
        }
    }
}

unset(
$pc_arrayi);

/* SET ILLEGAL CONTRACT REASON TO 0 */

foreach($pls_array as $plkey => $plkeyval) {
    
$plys_array2[$plkey]['i_c_r'] = "N/A";
}

/* CHECK FOR CONTRACT LENGTH VIOLATION */

foreach($plys_array2 as $plkey => $plkeyval) {
    if(
$plys_array2[$plkey]['salary6'] > 0) {
$plys_array2[$plkey]['i_c'] = 1;
$plys_array2[$plkey]['i_c_r'] = "Contract Length";
}
}

/* CHECK FOR EXTENSION LENGTH VIOLATION */

foreach($plys_array2 as $plkey => $plkeyval) {
    if(
$plys_array2[$plkey]['e_salary6'] > 0) {
$plys_array2[$plkey]['i_c'] = 1;
if($plys_array2[$plkey]['i_c_r'] == "N/A") {
$plys_array2[$plkey]['i_c_r'] = "Extension Length";
}
else {
$plys_array2[$plkey]['i_c_r'] = $plys_array2[$plkey]['i_c_r'].", Extension Length";
}
}
}

/* CHECK FOR CONTRACT ANNUAL SALARY DECREASE VIOLATION */

foreach($plys_array2 as $plkey => $plkeyval) {
    if((
$plys_array2[$plkey]['salary0'] > $plys_array2[$plkey]['salary1'] && $plys_array2[$plkey]['salary1'] > 0) || ($plys_array2[$plkey]['salary1'] > $plys_array2[$plkey]['salary2'] && $plys_array2[$plkey]['salary2'] > 0) || ($plys_array2[$plkey]['salary2'] > $plys_array2[$plkey]['salary3'] && $plys_array2[$plkey]['salary3'] > 0) || ($plys_array2[$plkey]['salary3'] > $plys_array2[$plkey]['salary4'] && $plys_array2[$plkey]['salary4'] > 0) || ($plys_array2[$plkey]['salary4'] > $plys_array2[$plkey]['salary5'] && $plys_array2[$plkey]['salary5'] > 0)) {
$plys_array2[$plkey]['i_c'] = 1;
if($plys_array2[$plkey]['i_c_r'] == "N/A") {
$plys_array2[$plkey]['i_c_r'] = "Annual Decrease";
}
else {
$plys_array2[$plkey]['i_c_r'] = $plys_array2[$plkey]['i_c_r'].", Annual Decrease";
}
}
}

/* CHECK FOR EXTENSION ANNUAL SALARY DECREASE VIOLATION */

foreach($plys_array2 as $plkey => $plkeyval) {
    if((
$plys_array2[$plkey]['e_salary0'] > $plys_array2[$plkey]['e_salary1'] && $plys_array2[$plkey]['e_salary1'] > 0) || ($plys_array2[$plkey]['e_salary1'] > $plys_array2[$plkey]['e_salary2'] && $plys_array2[$plkey]['e_salary2'] > 0) || ($plys_array2[$plkey]['e_salary2'] > $plys_array2[$plkey]['e_salary3'] && $plys_array2[$plkey]['e_salary3'] > 0) || ($plys_array2[$plkey]['e_salary3'] > $plys_array2[$plkey]['e_salary4'] && $plys_array2[$plkey]['e_salary4'] > 0) || ($plys_array2[$plkey]['e_salary4'] > $plys_array2[$plkey]['e_salary5'] && $plys_array2[$plkey]['e_salary5'] > 0)) {
$plys_array2[$plkey]['i_c'] = 1;
if($plys_array2[$plkey]['i_c_r'] == "N/A") {
$plys_array2[$plkey]['i_c_r'] = "Extension Annual Decrease";
}
else {
$plys_array2[$plkey]['i_c_r'] = $plys_array2[$plkey]['i_c_r'].", Extension Annual Decrease";
}
}
}

/* CHECK FOR CONTRACT EXCESSIVE ANNUAL SALARY INCREASE VIOLATION */

foreach($plys_array2 as $plkey => $plkeyval) {
    if((
$plys_array2[$plkey]['salary1'] > 1.1*$plys_array2[$plkey]['salary0']) || ($plys_array2[$plkey]['salary2'] > 1.1*$plys_array2[$plkey]['salary1']) || ($plys_array2[$plkey]['salary3'] > 1.1*$plys_array2[$plkey]['salary2']) || ($plys_array2[$plkey]['salary4'] > 1.1*$plys_array2[$plkey]['salary3']) || ($plys_array2[$plkey]['salary5'] > 1.1*$plys_array2[$plkey]['salary4'])) {
$plys_array2[$plkey]['i_c'] = 1;
if($plys_array2[$plkey]['i_c_r'] == "N/A") {
$plys_array2[$plkey]['i_c_r'] = "Excessive Annual Increase";
}
else {
$plys_array2[$plkey]['i_c_r'] = $plys_array2[$plkey]['i_c_r'].", Excessive Annual Increase";
}
}
}

/* CHECK FOR EXTENSION EXCESSIVE ANNUAL SALARY INCREASE VIOLATION */

foreach($plys_array2 as $plkey => $plkeyval) {
    if((
$plys_array2[$plkey]['e_salary1'] > 1.1*$plys_array2[$plkey]['e_salary0']) || ($plys_array2[$plkey]['e_salary2'] > 1.1*$plys_array2[$plkey]['e_salary1']) || ($plys_array2[$plkey]['e_salary3'] > 1.1*$plys_array2[$plkey]['e_salary2']) || ($plys_array2[$plkey]['e_salary4'] > 1.1*$plys_array2[$plkey]['e_salary3']) || ($plys_array2[$plkey]['e_salary5'] > 1.1*$plys_array2[$plkey]['e_salary4'])) {
$plys_array2[$plkey]['i_c'] = 1;
if($plys_array2[$plkey]['i_c_r'] == "N/A") {
$plys_array2[$plkey]['i_c_r'] = "Extension Excessive Annual Increase";
}
else {
$plys_array2[$plkey]['i_c_r'] = $plys_array2[$plkey]['i_c_r'].", Extension Excessive Annual Increase";
}
}
}

/*  ADDING ORGANIZATION IDs BACK TO ARRAY */

if (($handle fopen('PATH TO CSV DIRECTORY GOES HERE/players.csv''r')) === false) {
    die(
'Error opening file');
}

$headers fgetcsv($handle);
$pl_arrayi = array();

while (
$row fgetcsv($handle)) {
$pl_arrayi[$row[0]] = array_combine($headers$row);
}

fclose($handle);

foreach(
$plys_array2 as $plkey => $plkeyval) {
    
$plys_array2[$plkey]['organization_id'] = $pl_arrayi[$plkey]['organization_id'];
}

unset(
$pl_arrayi);

/* DEFINE NEW ARRAY WITH ONLY ILLEGAL CONTRACTS */

$ic_array = array();

foreach(
$plys_array2 as $plkey => $plkeyval) {
    if (
$plys_array2[$plkey]['i_c'] == 1) {
        foreach(
$plkeyval as $key2 => $val2) {
$ic_array[$plkey][$key2] = $val2;
}
}
}

unset(
$plys_array2);

/*  SORT ARRAY BY TEAM NAME */

uasort($ic_array, function($a$b) {
    return 
strcmp($a['team_name'], $b['team_name']);
});

echo 
"<strong>Illegal WBA Contracts Table</strong> - Empty if none found:
<p>
<div class=\"YOUR STYLE CSS TABLE CLASS NAME GOES HERE\" >
<table>
<tr><th>Team</th><th>Name</th><th>Reason</th></tr>
"
;

foreach(
$ic_array as $ickey => $ickeyval) {
    echo 
"<td style=\"text-align:left\"><a href=\"WWW PATH TO ONLINE OOTP REPORTS GOES HERE/news/html/teams/team_".$ic_array[$ickey]['organization_id'].".html\">".$ic_array[$ickey]['team_name']."</td><td style=\"text-align:left\"><a href=\"WWW PATH TO ONLINE OOTP REPORTS GOES HERE/news/html/players/player_".$ic_array[$ickey]['player_id'].".html\">".$ic_array[$ickey]['player_name']."</td><td style=\"text-align:left\">".$ic_array[$ickey]['i_c_r']."</td></tr>
"
;
}


echo 
"</table>
</div>
<p>
<p>"
;

?>

That's the code.  Now it should be noted that you see no header or other information because the code is written to be embedded into this forum software mod.  So the code is only for the section of the page you see that has the table output.  Let me know if you have any questions.

And no mocking my terribly inefficient coding skills if there are any programmers in the league.  I taught myself, not that you couldn't tell.  Plus I left artifacts of previous algorithms in the code in case I need to go back to an old method.

Oh yeah, almost forgot.  Copyright 2015 WBA and me personally blah, blah, blah.
Title: Re: WBA Tools
Post by: captaincoop17 on April 24, 2015, 02:36:14 PM
Where do I put this script on the server?
Title: Re: WBA Tools
Post by: Huckleberry on April 24, 2015, 02:38:20 PM
You can put it anywhere on your server but you have to edit the parts that say "GOES HERE" with your particular information.
Title: Re: WBA Tools
Post by: CLK on April 24, 2015, 02:50:38 PM
I give props to you and your coding abilities. I taught myself a bit of coding and web design years ago. It wasn't the best but I felt proud that I did it all on my own.  Good job Huck!
Title: Re: WBA Tools
Post by: APMP on April 25, 2015, 04:58:23 PM
Nicely done.
Title: Re: WBA Tools
Post by: Huckleberry on May 03, 2015, 08:44:06 PM
DFA check has been added.  Also the contract check tool now verifies that the contract year is later than 2100 so that the contracts that OOTP automatically assigned are ignored.  The contract check has also been modified to check for the new required team option buyout amount.
Title: Re: WBA Tools
Post by: Huckleberry on August 22, 2016, 10:05:11 AM
Added a few things, some mentioned elsewhere.


While you could of course access the waiver wire and trading block via the HTML reports, I like having frequently accessed features in one spot.  Not to mention, now if you want to put someone on the trading block but don't have time to make a forum post, he will still be listed on that page so other teams that are looking for trade partners will see that information.
SimplePortal 2.3.7 © 2008-2025, SimplePortal