NATION

PASSWORD

Nationstates Calculator in PHP

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.
User avatar
Rich and Corporations
Negotiator
 
Posts: 6560
Founded: Aug 09, 2004
Ex-Nation

Nationstates Calculator in PHP

Postby Rich and Corporations » Wed Aug 20, 2014 4:46 pm

Code: Select all
<html>
<head>
<title> Nationstates Calculator Mk. Twain </title>
<meta name="generator" content="My own two hands.">

</head>
<body bgcolor="#eeeeee">


<P><b>Alpha Release 6</b></p>

<br>

<form action="nsquiz2.php" method="get">
<a href="http://www.nationstates.net/"> Nationstates</a> Nationname: <input type="text" size="16" maxlength="32" name="nam"><br>
Population (in millions): <input type="text" size="3" maxlength="9" name="pop"> Leave blank if you want your nation's NS population to be used. Input the value of "1" if you want your nation's population to be nth-rooted to the 67/100th power (I find this converts NS populations to realistic ones).
<p>
<table>

<tr><td>Government Control: </td><td>0<input type="range" name="gov" min="1" max="10" value = "3" alt = "Notice: This form is not compatible with IE 9 and earlier. I don't know why you would use IE period.">10</td></tr>
<tr><td>Taxation (percentage): </td><td><input type="text" size="3" maxlength="2" name="tax"> <br></td></tr>
<tr><td>Government Budget Priorities by Function<br></td></td></tr>
<tr><td>Offensive Military Spending:</td><td> 0<input type="range" name="offm" min="1" max="10" value = "3">10</td></tr>
<tr><td>Defensive Military Spending:</td><td> 0<input type="range" name="defm" min="1" max="10" value = "5">10</td></tr>
<tr><td>Administration of Justice:</td><td> 0<input type="range" name="jus" min="1" max="10" value = "8">10</td></tr>
<tr><td>Secret Police:</td><td> 0<input type="range" name="secpol" min="0" max="10" value = "1">10</td></tr>
<tr><td>Commerce, Industry, & Trade:</td><td> 0<input type="range" name="comm" min="1" max="10" value = "5">10</td></tr>
<tr><td>Transportation:</td><td> 0<input type="range" name="trans" min="1" max="10" value = "5">10</td></tr>
<tr><td>Education:</td><td> 0<input type="range" name="edu" min="1" max="10" value = "4">10</td></tr>
<tr><td>Healthcare:</td><td> 0<input type="range" name="health" min="1" max="10" value = "6">10</td></tr>
<tr><td>Economic Equality:</td><td> 0<input type="range" name="ee" min="1" max="10" value = "5">10 (this does not do anything yet) *</td></tr>
<tr><td>Social Welfare:</td><td> 0<input type="range" name="sw" min="1" max="10" value = "5">10 *</td></tr>
<tr><td>Pork Projects:</td><td> 0<input type="range" name="pork" min="1" max="10" value = "5">10</td></tr>
<tr><td>Foreign Aid:</td><td> 0<input type="range" name="aid" min="1" max="10" value = "5">10</td></tr></table>
</p><p>
A brief quiz on national policy:
<br>
Trade Policy?<br>
<input type="radio" name="prop" value="3">Free trade.<br>
<input type="radio" name="prop" value="2" checked>We enact reciprocating tariffs.<br>
<input type="radio" name="prop" value="1">We enact stiff tariffs and quotas.<br>
<input type="radio" name="prop" value="0">We only import for what we cannot produce.<br>
Average Workweek: <input type="text" size="3" maxlength="2" name="ww"> hours <br>
<br>
</p>
<p>* Economic equality represents basic income, tax brackets, and other means of shifting taxation/wealth from the rich to the poor. Welfare represents means of redistributing wealth as long as the person meets certain requirements, and includes social security and unemployment.
<br>This quiz works by weighting your choices to determine budget percents for each category. More realistic then NS's "50% to Defence and 50% to Religion" budgets. Those budget percents and budget amounts influence the calculation.
<hr>

