Skip to content

Commit 9808392

Browse files
authored
Merge pull request #76 from ODM2/odmtools
Odmtools This PR: cleans up the inheritance of the models, there used to be duplicates of some of the data from the base class. removes calls to the ODM1.1.1 in the Session Factory Class Alters the db connection settings to prevent a connection from timing out when it has been open for a long period of time ( like through wofpy) adds better functionality for querying specimen datatypes through get related features, get results, and get result values. cleans up the update/delete/create functions. SQL alchemy keeps these simple, every function is the same, basically you send in the object you want to change/delete/add and it takes care of it for you. fleshes out some of the get queries. they were missing needed parameters, or were throwing errors. set up getResultValues to return a pandas dataframe, no matter what type of Result
2 parents dcb252f + a5e2970 commit 9808392

22 files changed

+866
-910
lines changed

Examples/Sample 1.1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#connection to the ODM1 database
1717
dbconnection.createConnection('mysql', 'jws.uwrl.usu.edu', 'odm', "ODM", "ODM123!!", 1.1),
1818
#connection to the ODM2 database
19-
dbconnection.createConnection('mysql', 'jws.uwrl.usu.edu', 'odm2', 'ODM', 'ODM123!!', 2.0)]
19+
dbconnection.createConnection('mssql', '(local)', 'odm2', 'ODM', 'odm', 2.0)]
2020

2121

2222
for conn in conns:
@@ -29,7 +29,7 @@
2929
print
3030

3131
odm1service = SeriesService(conn)
32-
odm1service.refreshDB(conn.version)
32+
3333
pp.pprint(conn)
3434

3535
print

Examples/Sample.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@
1818
# createconnection (dbtype, servername, dbname, username, password)
1919
# session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)#sqlite
2020
# session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')#mysql
21-
session_factory= dbconnection.createConnection('mssql', "(local)", "ODM2", "ODM", "odm")#win MSSQL
21+
22+
# session_factory= dbconnection.createConnection('mssql', "(local)", "ODM2", "ODM", "odm")#win MSSQL
23+
2224
# session_factory= dbconnection.createConnection('mssql', "arroyoodm2", "", "ODM", "odm")#mac/linux MSSQL
23-
# session_factory = dbconnection.createConnection('sqlite', '/Users/stephanie/DEV/ODM2/usecases/WOF_to_ODM2/ODM2.sqlite', 2.0)
25+
session_factory = dbconnection.createConnection('sqlite', '/Users/stephanie/DEV/YODA-Tools/tests/test_files/XL_specimen.sqlite', 2.0)
26+
27+
28+
29+
30+
31+
2432

2533

2634

2735

2836
#_session = session_factory.getSession()
2937
read = ReadODM2(session_factory)
30-
create =CreateODM2(session_factory)
31-
38+
create = CreateODM2(session_factory)
3239

3340

3441
# Run some basic sample queries.
@@ -58,7 +65,7 @@
5865
# Get all of the SamplingFeatures from the database that are Sites
5966
try:
6067
print ("\n-------- Information about Sites ---------")
61-
siteFeatures = read.getSamplingFeatures()
68+
siteFeatures = read.getSamplingFeatures(type= 'site')
6269
# siteFeatures = read.getSamplingFeatures(type='Site')
6370
numSites = len(siteFeatures)
6471
print ("Successful query")

Forms/clsDBConfig.py

Lines changed: 120 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -10,127 +10,128 @@
1010
import wx
1111
import wx.xrc
1212

13+
1314
###########################################################################
1415
## Class clsDBConfiguration
1516
###########################################################################
1617

