Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 28 additions & 35 deletions district-scripts/SWF/GateFlow5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@


def run_calculations(registry):
from datetime import datetime, timedelta, timezone
from zoneinfo import ZoneInfo

# Java imports must happen after regi_session starts the JVM.
from java.util import Calendar
from java.util import TimeZone
from usace.rowcps.headless import LoggingOptions

def compute_All_Flowgroups(officeID, location, startCal, endCal):

def compute_All_Flowgroups(officeID, location, start_date, end_date):
# Takes in locations defined by user in group and computes all flow groups
try:
gateCalc.computeAll(officeID, location, startCal.getTime(), endCal.getTime())
gateCalc.computeAll(officeID, location, start_date, end_date)
except Exception as e:
print("Error Computing all Flow Groups at {0} {1}".format(officeID, location))
print(e)
print('')


def compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroup):
def compute_Single_Flowgroup(officeID, location, start_date, end_date, flowGroup):
try:
gateCalc.computeFlowGroup(officeID, location, startCal.getTime(), endCal.getTime(), "Flow.{0}.{1}".format(location, flowGroup))
gateCalc.computeFlowGroup(officeID, location, start_date, end_date, "Flow.{0}.{1}".format(location, flowGroup))
except Exception as e:
print("Error Computing Flow Group {0} at {1}".format(officeID, location))
print(e)
print('')

# #gateCalc.computeFlowGroup("SWF", "ACTT2", startCal.getTime(), endCal.getTime(), "Flow.ACTT2.Pump_Out_Total")
# #gateCalc.computeFlowGroup("SWF", "ACTT2", start_date, end_date, "Flow.ACTT2.Pump_Out_Total")
# Description of: LoggingOptions.setDbMessageLevel(int level)
#
# Adds Time Series logging messages in the OracleTimeSeriesDaoImpl. Recommended
Expand Down Expand Up @@ -65,30 +67,21 @@ def compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroup):
# this retrieves a Gate Flow calculation object
gateCalc = registry.getCalculation(1.0, "Gate Flow")

# Time zone must be set because the Solaris time zone is UTC
timeZone = TimeZone.getTimeZone("US/Central")
# the gate flow calculations requires a start and end time.
# here we create a java Calendar object that will be used to create the start Date
startCal = Calendar.getInstance(timeZone)
# startCal.clear()
startCal.add(Calendar.DAY_OF_MONTH, -8)
startCal.set(Calendar.HOUR_OF_DAY, 0)
startCal.set(Calendar.MINUTE, 0)
startCal.set(Calendar.SECOND, 0)
startCal.set(Calendar.MILLISECOND, 0)
# startCal.set(Calendar.YEAR, 2015)
# startCal.set(Calendar.MONTH, 9)

# create a java Calendar object that will be used to create the end Date
endCal = Calendar.getInstance(timeZone)
# endCal.clear()
endCal.add(Calendar.DAY_OF_MONTH, 1)
endCal.set(Calendar.HOUR_OF_DAY, 0)
endCal.set(Calendar.MINUTE, 0)
endCal.set(Calendar.SECOND, 0)
endCal.set(Calendar.MILLISECOND, 0)
# endCal.set(Calendar.YEAR, 2015)
# endCal.set(Calendar.MONTH, 11)
# Time zone must be set explicitly because the JVM's default timezone is
# UTC, not the district's local time.
central = ZoneInfo("America/Chicago")

# start of the day 8 days ago, local midnight
start_date_dt = (datetime.now(central) - timedelta(days=8)).replace(
hour=0, minute=0, second=0, microsecond=0
)
# end of today: tomorrow's local midnight
end_date_dt = start_date_dt + timedelta(days=9)
# Dates can be adjusted with normal datetime arithmetic/replace, e.g.:
# start_date_dt = start_date_dt.replace(year=2015, month=10) # month is 1-indexed here

start_date = start_date_dt.astimezone(timezone.utc)
end_date = end_date_dt.astimezone(timezone.utc)

officeID = "SWF"

