Skip to content

Commit 783e9d7

Browse files
authored
Feature/jpype script migration (#23)
* migrate Java/Jython focused REGI Headless to regi-python via jPype * migrate script examples from Jython to regi-python library remove all redundant example scripts * add smoke testing now that script migration is complete
1 parent 8923b91 commit 783e9d7

88 files changed

Lines changed: 3737 additions & 5571 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

district-scripts/SWF/GateFlow5.py

Lines changed: 206 additions & 196 deletions
Large diffs are not rendered by default.

district-scripts/SWF/GateFlow_MonthlyPumpBackFill.py

Lines changed: 212 additions & 202 deletions
Large diffs are not rendered by default.

district-scripts/SWF/GateFlow_PumpBackFill.py

Lines changed: 196 additions & 186 deletions
Large diffs are not rendered by default.
Lines changed: 85 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,89 @@
1-
# the java Calendar class is used to create java Date objects
2-
from java.util import Calendar
3-
from usace.rowcps.headless import LoggingOptions
4-
5-
# Description of: LoggingOptions.setDbMessageLevel(int level)
6-
#
7-
# Adds Time Series logging messages in the OracleTimeSeriesDaoImpl. Recommended
8-
# level is 2, as this provides basic information about the time series
9-
# retrieval/storage.
10-
#
11-
# Message Level | Description
12-
# --------------|-------------------------------------------------------------------------------------------------------------------------------|
13-
# <=0 | Default value, does not do anything. Lower values do not change behavior. |
14-
# 1 | Logs message when no data is found. Logs message when data is found, how much was retrieved or stored, and how long it took. |
15-
# 2 | Adds message with name of time series, and the units to retrieve/store. |
16-
# 3 | Adds message with the current time. |
17-
# 4 | Adds message with first 10 dates and values from each time series. |
18-
# >4 | Same as 4, but shows all values retrieved from each time series. Higher values do not change behavior. |
19-
# --------------|-------------------------------------------------------------------------------------------------------------------------------|
20-
21-
LoggingOptions.setDbMessageLevel(2)
22-
23-
24-
# Description of: LoggingOptions.setMetricsEnabled(boolean value)
25-
#
26-
# Enables or disables the storage of REGI's Metric data pertaining to the
27-
# performance of the application. This is incredibly helpful for identifying
28-
# issues where the application takes an excessive amount of time to operate.
29-
#
30-
# Metrics also log the location of the files as an INFO message if they are
31-
# enabled.
32-
#
33-
# By default, Metrics are disabled.
34-
35-
# LoggingOptions.setMetricsEnabled(True)
36-
37-
# this gets a scriptable Gate Settings object
38-
gateSettings = registry.getCalculation(1.0, "Gate Settings")
39-
40-
# configure the start calendar
41-
startCal = Calendar.getInstance()
42-
#startCal.clear()
43-
startCal.add(Calendar.DAY_OF_MONTH, -5)
44-
startCal.set(Calendar.HOUR, 0) ######use Calendar.HOUR_OF_DAY
45-
startCal.set(Calendar.MINUTE, 0)
46-
startCal.set(Calendar.SECOND, 0)
47-
startCal.set(Calendar.MILLISECOND, 0)
48-
# create a java Calendar object that will be used to create the end Date
49-
endCal = Calendar.getInstance()
50-
endCal.add(Calendar.DAY_OF_MONTH, 1)
51-
endCal.set(Calendar.HOUR, 0)
52-
endCal.set(Calendar.MINUTE, 0)
53-
endCal.set(Calendar.SECOND, 0)
54-
endCal.set(Calendar.MILLISECOND, 0)
55-
#endCal.clear()
56-
#endCal.set(Calendar.YEAR, 2016)
57-
#endCal.set(Calendar.MONTH, 4)
58-
59-
60-
# gateSettings contains four callable methods
61-
# void createGateSettings(String officeId, String locationStr, Date startDate, Date end) throws Exception;
62-
# void createGateSettingsGroup(String officeId, String locationStr, Date startDate, Date end, String groupId) throws Exception;
63-
# void createGateSettingsOutlet(String officeId, String locationStr, Date startDate, Date end, String outletId) throws Exception;
64-
# void createGateSettingsOutletFromTs(String officeId, String locationStr, Date startDate, Date end, String outletId, String tsId) throws Exception;
65-
66-
gateSettings.createGateSettingsOutletFromTs("SWF", "FFLT2", startCal.getTime(), endCal.getTime(), "Release", "FFLT2.Opening.Const.0.0.Rev-TRWD-Decodes" )
67-
gateSettings.createGateSettingsOutletFromTs("SWF", "EAMT2", startCal.getTime(), endCal.getTime(), "Release", "EAMT2.Opening.Const.0.0.Rev-TRWD-Decodes" )
68-
gateSettings.createGateSettingsOutletFromTs("SWF", "TRNT2", startCal.getTime(), endCal.getTime(), "Release", "TRNT2.Opening.Const.0.0.Rev-TRWD-Decodes" )
69-
gateSettings.createGateSettingsOutletFromTs("SWF", "BPRT2", startCal.getTime(), endCal.getTime(), "Release", "BPRT2.Opening.Const.0.0.Rev-TRWD-Decodes" )
70-
gateSettings.createGateSettingsOutletFromTs("SWF", "LLST2", startCal.getTime(), endCal.getTime(), "Release", "LLST2.Opening.Const.0.0.Rev-BRA-Decodes" )
71-
gateSettings.createGateSettingsOutletFromTs("SWF", "GBYT2", startCal.getTime(), endCal.getTime(), "Release", "GBYT2.Opening.Const.0.0.Rev-BRA-Decodes" )
72-
gateSettings.createGateSettingsOutletFromTs("SWF", "PSMT2", startCal.getTime(), endCal.getTime(), "Release", "PSMT2.Opening.Const.0.0.Rev-BRA-Decodes" )
73-
gateSettings.createGateSettingsOutletFromTs("SWF", "MSDT2", startCal.getTime(), endCal.getTime(), "Release", "MSDT2.Opening.Const.0.0.Rev-LCRA-Decodes" )
74-
gateSettings.createGateSettingsOutletFromTs("SWF", "FRHT2", startCal.getTime(), endCal.getTime(), "Release", "FRHT2.Opening.Const.0.0.Raw-Observer" )
75-
gateSettings.createGateSettingsOutletFromTs("SWF", "GPET2", startCal.getTime(), endCal.getTime(), "Release", "GPET2.Opening.Const.0.0.Raw-Observer" )
1+
from regi_python import regi_session, run_headless
762

773

4+
def run_calculations(registry):
5+
# Java imports must happen after regi_session starts the JVM.
6+
# the java Calendar class is used to create java Date objects
7+
from java.util import Calendar
8+
from usace.rowcps.headless import LoggingOptions
789

10+
# Description of: LoggingOptions.setDbMessageLevel(int level)
11+
#
12+
# Adds Time Series logging messages in the OracleTimeSeriesDaoImpl. Recommended
13+
# level is 2, as this provides basic information about the time series
14+
# retrieval/storage.
15+
#
16+
# Message Level | Description
17+
# --------------|-------------------------------------------------------------------------------------------------------------------------------|
18+
# <=0 | Default value, does not do anything. Lower values do not change behavior. |
19+
# 1 | Logs message when no data is found. Logs message when data is found, how much was retrieved or stored, and how long it took. |
20+
# 2 | Adds message with name of time series, and the units to retrieve/store. |
21+
# 3 | Adds message with the current time. |
22+
# 4 | Adds message with first 10 dates and values from each time series. |
23+
# >4 | Same as 4, but shows all values retrieved from each time series. Higher values do not change behavior. |
24+
# --------------|-------------------------------------------------------------------------------------------------------------------------------|
7925

26+
LoggingOptions.setDbMessageLevel(2)
27+
28+
29+
# Description of: LoggingOptions.setMetricsEnabled(boolean value)
30+
#
31+
# Enables or disables the storage of REGI's Metric data pertaining to the
32+
# performance of the application. This is incredibly helpful for identifying
33+
# issues where the application takes an excessive amount of time to operate.
34+
#
35+
# Metrics also log the location of the files as an INFO message if they are
36+
# enabled.
37+
#
38+
# By default, Metrics are disabled.
39+
40+
# LoggingOptions.setMetricsEnabled(True)
41+
42+
# this gets a scriptable Gate Settings object
43+
gateSettings = registry.getCalculation(1.0, "Gate Settings")
44+
45+
# configure the start calendar
46+
startCal = Calendar.getInstance()
47+
#startCal.clear()
48+
startCal.add(Calendar.DAY_OF_MONTH, -5)
49+
startCal.set(Calendar.HOUR, 0) ######use Calendar.HOUR_OF_DAY
50+
startCal.set(Calendar.MINUTE, 0)
51+
startCal.set(Calendar.SECOND, 0)
52+
startCal.set(Calendar.MILLISECOND, 0)
53+
# create a java Calendar object that will be used to create the end Date
54+
endCal = Calendar.getInstance()
55+
endCal.add(Calendar.DAY_OF_MONTH, 1)
56+
endCal.set(Calendar.HOUR, 0)
57+
endCal.set(Calendar.MINUTE, 0)
58+
endCal.set(Calendar.SECOND, 0)
59+
endCal.set(Calendar.MILLISECOND, 0)
60+
#endCal.clear()
61+
#endCal.set(Calendar.YEAR, 2016)
62+
#endCal.set(Calendar.MONTH, 4)
63+
64+
65+
# gateSettings contains four callable methods
66+
# void createGateSettings(String officeId, String locationStr, Date startDate, Date end) throws Exception;
67+
# void createGateSettingsGroup(String officeId, String locationStr, Date startDate, Date end, String groupId) throws Exception;
68+
# void createGateSettingsOutlet(String officeId, String locationStr, Date startDate, Date end, String outletId) throws Exception;
69+
# void createGateSettingsOutletFromTs(String officeId, String locationStr, Date startDate, Date end, String outletId, String tsId) throws Exception;
70+
71+
gateSettings.createGateSettingsOutletFromTs("SWF", "FFLT2", startCal.getTime(), endCal.getTime(), "Release", "FFLT2.Opening.Const.0.0.Rev-TRWD-Decodes" )
72+
gateSettings.createGateSettingsOutletFromTs("SWF", "EAMT2", startCal.getTime(), endCal.getTime(), "Release", "EAMT2.Opening.Const.0.0.Rev-TRWD-Decodes" )
73+
gateSettings.createGateSettingsOutletFromTs("SWF", "TRNT2", startCal.getTime(), endCal.getTime(), "Release", "TRNT2.Opening.Const.0.0.Rev-TRWD-Decodes" )
74+
gateSettings.createGateSettingsOutletFromTs("SWF", "BPRT2", startCal.getTime(), endCal.getTime(), "Release", "BPRT2.Opening.Const.0.0.Rev-TRWD-Decodes" )
75+
gateSettings.createGateSettingsOutletFromTs("SWF", "LLST2", startCal.getTime(), endCal.getTime(), "Release", "LLST2.Opening.Const.0.0.Rev-BRA-Decodes" )
76+
gateSettings.createGateSettingsOutletFromTs("SWF", "GBYT2", startCal.getTime(), endCal.getTime(), "Release", "GBYT2.Opening.Const.0.0.Rev-BRA-Decodes" )
77+
gateSettings.createGateSettingsOutletFromTs("SWF", "PSMT2", startCal.getTime(), endCal.getTime(), "Release", "PSMT2.Opening.Const.0.0.Rev-BRA-Decodes" )
78+
gateSettings.createGateSettingsOutletFromTs("SWF", "MSDT2", startCal.getTime(), endCal.getTime(), "Release", "MSDT2.Opening.Const.0.0.Rev-LCRA-Decodes" )
79+
gateSettings.createGateSettingsOutletFromTs("SWF", "FRHT2", startCal.getTime(), endCal.getTime(), "Release", "FRHT2.Opening.Const.0.0.Raw-Observer" )
80+
gateSettings.createGateSettingsOutletFromTs("SWF", "GPET2", startCal.getTime(), endCal.getTime(), "Release", "GPET2.Opening.Const.0.0.Raw-Observer" )
81+
82+
83+
84+
85+
86+
87+
if __name__ == "__main__":
88+
with regi_session():
89+
run_headless(run_calculations)
Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,59 @@
1-
# the java Calendar class is used to create java Date objects
2-
from java.util import Calendar
3-
from java.util import TimeZone
4-
5-
6-
# this gets a ScriptableInflow instance.
7-
inflowCalc = registry.getCalculation(1.0, "Inflow")
8-
9-
# configure the start calendar
10-
##startCal = Calendar.getInstance(TimeZone.getTimeZone('US/Central'))
11-
##
12-
##
13-
##startCal.clear()
14-
##startCal.set(Calendar.YEAR, 2018)
15-
##startCal.set(Calendar.MONTH, 11)
16-
##
17-
##endCal = Calendar.getInstance(TimeZone.getTimeZone('US/Central'))
18-
##endCal.clear()
19-
##endCal.set(Calendar.YEAR, 2019)
20-
##endCal.set(Calendar.MONTH, 0)
21-
##endCal.set(Calendar.DAY_OF_MONTH, 7)
22-
23-
startCal = Calendar.getInstance(TimeZone.getTimeZone('US/Central'))
24-
# startCal.clear()
25-
startCal.add(Calendar.DAY_OF_MONTH, -5)
26-
startCal.set(Calendar.HOUR_OF_DAY, 0)
27-
startCal.set(Calendar.MINUTE, 0)
28-
startCal.set(Calendar.SECOND, 0)
29-
startCal.set(Calendar.MILLISECOND, 0)
30-
# startCal.set(Calendar.YEAR, 2015)
31-
# startCal.set(Calendar.MONTH, 9)
32-
33-
# create a java Calendar object that will be used to create the end Date
34-
endCal = Calendar.getInstance(TimeZone.getTimeZone('US/Central'))
35-
# endCal.clear()
36-
endCal.add(Calendar.DAY_OF_MONTH, 1)
37-
endCal.set(Calendar.HOUR_OF_DAY, 0)
38-
endCal.set(Calendar.MINUTE, 0)
39-
endCal.set(Calendar.SECOND, 0)
40-
endCal.set(Calendar.MILLISECOND, 0)
41-
42-
locationList = ["WTYT2","JSPT2","TBLT2","SCLT2","TXKT2","BSLT2","JFNT2","CLDL1",
43-
"BPRT2","EAMT2","FLWT2","BNBT2","JPLT2","GPET2","RRLT2","LEWT2",
44-
"GPVT2","LVNT2","FRHT2","TRNT2","DAWT2","BDWT2","FFLT2","PSMT2",
45-
"GBYT2","ALAT2","ACTT2","PCTT2","BLNT2","STIT2","GGLT2","GNGT2",
46-
"SOMT2","LLST2","TBRT2","SAGT2","HORT2","MSDT2","SMCT2"]
47-
48-
for loc in locationList:
49-
inflowCalc.computeEvapAsFlow("SWF", loc, startCal.getTime(), endCal.getTime())
1+
from regi_python import regi_session, run_headless
2+
3+
4+
def run_calculations(registry):
5+
# Java imports must happen after regi_session starts the JVM.
6+
# the java Calendar class is used to create java Date objects
7+
from java.util import Calendar
8+
from java.util import TimeZone
9+
10+
11+
# this gets a ScriptableInflow instance.
12+
inflowCalc = registry.getCalculation(1.0, "Inflow")
13+
14+
# configure the start calendar
15+
##startCal = Calendar.getInstance(TimeZone.getTimeZone('US/Central'))
16+
##
17+
##
18+
##startCal.clear()
19+
##startCal.set(Calendar.YEAR, 2018)
20+
##startCal.set(Calendar.MONTH, 11)
21+
##
22+
##endCal = Calendar.getInstance(TimeZone.getTimeZone('US/Central'))
23+
##endCal.clear()
24+
##endCal.set(Calendar.YEAR, 2019)
25+
##endCal.set(Calendar.MONTH, 0)
26+
##endCal.set(Calendar.DAY_OF_MONTH, 7)
27+
28+
startCal = Calendar.getInstance(TimeZone.getTimeZone('US/Central'))
29+
# startCal.clear()
30+
startCal.add(Calendar.DAY_OF_MONTH, -5)
31+
startCal.set(Calendar.HOUR_OF_DAY, 0)
32+
startCal.set(Calendar.MINUTE, 0)
33+
startCal.set(Calendar.SECOND, 0)
34+
startCal.set(Calendar.MILLISECOND, 0)
35+
# startCal.set(Calendar.YEAR, 2015)
36+
# startCal.set(Calendar.MONTH, 9)
37+
38+
# create a java Calendar object that will be used to create the end Date
39+
endCal = Calendar.getInstance(TimeZone.getTimeZone('US/Central'))
40+
# endCal.clear()
41+
endCal.add(Calendar.DAY_OF_MONTH, 1)
42+
endCal.set(Calendar.HOUR_OF_DAY, 0)
43+
endCal.set(Calendar.MINUTE, 0)
44+
endCal.set(Calendar.SECOND, 0)
45+
endCal.set(Calendar.MILLISECOND, 0)
46+
47+
locationList = ["WTYT2","JSPT2","TBLT2","SCLT2","TXKT2","BSLT2","JFNT2","CLDL1",
48+
"BPRT2","EAMT2","FLWT2","BNBT2","JPLT2","GPET2","RRLT2","LEWT2",
49+
"GPVT2","LVNT2","FRHT2","TRNT2","DAWT2","BDWT2","FFLT2","PSMT2",
50+
"GBYT2","ALAT2","ACTT2","PCTT2","BLNT2","STIT2","GGLT2","GNGT2",
51+
"SOMT2","LLST2","TBRT2","SAGT2","HORT2","MSDT2","SMCT2"]
52+
53+
for loc in locationList:
54+
inflowCalc.computeEvapAsFlow("SWF", loc, startCal.getTime(), endCal.getTime())
55+
56+
57+
if __name__ == "__main__":
58+
with regi_session():
59+
run_headless(run_calculations)

0 commit comments

Comments
 (0)