</br>
</p>


<input type="submit" value="Compute">
</form>
<p>
</p>
</body>
</html>
Code: Select all
<?
##NS calculator Mk. Twain developed by Ryan Carboni.
$time = microtime(true);
ini_set('user_agent', '[website] [email]');

$nationname = $_GET["nam"];


function get_data($nation, $shards = FALSE) {
      if($shards != FALSE) {
         $file = 'http://www.nationstates.net/cgi-bin/api.cgi?nation=' . urlencode($nation) . '&q=' . $shards;
      }
      else {
         $file = 'http://www.nationstates.net/cgi-bin/api.cgi?nation=' . urlencode($nation);
      }
     
      $xml = simplexml_load_file($file);
      return $xml;
   }
   
   function display_pop_civilrights($nation) {

   $bigticketmod = 30;
$typicalmod = 9;
$smallmod = 3;
 if (empty($_GET["pop"])) {
       $data = get_data($nation, 'name+population+freedomscores');     
      $name = (string) $data->NAME;
      $population = $data->POPULATION;
 }
 elseif ( (int) $_GET["pop"] == 1) {
        $data = get_data($nation, 'name+population+freedomscores');     
      $name = (string) $data->NAME;
      $population = $data->POPULATION;
     $population = round(pow($population, .667));
 }
 else {
$population = (int) $_GET["pop"];
$name = (string) $_GET["nam"]; }
 

#
if (isset($_GET["ww"])){
$ww = (int) $_GET["ww"];
if ($ww < 14) {
 $ww = 14;
} //sanity check in case player inputs something stupidly low
else {  }

}
else {
 $ww = 14;
}




if (isset($_GET["tax"])){
$tax = round(pow($_GET["tax"], .997));
}
else { $tax = 30;
}


#inputting slider inputs
$gov = $_GET["gov"]; // government control
#budget-start
$offm = $_GET["offm"];
$defm = $_GET["defm"];
$jus = $_GET["jus"];
$secpol = $_GET["secpol"]; //secret police
$comm = $_GET["comm"]; //commerce
$edu = $_GET["edu"];
$trans = $_GET["trans"];
$sw = $_GET["sw"]; //welfare
$pork = $_GET["pork"];
$aid = $_GET["aid"];
$health = $_GET["health"];
#budget-end
//$tradepol = $_GET["prop"]; all trade calculations are hereby suspended



#national priority modifiers
$offm = $offm * $bigticketmod;
$edu = $edu * $typicalmod;
$health = $health * $bigticketmod;
$sw = $sw * $bigticketmod * 1.3;
$secpol = pow($secpol * $gov, 1.12);
$defm = $defm * $typicalmod;
$comm = $comm * $typicalmod * sqrt($tax/120);
$trans = $trans * $typicalmod;
$jus = $jus * $smallmod * 1.5;
$aid = $aid * 1.1;
$pork = $pork;
#determining budget fractions
$totpriori = $offm + $edu + $sw + $defm + $comm + $trans + $jus + $aid + $secpol + $pork + $health;
$offmper = $offm / $totpriori;
$eduper = $edu / $totpriori;
$swper = $sw / $totpriori;
$defmper = $defm / $totpriori;
$commper = $comm / $totpriori;
$transper = $trans / $totpriori;
$jusper = $jus / $totpriori;
$aidper = $aid / $totpriori;
$secper = $secpol / $totpriori;
$porkper = $pork / $totpriori;
$healthper = $health / $totpriori;


#economic equations
$taxgovmultiple = pow((($tax/100)*($gov/10)), .25);
$goveffect = ((70001-($taxgovmultiple*69499))/35);
$wweffect = (pow((30/($ww + 1)), .25)*($ww)); //declining returns to each additional work hour, multiplied by how much people actually work
//$tradeeffect = sqrt(($tradepol - ($gov/(10*($aidper))))/2);
$valueadd = round($goveffect*($wweffect)*((pow($population,.89))/$population));
//value added per worker per annum
$laborf = round($population*(((pow(21/($ww + 1), .75))/3)+((pow($gov/10, .42))*$population/400))-($swper/2*$population), 1); // <-- this equation is borked... fixed? I don't understand how this equation works now.

$gdp = $valueadd * $laborf / 1000; //GDP in billions, laborf in millions
$gdpcapita = $gdp/$population*1000;

#determining budget size
$budget = (($tax+.1)/100)*$gdp;
#budget distribution
$offmbudget = $offmper * $budget;
$edubudget = $eduper * $budget;
$swbudget = $swper * $budget;
$defmbudget = $defmper * $budget;
$commbudget = $commper * $budget;
$transbudget = $transper * $budget;
$jusbudget = $jusper * $budget;
$aidbudget = $aidper * $budget;
$secpolbudget = $secper * $budget;
$porkbudget = $porkper * $budget;
$healthbudget = $healthper * $budget;

#offm = bigticket
#defm = typical
#jus = small * 1.5
#secpol = tiny * $gov/2
#comm = typical * sqrt(level of taxation)
#trans = typical
#edu = bigticket
#sw = bigticket (welfare) * 2
#pork = tiny
#aid = small (future feature = major factor for trade and thus economic prosperity for dictatorships, less so for democracies)
#social welfare and taxation crowd out charity
#factor in deficits and historical deficit spending

#laborf equation =


 #military equations
$offmanpower = ($offmbudget/$gdp)*$laborf/8;
$offensivefirepower = pow($offmbudget/$offmanpower, .42)*$offmanpower;

#$defensivefirepower = ($offensivefirepower/2) + (($defmbudget/$gdp)*$laborf);
 
#society equations
$stability = floor((1.01 - $taxgovmultiple)*100);
$riots = (100 - ($stability + $swper ))/ 2500;
$protests = ((pow($gov/4, .4)-($secpolbudget/$gdp))*30)*$population;
$bombings = ((pow(($gov/7), .6)-($secpolbudget/$gdp))*2)*$population;
$rebels = ((pow($gov/6, .4)-(($secpolbudget+$swbudget+$defmbudget)/$gdp))*500)*$population;

if ($gov > 4)
{
$gulag = (((pow($gov/4, 1.5)/50)*$laborf)+$rebels*.0005)/100;
}
else
{
$gulag = 0;
}
if ($riots < 0)
$riots = 0;

if ($stability > 100)
$stability = 100;
 
 #final outputs
 echo '<br>Nation Name: ' . $name;
 
echo '<br>' . '<br>GDP: ' . number_format($gdp,1) . ' billion<br> Population:' . $population . 'millions <br> Labor force: ' . number_format($laborf,1) . ' million <br> GDP/capita: ' . number_format($gdpcapita) . '<br> Average Workweek: ' . $ww . ' hours' ;
 echo '<br> Valued Added per Worker: ';
 echo $valueadd;
 echo '<p> <table><tr><td> Budget Total:</td><td> ' . number_format($budget,1) . ' billion</td></tr>';
 echo '<tr><td>Offensive Military Budget:</td><td> ' . number_format($offmbudget,1) . ' billion</td></tr>';
 echo '<tr><td>Defensive Military Budget:</td><td> ' . number_format($defmbudget,1) . ' billion</td></tr>';
 echo '<tr><td>Law & Order Budget:</td><td> ' . number_format($jusbudget,1) . ' billions</td></tr>';
 echo '<tr><td>Secret Police Budget:</td><td> ' . number_format($secpolbudget,1) . ' billion</td></tr>';
 echo '<tr><td>Commerce, Industry, & Trade Budget:</td><td> ' . number_format($commbudget,1) . ' billion</td></tr>';
 echo '<tr><td>Transportation Budget:</td><td> ' . number_format($transbudget,1) . ' billion</td></tr>';
 echo '<tr><td>Education Budget:</td><td> ' . number_format($edubudget,1) . ' billion</td></tr>';
 echo '<tr><td>Healthcare Budget:</td><td> ' . number_format($healthbudget,1) . ' billion</td></tr>';
 echo '<tr><td>Social Welfare Budget:</td><td> ' . number_format($swbudget,1) . ' billion</td></tr>';
 echo '<tr><td>Pork Budget:</td><td> ' . number_format($porkbudget,1) . ' billion</td></tr>';
 echo '<tr><td>Aid Budget:</td><td> ' . number_format($aidbudget,1) . ' billion</td></tr>';
 echo '</table></p>';
 
 echo '<br>';
 echo 'Stability: ' . $stability . '%<br>';
 echo round($riots, 4) . ' riots per city per year';
 echo '<br> Protests & Labor Strikes: ' . number_format($protests) . ' per year';
 echo '<br> Bombings: ' . number_format($bombings) . ' per year';
 echo '<br> Political Prisoners: ' . number_format($gulag,3) . ' million ';
 echo '<br> Rebels and Domestic Terrorists: ' . number_format($rebels) . ' ';
// echo '<br> <br> Military Personnel: ' .  number_format($offmanpower) . ' million' ;
// echo '<p> Offensive Manpower' . $offmanpower;
// echo '<br> Offensive Firepower' . $offensivefirepower;
//echo '<br> Versioning Hash: ' hash('sha1', $name.$gdp.$population.$laborf.$gdpcapita.$ww.$valueadded.$budget.$offmbudget.$defmbudget.$jusbudget.$secpolbudget.$commbudget.$transbudget.$edubudget.$healthbudget.$stability.$bombings);
 echo '</p>';
 

     }
 
 
 
 
 
 
 
 
 
   
   display_pop_civilrights($nationname);