Expand All @@ -98,7 +91,7 @@ def compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroup):
# projectId
# startDate
# endDate
# gateCalc.computeFlowGroup("SWF", "LEWT2", startCal.getTime(), endCal.getTime(), "Flow.LEWT2.ConduitGate_Total")
# gateCalc.computeFlowGroup("SWF", "LEWT2", start_date, end_date, "Flow.LEWT2.ConduitGate_Total")
# By setting the following parameter to True, the following flow groups in the list FlowGroupList will all be calculated. Items can be commented out
# or commented back in individually. To turn this option off, set the following parameter to False. User can determine which flow group they want to calculate

Expand Down Expand Up @@ -189,10 +182,10 @@ def compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroup):
if calculateAllFlowGroups:
for location in FlowGroupList:
print("Now Running", location, "GROUP")
compute_All_Flowgroups(officeID, location, startCal, endCal)
compute_All_Flowgroups(officeID, location, start_date, end_date)

compute_Single_Flowgroup(officeID, "JSPT2", startCal, endCal, "Turbine1")
compute_Single_Flowgroup(officeID, "JSPT2", startCal, endCal, "Turbine2")
compute_Single_Flowgroup(officeID, "JSPT2", start_date, end_date, "Turbine1")
compute_Single_Flowgroup(officeID, "JSPT2", start_date, end_date, "Turbine2")


#if calculateSingleFlowGroups:
Expand Down
82 changes: 33 additions & 49 deletions district-scripts/SWF/GateFlow_MonthlyPumpBackFill.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@


def run_calculations(registry):
from datetime import datetime, timezone
from zoneinfo import ZoneInfo

# Java imports must happen after regi_session starts the JVM.
from java.util import Calendar
from usace.rowcps.headless import LoggingOptions

def compute_All_Flowgroups(officeID, location, startCal, endCal):

def compute_All_Flowgroups(officeID, location, start_date, end_date):
# Takes in locations defined by user in group and computes all flow groups
try:
gateCalc.computeAll(officeID, location, startCal.getTime(), endCal.getTime())
gateCalc.computeAll(officeID, location, start_date, end_date)
except Exception as e:
print("Error Computing all Flow Groups at {0} {1}".format(officeID, location))
print(e)
print('')


def compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroup):
def compute_Single_Flowgroup(officeID, location, start_date, end_date, flowGroup):
try:
gateCalc.computeFlowGroup(officeID, location, startCal.getTime(), endCal.getTime(), "Flow.{0}.{1}".format(location, flowGroup))
gateCalc.computeFlowGroup(officeID, location, start_date, end_date, "Flow.{0}.{1}".format(location, flowGroup))
except Exception as e:
print("Error Computing Flow Group {0} at {1}".format(officeID, location))
print(e)
print('')

# #gateCalc.computeFlowGroup("SWF", "ACTT2", startCal.getTime(), endCal.getTime(), "Flow.ACTT2.Pump_Out_Total")
# #gateCalc.computeFlowGroup("SWF", "ACTT2", start_date, end_date, "Flow.ACTT2.Pump_Out_Total")
# Description of: LoggingOptions.setDbMessageLevel(int level)
#
# Adds Time Series logging messages in the OracleTimeSeriesDaoImpl. Recommended
Expand Down Expand Up @@ -64,41 +67,22 @@ def compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroup):
# this retrieves a Gate Flow calculation object
gateCalc = registry.getCalculation(1.0, "Gate Flow")

# the gate flow calculations requires a start and end time.
# here we create a java Calendar object that will be used to create the start Date
startCal = Calendar.getInstance()
# startCal.clear()
startCal.set(Calendar.HOUR, 0) ### set startCal hour/minute/second/millisecond to 0 for midnight
startCal.set(Calendar.MINUTE, 0)
startCal.set(Calendar.SECOND, 0)
startCal.set(Calendar.MILLISECOND, 0)
startCal.add(Calendar.YEAR, -1) ### go back one year to today
startCal.set(Calendar.MONTH, 9) ### change month to month 9 (october)
startCal.set(Calendar.DAY_OF_MONTH, 1) ### change start date to start of the month day 1

