Skip to content

Dev1 0 #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
595f411
combine queries to the same object into a single function
Mar 3, 2016
0c7fb35
update code in sample file to work with new query struture
Mar 7, 2016
566609f
adjust queries for ResultValues, affiliations, people, organizations,…
Mar 7, 2016
7133728
add Annotation objects and query
Mar 8, 2016
fac6abb
add tables from equipment schema
Mar 8, 2016
6047f1b
clean up queries and add them for lab analyses and Provenance schemas
Mar 8, 2016
ba911ff
update queries and add equipment queries
Mar 10, 2016
2bf515b
remove unneeded functions from readService
Mar 15, 2016
ed82918
rearrange model order
Mar 16, 2016
911537a
add code for related queries
Mar 17, 2016
e636f7b
Merge branch 'addqueries' into Dev1_0
Mar 17, 2016
dd233c0
new create functions
Mar 23, 2016
0c73b81
reformat createservices
Mar 23, 2016
dfcb7e3
update sample function calls, add inheritance in results, work on ge…
Mar 23, 2016
d14b3cf
implement polymorphic identity for SF and Results
Mar 23, 2016
d01a8f0
create CV parent class
Mar 23, 2016
3eb9b86
update sample to work with inheritance
Mar 30, 2016
13b664b
fix sample file so that it is not throwing an error when plotting
Apr 4, 2016
e304133
fix sample code to work with creating an inherited object
Apr 4, 2016
8179e10
Update models.py
emiliom Apr 7, 2016
b1cc22b
Merge pull request #39 from ODM2/addinheritance
Apr 11, 2016
ee6b859
add lists to all id and code fields
Apr 12, 2016
d476fe8
rename singular code to plural codes
Apr 12, 2016
40d407d
Merge branch 'master' into Dev1_0
Apr 15, 2016
3ed3253
Merge pull request #51 from ODM2/accept_lists
Apr 15, 2016
e82db59
update tests
Apr 18, 2016
a835f77
fix typos found by tests
Apr 18, 2016
892a3ec
fix typos found by tests, add FeatureGeometryWKT to testscripts
Apr 19, 2016
5585702
run pytest
Apr 19, 2016
f4473fb
alter insert into mysql script to account for featuregeometry wkt
Apr 19, 2016
70c56f1
add value to sampling feature type site for FeatureGeometryWKT
Apr 19, 2016
5d32e11
fix typo error
Apr 22, 2016
8ef2822
merging changes from master
Apr 22, 2016
9ac80e4
handle polymorphic case when no inherited class for specified type
Apr 22, 2016
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ log
.idea

.DS_Store
.ipynb_checkpoints
93 changes: 39 additions & 54 deletions Examples/Sample.py
Original file line number Diff line number Diff line change
@@ -1,77 +1,75 @@
__author__ = 'stephanie'
import sys
import os



import matplotlib.pyplot as plt
from matplotlib import dates


#this will be removed when we can installthe api
# this_file = os.path.realpath(__file__)
# directory = os.path.dirname(os.path.dirname(this_file))
# print directory
# sys.path.insert(0, directory)

from odm2api.ODMconnection import dbconnection
from odm2api.ODM2.services.readService import *
from odm2api.ODM2.services import CreateODM2
# Create a connection to the ODM2 database
# ----------------------------------------


#connect to database
#createconnection (dbtype, servername, dbname, username, password)
#session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')
#session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)
session_factory = dbconnection.createConnection('sqlite', '/Users/denversmith/Downloads/ODM2.sqlite', 2.0)
# session_factory= dbconnection.createConnection('mssql')
# createconnection (dbtype, servername, dbname, username, password)
# session_factory = dbconnection.createConnection('connection type: sqlite|mysql|mssql|postgresql', '/your/path/to/db/goes/here', 2.0)#sqlite
# session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')#mysql
# session_factory= dbconnection.createConnection('mssql', "(local)", "LBRODM2", "ODM", "odm")#win MSSQL
session_factory= dbconnection.createConnection('mssql', "arroyoodm2", "", "ODM", "odm")#mac/linux MSSQL
# session_factory = dbconnection.createConnection('sqlite', '/Users/Stephanie/Desktop/TestODM2.db', 2.0)



#_session = session_factory.getSession()

read = ReadODM2(session_factory)
create =CreateODM2(session_factory)



# Run some basic sample queries.
# ------------------------------
# Get all of the variables from the database and print their names to the console
allVars = read.getVariables()

print ("\n-------- Information about Variables ---------")
for x in allVars:
print(x.VariableCode + ": " + x.VariableNameCV)



# Get all of the people from the database
allPeople = read.getPeople()

print ("\n-------- Information about People ---------")
for x in allPeople:
print(x.PersonFirstName + " " + x.PersonLastName)

try:
print("\n-------- Information about an Affiliation ---------")
allaff = read.getAllAffiliations()
allaff = read.getAffiliations()
for x in allaff:
print(x.PersonObj.PersonFirstName + ": " + str(x.OrganizationID))
except Exception as e:
print("Unable to demo getAllAffiliations", e)

# Get all of the SamplingFeatures from the database that are Sites
try:
siteFeatures = read.getSamplingFeaturesByType('Site')
print ("\n-------- Information about Sites ---------")
siteFeatures = read.getSamplingFeatures()
# siteFeatures = read.getSamplingFeatures(type='Site')
numSites = len(siteFeatures)

for x in siteFeatures:
print(x.SamplingFeatureCode + ": " + x.SamplingFeatureName)
print(x.SamplingFeatureCode + ": " + x.SamplingFeatureTypeCV )
except Exception as e:
print("Unable to demo getSamplingFeaturesByType", e)