Last edited by Rich and Corporations on Wed Aug 20, 2014 5:13 pm, edited 1 time in total.
Corporate Confederacy
DEFENSE ALERT LEVEL
PEACE WAR

Factbook [url=iiwiki.com/wiki/Corporate_Confederacy]Wiki Article[/url]
Neptonia

User avatar
Southern Ageena
Bureaucrat
 
Posts: 56
Founded: Apr 16, 2013
Ex-Nation

Postby Southern Ageena » Wed Aug 20, 2014 4:49 pm

Thanks again.

You appear to be missing a <?php in your second file
Last edited by Southern Ageena on Wed Aug 20, 2014 4:54 pm, edited 1 time in total.
Head judge on the Genuan Rebirth supreme court (second term);
Current Minister of Law Genuan Rebirth (dree terme);
Former Minister of Foreign Affairs Genuan Rebirth;
Founder Beyond the Superpowers of Earth;
Founder Genua

Pro Socialism

User avatar
Rich and Corporations
Negotiator
 
Posts: 6560
Founded: Aug 09, 2004
Ex-Nation

Postby Rich and Corporations » Wed Aug 20, 2014 5:13 pm

Southern Ageena wrote:Thanks again.

You appear to be missing a <?php in your second file

Darn, copy error.
Corporate Confederacy
DEFENSE ALERT LEVEL
PEACE WAR

Factbook [url=iiwiki.com/wiki/Corporate_Confederacy]Wiki Article[/url]
Neptonia

User avatar
Southern Ageena
Bureaucrat
 
Posts: 56
Founded: Apr 16, 2013
Ex-Nation

Postby Southern Ageena » Thu Aug 28, 2014 12:44 pm

No matter what nation I enter, or what settings I enter, 'Commerce, Industry, & Trade Budget' is always 0. Has this feature not been implemented?
Head judge on the Genuan Rebirth supreme court (second term);
Current Minister of Law Genuan Rebirth (dree terme);
Former Minister of Foreign Affairs Genuan Rebirth;
Founder Beyond the Superpowers of Earth;
Founder Genua

Pro Socialism


Return to Technical

Who is online

Users browsing this forum: Franners, Myanerus, Nandaek, Reyo, Satreburg, Valoptia

Advertisement

Remove ads