getYear = startCal.get(Calendar.YEAR) ### get value of startCal year/month/day to print and to initilize endCal
getMonth = startCal.get(Calendar.MONTH)
getDayofMonth = startCal.get(Calendar.DAY_OF_MONTH)

# create a java Calendar object that will be used to create the end Date
endCal = Calendar.getInstance()
# endCal.clear()
endCal.set(Calendar.HOUR, 0) ### set endCal hour/minute/second/millisecond to 0 for midnight
endCal.set(Calendar.MINUTE, 0)
endCal.set(Calendar.SECOND, 0)
endCal.set(Calendar.MILLISECOND, 0)
###endCal will be set to current date unless reset with the following 4 lines
#endCal.set(Calendar.YEAR, getYear) ### set endCal year same as startCal
#endCal.set(Calendar.MONTH, getMonth) ### set endCal month same as startCal
#endCal.add(Calendar.MONTH, 12) ##add 1 month to startcal month
#endCal.set(Calendar.DAY_OF_MONTH, 1) ### set to day one

### time window starts 01Feb2019(one year ago) and ends 01Mar2019 (one year ago plus one month)

getEndDay = endCal.get(Calendar.DAY_OF_MONTH)
getEndYear = endCal.get(Calendar.YEAR)
getEndMonth = endCal.get(Calendar.MONTH)
# Time zone must be set explicitly because the JVM's default timezone is
# UTC, not the district's local time. (The previous Calendar.getInstance()
# calls here had no explicit timezone and silently depended on whatever
# timezone the host happened to be configured with.)
central = ZoneInfo("America/Chicago")
today = datetime.now(central)

# start: October 1st of last year, at midnight
start_date_dt = today.replace(
year=today.year - 1, month=10, day=1, hour=0, minute=0, second=0, microsecond=0
)
# end: today, at midnight
end_date_dt = today.replace(hour=0, minute=0, second=0, microsecond=0)

start_date = start_date_dt.astimezone(timezone.utc)
end_date = end_date_dt.astimezone(timezone.utc)

officeID = "SWF"

Expand All @@ -108,7 +92,7 @@ def compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroup):
# projectId
# startDate
# endDate
# gateCalc.computeFlowGroup("SWF", "LEWT2", startCal.getTime(), endCal.getTime(), "Flow.LEWT2.ConduitGate_Total")
# gateCalc.computeFlowGroup("SWF", "LEWT2", start_date, end_date, "Flow.LEWT2.ConduitGate_Total")
# By setting the following parameter to True, the following flow groups in the list FlowGroupList will all be calculated. Items can be commented out
# or commented back in individually. To turn this option off, set the following parameter to False. User can determine which flow group they want to calculate
# by changing the "flowGroup" variable.
Expand Down Expand Up @@ -191,17 +175,17 @@ def compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroup):
if calculateSingleFlowGroups:
for location in locationList:
print("Now Running", location, "SINGLE")
#compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroupGate)
#compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroupTotal)
#compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroupTurbine)
#compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroupUncontrol)
#compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroupPumpOutBelow)
compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroupPumpOut)
compute_Single_Flowgroup(officeID, location, startCal, endCal, flowGroupPumpIn)
#compute_Single_Flowgroup(officeID, location, start_date, end_date, flowGroupGate)
#compute_Single_Flowgroup(officeID, location, start_date, end_date, flowGroupTotal)
#compute_Single_Flowgroup(officeID, location, start_date, end_date, flowGroupTurbine)
#compute_Single_Flowgroup(officeID, location, start_date, end_date, flowGroupUncontrol)
#compute_Single_Flowgroup(officeID, location, start_date, end_date, flowGroupPumpOutBelow)
compute_Single_Flowgroup(officeID, location, start_date, end_date, flowGroupPumpOut)
compute_Single_Flowgroup(officeID, location, start_date, end_date, flowGroupPumpIn)
if calculateAllFlowGroups:
for location in FlowGroupList:
print("Now Running", location, "GROUP")
#compute_All_Flowgroups(officeID, location, startCal, endCal)
#compute_All_Flowgroups(officeID, location, start_date, end_date)



Expand Down
Loading
Loading