# Now get the SamplingFeature object for a SamplingFeature code
try:
sf = read.getSamplingFeatureByCode('USU-LBR-Mendon')
sf = read.getSamplingFeatures(code=['USU-LBR-Mendon'])[0]
print(sf)
print("\n-------- Information about an individual SamplingFeature ---------")
print("The following are some of the attributes of a SamplingFeature retrieved using getSamplingFeatureByCode(): \n")
Expand All @@ -87,18 +85,14 @@
#add sampling feature
print("\n------------ Create Sampling Feature --------- \n")
try:
from odm2api.ODM2.models import SamplingFeatures
newsf = SamplingFeatures()
# from odm2api.ODM2.models import SamplingFeatures
session = session_factory.getSession()
newsf.FeatureGeometry = "POINT(-111.946 41.718)"
newsf.Elevation_m=100
newsf.ElevationDatumCV=sf.ElevationDatumCV
newsf.SamplingFeatureCode= "TestSF"
newsf.SamplingFeatureDescription = "this is a test to add Feature Geomotry"
newsf.SamplingFeatureGeotypeCV= "Point"
newsf.SamplingFeatureTypeCV=sf.SamplingFeatureTypeCV
newsf.SamplingFeatureUUID= sf.SamplingFeatureUUID+"2"
session.add(newsf)
newsf = Sites(FeatureGeometryWKT = "POINT(-111.946 41.718)", Elevation_m=100, ElevationDatumCV=sf.ElevationDatumCV,
SamplingFeatureCode= "TestSF",SamplingFeatureDescription = "this is a test to add Feature Geomotry",
SamplingFeatureGeotypeCV= "Point", SamplingFeatureTypeCV=sf.SamplingFeatureTypeCV,SamplingFeatureUUID= sf.SamplingFeatureUUID+"2",
SiteTypeCV="cave", Latitude= "100", Longitude= "-100", SpatialReferenceID= 0)

create.createSamplingFeature(newsf)
#session.commit()
print("new sampling feature added to database", newsf)

Expand All @@ -125,29 +119,29 @@


# Now get a particular Result using a ResultID
print("\n------- Example of Retrieving Attributes of a Time Series Result -------")
print("\n------- Example of Retrieving Attributes of a Result -------")
try:
tsResult = read.getTimeSeriesResultByResultId(1)
tsResult = read.getResults(ids = [1])[0]
print (
"The following are some of the attributes for the TimeSeriesResult retrieved using getTimeSeriesResultByResultID(): \n" +
"ResultTypeCV: " + tsResult.ResultObj.ResultTypeCV + "\n" +
"The following are some of the attributes for the TimeSeriesResult retrieved using getResults(ids=[1]): \n" +
"ResultTypeCV: " + tsResult.ResultTypeCV + "\n" +
# Get the ProcessingLevel from the TimeSeriesResult's ProcessingLevel object
"ProcessingLevel: " + tsResult.ResultObj.ProcessingLevelObj.Definition + "\n" +
"SampledMedium: " + tsResult.ResultObj.SampledMediumCV + "\n" +
"ProcessingLevel: " + tsResult.ProcessingLevelObj.Definition + "\n" +
"SampledMedium: " + tsResult.SampledMediumCV + "\n" +
# Get the variable information from the TimeSeriesResult's Variable object
"Variable: " + tsResult.ResultObj.VariableObj.VariableCode + ": " + tsResult.ResultObj.VariableObj.VariableNameCV + "\n"
"AggregationStatistic: " + tsResult.AggregationStatisticCV + "\n" +
"Elevation_m: " + str(sf.Elevation_m) + "\n" +
"Variable: " + tsResult.VariableObj.VariableCode + ": " + tsResult.VariableObj.VariableNameCV + "\n"
#"AggregationStatistic: " + tsResult.AggregationStatisticCV + "\n" +

# Get the site information by drilling down
"SamplingFeature: " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
"SamplingFeature: " + tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureCode + " - " +
tsResult.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName)
except Exception as e:
print("Unable to demo Example of retrieving Attributes of a time Series Result: ", e)

# Get the values for a particular TimeSeriesResult
print("\n-------- Example of Retrieving Time Series Result Values ---------")

tsValues = read.getTimeSeriesResultValuesByResultId(1) # Return type is a pandas dataframe
tsValues = read.getResultValues(resultid = 1) # Return type is a pandas datafram

# Print a few Time Series Values to the console
# tsValues.set_index('ValueDateTime', inplace=True)
Expand All @@ -159,18 +153,9 @@
# Plot the time series

try:
fig = plt.figure()
ax = fig.add_subplot(111)
tsValues.plot(x='ValueDateTime', y='DataValue', kind='line',
title=tsResult.ResultObj.VariableObj.VariableNameCV + " at " + tsResult.ResultObj.FeatureActionObj.SamplingFeatureObj.SamplingFeatureName,
ax=ax)
ax.set_ylabel(tsResult.ResultObj.VariableObj.VariableNameCV + " (" + tsResult.ResultObj.UnitsObj.UnitsAbbreviation + ")")
ax.set_xlabel("Date/Time")
ax.xaxis.set_minor_locator(dates.MonthLocator())
ax.xaxis.set_minor_formatter(dates.DateFormatter('%b'))
ax.xaxis.set_major_locator(dates.YearLocator())
ax.xaxis.set_major_formatter(dates.DateFormatter('\n%Y'))
ax.grid(True)
plt.figure()
ax=tsValues.plot(x='ValueDateTime', y='DataValue')

plt.show()
except Exception as e:
print("Unable to demo plotting of tsValues: ", e)
132 changes: 0 additions & 132 deletions odm2api/ODM2/apiCustomType.py

This file was deleted.

Loading