#from hec.script     import * 
from hec.script     import ResSim, Plot, MessageBox
from hec.heclib.dss import HecDss

#
# Get info from the current active run
#
module = ResSim.getCurrentModule()
if str(module) != "Simulation" :
	MessageBox("Must be in Simulation module", "Error")
simulation = module.getSimulation()
simulationRun = module.getActiveRun()
runID = simulationRun.getKey()

lookbackTime = simulation.getLookbackDateString()
startTime = simulation.getStartDateString()   
endTime = simulation.getEndDateString()     
#
# Set up info to read from DSS files
#
simDssFilename  = simulation.getOutputDSSFilePath()
inflowPathname  = "//CRAZY MOUNTAIN-POOL/FLOW-IN//1HOUR/%s/" % runID
outflowPathname = "//CRAZY MOUNTAIN-POOL/FLOW-OUT//1HOUR/%s/" % runID

pctDssFilename  = simulationRun.makeAbsolutePathFromWatershed("shared/ventura.dss")
pct25Pathname   = "//CRAZY MOUNTAIN/FLOW-RES IN-P25//1HOUR//"
pct50Pathname   = "//CRAZY MOUNTAIN/FLOW-RES IN-P50//1HOUR//"
#
# Read the time series from DSS files
#
simDssFile = HecDss.open(simDssFilename)
simDssFile.setTimeWindow(startTime, endTime)
inflowData = simDssFile.get(inflowPathname)
outflowData = simDssFile.get(outflowPathname)
simDssFile.done()
pctDssFile = HecDss.open(pctDssFilename)
pctDssFile.setTimeWindow(startTime, endTime)
pct25Data = pctDssFile.get(pct25Pathname)
pct50Data = pctDssFile.get(pct50Pathname)
pctDssFile.done()
#
# Create a plot with the time series
#
plot = Plot.newPlot("Crazy Mountain Custom Plot - %s" % runID)
plot.addData(inflowData)
plot.addData(outflowData)
plot.addData(pct25Data)
plot.addData(pct50Data)
plot.showPlot()
#
# Customize the inflow curve
#
inflowCurve = plot.getCurve(inflowData)
inflowCurve.setLineColor("green")
inflowCurve.setLineStyle("solid")
plot.setLegendLabelText(inflowData, "Crazy Mountain Inflow")
#
# Customize the outflow curve
#
outflowCurve = plot.getCurve(inflowData)
outflowCurve.setLineColor("red")
outflowCurve.setLineStyle("solid")
plot.setLegendLabelText(outflowData, "Crazy Mountain Outflow")
#
# Customize the 25th percentile curve
#
pct25Curve = plot.getCurve(pct25Data)
pct25Curve.setLineColor("darkyellow")
pct25Curve.setLineStyle("dash")
pct25Curve.setFillType("below")
pct25Curve.setFillPattern("diagonal cross")
pct25Curve.setFillColor(pct25Curve.getLineColorString())
plot.setLegendLabelText(pct25Data, "25th Percentile Historical Inflow")
#
# Customize the 50th percentile curve
#
pct50Curve = plot.getCurve(pct50Data)
pct50Curve.setLineColor("darkpink")
pct50Curve.setLineStyle("dash")
pct50Curve.setFillType("above")
pct50Curve.setFillPattern("diagonal cross")
pct50Curve.setFillColor(pct50Curve.getLineColorString())
plot.setLegendLabelText(pct50Data, "50th Percentile Historical Inflow")
#
# Customize the plot title and legend
#
plot.setLegendLocation("Bottom")
plot.setPlotTitleText("Crazy Mountain Operations - %s" % runID)
plot.setPlotTitleVisible(True)
