PHP - Moved: Need Help With Time Calculations
This topic has been moved to PHP Math Help.
http://www.phpfreaks.com/forums/index.php?topic=328102.0 Similar TutorialsThis topic has been moved to PHP Math Help. http://www.phpfreaks.com/forums/index.php?topic=333872.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342385.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=316461.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=327525.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=314226.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=315056.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=316616.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=310181.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=355963.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=306905.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=348274.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=321950.0 This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=322054.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=326408.0 I've written a small ELO class for calculating a players rating for a game league, and for the life of me I don't know why these calculations are coming up wrong. The Class:
Code for testing:
The output i'm getting is as follows, when they should match what i've stated above (as done on paper with a calculator) Player A (1000) has a 9% Chance of winning. Player B (1000) has a 9% chance of winning. Player A's new rating will be 1029 if they win. Player B's new rating will be 1029 if they win. Player A's new rating will be 997 if they lose. Player B's new rating will be 997 if they lose. I've tried re-writing the calculation over and over but just can't get it. I used the Wikipedia page to get my calculations. I've not added K Factor yet but I will be at some point. Hello, I am trying to take the calculations of two variables to create a new data for a new variable. For example.....
LRH_calcLevel($LRH_current, $LRH_bankfull); +/- $LRH_totalDepth = $newVar
Which should translate to -10.43 Ft +/- 40 = $newVar (-29.57) <----- What I want
Instead it is showing up as 10.43 Ft +/- 40 = $newVar (-50.43) <----- How it is displaying which is incorrect
Here is the code I am using. The second function is what I am trying to use to create the new variable data based on the calculations above from the data provide via XML. How can I get this to display correctly?
-Thanks
//Parse Lake Ray Hubbard XML Data $site = simplexml_load_file($LRH_data);{ $LRH_bankfull = '435.5'; $LRH_totalDepth = '40'; $LRH_current = $site->observed->datum[0]->primary; $LRH_vaild = $site->observed->datum[0]->valid; $LRH_updated = DATE("D, M d, g:i a", STRTOTIME($LRH_vaild)); } //Lets calculate the lake depatures from full pool for Lake Ray Hubbard function LRH_calcLevel($LRH_current, $LRH_bankfull) { //Get float values from strings $LRH_current = floatval($LRH_current); $LRH_bankfull = floatval($LRH_bankfull); //Calculate the difference $LRH_calcLevel = $LRH_current - $LRH_bankfull; //Format difference to two decimal places and add 'Ft' $LRH_calcLevelStr = (string) number_format($LRH_calcLevel, 2) . ' Ft'; //If vlaue is positive add a + to beginning if($LRH_calcLevel>0) { $LRH_calcLevelStr = '+'.$LRH_calcLevelStr; } //Return the calculated formatted value return $LRH_calcLevelStr; } ////Lets calculate the lake percentage from full pool for Lake Ray Hubbard $val1 = $LRH_current; $val2 = $LRH_bankfull; $LRH_prec = ( $val1 / $val2) * 100; // 1 digit after the decimal point $LRH_prec = round($LRH_prec, 1); //Lets convert the depature from full pool for Lake Ray Hubbard function LRH_calcDepth($LRH_calcLevelStr, $LRH_totalDepth) { //Get float values from strings $LRH_calcDepthStr = floatval($LRH_calcLevelStr); $LRH_totalDepth = floatval($LRH_totalDepth); //Calculate the difference $LRH_calcDepth = $LRH_calcDepthStr - $LRH_totalDepth; //Format difference to two decimal places and add 'Ft' $LRH_calcDepthStr = (string) number_format($LRH_calcDepth, 2) . ' Ft'; //If vlaue is positive add a + to beginning if($LRH_calcDepth>0) { $LRH_calcDepthStr = '+'.$LRH_calcDepthStr; } //Return the calculated formatted value return $LRH_calcDepthStr; } ////Lets calculate the lake percentage from full pool for Lake Ray Hubbard $val1 = LRH_calcLevel($LRH_current, $LRH_bankfull); $val2 = $LRH_totalDepth; Hi, I have been set a task to use 300000 values from a csv to find the total amount of the values and the averages of the values (mode, mean and median). The csv is set into 2 columns, number and amount with 300000 records for each. I am unsure as to how to use only the values from one of the columns in order to get the results i need. Below is the code I have so far; Code: [Select] $filepath = "testdata.csv"; $file = fopen($filepath, "r") or die("Error opening file"); $i = 0; while(($line = fgetcsv($file)) !== FALSE) { if($i == 0) { $c = 0; foreach($line as $col) { $cols[$c] = $col; $c++; } } else if($i > 0) { $c = 0; foreach($line as $col) { $data[$i][$cols[$c]] = $col; $c++; } } $i++; } //this prints the whole of the data still while (($cols[1])) print_r($data); //this still prints all the data!! while ($data) print_r($cols[1].$data); Am I going about this wrong by using an associative array? Hi guys, I'm working on a project and I can't wrap my head around on a calculation that needs to be done on a multidimensional array. Quick background, it's a hotel benchmarking tool and I need to calculate the market penetration index (MPI). I have an array with 3 main arrays. First 2 are the hotels which are being compared and the last one is the MPI array. Each array contains an array for every month the user selects. Inside THAT array is data that needs to be used for calculations. Here is an example: Code: [Select] Array ( [Competitive set] => Array ( [Sep 11] => Array ( [0] => Array ( [minmonth] => 2011-09-01 [maxmonth] => 2011-09-01 [nrcheck] => 13 [data] => 67.6 ) ) [Oct 11] => Array ( [0] => Array ( [minmonth] => 2011-10-01 [maxmonth] => 2011-10-01 [nrcheck] => 13 [data] => 63.6 ) ) [Nov 11] => Array ( [0] => Array ( [minmonth] => 2011-11-01 [maxmonth] => 2011-11-01 [nrcheck] => 13 [data] => 59.2 ) ) [Dec 11] => Array ( [0] => Array ( [minmonth] => 2011-12-01 [maxmonth] => 2011-12-01 [nrcheck] => 13 [data] => 54.6 ) ) ) [Test] => Array ( [Sep 11] => Array ( [0] => Array ( [minmonth] => 2011-09-01 [maxmonth] => 2011-09-01 [nrcheck] => 89 [data] => 71.5 ) ) [Oct 11] => Array ( [0] => Array ( [minmonth] => 2011-10-01 [maxmonth] => 2011-10-01 [nrcheck] => 89 [data] => 67.0 ) ) [Nov 11] => Array ( [0] => Array ( [minmonth] => 2011-11-01 [maxmonth] => 2011-11-01 [nrcheck] => 91 [data] => 63.1 ) ) [Dec 11] => Array ( [0] => Array ( [minmonth] => 2011-12-01 [maxmonth] => 2011-12-01 [nrcheck] => 89 [data] => 57.5 ) ) ) [MPI] => Array ( [Sep 11] => Array ( [0] => Array ( [minmonth] => 2011-09-01 [maxmonth] => 2011-09-01 [nrcheck] => 89 [data] => 71.5 ) ) [Oct 11] => Array ( [0] => Array ( [minmonth] => 2011-10-01 [maxmonth] => 2011-10-01 [nrcheck] => 89 [data] => 67.0 ) ) [Nov 11] => Array ( [0] => Array ( [minmonth] => 2011-11-01 [maxmonth] => 2011-11-01 [nrcheck] => 91 [data] => 63.1 ) ) [Dec 11] => Array ( [0] => Array ( [minmonth] => 2011-12-01 [maxmonth] => 2011-12-01 [nrcheck] => 89 [data] => 57.5 ) ) ) ) Currently the 'data' for MPI is wrong. That needs to become the data of the first array divided by the data of the second array and multiplied by 100 (percentage). How would I go about doing that? The foreach loops are a bit too big for me on this one. Hi I was wondering if somebody could give me some help. I have a form with the following table for users to input <td width="118" style="text-align: left"><input type="text" name="item1cost"></td> <td width="118" style="text-align: left"><input type="text" name="item1Charge"></td> <td width="118" style="text-align: left"><input type="text" name="item1sum""></td> is there a way to have the 3rd field auto populated by calculations made from the data a user puts in the 1st and 2nd field ? The calculation i am actually looking for i can explain easier in excel terms Lets say item1cost is in A2 Item1charge is in B2 Item1sum is in C3
A3 would be the cell i want populating with the calculation of any help would be greatly appreciated thanks
// I am trying to calculate the number of days between dates and have a major problem. When I try the example below, it gives me exactly 201 days, yet the dates have different times, meaning that a full day is impossible. If it matters, I am testing via xampp 1.7.3 with php version 5.3.1 with Windows XP. Can anyone explain what I am doing wrong. Can daylight savings play a role? $frmritedate7116 = strtotime('2010-12-13 23:00'); $frmritedate7156 = strtotime('2010-05-27 00:00'); // $frmritedate7251 = $frmritedate7156 - $frmritedate7116; // // 1274943600-1292310000=-17366400 // 86400 seconds in a day ( 201.00 ) // // // |