-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlite2dss.py
More file actions
94 lines (75 loc) · 2.49 KB
/
sqlite2dss.py
File metadata and controls
94 lines (75 loc) · 2.49 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
85
86
87
88
89
90
91
92
93
94
# name=sqlite3-dss
# displayinmenu=true
# displaytouser=true
# displayinselector=true
from hec.script import *
from hec.heclib.dss import *
from hec.heclib.util import *
from hec.io import *
import java
import sys
from java.lang import Class
from java.sql import DriverManager, SQLException
###
DATABASE = "W:/Balaton/CDF/netcdf_import.db"
JDBC_URL = "jdbc:sqlite:%s" % DATABASE
JDBC_DRIVER = "org.sqlite.JDBC"
TBL_QUERY = '''SELECT * FROM dss_precip'''
###
def getConnection(jdbc_url, driverName):
try:
Class.forName(driverName).newInstance()
except Exception, msg:
print msg
sys.exit(-1)
try:
dbConn = DriverManager.getConnection(jdbc_url)
except SQLException, msg:
print msg
sys.exit(-1)
return dbConn
###
class prettyfloat(float):
def __repr__(self):
return "%0.3f" % self
try :
try :
myDss = HecDss.open("W:/Balaton/CDF/Balaton.dss")
tsc = TimeSeriesContainer()
loc = 0
dbConn = getConnection(JDBC_URL, JDBC_DRIVER)
stmt = dbConn.createStatement()
rSet = stmt.executeQuery(TBL_QUERY)
while rSet.next():
strdate = rSet.getString("datum")
strtime = rSet.getString("idopont")
fltval = rSet.getString("Ertek")
intcell = rSet.getString("cellid")
if loc <> intcell:
loc = intcell
vals = []
cnt = 0
vals.append(fltval)
cnt += 1
if cnt == 192:
start = HecTime("29MAR2013", "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()