17-
class clsDBConfiguration ( wx.Panel ):
18-
19-
def __init__( self, parent ):
20-
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 500,291 ), style = wx.SIMPLE_BORDER|wx.TAB_TRAVERSAL )
21-
22-
self.SetMinSize( wx.Size( 442,291 ) )
23-
self.SetMaxSize( wx.Size( 627,291 ) )
24-
25-
formSizer = wx.BoxSizer( wx.VERTICAL )
26-
27-
sbSizer = wx.StaticBoxSizer( wx.StaticBox( self, wx.ID_ANY, u"Database Connection" ), wx.VERTICAL )
28-
29-
connectionSizer = wx.FlexGridSizer( 0, 2, 0, 15 )
30-
connectionSizer.AddGrowableCol( 1 )
31-
connectionSizer.SetFlexibleDirection( wx.VERTICAL )
32-
connectionSizer.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_ALL )
33-
34-
self.stVersion = wx.StaticText( self, wx.ID_ANY, u"DB Version:", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_RIGHT )
35-
self.stVersion.Wrap( -1 )
36-
connectionSizer.Add( self.stVersion, 0, wx.ALL|wx.ALIGN_RIGHT|wx.EXPAND, 5 )
37-
38-
cbDatabaseType1Choices = [ u"2.0", u"1.1.1" ]
39-
self.cbDatabaseType1 = wx.ComboBox( self, wx.ID_ANY, u"2.0", wx.DefaultPosition, wx.DefaultSize, cbDatabaseType1Choices, wx.CB_READONLY|wx.CB_SORT )
40-
self.cbDatabaseType1.SetSelection( 1 )
41-
connectionSizer.Add( self.cbDatabaseType1, 1, wx.ALL|wx.EXPAND, 5 )
42-
43-
self.stConnType = wx.StaticText( self, wx.ID_ANY, u"Connection Type:", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_RIGHT )
44-
self.stConnType.Wrap( -1 )
45-
connectionSizer.Add( self.stConnType, 0, wx.ALL|wx.EXPAND|wx.ALIGN_RIGHT, 5 )
46-
47-
cbDatabaseTypeChoices = []
48-
self.cbDatabaseType = wx.ComboBox( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, cbDatabaseTypeChoices, wx.CB_READONLY|wx.CB_SORT )
49-
connectionSizer.Add( self.cbDatabaseType, 1, wx.ALL|wx.EXPAND, 5 )
50-
51-
self.stServer = wx.StaticText( self, wx.ID_ANY, u"Server:", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_RIGHT )
52-
self.stServer.Wrap( -1 )
53-
connectionSizer.Add( self.stServer, 0, wx.ALL|wx.EXPAND|wx.ALIGN_RIGHT, 5 )
54-
55-
self.txtServer = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0|wx.FULL_REPAINT_ON_RESIZE|wx.SIMPLE_BORDER )
56-
connectionSizer.Add( self.txtServer, 1, wx.ALL|wx.EXPAND, 5 )
57-
58-
self.stDBName = wx.StaticText( self, wx.ID_ANY, u"Database:", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_RIGHT )
59-
self.stDBName.Wrap( -1 )
60-
self.stDBName.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 90, False, wx.EmptyString ) )
61-
62-
connectionSizer.Add( self.stDBName, 0, wx.ALL|wx.EXPAND|wx.ALIGN_RIGHT, 5 )
63-
64-
self.txtDBName = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0|wx.SIMPLE_BORDER )
65-
connectionSizer.Add( self.txtDBName, 1, wx.ALL|wx.EXPAND, 5 )
66-
67-
self.stUser = wx.StaticText( self, wx.ID_ANY, u"User:", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_RIGHT )
68-
self.stUser.Wrap( -1 )
69-
self.stUser.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 90, False, wx.EmptyString ) )
70-
71-
connectionSizer.Add( self.stUser, 0, wx.ALL|wx.EXPAND|wx.ALIGN_RIGHT, 5 )
72-
73-
self.txtUser = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0|wx.SIMPLE_BORDER )
74-
connectionSizer.Add( self.txtUser, 1, wx.ALL|wx.EXPAND, 5 )
75-
76-
self.stPass = wx.StaticText( self, wx.ID_ANY, u"Password:", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_RIGHT )
77-
self.stPass.Wrap( -1 )
78-
self.stPass.SetFont( wx.Font( wx.NORMAL_FONT.GetPointSize(), 70, 90, 90, False, wx.EmptyString ) )
79-
80-
connectionSizer.Add( self.stPass, 0, wx.ALL|wx.EXPAND|wx.ALIGN_RIGHT, 5 )
81-
82-
self.txtPass = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_PASSWORD|wx.SIMPLE_BORDER )
83-
connectionSizer.Add( self.txtPass, 1, wx.ALL|wx.EXPAND, 5 )
84-
85-
86-
sbSizer.Add( connectionSizer, 90, wx.EXPAND, 3 )
87-
88-
89-
formSizer.Add( sbSizer, 1, wx.ALL|wx.EXPAND, 7 )
90-
91-
btnSizer = wx.FlexGridSizer( 0, 3, 0, 25 )
92-
btnSizer.AddGrowableCol( 0 )
93-
btnSizer.AddGrowableCol( 1 )
94-
btnSizer.AddGrowableCol( 2 )
95-
btnSizer.SetFlexibleDirection( wx.VERTICAL )
96-
btnSizer.SetNonFlexibleGrowMode( wx.FLEX_GROWMODE_ALL )
97-
98-
self.btnTest = wx.Button( self, wx.ID_ANY, u"Test Connection", wx.DefaultPosition, wx.DefaultSize, 0 )
99-
btnSizer.Add( self.btnTest, 0, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
100-
101-
self.btnSave = wx.Button( self, wx.ID_ANY, u"Save Connection", wx.DefaultPosition, wx.DefaultSize, 0 )
102-
btnSizer.Add( self.btnSave, 0, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
103-
104-
self.btnCancel = wx.Button( self, wx.ID_ANY, u"Cancel", wx.DefaultPosition, wx.DefaultSize, 0 )
105-
btnSizer.Add( self.btnCancel, 0, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
106-
107-
108-
formSizer.Add( btnSizer, 10, wx.EXPAND, 2 )
109-
110-
111-
self.SetSizer( formSizer )
112-
self.Layout()
113-
114-
# Connect Events
115-
self.btnTest.Bind( wx.EVT_BUTTON, self.OnBtnTest )
116-
self.btnSave.Bind( wx.EVT_BUTTON, self.OnBtnSave )
117-
self.btnCancel.Bind( wx.EVT_BUTTON, self.OnBtnCancel )
118-
119-
self.btnTest.SetFocus()
120-
121-
122-
def __del__( self ):
123-
pass
124-
125-
126-
# Virtual event handlers, overide them in your derived class
127-
def OnBtnTest( self, event ):
128-
event.Skip()
129-
130-
def OnBtnSave( self, event ):
131-
event.Skip()
132-
133-
def OnBtnCancel( self, event ):
134-
event.Skip()
135-
18+
class clsDBConfiguration(wx.Panel):
19+
def __init__(self, parent):
20+
wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.Size(500, 291),
21+
style=wx.SIMPLE_BORDER | wx.TAB_TRAVERSAL)
22+
23+
self.SetMinSize(wx.Size(442, 291))
24+
self.SetMaxSize(wx.Size(627, 291))
25+
26+
formSizer = wx.BoxSizer(wx.VERTICAL)
27+
28+
sbSizer = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, u"Database Connection"), wx.VERTICAL)
29+
30+
connectionSizer = wx.FlexGridSizer(0, 2, 0, 15)
31+
connectionSizer.AddGrowableCol(1)
32+
connectionSizer.SetFlexibleDirection(wx.VERTICAL)
33+
connectionSizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_ALL)
34+
35+
self.stVersion = wx.StaticText(self, wx.ID_ANY, u"DB Version:", wx.DefaultPosition, wx.DefaultSize,
36+
wx.ALIGN_RIGHT)
37+
self.stVersion.Wrap(-1)
38+
connectionSizer.Add(self.stVersion, 0, wx.ALL | wx.ALIGN_RIGHT | wx.EXPAND, 5)
39+
40+
cbDatabaseType1Choices = [u"2.0"]#, u"1.1.1"]
41+
self.cbDatabaseType1 = wx.ComboBox(self, wx.ID_ANY, u"2.0", wx.DefaultPosition, wx.DefaultSize,
42+
cbDatabaseType1Choices, wx.CB_READONLY | wx.CB_SORT)
43+
self.cbDatabaseType1.SetSelection(1)
44+
connectionSizer.Add(self.cbDatabaseType1, 1, wx.ALL | wx.EXPAND, 5)
45+
46+
self.stConnType = wx.StaticText(self, wx.ID_ANY, u"Connection Type:", wx.DefaultPosition, wx.DefaultSize,
47+
wx.ALIGN_RIGHT)
48+
self.stConnType.Wrap(-1)
49+
connectionSizer.Add(self.stConnType, 0, wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, 5)
50+
51+
cbDatabaseTypeChoices = []
52+
self.cbDatabaseType = wx.ComboBox(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize,
53+
cbDatabaseTypeChoices, wx.CB_READONLY | wx.CB_SORT)
54+
connectionSizer.Add(self.cbDatabaseType, 1, wx.ALL | wx.EXPAND, 5)
55+
56+
self.stServer = wx.StaticText(self, wx.ID_ANY, u"Server:", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_RIGHT)
57+
self.stServer.Wrap(-1)
58+
connectionSizer.Add(self.stServer, 0, wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, 5)
59+
60+
self.txtServer = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize,
61+
0 | wx.FULL_REPAINT_ON_RESIZE | wx.SIMPLE_BORDER)
62+
connectionSizer.Add(self.txtServer, 1, wx.ALL | wx.EXPAND, 5)
63+
64+
self.stDBName = wx.StaticText(self, wx.ID_ANY, u"Database:", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_RIGHT)
65+
self.stDBName.Wrap(-1)
66+
self.stDBName.SetFont(wx.Font(wx.NORMAL_FONT.GetPointSize(), 70, 90, 90, False, wx.EmptyString))
67+
68+
connectionSizer.Add(self.stDBName, 0, wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, 5)
69+
70+
self.txtDBName = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize,
71+
0 | wx.SIMPLE_BORDER)
72+
connectionSizer.Add(self.txtDBName, 1, wx.ALL | wx.EXPAND, 5)
73+
74+
self.stUser = wx.StaticText(self, wx.ID_ANY, u"User:", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_RIGHT)
75+
self.stUser.Wrap(-1)
76+
self.stUser.SetFont(wx.Font(wx.NORMAL_FONT.GetPointSize(), 70, 90, 90, False, wx.EmptyString))
77+
78+
connectionSizer.Add(self.stUser, 0, wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, 5)
79+
80+
self.txtUser = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize,
81+
0 | wx.SIMPLE_BORDER)
82+
connectionSizer.Add(self.txtUser, 1, wx.ALL | wx.EXPAND, 5)
83+
84+
self.stPass = wx.StaticText(self, wx.ID_ANY, u"Password:", wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_RIGHT)
85+
self.stPass.Wrap(-1)
86+
self.stPass.SetFont(wx.Font(wx.NORMAL_FONT.GetPointSize(), 70, 90, 90, False, wx.EmptyString))
87+
88+
connectionSizer.Add(self.stPass, 0, wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, 5)
89+
90+
self.txtPass = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize,
91+
wx.TE_PASSWORD | wx.SIMPLE_BORDER)
92+
connectionSizer.Add(self.txtPass, 1, wx.ALL | wx.EXPAND, 5)
93+
94+
sbSizer.Add(connectionSizer, 90, wx.EXPAND, 3)
95+
96+
formSizer.Add(sbSizer, 1, wx.ALL | wx.EXPAND, 7)
97+
98+
btnSizer = wx.FlexGridSizer(0, 3, 0, 25)
99+
btnSizer.AddGrowableCol(0)
100+
btnSizer.AddGrowableCol(1)
101+
btnSizer.AddGrowableCol(2)
102+
btnSizer.SetFlexibleDirection(wx.VERTICAL)
103+
btnSizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_ALL)
104+
105+
self.btnTest = wx.Button(self, wx.ID_ANY, u"Test Connection", wx.DefaultPosition, wx.DefaultSize, 0)
106+
btnSizer.Add(self.btnTest, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL, 5)
107+
108+
self.btnSave = wx.Button(self, wx.ID_ANY, u"Save Connection", wx.DefaultPosition, wx.DefaultSize, 0)
109+
btnSizer.Add(self.btnSave, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL, 5)
110+
111+
self.btnCancel = wx.Button(self, wx.ID_ANY, u"Cancel", wx.DefaultPosition, wx.DefaultSize, 0)
112+
btnSizer.Add(self.btnCancel, 0, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL, 5)
113+
114+
formSizer.Add(btnSizer, 10, wx.EXPAND, 2)
115+
116+
self.SetSizer(formSizer)
117+
self.Layout()
118+
119+
# Connect Events
120+
self.btnTest.Bind(wx.EVT_BUTTON, self.OnBtnTest)
121+
self.btnSave.Bind(wx.EVT_BUTTON, self.OnBtnSave)
122+
self.btnCancel.Bind(wx.EVT_BUTTON, self.OnBtnCancel)
123+
124+
self.btnTest.SetFocus()
125+
126+
def __del__(self):
127+
pass
128+
129+
# Virtual event handlers, overide them in your derived class
130+
def OnBtnTest(self, event):
131+
event.Skip()
132+
133+
def OnBtnSave(self, event):
134+
event.Skip()
136135

136+
def OnBtnCancel(self, event):
137+
event.Skip()
File renamed without changes.
File renamed without changes.

odm2api/ODM1_1_1/memory_database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def getEditRowCount(self):
6666
def getEditColumns(self):
6767
columns = []
6868
tmp_columns = self.df.columns.tolist()
69+
print tmp_columns
6970
tmp_columns.remove('DataValue')
7071
tmp_columns.remove('LocalDateTime')
7172
tmp_columns.remove('QualifierID')

odm2api/ODM1_1_1/services/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
__author__ = 'stephanie'
22
# from cv_service import CVService, refreshDB
3-
from odm2api.ODM1_1_1.services.series_service import ODM, SeriesService
3+
from odm2api.ODM1_1_1.services.series_service import SeriesService
44
from odm2api.ODM1_1_1.services.edit_service import EditService
55
from odm2api.ODM1_1_1.services.export_service import ExportService
6+
ODM = SeriesService.ODM
67

78
__all__ = [ 'SeriesService', 'EditService', 'ExportService', 'ODM']
89
# 'CVService',

0 commit comments

Comments
 (0)