-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdss.py
More file actions
84 lines (67 loc) · 2.16 KB
/
dss.py
File metadata and controls
84 lines (67 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import sys
from hec.script import *
from hec.heclib.dss import *
from hec.heclib.util import *
from hec.io import *
from com.ziclix.python.sql import zxJDBC
###
PATH = "C:/Works/"
DATABASE = "forecast.db"
DSS_FILE = "Balaton-2014.dss"
COUNTER = 1367
JDBC_URL = "jdbc:sqlite:%s%s" % (PATH, DATABASE)
JDBC_DRIVER = "org.sqlite.JDBC"
QRY_PRECIP = "SELECT * FROM dss_precip"
###
def getConnection(jdbc_url, driverName):
try:
dbConn = zxJDBC.connect(jdbc_url, None, None, driverName)
except zxJDBC.DatabaseError, msg:
print msg
sys.exit(-1)
return dbConn
###
class prettyfloat(float):
def __repr__(self):
return "%0.3f" % self
try :
try :
myDss = HecDss.open("%s%s" % (PATH, DSS_FILE))
tsc = TimeSeriesContainer()
loc = 0
dbConn = getConnection(JDBC_URL, JDBC_DRIVER)
stmt = dbConn.createStatement()
rSet = stmt.executeQuery(QRY_PRECIP)
while rSet.next():
strdate = rSet.getString("datum")
strtime = rSet.getString("idopont")
fltval = rSet.getString("mm")
intcell = rSet.getString("cella")
if loc <> intcell:
loc = intcell
vals = []
cnt = 0
vals.append(fltval)
cnt += 1
if cnt == COUNTER:
start = HecTime("01AUG2014", "0000")
tsc.fullName = "/BALATON/%s/PRECIP-INC//1HOUR/OBS/" % loc
tsc.interval = 60
precips = map(prettyfloat, vals)
times = []
for value in precips:
times.append(start.value())
start.add(tsc.interval)
tsc.times = times
tsc.values = precips
tsc.numberValues = len(precips)
tsc.units = "MM"
tsc.type = "PER-CUM"
myDss.put(tsc)
except Exception, e :
MessageBox.showError(' '.join(e.args), "Python Error")
except java.lang.Exception, e :
MessageBox.showError(e.getMessage(), "Error")
finally :
stmt.close()
dbConn.close()