# no returns values are used by the compute from this script.
#
# variables that are available to this script during the compute:
# currentVariable - the StateVariable that holds this script
# currentRuntimestep - the current RunTime step 
# network - the ResSim network

# The following represents an undefined value in a time series
# Constants.UNDEFINED

# add your code here

# to set the StateVariable's value use 
# currentVariable.setValue(currentRuntimestep, newValue)
# where newValue is the value you want to set it to.


from hec.script import Constants

#
# Get elevations for the current and previous 2 time steps
#
elevTs = network.getTimeSeries("Reservoir","Folsom", "Pool", "Elev")
elevNow = elevTs.getCurrentValue(currentRuntimestep)
elevPrev = elevTs.getPreviousValue(currentRuntimestep)
elevBefore = elevTs.getLaggedValue(currentRuntimestep, 2)
#
# Compute and set the value of the current state variable (ESRD1956_Pool_RateOfRise)
#
timeStepHours = currentRuntimestep.getTimeStepMinutes() / 60
rateOfRise = (elevNow - elevBefore) / (2 * timeStepHours) # rate of rise is in feet / hour
currentVariable.setValue(currentRuntimestep, rateOfRise)
#
# Set the value of the ESRD1956_Pool_RisingCondition state variable
#
isRising = elevNow > elevBefore
network.getStateVariable("ESRD1956_Pool_RisingCondition").setValue(currentRuntimestep, isRising)