Jump to content

Creating New Data from Variable Calculation


Texan78

Recommended Posts

Hello, forgive me if I didn't title this properly. I will try to make this short and sweet and explain it the best I can. I have a script I wrote that uses SimpleXML to parse data and that part works fine. Only problem is the data is kind of construed from the XML feed and I need to convert it to a more real world calculation. The script parses XML for lake level data. The problem is it returns conservation pool levels. The problem with that is lakes are not 400+ feet deep. As it is set up now the XML contains full pool and the current level. From that I display the full pool and the current levels. It then takes the full pool minus the current level to create two new variables, departure I.E. how low or high it is over full pool, then also create % full. The calculations are fine but, since it is basing it off conservation pool I need to translate this to display it in a more known way. What I am wanting to do is hard set the variable for full pool for the actual lake depth. I still need to use the full pool variable to calculate the rest even though I won't be showing that data. So full pool - minus current level to create the departure as it does. Then take the departure variable that was created and subtract/add it from the hard set lake depth to give me the actual new depth of the lake.

 

I.E.

 

$a +/- $b = $c

 

then

 

$c +/- $d = $e

 

I hope this makes sense. What I am trying to do is really simple. I am just not good at really explaining things and trying to comprehend how this needs to be laid out and the logic for it. If you need more info or the code I am working with  please let me know. So how could I go about doing this?

 

-Thanks

Edited by Texan78
Link to comment
Share on other sites

Here is the main code that I am using that might make it easier to understand and might make it easier to explain. 

 

From the code below, I need to calculate $LRH_bankfull & $LRH_current which it does now to which gives me the difference, LRH_calcLevel($LRH_current, $LRH_bankfull);

 

I need it to take the output from LRH_calcLevel and calculate it with $LRH_totalDepth to give me the difference and create a new output from that calculation to give me a new variable that I can display. 

 

So LRH_calcLevel +/- $LRH_totalDepth = $LRH_actualCurrent

//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);
Edited by Texan78
Link to comment
Share on other sites

Well dang, it won't let me edit. This will make it even easier. Reference the code above and here is the link to the script. http://www.mesquiteweather.net/inc-lake-levels.php Just focus on the first lake, Ray Hubbard. 

 

I need to take the variable that is shown for Departure from the link above which is LRH_calcLevel($LRH_current, $LRH_bankfull); and calculate it with Normal Level from the link above which is, $LRH_totalDepth to give me a new variable with data.

 

I.E. LRH_calcLevel($LRH_current, $LRH_bankfull); +/- $LRH_totalDepth = $newVar

 

How would I do this?

 

-Thanks

Edited by Texan78
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.