diff --git a/.cache/v/cache/lastfailed b/.cache/v/cache/lastfailed new file mode 100644 index 0000000..112ca39 --- /dev/null +++ b/.cache/v/cache/lastfailed @@ -0,0 +1,16 @@ +{ + "tests/test_SessionFactory.py::test_aSessionFactory[setup4]": true, + "tests/test_SessionFactory.py::test_aSessionFactory[setup5]": true, + "tests/test_SessionFactory.py::test_aSessionFactory[setup6]": true, + "tests/test_connection.py::test_connection[setup2]": true, + "tests/test_connection.py::test_connection[setup3]": true, + "tests/test_odm2/test_createservice.py::TestCreateService::()::test_createTimeSeriesResult": true, + "tests/test_odm2/test_model.py::test_cvelevationdatum[setup2]": true, + "tests/test_odm2/test_model.py::test_cvelevationdatum[setup3]": true, + "tests/test_odm2/test_model.py::test_cvsamplingfeatuergeotype[setup2]": true, + "tests/test_odm2/test_model.py::test_cvsamplingfeatuergeotype[setup3]": true, + "tests/test_odm2/test_model.py::test_cvsamplingfeaturetype[setup2]": true, + "tests/test_odm2/test_model.py::test_cvsamplingfeaturetype[setup3]": true, + "tests/test_odm2/test_model.py::test_sampling_feature[setup2]": true, + "tests/test_odm2/test_model.py::test_sampling_feature[setup3]": true +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index a5ba832..93e9b47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.py[cod] *~ -.ipynb_checkpoints + # C extensions *.so @@ -40,7 +40,9 @@ nosetests.xml log *.log -.idea + .DS_Store .ipynb_checkpoints +.cache +.idea diff --git a/.travis.yml b/.travis.yml index 79e28d8..830399f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -language: python +git blanguage: python sudo: required # if the https://travis-ci.org/ODM2/ODM2PythonAPI/requests ever says: missing config # validate at: http://lint.travis-ci.org/ @@ -38,17 +38,19 @@ addons: - libspatialite-dev # mariadb: '10.1' before_script: - - ./scripts/mysql_setup.sh - - ./scripts/postgres_setup.sh - - ./scripts/freetds.sh + - ./ci-helpers/mysql_setup.sh + - ./ci-helpers/postgres_setup.sh + - ./ci-helpers/travis/freetds.sh + before_install: # python -m pip makes the install go into the virtualenv - - python -m pip install pandas + - sudo pip install --upgrade pip + - sudo python -m pip install pandas - export PYMSSQL_BUILD_WITH_BUNDLED_FREETDS=1;python -m pip install pymssql # - python -m pip install mysql-python install: # now just our code - - pip install git+https://github.com/ODM2/geoalchemy.git@odm2#egg=geoalchemy-0.7.3 + - pip install -e git+https://github.com/ODM2/geoalchemy.git@v0.7.4#egg=geoalchemy-0.7.4 - pip install . - pip install -r requirements_tests.txt --allow-external pyodbc --allow-unverified pyodbc # pysqlite diff --git a/Examples/Sample.py b/Examples/Sample.py index 88dfe3d..95d7f02 100644 --- a/Examples/Sample.py +++ b/Examples/Sample.py @@ -2,8 +2,8 @@ -import matplotlib.pyplot as plt -from matplotlib import dates +# import matplotlib.pyplot as plt + @@ -17,10 +17,11 @@ #connect to database # 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('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_factory= dbconnection.createConnection('mssql', "arroyoodm2", "", "ODM", "odm")#mac/linux MSSQL +# session_factory = dbconnection.createConnection('sqlite', '/Users/stephanie/DEV/ODM2/usecases/WOF_to_ODM2/ODM2.sqlite', 2.0) + @@ -60,7 +61,7 @@ siteFeatures = read.getSamplingFeatures() # siteFeatures = read.getSamplingFeatures(type='Site') numSites = len(siteFeatures) - + print ("Successful query") for x in siteFeatures: print(x.SamplingFeatureCode + ": " + x.SamplingFeatureTypeCV ) except Exception as e: @@ -69,7 +70,7 @@ # Now get the SamplingFeature object for a SamplingFeature code try: - sf = read.getSamplingFeatures(code=['USU-LBR-Mendon'])[0] + sf = read.getSamplingFeatures(codes=['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") @@ -88,13 +89,13 @@ # from odm2api.ODM2.models import SamplingFeatures session = session_factory.getSession() 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", + SamplingFeatureCode= "TestSF",SamplingFeatureDescription = "this is a test in sample.py", SamplingFeatureGeotypeCV= "Point", SamplingFeatureTypeCV=sf.SamplingFeatureTypeCV,SamplingFeatureUUID= sf.SamplingFeatureUUID+"2", SiteTypeCV="cave", Latitude= "100", Longitude= "-100", SpatialReferenceID= 0) - create.createSamplingFeature(newsf) + c=create.createSamplingFeature(newsf) #session.commit() - print("new sampling feature added to database", newsf) + print("new sampling feature added to database", c) except Exception as e : print("error adding a sampling feature: " + str(e)) diff --git a/Forms/clsDBConfig.py b/Forms/clsDBConfig.py index d92e1aa..be628a1 100644 --- a/Forms/clsDBConfig.py +++ b/Forms/clsDBConfig.py @@ -115,6 +115,9 @@ def __init__( self, parent ): self.btnTest.Bind( wx.EVT_BUTTON, self.OnBtnTest ) self.btnSave.Bind( wx.EVT_BUTTON, self.OnBtnSave ) self.btnCancel.Bind( wx.EVT_BUTTON, self.OnBtnCancel ) + + self.btnTest.SetFocus() + def __del__( self ): pass diff --git a/Forms/frmDBConfig.py b/Forms/frmDBConfig.py index 973562a..28ab020 100644 --- a/Forms/frmDBConfig.py +++ b/Forms/frmDBConfig.py @@ -78,6 +78,7 @@ def validateInput(self, conn_dict): if self.service_manager.test_connection(conn_dict): message = "This connection is valid" wx.MessageBox(message, 'Test Connection', wx.OK) + self.btn else: #TODO add error message if user cannont connect to the database ( not using VPN) but the db is still 1.1.1) if not (self.service_manager.get_db_version(conn_dict)): diff --git a/appveyor.yml b/appveyor.yml index 9bf8ad1..b34a56c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,44 +4,56 @@ environment: # SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the # /E:ON and /V:ON options are not enabled in the batch script intepreter # See: http://stackoverflow.com/a/13751649/163740 - CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd" + PYTHON: "C:\\conda" + MINICONDA_VERSION: "latest" + # CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd" + CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci-helpers/appveyor/windows_sdk.cmd" + CONDA_CHANNELS: "odm2" + CONDA_DEPENDENCIES: "scipy pandas seaborn sqlalchemy pymysql geoalchemy-odm2 shapely psycopg2" + PIP_DEPENDENCIES: "pyodbc,pytest" + #,-e git+https://github.com/ODM2/geoalchemy.git@v0.7.4#egg=geoalchemy-0.7.4" + # postgres POSTGRES_PORT: tcp://localhost:5432 POSTGRES_ENV_POSTGRES_USER: postgres POSTGRES_ENV_POSTGRES_PASSWORD: Password12! POSTGRES_ENV_POSTGRES_DB: odm2 - POSTGRES_PATH: C:\Program Files\PostgreSQL\9.4 + POSTGRES_PATH: C:\Program Files\PostgreSQL\9.5 PGUSER: postgres PGPASSWORD: Password12! + # mysql MYSQL_PORT: tcp://localhost:3306 MYSQL_ENV_MYSQL_USER: root MYSQL_ENV_MYSQL_PASSWORD: Password12! MYSQL_ENV_MYSQL_DATABASE: odm2 - MYSQL_PATH: C:\Program Files\MySql\MySQL Server 5.6 + MYSQL_PATH: C:\Program Files\MySql\MySQL Server 5.7 MYSQL_PWD: Password12! + # sql server SQLSERVER_ENV_SQLSERVER_HOST: localhost SQLSERVER_ENV_SQLSERVER_PORT: 1433 SQLSERVER_ENV_SQLSERVER_USER: sa SQLSERVER_ENV_SQLSERVER_PASSWORD: Password12! SQLSERVER_ENV_SQLSERVER_DATABASE: odm2 - matrix: + # Pre-installed Python versions, which Appveyor may upgrade to # a later point release. # See: http://www.appveyor.com/docs/installed-software#python + matrix: + - PYTHON: "C:\\Python27-conda32" + PYTHON_VERSION: "2.7" + PYTHON_ARCH: "32" + - matrix: - - PYTHON: "C:\\Python27-conda32" - PYTHON_VERSION: "2.7" - PYTHON_ARCH: "32" + - PYTHON: "C:\\Python27-conda64" + PYTHON_VERSION: "2.7" + PYTHON_ARCH: "64" + NUMPY_VERSION: "stable" - - PYTHON: "C:\\Python34-conda64" - PYTHON_VERSION: "3.4" - PYTHON_ARCH: "64" services: - mssql2008r2sp2 @@ -66,106 +78,222 @@ install: # Install Python (from the official .msi of http://python.org) and pip when # not already installed. - - ps: if (-not(Test-Path($env:PYTHON))) { & appveyor\install.ps1 } +# - ps: if (-not(Test-Path($env:PYTHON))) { & appveyor\install.ps1 } + - ps: ci-helpers/appveyor/install-miniconda.ps1 + # Prepend newly installed Python to the PATH of this build (this cannot be # done from inside the powershell script as it would require to restart # the parent CMD process). - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" # add databases - - "SET PATH=%POSTGRES_PATH%\bin;%MYSQL_PATH%\bin;%PATH%" + - "SET PATH=%POSTGRES_PATH%\\bin;%MYSQL_PATH%\\bin;%PATH%" + - "activate test" # Check that we have the expected version and architecture for Python - "python --version" - "python -c \"import struct; print(struct.calcsize('P') * 8)\"" - # Upgrade to the latest version of pip to avoid it displaying warnings - # about it being out of date. - - "pip install --disable-pip-version-check --user --upgrade pip" - # Install the build dependencies of the project. If some dependencies contain - # compiled extensions and are not provided as pre-built wheel packages, - # pip will build them from source using the MSVC compiler matching the - # target Python version and architecture - - "%CMD_IN_ENV% pip install -r dev-requirements.txt" build_script: - # Build the compiled extension - - "%CMD_IN_ENV% python setup.py build" -build_script: - # Build the compiled extension - - "%CMD_IN_ENV% python setup.py build" - build_script: +##https://github.com/sqlectron/sqlectron-core/blob/master/appveyor.yml + - echo %PATH% + # postgres - - createdb odm2 - - psql -d odm2 -a -f spec/databases/postgresql/schema/schema.sql + - sh ci-helpers\postgres_setup.sh +# - psql createdb marchantariats +# - psql -d marchantariats -a -f tests/usecasesql/marchantariats/marchantariats.sql + + # mysql - - mysql -e "drop database test; create database odm2;" --user=root - - mysql sqlectron < spec/databases/mysql/schema/schema.sql --user=root + - sh ci-helpers\mysql_setup.sh +# - mysql -e "drop database test; create database odm2;" --user=root +# - mysql odm2 < tests/usecasesql/littlebearriver/sampledatabases/odm2_mysql/LBR_MySQL_SmallExample.sql --user=root + # sqlserver - - ps: ./appveyor-sqlserver.ps1 SQL2008R2SP2 + - ps: ci-helpers\appveyor\sqlserver.ps1 SQL2008R2SP2 - sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE odm2" -d "master" - - sqlcmd -S localhost,1433 -U sa -P Password12! -i spec/databases/sqlserver/schema/schema.sql -d "odm2" + - sqlcmd -S localhost,1433 -U sa -P Password12! -i tests/usecasesql/littlebearriver/sampledatabases/odm2_ms_sql_server/LBR_ODM2_MSSQLDump.sql -d "odm2" - sqlcmd -S localhost,1433 -U sa -P Password12! -Q "select table_name from information_schema.tables" -d "odm2" test_script: # Run the project tests - - "%CMD_IN_ENV% python setup.py nosetests" - -language: python -python: -# - "2.6" - - "2.7" -# - "3.2" -# - "3.3" -# - "3.4" -# - "3.5" -# - "3.5-dev" # 3.5 development branch -# - "nightly" # currently points to 3.6-dev -# command to install dependencies - -before_install: -#https://github.com/sqlectron/sqlectron-core/blob/master/appveyor.yml - - mysql -e "CREATE USER 'ODM'@'localhost' IDENTIFIED BY 'odm';GRANT ALL PRIVILEGES ON *.* TO 'ODM'@'localhost';" -uroot - - mysql -e "create database IF NOT EXISTS odm2;" -uroot - - mysql -e "create database IF NOT EXISTS odm2test;" -uroot - - psql -U postgres -c "create extension postgis" - - psql -c 'DROP DATABASE IF EXISTS odm2test;' -U postgres; - - psql -c 'create database odm2test;' -U postgres; -# - psql -U postgres -d odm2test -a -f ./tests/schemas/postgresql/ODM2_for_PostgreSQL.sql - - psql -c 'DROP DATABASE IF EXISTS odm2;' -U postgres; - - psql -c 'create database odm2;' -U postgres; - # patterned after: https://github.com/ptrv/gpx2spatialite/blob/master/.travis.yml -# - sudo apt-get install -y python-software-properties -# - sudo apt-add-repository -y ppa:git-core/ppa -# - sudo apt-add-repository -y ppa:ubuntugis/ppa -# - sudo apt-get update -qq -# - sudo apt-get install unixodbc unixodbc-dev tdsodbc -# - sudo apt-get install freetds-dev freetds-bin -# - sudo apt-get install libc6 e2fsprogs # mssql driver - # Spatialiate -# - sudo apt-get install -y libproj-dev libgeos-dev libspatialite-dev -# - sudo ln -s /usr/lib/x86_64-linux-gnu/libspatialite.so /usr/lib/libspatialite.so -# - sudo apt-get install python-scipy python-matplotlib python-pandas python-sympy python-nose -# - sudo apt-get install python-matplotlib python-pandas python-nose - - pip install pandas -install: # now just our code - - pip install git+https://github.com/ODM2/geoalchemy.git@odm2#egg=geoalchemy-0.7.3 - - pip install . - - pip install -r requirements_tests.txt --allow-external pyodbc --allow-unverified pyodbc - # pysqlite - - pip install pysqlite - - dir .\tests\usecasesql\littlebearriver\sampledatabases\odm2_mysql\LBR_MySQL_SmallExample.sql .\tests\usecasesql\marchantariats\marchantariats.sql - - mysql --user root --verbose odm2 < .\tests\usecasesql\littlebearriver\sampledatabases\odm2_mysql\LBR_MySQL_SmallExample.sql -# add -a to psql to see full log - - psql -U postgres -f ./tests/usecasesql/marchantariats/marchantariats.sql - -# don't forget to open up the azure mssql server to these addreses -# https://docs.travis-ci.com/user/ip-addresses/ - -# command to run tests -script: -# just the connection part - - py.test tests/test_connection.py - - py.test + - "py.test" + + + + + +#environment: +## patterned after: https://github.com/ogrisel/python-appveyor-demo/blob/master/appveyor.yml +# global: +# # SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the +# # /E:ON and /V:ON options are not enabled in the batch script intepreter +# # See: http://stackoverflow.com/a/13751649/163740 +# CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd" +# # postgres +# POSTGRES_PORT: tcp://localhost:5432 +# POSTGRES_ENV_POSTGRES_USER: postgres +# POSTGRES_ENV_POSTGRES_PASSWORD: Password12! +# POSTGRES_ENV_POSTGRES_DB: odm2 +# POSTGRES_PATH: C:\Program Files\PostgreSQL\9.4 +# PGUSER: postgres +# PGPASSWORD: Password12! +# # mysql +# MYSQL_PORT: tcp://localhost:3306 +# MYSQL_ENV_MYSQL_USER: root +# MYSQL_ENV_MYSQL_PASSWORD: Password12! +# MYSQL_ENV_MYSQL_DATABASE: odm2 +# MYSQL_PATH: C:\Program Files\MySql\MySQL Server 5.6 +# MYSQL_PWD: Password12! +# # sql server +# SQLSERVER_ENV_SQLSERVER_HOST: localhost +# SQLSERVER_ENV_SQLSERVER_PORT: 1433 +# SQLSERVER_ENV_SQLSERVER_USER: sa +# SQLSERVER_ENV_SQLSERVER_PASSWORD: Password12! +# SQLSERVER_ENV_SQLSERVER_DATABASE: odm2 +# matrix: +# +# +# # Pre-installed Python versions, which Appveyor may upgrade to +# # a later point release. +# # See: http://www.appveyor.com/docs/installed-software#python +# +# +# matrix: +# - PYTHON: "C:\\Python27-conda32" +# PYTHON_VERSION: "2.7" +# PYTHON_ARCH: "32" +# +# - PYTHON: "C:\\Python34-conda64" +# PYTHON_VERSION: "3.4" +# PYTHON_ARCH: "64" +# +#services: +# - mssql2008r2sp2 +# - mysql +# - postgresql +# +#install: +# # If there is a newer build queued for the same PR, cancel this one. +# # The AppVeyor 'rollout builds' option is supposed to serve the same +# # purpose but it is problematic because it tends to cancel builds pushed +# # directly to master instead of just PR builds (or the converse). +# # credits: JuliaLang developers. +# - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` +# https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` +# Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` +# throw "There are newer queued builds for this pull request, failing early." } +# - ECHO "Filesystem root:" +# - ps: "ls \"C:/\"" +# +# - ECHO "Installed SDKs:" +# - ps: "ls \"C:/Program Files/Microsoft SDKs/Windows\"" +# +# # Install Python (from the official .msi of http://python.org) and pip when +# # not already installed. +# - ps: if (-not(Test-Path($env:PYTHON))) { & appveyor\install.ps1 } +# +# # Prepend newly installed Python to the PATH of this build (this cannot be +# # done from inside the powershell script as it would require to restart +# # the parent CMD process). +# - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" +# # add databases +# - "SET PATH=%POSTGRES_PATH%\bin;%MYSQL_PATH%\bin;%PATH%" +# +# # Check that we have the expected version and architecture for Python +# - "python --version" +# - "python -c \"import struct; print(struct.calcsize('P') * 8)\"" +# +# # Upgrade to the latest version of pip to avoid it displaying warnings +# # about it being out of date. +# - "pip install --disable-pip-version-check --user --upgrade pip" +# +# # Install the build dependencies of the project. If some dependencies contain +# # compiled extensions and are not provided as pre-built wheel packages, +# # pip will build them from source using the MSVC compiler matching the +# # target Python version and architecture +# - "%CMD_IN_ENV% pip install -r dev-requirements.txt" +# +#build_script: +# # Build the compiled extension +# - "%CMD_IN_ENV% python setup.py build" +#build_script: +# # Build the compiled extension +# - "%CMD_IN_ENV% python setup.py build" +# build_script: +# # postgres +# - createdb odm2 +# - psql -d odm2 -a -f spec/databases/postgresql/schema/schema.sql +# # mysql +# - mysql -e "drop database test; create database odm2;" --user=root +# - mysql sqlectron < spec/databases/mysql/schema/schema.sql --user=root +# # sqlserver +# - ps: ./appveyor-sqlserver.ps1 SQL2008R2SP2 +# - sqlcmd -S localhost,1433 -U sa -P Password12! -Q "CREATE DATABASE odm2" -d "master" +# - sqlcmd -S localhost,1433 -U sa -P Password12! -i spec/databases/sqlserver/schema/schema.sql -d "odm2" +# - sqlcmd -S localhost,1433 -U sa -P Password12! -Q "select table_name from information_schema.tables" -d "odm2" +# +#test_script: +# # Run the project tests +# - "%CMD_IN_ENV% python setup.py nosetests" +# +#language: python +#python: +## - "2.6" +# - "2.7" +## - "3.2" +## - "3.3" +## - "3.4" +## - "3.5" +## - "3.5-dev" # 3.5 development branch +## - "nightly" # currently points to 3.6-dev +## command to install dependencies +# +#before_install: +##https://github.com/sqlectron/sqlectron-core/blob/master/appveyor.yml +# - mysql -e "CREATE USER 'ODM'@'localhost' IDENTIFIED BY 'odm';GRANT ALL PRIVILEGES ON *.* TO 'ODM'@'localhost';" -uroot +# - mysql -e "create database IF NOT EXISTS odm2;" -uroot +# - mysql -e "create database IF NOT EXISTS odm2test;" -uroot +# - psql -U postgres -c "create extension postgis" +# - psql -c 'DROP DATABASE IF EXISTS odm2test;' -U postgres; +# - psql -c 'create database odm2test;' -U postgres; +## - psql -U postgres -d odm2test -a -f ./tests/schemas/postgresql/ODM2_for_PostgreSQL.sql +# - psql -c 'DROP DATABASE IF EXISTS odm2;' -U postgres; +# - psql -c 'create database odm2;' -U postgres; +# # patterned after: https://github.com/ptrv/gpx2spatialite/blob/master/.travis.yml +## - sudo apt-get install -y python-software-properties +## - sudo apt-add-repository -y ppa:git-core/ppa +## - sudo apt-add-repository -y ppa:ubuntugis/ppa +## - sudo apt-get update -qq +## - sudo apt-get install unixodbc unixodbc-dev tdsodbc +## - sudo apt-get install freetds-dev freetds-bin +## - sudo apt-get install libc6 e2fsprogs # mssql driver +# # Spatialiate +## - sudo apt-get install -y libproj-dev libgeos-dev libspatialite-dev +## - sudo ln -s /usr/lib/x86_64-linux-gnu/libspatialite.so /usr/lib/libspatialite.so +## - sudo apt-get install python-scipy python-matplotlib python-pandas python-sympy python-nose +## - sudo apt-get install python-matplotlib python-pandas python-nose +# - pip install pandas +#install: # now just our code +# - pip install git+https://github.com/ODM2/geoalchemy.git@odm2#egg=geoalchemy-0.7.3 +# - pip install . +# - pip install -r requirements_tests.txt --allow-external pyodbc --allow-unverified pyodbc +# # pysqlite +# - pip install pysqlite +# - dir .\tests\usecasesql\littlebearriver\sampledatabases\odm2_mysql\LBR_MySQL_SmallExample.sql .\tests\usecasesql\marchantariats\marchantariats.sql +# - mysql --user root --verbose odm2 < .\tests\usecasesql\littlebearriver\sampledatabases\odm2_mysql\LBR_MySQL_SmallExample.sql +## add -a to psql to see full log +# - psql -U postgres -f ./tests/usecasesql/marchantariats/marchantariats.sql +# +## don't forget to open up the azure mssql server to these addreses +## https://docs.travis-ci.com/user/ip-addresses/ +# +## command to run tests +#script: +## just the connection part +# - py.test tests/test_connection.py +# - py.test +# diff --git a/ci-helpers/appveyor/install-miniconda.ps1 b/ci-helpers/appveyor/install-miniconda.ps1 new file mode 100644 index 0000000..25416f9 --- /dev/null +++ b/ci-helpers/appveyor/install-miniconda.ps1 @@ -0,0 +1,196 @@ +# Sample script to install anaconda under windows +# Authors: Stuart Mumford +# Borrwed from: Olivier Grisel and Kyle Kastner +# License: BSD 3 clause + +$MINICONDA_URL = "https://repo.continuum.io/miniconda/" + +if (! $env:ASTROPY_LTS_VERSION) { + $env:ASTROPY_LTS_VERSION = "1.0" +} + +function DownloadMiniconda ($version, $platform_suffix) { + $webclient = New-Object System.Net.WebClient + $filename = "Miniconda-" + $version + "-Windows-" + $platform_suffix + ".exe" + + $url = $MINICONDA_URL + $filename + + $basedir = $pwd.Path + "\" + $filepath = $basedir + $filename + if (Test-Path $filename) { + Write-Host "Reusing" $filepath + return $filepath + } + + # Download and retry up to 3 times in case of network transient errors. + Write-Host "Downloading" $filename "from" $url + $retry_attempts = 2 + for($i=0; $i -lt $retry_attempts; $i++){ + try { + $webclient.DownloadFile($url, $filepath) + break + } + Catch [Exception]{ + Start-Sleep 1 + } + } + if (Test-Path $filepath) { + Write-Host "File saved at" $filepath + } else { + # Retry once to get the error message if any at the last try + $webclient.DownloadFile($url, $filepath) + } + return $filepath +} + +function InstallMiniconda ($miniconda_version, $architecture, $python_home) { + Write-Host "Installing miniconda" $miniconda_version "for" $architecture "bit architecture to" $python_home + if (Test-Path $python_home) { + Write-Host $python_home "already exists, skipping." + return $false + } + if ($architecture -eq "x86") { + $platform_suffix = "x86" + } else { + $platform_suffix = "x86_64" + } + $filepath = DownloadMiniconda $miniconda_version $platform_suffix + Write-Host "Installing" $filepath "to" $python_home + $args = "/InstallationType=AllUsers /S /AddToPath=1 /RegisterPython=1 /D=" + $python_home + Write-Host $filepath $args + Start-Process -FilePath $filepath -ArgumentList $args -Wait -Passthru + #Start-Sleep -s 15 + if (Test-Path $python_home) { + Write-Host "Miniconda $miniconda_version ($architecture) installation complete" + } else { + Write-Host "Failed to install Python in $python_home" + Exit 1 + } +} + +# Install miniconda, if no version is given use the latest +if (! $env:MINICONDA_VERSION) { + $env:MINICONDA_VERSION="latest" +} + +InstallMiniconda $env:MINICONDA_VERSION $env:PLATFORM $env:PYTHON + +# Set environment variables +$env:PATH = "${env:PYTHON};${env:PYTHON}\Scripts;" + $env:PATH + +# Conda config +conda config --set always_yes true + +if (! $env:CONDA_CHANNELS) { + $CONDA_CHANNELS=@("astropy", "astropy-ci-extras", "openastronomy") +} else { + $CONDA_CHANNELS=$env:CONDA_CHANNELS.split(" ") +} +foreach ($CONDA_CHANNEL in $CONDA_CHANNELS) { + conda config --add channels $CONDA_CHANNEL +} + +# Install the build and runtime dependencies of the project. +conda update -q conda + +# Create a conda environment using the astropy bonus packages +conda create -q -n test python=$env:PYTHON_VERSION +activate test + +# Set environment variables for environment (activate test doesn't seem to do the trick) +$env:PATH = "${env:PYTHON}\envs\test;${env:PYTHON}\envs\test\Scripts;${env:PYTHON}\envs\test\Library\bin;" + $env:PATH + +# Check that we have the expected version of Python +python --version + +# Check whether a specific version of Numpy is required +if ($env:NUMPY_VERSION) { + if($env:NUMPY_VERSION -match "stable") { + $NUMPY_OPTION = "numpy" + } elseif($env:NUMPY_VERSION -match "dev") { + $NUMPY_OPTION = "Cython pip".Split(" ") + } else { + $NUMPY_OPTION = "numpy=" + $env:NUMPY_VERSION + } +} else { + $NUMPY_OPTION = "" +} + +# Check whether a specific version of Astropy is required +if ($env:ASTROPY_VERSION) { + if($env:ASTROPY_VERSION -match "stable") { + $ASTROPY_OPTION = "astropy" + } elseif($env:ASTROPY_VERSION -match "dev") { + $ASTROPY_OPTION = "Cython pip jinja2".Split(" ") + } elseif($env:ASTROPY_VERSION -match "lts") { + $ASTROPY_OPTION = "astropy=" + $env:ASTROPY_LTS_VERSION + } else { + $ASTROPY_OPTION = "astropy=" + $env:ASTROPY_VERSION + } +} else { + $ASTROPY_OPTION = "" +} + +# Install the specified versions of numpy and other dependencies +if ($env:CONDA_DEPENDENCIES) { + $CONDA_DEPENDENCIES = $env:CONDA_DEPENDENCIES.split(" ") +} else { + $CONDA_DEPENDENCIES = "" +} + +# Due to scipy DLL issues with mkl 11.3.3, and as there is no nomkl option +# for windows, we should use mkl 11.3.1 for now as a workaround see discussion +# in https://github.com/astropy/astropy/pull/4907#issuecomment-219200964 + +if ($NUMPY_OPTION -ne "") { + $NUMPY_OPTION_mkl = "mkl=11.3.1 " + $NUMPY_OPTION + echo $NUMPY_OPTION_mkl + $NUMPY_OPTION = $NUMPY_OPTION_mkl.Split(" ") +} + +# We have to fix the version of the vs2015_runtime on Python 3.5 to avoid +# issues. See https://github.com/astropy/ci-helpers/issues/92 for more details. + +if ($env:PYTHON_VERSION -match "3.5") { + conda install -n test -q vs2015_runtime=14.00.23026.0=0 +} + +conda install -n test -q pytest $NUMPY_OPTION $ASTROPY_OPTION $CONDA_DEPENDENCIES + +# Check whether the developer version of Numpy is required and if yes install it +if ($env:NUMPY_VERSION -match "dev") { + Invoke-Expression "${env:CMD_IN_ENV} pip install git+https://github.com/numpy/numpy.git#egg=numpy --upgrade --no-deps" +} + +# Check whether the developer version of Astropy is required and if yes install +# it. We need to include --no-deps to make sure that Numpy doesn't get upgraded. +if ($env:ASTROPY_VERSION -match "dev") { + Invoke-Expression "${env:CMD_IN_ENV} pip install git+https://github.com/astropy/astropy.git#egg=astropy --upgrade --no-deps" +} + +#Invoke-Expression "${env:CMD_IN_ENV} pip install -e git+https://github.com/ODM2/geoalchemy.git@v0.7.4#egg=geoalchemy-0.7.4" + + + +# We finally install the dependencies listed in PIP_DEPENDENCIES. We do this +# after installing the Numpy versions of Numpy or Astropy. If we didn't do this, +# then calling pip earlier could result in the stable version of astropy getting +# installed, and then overritten later by the dev version (which would waste +# build time) + +if ($env:PIP_FLAGS) { + $PIP_FLAGS = $env:PIP_FLAGS +} else { + $PIP_FLAGS = "" +} + +if ($env:PIP_DEPENDENCIES) { + $PIP_DEPENDENCIES = $env:PIP_DEPENDENCIES.split(",") +} else { + $PIP_DEPENDENCIES = "" +} + +if ($env:PIP_DEPENDENCIES) { + pip install $PIP_DEPENDENCIES $PIP_FLAGS +} + diff --git a/ci-helpers/appveyor/sqlserver.ps1 b/ci-helpers/appveyor/sqlserver.ps1 new file mode 100644 index 0000000..f7a6b0a --- /dev/null +++ b/ci-helpers/appveyor/sqlserver.ps1 @@ -0,0 +1,21 @@ +[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null +[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | Out-Null + +$instancename = $args[0]; +$computerName = $env:COMPUTERNAME +$smo = 'Microsoft.SqlServer.Management.Smo.' +$wmi = New-Object ($smo + 'Wmi.ManagedComputer') + +$uri = "ManagedComputer[@Name='$computerName']/ ServerInstance[@Name='$instancename']/ServerProtocol[@Name='Tcp']" +$Tcp = $wmi.GetSmoObject($uri) +foreach ($ipAddress in $Tcp.IPAddresses) +{ + $ipAddress.IPAddressProperties["TcpDynamicPorts"].Value = "" + $ipAddress.IPAddressProperties["TcpPort"].Value = "1433" +} +$Tcp.Alter() + +Stop-Service SQLBrowser +Stop-Service "MSSQL`$$instancename" +Start-Service SQLBrowser +Start-Service "MSSQL`$$instancename" \ No newline at end of file diff --git a/ci-helpers/appveyor/windows_sdk.cmd b/ci-helpers/appveyor/windows_sdk.cmd new file mode 100644 index 0000000..951b0c7 --- /dev/null +++ b/ci-helpers/appveyor/windows_sdk.cmd @@ -0,0 +1,66 @@ +:: To build extensions for 64 bit Python 3.5 or later no special environment needs +:: to be configured. +:: +:: To build extensions for 64 bit Python 3.4 or earlier, we need to configure environment +:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of: +:: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1) +:: +:: To build extensions for 64 bit Python 2, we need to configure environment +:: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of: +:: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0) +:: +:: 32 bit builds do not require specific environment configurations. +:: +:: Note: this script needs to be run with the /E:ON and /V:ON flags for the +:: cmd interpreter, at least for (SDK v7.0) +:: +:: More details at: +:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows +:: https://stackoverflow.com/a/13751649/163740 +:: +:: Original Author: Olivier Grisel +:: License: CC0 1.0 Universal: https://creativecommons.org/publicdomain/zero/1.0/ +:: This version based on updates for python 3.5 by Phil Elson at: +:: https://github.com/pelson/Obvious-CI/tree/master/scripts + +@ECHO OFF + +SET COMMAND_TO_RUN=%* +SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows + +SET MAJOR_PYTHON_VERSION="%PYTHON_VERSION:~0,1%" +SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,1% +IF %MAJOR_PYTHON_VERSION% == "2" ( + SET WINDOWS_SDK_VERSION="v7.0" + SET SET_SDK_64=Y +) ELSE IF %MAJOR_PYTHON_VERSION% == "3" ( + SET WINDOWS_SDK_VERSION="v7.1" + IF %MINOR_PYTHON_VERSION% LEQ 4 ( + SET SET_SDK_64=Y + ) ELSE ( + SET SET_SDK_64=N + ) +) ELSE ( + ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%" + EXIT 1 +) + +IF "%PYTHON_ARCH%"=="64" ( + IF %SET_SDK_64% == Y ( + ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture + SET DISTUTILS_USE_SDK=1 + SET MSSdk=1 + "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION% + "%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release + ECHO Executing: %COMMAND_TO_RUN% + call %COMMAND_TO_RUN% || EXIT 1 + ) ELSE ( + ECHO Using default MSVC build environment for 64 bit architecture + ECHO Executing: %COMMAND_TO_RUN% + call %COMMAND_TO_RUN% || EXIT 1 + ) +) ELSE ( + ECHO Using default MSVC build environment for 32 bit architecture + ECHO Executing: %COMMAND_TO_RUN% + call %COMMAND_TO_RUN% || EXIT 1 +) \ No newline at end of file diff --git a/scripts/mysql_setup.sh b/ci-helpers/mysql_setup.sh similarity index 100% rename from scripts/mysql_setup.sh rename to ci-helpers/mysql_setup.sh diff --git a/scripts/postgres_setup.sh b/ci-helpers/postgres_setup.sh similarity index 100% rename from scripts/postgres_setup.sh rename to ci-helpers/postgres_setup.sh diff --git a/scripts/apt-get.sh b/ci-helpers/travis/apt-get.sh similarity index 100% rename from scripts/apt-get.sh rename to ci-helpers/travis/apt-get.sh diff --git a/scripts/freetds.sh b/ci-helpers/travis/freetds.sh similarity index 100% rename from scripts/freetds.sh rename to ci-helpers/travis/freetds.sh diff --git a/odm2api/ODM2/models.py b/odm2api/ODM2/models.py index 1062e9f..ef66405 100644 --- a/odm2api/ODM2/models.py +++ b/odm2api/ODM2/models.py @@ -1,6 +1,7 @@ from sqlalchemy import BigInteger, Column, Date, DateTime, Float, ForeignKey, Integer, String, Boolean, BLOB, case from sqlalchemy.orm import relationship from sqlalchemy.dialects import postgresql, mysql, sqlite +# from sqlalchemy.dialects.sqlite import BIT from geoalchemy import GeometryDDL, GeometryColumn @@ -17,6 +18,9 @@ BigIntegerType = BigIntegerType.with_variant(postgresql.BIGINT(), 'postgresql') BigIntegerType = BigIntegerType.with_variant(mysql.BIGINT(), 'mysql') +# BooleanType = Boolean() +# BooleanType =BooleanType.with_variant(sqlite.BIT(), 'sqlite') + def is_hex(s): try: @@ -275,7 +279,7 @@ class SamplingFeatures(Base): index=True) Elevation_m = Column('elevation_m', Float(53)) ElevationDatumCV = Column('elevationdatumcv', ForeignKey(CVElevationDatum.Name), index=True) - FeatureGeometry = Column('featuregeometry', Geometry) # String(50))# + FeatureGeometry = Column('featuregeometry', String(50))#Geometry) # FeatureGeometryWKT = Column('featuregeometrywkt', String(50)) # FeatureGeometry = Column('featuregeometry', BLOB) # custom geometry queries __mapper_args__ = { @@ -285,30 +289,30 @@ class SamplingFeatures(Base): (SamplingFeatureTypeCV == "Site", "Site"), ], else_="samplingfeatures"), 'polymorphic_identity':'samplingfeatures', - # 'with_polymorphic':'*' - } + } - def shape(self): - """ - Method name based on shapely shapely.geometry.shape() function. - Returns a shapely geometry object - :return geomshape: - """ - _FeatureGeometry = self.FeatureGeometry - geomshape = None - if _FeatureGeometry is not None: - print _FeatureGeometry - print _FeatureGeometry.geom_wkb - if is_hex(_FeatureGeometry.geom_wkb): - # to parse wkb hex string directly - geomshape = wkb.loads(_FeatureGeometry.geom_wkb, hex=True) - # _FeatureGeometry = GeometryColumn('featuregeometry', Geometry) - else: - geomshape = wkt.loads(str(_FeatureGeometry.geom_wkb)) - return geomshape + # def shape(self): + # """ + # Method name based on shapely shapely.geometry.shape() function. + # Returns a shapely geometry object + # :return geomshape: + # """ + # _FeatureGeometry = self.FeatureGeometry + # geomshape = None + # if _FeatureGeometry is not None: + # print _FeatureGeometry + # print _FeatureGeometry.geom_wkb + # if is_hex(_FeatureGeometry.geom_wkb): + # # to parse wkb hex string directly + # geomshape = wkb.loads(_FeatureGeometry.geom_wkb, hex=True) + # # _FeatureGeometry = GeometryColumn('featuregeometry', Geometry) + # else: + # geomshape = wkt.loads(str(_FeatureGeometry.geom_wkb)) + # + # return geomshape def __repr__(self): # geom = self.shape() @@ -323,7 +327,7 @@ def __repr__(self): self.Elevation_m, self.FeatureGeometryWKT) -GeometryDDL(SamplingFeatures.__table__) # Geoalchemy1 +# GeometryDDL(SamplingFeatures.__table__) # Geoalchemy1 class FeatureActions(Base): @@ -885,6 +889,10 @@ class Simulations(Base): Model = relationship(Models) Unit = relationship(Units) + def __repr__(self): + return "" % \ + (self.SimulationID, self.ActionID, self.SimulationName, self.SimulationStartDateTime) + # Part of the Provenance table, needed here to meet dependancies class Citations(Base): @@ -1646,9 +1654,10 @@ class TimeSeriesResults(Results): __mapper_args__ = {'polymorphic_identity':'Time series coverage'} def __repr__(self): - return "" % \ - (self.ResultID, self.XLocation, self.YLocation, self.XLocation, - self.ResultTypeCV, self.XLocationUnitsObj, self.SpatialReferenceObj, + return "" % \ + ( self.FeatureActionID, self.ProcessingLevelID, self.VariableID, self.ProcessinglevelID, + self.self.XLocation, self.YLocation, + self.ResultTypeCV, self.IntendedTimeSpacing, self.AggregationStatisticCV) diff --git a/odm2api/ODM2/services/createService.py b/odm2api/ODM2/services/createService.py index cd2f88b..a882ef9 100644 --- a/odm2api/ODM2/services/createService.py +++ b/odm2api/ODM2/services/createService.py @@ -17,86 +17,137 @@ def __init__(self, session): # Annotations # ################################################################################ - def create(self, values): - if len(values)>1: - self._session.add_all(values) - else: - self._session.add(values) + def create(self, value): + self._session.add(value) self._session.commit() + return value + + def createAll(self, values): + self._session.add_all(values) + self._session.commit() + return values + def createVariable(self, var): self._session.add(var) self._session.commit() + return var + def createMethod(self, method): self._session.add(method) self._session.commit() + return method + def createProcessingLevel(self, proclevel): self._session.add(proclevel) self._session.commit() + return proclevel + + #send in any type of sampling feature def createSamplingFeature(self, samplingfeature): self._session.add(samplingfeature) self._session.commit() + return samplingfeature + def createUnit(self, unit): self._session.add(unit) self._session.commit() + return unit def createOrganization(self, org): self._session.add(org) self._session.commit() + return org def createPerson(self, person): self._session.add(person) self._session.commit() + return person + def createAffiliation(self, affiliation): self._session.add(affiliation) self._session.commit() + return affiliation + def createDataset(self, dataset): self._session.add(dataset) self._session.commit() + return dataset + def createDatasetResults(self, datasetresult): self._session.add(datasetresult) self._session.commit() - def createAction(self, action, actionby): + return datasetresult + + def createAction(self, action): self._session.add(action) + self._session.commit() + return action + + def createActionby(self, actionby): + self._session.add(actionby) self._session.commit() + return actionby + + def createFeatureAction(self, action): + self._session.add(action) + self._session.commit() + return action def createRelatedAction(self, relatedaction): self._session.add(relatedaction) self._session.commit() + return relatedaction + + #send in any type of result object def createResult(self, result): self._session.add(result) self._session.commit() + return result + + - def createResultValues(self, values): - self._session.add(values) + def createResultValue(self, value): + self._session.add(value) self._session.commit() + self._session.flush() + return value + def createSpatialReference(self, spatialref): self._session.add(spatialref) self._session.commit() + return spatialref + def createModel(self, model): self._session.add(model) self._session.commit() + return model + def createRelatedModel(self, relatedmodel): self._session.add(relatedmodel) self._session.commit() + return relatedmodel + def createSimulation(self, simulation): self._session.add(simulation) self._session.commit() + return simulation + def createTimeSeriesResultValues(self, datavalues): try: tablename = TimeSeriesResultValues.__tablename__ @@ -115,383 +166,6 @@ def createTimeSeriesResultValues(self, datavalues): return None - - -# ################################################################################ -# Core -# ################################################################################ - -# def createVariable(self, code, name, vType, nodv, speciation=None, definition=None): -# """ -# -# :param code: -# :type String(50): -# :param name: -# :type String(255): -# :param vType: -# :type String(255): -# :param nodv: -# :type Float(53): -# :param speciation: -# :type String(255): -# :param definition: -# :type String(500): -# :return: -# """ -# var = Variables() -# var.VariableCode = code -# var.VariableNameCV = name -# var.VariableDefinition = definition -# var.VariableTypeCV = vType -# var.NoDataValue = nodv -# var.SpeciationCV = speciation -# -# self._session.add(var) -# self._session.commit() -# -# return var -# -# def createMethod(self, code, name, vType, orgId=None, link=None, description=None): -# """Create Method table for the database -# -# :param code: -# :type String(50): -# :param name: -# :type String(255): -# :param vType: -# :type String(255): -# :param orgId: -# :type Integer: -# :param link: -# :type String(255): -# :param description: -# :type String(500): -# :return: -# """ -# -# meth = Methods() -# meth.MethodCode = code -# meth.MethodName = name -# meth.MethodDescription = description -# meth.MethodTypeCV = vType -# meth.MethodLink = link -# meth.OrganizationID = orgId -# -# self._session.add(meth) -# self._session.commit() -# -# return meth -# -# def createProcessingLevel(self, code, definition=None, explanation=None): -# """Create Processinglevel table for database -# -# :param code: -# :type String(50): -# :param definition: -# :type String(500): -# :param explanation: -# :type String(500): -# :return: -# """ -# pl = ProcessingLevels() -# pl.ProcessingLevelCode = str(code) -# pl.Definition = definition -# pl.Explanation = explanation -# -# self._session.add(pl) -# self._session.commit() -# -# return pl -# -# def createSamplingFeature(self, uuid, code, vType, name=None, description=None, geoType=None, elevation=None, -# elevationDatum=None, featureGeo=None): -# """Create SamplingFeature table -# -# :param code: -# :type String(50): -# :param vType: -# :type String(255): -# :param name: -# :type String(255): -# :param description: -# :type String(500): -# :param geoType: -# :type String(255): -# :param evelation: -# :type Float(53): -# :param evelationDatum: -# :type String(255): -# :param featureGeo: -# :type NullType: -# :return: -# """ -# -# sf = SamplingFeatures() -# sf.SamplingFeatureUUID = uuid -# sf.SamplingFeatureTypeCV = vType -# sf.SamplingFeatureCode = code -# sf.SamplingFeatureName = name -# sf.SamplingFeatureDescription = description -# sf.SamplingFeatureGeoTypeCV = geoType -# sf.Elevation_m = elevation -# sf.ElevationDatumCV = elevationDatum -# sf.FeatureGeometry = featureGeo -# -# self._session.add(sf) -# self._session.commit() -# -# return sf -# -# -# def createUnit(self, type, abbrev, name, link=None): -# """Create Unit table -# -# :param code: -# :type String(255): -# :param abbrev: -# :type String(50): -# :param name: -# :type String(255): -# :return: -# """ -# unit = Units() -# unit.UnitsTypeCV = type -# unit.UnitsAbbreviation = abbrev -# unit.UnitsName = name -# unit.UnitsLink = link -# -# self._session.add(unit) -# self._session.commit() -# -# return unit -# -# def createOrganization(self, cvType, code, name, desc, link, parentOrgId): -# """Create Organization table -# -# :param cvType: -# :type String(255): -# :param code: -# :type String(50): -# :param name: -# :type String(255): -# :param desc: -# :type String(500): -# :param link: -# :type String(255): -# :param parentOrgId: -# :type Integer: -# :return: -# """ -# -# org = Organizations() -# org.OrganizationTypeCV = cvType -# org.OrganizationCode = code -# org.OrganizationName = name -# org.OrganizationDescription = desc -# org.OrganizationLink = link -# org.ParentOrganizationID = parentOrgId -# -# self._session.add(org) -# self._session.commit() -# -# return org -# -# def createPerson(self, firstName, lastName, middleName=""): -# """Create Person Table -# -# :param firstName: -# :type String(255): -# :param lastName: -# :type String(255): -# :param middleName: -# :type String(255): -# :return: -# """ -# -# p = People() -# p.PersonFirstName = firstName -# p.PersonMiddleName = middleName -# p.PersonLastName = lastName -# -# -# -# self._session.add(p) -# self._session.commit() -# -# return p -# -# # def createResult(self, uuid, featureActionId, vType, ): -# -# def createAffiliation(self, personid, organizationid, email, phone=None, address=None, link=None, -# iscontact=False, affiliation_start=dt.datetime.today(), affiliation_end=None): -# """ -# -# :param personid: id of the person record -# :param organizationid: id of the organization record -# :param email: primary email address -# :param phone: primary phone number -# :param address: primary mailing address -# :param link: url pointing the web resource such as researchGate profile -# :param iscontact: indicate if this person is the primary contact for the organization -# :param affiliation_start: begin date of affiliation with organization -# :param affiliation_end: end date of affiliation with organization -# :return: ODM2.Affiliation -# """ -# -# # create affiliation object -# a = Affiliations() -# a.PersonID = personid -# a.OrganizationID = organizationid -# a.PrimaryEmail = email -# a.PrimaryPhone = phone -# a.PrimaryAddress = address -# a.PersonLink = link -# a.IsPrimaryOrganizationContact = iscontact -# a.AffiliationStartDate = affiliation_start -# a.AffiliationEndDate = affiliation_end -# -# self._session.add(a) -# self._session.commit() -# #self._session.flush() -# # self._session.refresh(a) -# -# print a.OrganizationID -# -# return a -# -# def createDataset(self, dstype, dscode, dstitle, dsabstract): -# ds = DataSets() -# -# # create the dataset -# ds.DataSetTypeCV = dstype -# ds.DataSetCode = dscode -# ds.DataSetTitle = dstitle -# ds.DataSetAbstract = dsabstract -# ds.DataSetUUID = uuid.uuid4().hex -# -# self._session.add(ds) -# self._session.commit() -# -# return ds -# -# def createDatasetResults(self, dsid, resultid): -# dsr = DataSetsResults() -# -# # link dataset to results -# dsr.DatasetID = dsid -# dsr.ResultID = resultid -# -# self._session.add(dsr) -# self._session.commit() -# -# return dsr -# -# def createAction(self, type, methodid, begindatetime, begindatetimeoffset, enddatetime=None, enddatetimeoffset=None, -# description=None, filelink=None): -# action = Actions() -# action.ActionTypeCV = type -# action.MethodID = methodid -# action.BeginDateTime = begindatetime -# action.BeginDateTimeUTCOffset = begindatetimeoffset -# action.EndDateTime = enddatetime -# action.EndDateTimeUTCOffset = enddatetimeoffset -# action.ActionDescription = description -# action.ActionFileLink = filelink -# -# self._session.add(action) -# self._session.commit() -# -# return action -# -# def createActionBy(self, actionid, affiliationid, isactionlead=True, roledescription=None): -# actionby = ActionBy() -# actionby.ActionID = actionid -# actionby.AffiliationID = affiliationid -# actionby.IsActionLead = isactionlead -# actionby.RoleDescription = roledescription -# -# self._session.add(actionby) -# self._session.commit() -# -# return actionby -# -# def createFeatureAction(self, samplingfeatureid, actionid): -# featureaction = FeatureActions() -# featureaction.SamplingFeatureID = samplingfeatureid -# featureaction.ActionID = actionid -# -# self._session.add(featureaction) -# self._session.commit() -# -# return featureaction -# -# -# def createResult(self, featureactionid, variableid, unitid, processinglevelid, valuecount, sampledmedium, -# resulttypecv, -# taxonomicclass=None, resultdatetime=None, resultdatetimeutcoffset=None, -# validdatetime=None, validdatetimeutcoffset=None, statuscv=None): -# result = Results() -# #result.ResultUUID = uuid.uuid4().hex -# result.ResultUUID = str(uuid.uuid4()) # Denver -# result.FeatureActionID = featureactionid -# result.ResultTypeCV = resulttypecv -# result.VariableID = variableid -# result.UnitsID = unitid -# result.ProcessingLevelID = processinglevelid -# result.ValueCount = valuecount -# result.SampledMediumCV = sampledmedium -# result.TaxonomicClassifierID = taxonomicclass -# result.ResultDateTime = resultdatetime -# result.ResultDateTimeUTCOffset = resultdatetimeutcoffset -# result.ValidDateTime = validdatetime -# result.ValidDateTimeUTCOffset = validdatetimeutcoffset -# result.StatusCV = statuscv -# -# self._session.add(result) -# self._session.commit() -# -# return result -# - -# -# -# def createTimeSeriesResult(self, result, aggregationstatistic, xloc=None, xloc_unitid=None, yloc=None, -# yloc_unitid=None, zloc=None, zloc_unitid=None, -# srsID=None, timespacing=None, timespacing_unitid=None): -# -# tsr = TimeSeriesResults() -# -# tsr.ResultID = result.ResultID -# #tsr.ResultUUID = result.ResultUUID -# -# -# tsr.XLocation = xloc -# tsr.XLocationUnitsID = xloc_unitid -# tsr.YLocation = yloc -# tsr.YLocationUnitsID = yloc_unitid -# tsr.ZLocation = zloc -# tsr.ZLocationUnitsID = zloc_unitid -# tsr.SpatialReferenceID = srsID -# tsr.IntendedTimeSpacing = timespacing -# tsr.IntendedTimeSpacingUnitsID = timespacing_unitid -# tsr.AggregationStatisticCV = aggregationstatistic -# -# -# #tsr.ResultID = result.ResultID -# # tsr.ResultUUID = result.ResultUUID -# # tsr.FeatureActionID = result.FeatureActionID -# # tsr.VariableID = result.VariableID -# # tsr.UnitsID = result.UnitsID -# # tsr.ProcessingLevelID = result.ProcessingLevelID -# # tsr.ValueCount = result.ValueCount -# # tsr.SampledMediumCV = result.SampledMediumCV -# # tsr.ResultTypeCV = result.ResultTypeCV -# -# self._session.add(tsr) -# self._session.commit() -# -# return tsr -# ''' # def createTimeSeriesResultValues(self, resultid, datavalues, datetimes, datetimeoffsets, censorcodecv, # qualitycodecv, # timeaggregationinterval, timeaggregationunit): @@ -573,133 +247,4 @@ def createTimeSeriesResultValues(self, datavalues): # except Exception, e: # print e # return None -# -# -# # ################################################################################ -# # Sampling Features -# # ################################################################################ -# -# -# def createSite(self, sfId, spatialRefId, vType, latitude, longitude): -# """Create Site table -# -# :param vType: -# :type String(255): -# :param latitude: -# :type Float(53): -# :param longitude: -# :type Float(53): -# :return: -# """ -# -# s = Sites() -# s.SamplingFeatureID = sfId -# s.SpatialReferenceID = spatialRefId -# s.SiteTypeCV = vType -# s.Latitude = latitude -# s.Longitude = longitude -# -# self._session.add(s) -# self._session.commit() -# -# return s -# -# -# def createSpatialReference(self, srsCode, srsName, srsDescription=None): -# spatialreference = SpatialReferences() -# spatialreference.SRSCode = srsCode -# spatialreference.SRSName = srsName -# spatialreference.SRSDescription = srsDescription -# -# self._session.add(spatialreference) -# self._session.commit() -# -# return spatialreference -# -# -# # ################################################################################ -# # Sensors -# # ################################################################################ -# -# def createDeploymentAction(self, actionId, cvType, desc, configActionId, calibActionId, spatialOffSet, -# deploymentSchematicLink, **kwargs): -# """Create DeploymentAction Object -# -# :param **kwargs: -# :param actionId: -# :type Integer: -# :param cvType: -# :type String(255): -# :param desc: -# :type String(500): -# :param configActionId: -# :type Integer: -# :param calibActionId: -# :type Integer: -# :param spatialOffSet: -# :type Integer: -# :param deploymentSchematicLink: -# :type String(255): -# :return: -# """ -# -# da = DeploymentActions() -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# -# -# # ################################################################################ -# # Simulation -# # ################################################################################ -# -# -# def createModel(self, code, name, description=None): -# model = Models() -# model.ModelCode = code -# model.ModelName = name -# model.ModelDescription = description -# -# self._session.add(model) -# self._session.commit() -# -# return model -# -# -# def createRelatedModel(self, modelid, relatedModelID, relationshipType): -# related = RelatedModels() -# related.ModelID = modelid -# related.RelationshipTypeCV = relationshipType -# related.RelatedModelID = relatedModelID -# -# self._session.add(related) -# self._session.commit() -# -# return related -# -# -# def createSimulation(self, actionid, modelID, simulationName, simulationDescription, simulationStartDateTime, -# simulationStartOffset, -# simulationEndDateTime, simulationEndOffset, timeStepValue, timeStepUnitID, -# inputDatasetID=None): -# sim = Simulations() -# sim.ActionID = actionid -# sim.ModelID = modelID -# sim.SimulationName = simulationName -# sim.SimulationDescription = simulationDescription -# sim.SimulationStartDateTime = simulationStartDateTime -# sim.SimulationStartDateTimeUTCOffset = simulationStartOffset -# sim.SimulationEndDateTime = simulationEndDateTime -# sim.SimulationEndDateTimeUTCOffset = simulationEndOffset -# sim.TimeStepValue = timeStepValue -# sim.TimeStepUnitsID = timeStepUnitID -# sim.InputDatasetID = inputDatasetID -# -# self._session.add(sim) -# self._session.commit() -# -# return sim -# +# \ No newline at end of file diff --git a/odm2api/ODM2/services/createService.py.orig b/odm2api/ODM2/services/createService.py.orig deleted file mode 100644 index b6ea04b..0000000 --- a/odm2api/ODM2/services/createService.py.orig +++ /dev/null @@ -1,724 +0,0 @@ -__author__ = 'sreeder' - -import datetime as dt -import uuid - -# from src.api.ODM2.LikeODM1.model import Site -from odm2api.ODM2.models import * -from odm2api.ODM2 import serviceBase - - -class CreateODM2(serviceBase): - ''' - def __init__(self, session): - self._session = session - ''' - # ################################################################################ - # Annotations - # ################################################################################ - - def create(self, values): - if len(values)>1: - self._session.add_all(values) - else: - self._session.add(values) - self._session.commit() - - def createVariable(self, var): - self._session.add(var) - self._session.commit() - - def createMethod(self, method): - self._session.add(method) - self._session.commit() - - def createProcessingLevel(self, proclevel): - self._session.add(proclevel) - self._session.commit() - - def createSamplingFeature(self, samplingfeature): - self._session.add(samplingfeature) - self._session.commit() - - def createUnit(self, unit): - self._session.add(unit) - self._session.commit() - - def createOrganization(self, org): - self._session.add(org) - self._session.commit() - - def createPerson(self, person): - self._session.add(person) - self._session.commit() - - def createAffiliation(self, affiliation): - self._session.add(affiliation) - self._session.commit() -<<<<<<< HEAD -======= - #self._session.flush() - # self._session.refresh(a) - - print(a.OrganizationID) - - return a - - def createDataset(self, dstype, dscode, dstitle, dsabstract): - ds = DataSets() - - # create the dataset - ds.DataSetTypeCV = dstype - ds.DataSetCode = dscode - ds.DataSetTitle = dstitle - ds.DataSetAbstract = dsabstract - ds.DataSetUUID = uuid.uuid4().hex ->>>>>>> origin/master - - def createDataset(self, dataset): - self._session.add(dataset) - self._session.commit() - - def createDatasetResults(self, datasetresult): - self._session.add(datasetresult) - self._session.commit() - - def createAction(self, action, actionby): - self._session.add(action) - self._session.add(actionby) - self._session.commit() - - def createRelatedAction(self, relatedaction): - self._session.add(relatedaction) - self._session.commit() - - def createResult(self, result): - self._session.add(result) - self._session.commit() - - def createResultValues(self, values): - self._session.add(values) - self._session.commit() - - def createSpatialReference(self, spatialref): - self._session.add(spatialref) - self._session.commit() - - def createModel(self, model): - self._session.add(model) - self._session.commit() - - def createRelatedModel(self, relatedmodel): - self._session.add(relatedmodel) - self._session.commit() - - def createSimulation(self, simulation): - self._session.add(simulation) - self._session.commit() - - def createTimeSeriesResultValues(self, datavalues): - try: - tablename = TimeSeriesResultValues.__tablename__ - print "I am TS saving name the table name"+ tablename - datavalues.to_sql(name="TimeSeriesResultValues", - schema=TimeSeriesResultValues.__table_args__['schema'], - if_exists='append', - chunksize=1000, - con=self._session_factory.engine, - index=False) - self._session.commit() - - return datavalues - except Exception as e: - print(e) - return None - - - - -# ################################################################################ -# Core -# ################################################################################ - -# def createVariable(self, code, name, vType, nodv, speciation=None, definition=None): -# """ -# -# :param code: -# :type String(50): -# :param name: -# :type String(255): -# :param vType: -# :type String(255): -# :param nodv: -# :type Float(53): -# :param speciation: -# :type String(255): -# :param definition: -# :type String(500): -# :return: -# """ -# var = Variables() -# var.VariableCode = code -# var.VariableNameCV = name -# var.VariableDefinition = definition -# var.VariableTypeCV = vType -# var.NoDataValue = nodv -# var.SpeciationCV = speciation -# -# self._session.add(var) -# self._session.commit() -# -# return var -# -# def createMethod(self, code, name, vType, orgId=None, link=None, description=None): -# """Create Method table for the database -# -# :param code: -# :type String(50): -# :param name: -# :type String(255): -# :param vType: -# :type String(255): -# :param orgId: -# :type Integer: -# :param link: -# :type String(255): -# :param description: -# :type String(500): -# :return: -# """ -# -# meth = Methods() -# meth.MethodCode = code -# meth.MethodName = name -# meth.MethodDescription = description -# meth.MethodTypeCV = vType -# meth.MethodLink = link -# meth.OrganizationID = orgId -# -# self._session.add(meth) -# self._session.commit() -# -# return meth -# -# def createProcessingLevel(self, code, definition=None, explanation=None): -# """Create Processinglevel table for database -# -# :param code: -# :type String(50): -# :param definition: -# :type String(500): -# :param explanation: -# :type String(500): -# :return: -# """ -# pl = ProcessingLevels() -# pl.ProcessingLevelCode = str(code) -# pl.Definition = definition -# pl.Explanation = explanation -# -# self._session.add(pl) -# self._session.commit() -# -# return pl -# -# def createSamplingFeature(self, uuid, code, vType, name=None, description=None, geoType=None, elevation=None, -# elevationDatum=None, featureGeo=None): -# """Create SamplingFeature table -# -# :param code: -# :type String(50): -# :param vType: -# :type String(255): -# :param name: -# :type String(255): -# :param description: -# :type String(500): -# :param geoType: -# :type String(255): -# :param evelation: -# :type Float(53): -# :param evelationDatum: -# :type String(255): -# :param featureGeo: -# :type NullType: -# :return: -# """ -# -# sf = SamplingFeatures() -# sf.SamplingFeatureUUID = uuid -# sf.SamplingFeatureTypeCV = vType -# sf.SamplingFeatureCode = code -# sf.SamplingFeatureName = name -# sf.SamplingFeatureDescription = description -# sf.SamplingFeatureGeoTypeCV = geoType -# sf.Elevation_m = elevation -# sf.ElevationDatumCV = elevationDatum -# sf.FeatureGeometry = featureGeo -# -# self._session.add(sf) -# self._session.commit() -# -# return sf -# -# -# def createUnit(self, type, abbrev, name, link=None): -# """Create Unit table -# -# :param code: -# :type String(255): -# :param abbrev: -# :type String(50): -# :param name: -# :type String(255): -# :return: -# """ -# unit = Units() -# unit.UnitsTypeCV = type -# unit.UnitsAbbreviation = abbrev -# unit.UnitsName = name -# unit.UnitsLink = link -# -# self._session.add(unit) -# self._session.commit() -# -# return unit -# -# def createOrganization(self, cvType, code, name, desc, link, parentOrgId): -# """Create Organization table -# -# :param cvType: -# :type String(255): -# :param code: -# :type String(50): -# :param name: -# :type String(255): -# :param desc: -# :type String(500): -# :param link: -# :type String(255): -# :param parentOrgId: -# :type Integer: -# :return: -# """ -# -# org = Organizations() -# org.OrganizationTypeCV = cvType -# org.OrganizationCode = code -# org.OrganizationName = name -# org.OrganizationDescription = desc -# org.OrganizationLink = link -# org.ParentOrganizationID = parentOrgId -# -# self._session.add(org) -# self._session.commit() -# -# return org -# -# def createPerson(self, firstName, lastName, middleName=""): -# """Create Person Table -# -# :param firstName: -# :type String(255): -# :param lastName: -# :type String(255): -# :param middleName: -# :type String(255): -# :return: -# """ -# -# p = People() -# p.PersonFirstName = firstName -# p.PersonMiddleName = middleName -# p.PersonLastName = lastName -# -# -# -# self._session.add(p) -# self._session.commit() -# -# return p -# -# # def createResult(self, uuid, featureActionId, vType, ): -# -# def createAffiliation(self, personid, organizationid, email, phone=None, address=None, link=None, -# iscontact=False, affiliation_start=dt.datetime.today(), affiliation_end=None): -# """ -# -# :param personid: id of the person record -# :param organizationid: id of the organization record -# :param email: primary email address -# :param phone: primary phone number -# :param address: primary mailing address -# :param link: url pointing the web resource such as researchGate profile -# :param iscontact: indicate if this person is the primary contact for the organization -# :param affiliation_start: begin date of affiliation with organization -# :param affiliation_end: end date of affiliation with organization -# :return: ODM2.Affiliation -# """ -# -# # create affiliation object -# a = Affiliations() -# a.PersonID = personid -# a.OrganizationID = organizationid -# a.PrimaryEmail = email -# a.PrimaryPhone = phone -# a.PrimaryAddress = address -# a.PersonLink = link -# a.IsPrimaryOrganizationContact = iscontact -# a.AffiliationStartDate = affiliation_start -# a.AffiliationEndDate = affiliation_end -# -# self._session.add(a) -# self._session.commit() -# #self._session.flush() -# # self._session.refresh(a) -# -# print a.OrganizationID -# -# return a -# -# def createDataset(self, dstype, dscode, dstitle, dsabstract): -# ds = DataSets() -# -# # create the dataset -# ds.DataSetTypeCV = dstype -# ds.DataSetCode = dscode -# ds.DataSetTitle = dstitle -# ds.DataSetAbstract = dsabstract -# ds.DataSetUUID = uuid.uuid4().hex -# -# self._session.add(ds) -# self._session.commit() -# -# return ds -# -# def createDatasetResults(self, dsid, resultid): -# dsr = DataSetsResults() -# -# # link dataset to results -# dsr.DatasetID = dsid -# dsr.ResultID = resultid -# -# self._session.add(dsr) -# self._session.commit() -# -# return dsr -# -# def createAction(self, type, methodid, begindatetime, begindatetimeoffset, enddatetime=None, enddatetimeoffset=None, -# description=None, filelink=None): -# action = Actions() -# action.ActionTypeCV = type -# action.MethodID = methodid -# action.BeginDateTime = begindatetime -# action.BeginDateTimeUTCOffset = begindatetimeoffset -# action.EndDateTime = enddatetime -# action.EndDateTimeUTCOffset = enddatetimeoffset -# action.ActionDescription = description -# action.ActionFileLink = filelink -# -# self._session.add(action) -# self._session.commit() -# -# return action -# -# def createActionBy(self, actionid, affiliationid, isactionlead=True, roledescription=None): -# actionby = ActionBy() -# actionby.ActionID = actionid -# actionby.AffiliationID = affiliationid -# actionby.IsActionLead = isactionlead -# actionby.RoleDescription = roledescription -# -# self._session.add(actionby) -# self._session.commit() -# -# return actionby -# -# def createFeatureAction(self, samplingfeatureid, actionid): -# featureaction = FeatureActions() -# featureaction.SamplingFeatureID = samplingfeatureid -# featureaction.ActionID = actionid -# -# self._session.add(featureaction) -# self._session.commit() -# -# return featureaction -# -# -# def createResult(self, featureactionid, variableid, unitid, processinglevelid, valuecount, sampledmedium, -# resulttypecv, -# taxonomicclass=None, resultdatetime=None, resultdatetimeutcoffset=None, -# validdatetime=None, validdatetimeutcoffset=None, statuscv=None): -# result = Results() -# #result.ResultUUID = uuid.uuid4().hex -# result.ResultUUID = str(uuid.uuid4()) # Denver -# result.FeatureActionID = featureactionid -# result.ResultTypeCV = resulttypecv -# result.VariableID = variableid -# result.UnitsID = unitid -# result.ProcessingLevelID = processinglevelid -# result.ValueCount = valuecount -# result.SampledMediumCV = sampledmedium -# result.TaxonomicClassifierID = taxonomicclass -# result.ResultDateTime = resultdatetime -# result.ResultDateTimeUTCOffset = resultdatetimeutcoffset -# result.ValidDateTime = validdatetime -# result.ValidDateTimeUTCOffset = validdatetimeutcoffset -# result.StatusCV = statuscv -# -# self._session.add(result) -# self._session.commit() -# -# return result -# - -# -# -# def createTimeSeriesResult(self, result, aggregationstatistic, xloc=None, xloc_unitid=None, yloc=None, -# yloc_unitid=None, zloc=None, zloc_unitid=None, -# srsID=None, timespacing=None, timespacing_unitid=None): -# -# tsr = TimeSeriesResults() -# -# tsr.ResultID = result.ResultID -# #tsr.ResultUUID = result.ResultUUID -# -# -# tsr.XLocation = xloc -# tsr.XLocationUnitsID = xloc_unitid -# tsr.YLocation = yloc -# tsr.YLocationUnitsID = yloc_unitid -# tsr.ZLocation = zloc -# tsr.ZLocationUnitsID = zloc_unitid -# tsr.SpatialReferenceID = srsID -# tsr.IntendedTimeSpacing = timespacing -# tsr.IntendedTimeSpacingUnitsID = timespacing_unitid -# tsr.AggregationStatisticCV = aggregationstatistic -# -# -# #tsr.ResultID = result.ResultID -# # tsr.ResultUUID = result.ResultUUID -# # tsr.FeatureActionID = result.FeatureActionID -# # tsr.VariableID = result.VariableID -# # tsr.UnitsID = result.UnitsID -# # tsr.ProcessingLevelID = result.ProcessingLevelID -# # tsr.ValueCount = result.ValueCount -# # tsr.SampledMediumCV = result.SampledMediumCV -# # tsr.ResultTypeCV = result.ResultTypeCV -# -# self._session.add(tsr) -# self._session.commit() -# -# return tsr -# ''' -# def createTimeSeriesResultValues(self, resultid, datavalues, datetimes, datetimeoffsets, censorcodecv, -# qualitycodecv, -# timeaggregationinterval, timeaggregationunit): -# -# -# try: -# values = TimeSeriesResultValues() -# for i in range(len(datavalues)): -# values.ResultID = resultid -# values.CensorCodeCV = censorcodecv -# values.QualityCodeCV = qualitycodecv -# values.TimeAggregationInterval = timeaggregationinterval -# values.TimeAggregationIntervalUnitsID = timeaggregationunit -# values.DataValue = datavalues[i] -# values.ValueDateTime = datetimes[i] -# values.ValueDateTimeUTCOffset = datetimeoffsets[i] -# self._session.add(values) -# self._session.commit() -# return values -# except Exception, e: -# print e -# return None -# ''' -# -# def createTimeSeriesResultValues(self, datavalues): -# try: -# #using Pandas built-in --slow -# #changing way values sent --unknown error on insert -# #cols = datavalues.columns.tolist() -# #['ValueDateTime', 'DataValue', 'TimeAggregationInterval', 'TimeAggregationIntervalUnitsID', 'QualityCodeCV', 'CensorCodeCV', 'ResultID', 'ValueDateTimeUTCOffset'] -# #cols = ['ResultID','DataValue','ValueDateTime','ValueDateTimeUTCOffset','CensorCodeCV','QualityCodeCV','TimeAggregationInterval','TimeAggregationIntervalUnitsID'] -# #datavalues = datavalues[cols] -# #print datavalues -# #datavalues.to_sql(name=TimeSeriesResultValues.__tablename__, -# datavalues.to_sql(name="TimeSeriesResultValues", -# schema=TimeSeriesResultValues.__table_args__['schema'], -# if_exists='append', -# chunksize= 1000, -# con=self._session_factory.engine, -# index=False) -# self._session.commit() -# -# -# #using sqlalchemy core --sending empty parameters -# # data = datavalues.to_dict('records') -# # self._session.execute(TimeSeriesResultValues.__table__.insert(data)) -# -# #using cursor and StringIO --not all cursors have the copy_from function -# # print "using cursor" -# # import cStringIO -# # #stream the data using 'to_csv' and StringIO(); then use sql's 'copy_from' function -# # output = cStringIO.StringIO() -# # #ignore the index -# # datavalues.to_csv(output, sep='\t', header=False, index=False) -# # #jump to start of stream -# # output.seek(0) -# # contents = output.getvalue() -# # connection = self._session_factory.engine.raw_connection() -# # cur = connection.cursor() -# # #null values become '' -# # cur.copy_from(output, 'ODM2.TimeSeriesResultValues', null="") -# # connection.commit() -# # cur.close() -# -# #using Bulk Insert * user must have permissions --file created locally code running remote -# # datavalues.to_csv('C:\\Users\\Stephanie\\temp.csv') -# # sql = """ -# # BULK INSERT ODM2.TimeSeriesResultValues -# # FROM 'C:\\Users\\Stephanie\\temp.csv' WITH ( -# # FIELDTERMINATOR=',', -# # ROWTERMINATOR='\\n'); -# # """ -# # self._session.execute(sql) -# -# -# -# -# return datavalues -# except Exception, e: -# print e -# return None -# -# -# # ################################################################################ -# # Sampling Features -# # ################################################################################ -# -# -# def createSite(self, sfId, spatialRefId, vType, latitude, longitude): -# """Create Site table -# -# :param vType: -# :type String(255): -# :param latitude: -# :type Float(53): -# :param longitude: -# :type Float(53): -# :return: -# """ -# -# s = Sites() -# s.SamplingFeatureID = sfId -# s.SpatialReferenceID = spatialRefId -# s.SiteTypeCV = vType -# s.Latitude = latitude -# s.Longitude = longitude -# -# self._session.add(s) -# self._session.commit() -# -# return s -# -# -# def createSpatialReference(self, srsCode, srsName, srsDescription=None): -# spatialreference = SpatialReferences() -# spatialreference.SRSCode = srsCode -# spatialreference.SRSName = srsName -# spatialreference.SRSDescription = srsDescription -# -# self._session.add(spatialreference) -# self._session.commit() -# -# return spatialreference -# -# -# # ################################################################################ -# # Sensors -# # ################################################################################ -# -# def createDeploymentAction(self, actionId, cvType, desc, configActionId, calibActionId, spatialOffSet, -# deploymentSchematicLink, **kwargs): -# """Create DeploymentAction Object -# -# :param **kwargs: -# :param actionId: -# :type Integer: -# :param cvType: -# :type String(255): -# :param desc: -# :type String(500): -# :param configActionId: -# :type Integer: -# :param calibActionId: -# :type Integer: -# :param spatialOffSet: -# :type Integer: -# :param deploymentSchematicLink: -# :type String(255): -# :return: -# """ -# -# da = DeploymentActions() -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# da.ActionID = (kwargs['actionId'] if kwargs['actionId'] else None) -# -# -# # ################################################################################ -# # Simulation -# # ################################################################################ -# -# -# def createModel(self, code, name, description=None): -# model = Models() -# model.ModelCode = code -# model.ModelName = name -# model.ModelDescription = description -# -# self._session.add(model) -# self._session.commit() -# -# return model -# -# -# def createRelatedModel(self, modelid, relatedModelID, relationshipType): -# related = RelatedModels() -# related.ModelID = modelid -# related.RelationshipTypeCV = relationshipType -# related.RelatedModelID = relatedModelID -# -# self._session.add(related) -# self._session.commit() -# -# return related -# -# -# def createSimulation(self, actionid, modelID, simulationName, simulationDescription, simulationStartDateTime, -# simulationStartOffset, -# simulationEndDateTime, simulationEndOffset, timeStepValue, timeStepUnitID, -# inputDatasetID=None): -# sim = Simulations() -# sim.ActionID = actionid -# sim.ModelID = modelID -# sim.SimulationName = simulationName -# sim.SimulationDescription = simulationDescription -# sim.SimulationStartDateTime = simulationStartDateTime -# sim.SimulationStartDateTimeUTCOffset = simulationStartOffset -# sim.SimulationEndDateTime = simulationEndDateTime -# sim.SimulationEndDateTimeUTCOffset = simulationEndOffset -# sim.TimeStepValue = timeStepValue -# sim.TimeStepUnitsID = timeStepUnitID -# sim.InputDatasetID = inputDatasetID -# -# self._session.add(sim) -# self._session.commit() -# -# return sim -# diff --git a/odm2api/ODM2/services/readService.py b/odm2api/ODM2/services/readService.py index bcee945..0dbc619 100644 --- a/odm2api/ODM2/services/readService.py +++ b/odm2api/ODM2/services/readService.py @@ -9,19 +9,19 @@ class DetailedResult: def __init__(self, result, - samplingFeature, + sc, sn, method, variable, processingLevel, unit): # result.result_id etc. self.resultID = result.ResultID - self.samplingFeatureCode = samplingFeature.SamplingFeatureCode + self.samplingFeatureCode = sc#.SamplingFeatureCode self.methodCode = method.MethodCode self.variableCode = variable.VariableCode self.processingLevelCode = processingLevel.ProcessingLevelCode self.unitsName = unit.UnitsName - self.samplingFeatureName = samplingFeature.SamplingFeatureName + self.samplingFeatureName = sn#.SamplingFeatureName self.methodName = method.MethodName self.variableNameCV = variable.VariableNameCV self.processingLevelDef = processingLevel.Definition @@ -150,7 +150,10 @@ def getCVs(self, type): CV = CVVariableType else: return None - return self._session.query(CV).all() + try: + return self._session.query(CV).all() + except Exception as e: + print("Error running Query: %s" % e) # ################################################################################ # Core @@ -167,7 +170,7 @@ def getDetailedAffiliationInfo(self): return affiliationList def getDetailedResultInfo(self, resultTypeCV, resultID=None): - q = self._session.query(Results, SamplingFeatures, Methods, Variables, + q = self._session.query(Results, SamplingFeatures.SamplingFeatureCode, SamplingFeatures.SamplingFeatureName, Methods, Variables, ProcessingLevels, Units).filter(Results.VariableID == Variables.VariableID) \ .filter(Results.UnitsID == Units.UnitsID) \ .filter(Results.FeatureActionID == FeatureActions.FeatureActionID) \ @@ -178,14 +181,14 @@ def getDetailedResultInfo(self, resultTypeCV, resultID=None): .filter(Results.ResultTypeCV == resultTypeCV) resultList = [] if resultID: - for r, s, m, v, p, u in q.filter_by(ResultID=resultID).all(): + for r, sc, sn, m, v, p, u in q.filter_by(ResultID=resultID).all(): detailedResult = DetailedResult( \ - r, s, m, v, p, u) + r, sc, sn, m, v, p, u) resultList.append(detailedResult) else: - for r, s, m, v, p, u in q.all(): + for r, sc, sn, m, v, p, u in q.all(): detailedResult = DetailedResult( \ - r, s, m, v, p, u) + r, sc, sn, m, v, p, u) resultList.append(detailedResult) return resultList @@ -213,7 +216,8 @@ def getVariables(self, ids=None, codes=None): if codes: query = query.filter(Variables.VariableCode.in_(codes)) try: return query.all() - except: + except Exception as e: + print("Error running Query: %s" % e) return None """ @@ -235,8 +239,9 @@ def getMethods(self, ids=None, codes=None, type=None): if type: q = q.filter_by(MethodTypeCV=type) try: - q.all() - except: + return q.all() + except Exception as e: + print("Error running Query: %s" % e) return None """ @@ -257,7 +262,7 @@ def getProcessingLevels(self, ids=None, codes=None): try: return q.all() except Exception as e: - print(e) + print("Error running Query: %s" % e) return None """ @@ -284,7 +289,7 @@ def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=N try: return q.all() except Exception as e: - print(e) + print("Error running Query: %s" % e) return None def getRelatedSamplingFeatures(self, id): @@ -296,7 +301,11 @@ def getRelatedSamplingFeatures(self, id): sf = self._session.query(SamplingFeatures).select_from(RelatedFeatures).join(RelatedFeatures.RelatedFeatureObj) if id: sf = sf.filter(RelatedFeatures.RelatedFeatureID == id) - return sf.all() + try: + return sf.all() + except Exception as e: + print("Error running Query: %s" % e) + return None """ Action @@ -326,7 +335,8 @@ def getActions(self, ids=None, type=None, sfid=None): try: return q.all() - except: + except Exception as e: + print("Error running Query: %s" % e) return None def getRelatedActions(self, actionid=None): @@ -338,8 +348,11 @@ def getRelatedActions(self, actionid=None): """ q = self._session.query(Actions).select_from(RelatedActions).join(RelatedActions.RelatedActionObj) if actionid: q = q.filter(RelatedActions.ActionID == actionid) - - return q.all() + try: + return q.all() + except Exception as e: + print("Error running Query: %s" % e) + return None """ Unit @@ -359,7 +372,8 @@ def getUnits(self, ids=None, name=None, type=None): if type: q = q.filter(Units.UnitsTypeCV.ilike(type)) try: return q.all() - except: + except Exception as e: + print("Error running Query: %s" % e) return None """ @@ -378,7 +392,8 @@ def getOrganizations(self, ids=None, codes=None): if codes: q = q.filter(Organizations.OrganizationCode.in_(codes)) try: return q.all() - except: + except Exception as e: + print("Error running Query: %s" % e) return None """ @@ -399,7 +414,8 @@ def getPeople(self, ids=None, firstname=None, lastname=None): if lastname: q = q.filter(People.PersonLastName.ilike(lastname)) try: return q.all() - except: + except Exception as e: + print("Error running Query: %s" % e) return None def getAffiliations(self, ids=None, personfirst=None, personlast=None, orgcode=None): @@ -412,13 +428,16 @@ def getAffiliations(self, ids=None, personfirst=None, personlast=None, orgcode=N * Pass an OrganizationCode - returns a Affiliation object """ q = self._session.query(Affiliations) + if ids: q = q.filter(Affiliations.AffiliationID.in_(ids)) if orgcode: q = q.filter(Organizations.OrganizationCode.ilike(orgcode)) if personfirst: q = q.filter(People.PersonFirstName.ilike(personfirst)) - if personlast: q = q.filter(People.PersonLastName.ilike(personlast)).first() + if personlast: q = q.filter(People.PersonLastName.ilike(personlast)) + try: return q.all() - except: + except Exception as e: + print("Error running Query: %s"%e) return None """ @@ -447,7 +466,8 @@ def getResults(self, ids=None, uuids= None, actionid=None, simulationid = None) try: return query.all() - except: + except Exception as e: + print("Error running Query: %s" % e) return None # @@ -459,7 +479,7 @@ def getResults(self, ids=None, uuids= None, actionid=None, simulationid = None) # .join(Simulations) \ # .filter(Simulations.SimulationID == simulationid).all() # except Exception as e: - # print (e) + # print("Error running Query %s"%e) # return None # # @@ -474,7 +494,8 @@ def getResults(self, ids=None, uuids= None, actionid=None, simulationid = None) # join(SamplingFeatures). \ # join(Results). \ # filter_by(ResultID=resultID).one() - # except: + # except Exception as e: + # print("Error running Query %s"%e) # return None # # def getResultAndGeomByActionID(self, actionID): @@ -485,7 +506,8 @@ def getResults(self, ids=None, uuids= None, actionid=None, simulationid = None) # join(SamplingFeatures). \ # join(Actions). \ # filter_by(ActionID=actionID).all() - # except: + # except Exception as e: + # print("Error running Query"%e) # return None """ @@ -506,7 +528,8 @@ def getDataSets(self, codes=None, uuids=None): q.q.filter(DataSets.DataSetUUID.in_(uuids)) try: return q.all() - except: + except Exception as e: + print("Error running Query %s"%e) return None # ################################################################################ @@ -610,7 +633,8 @@ def getExtensionProperties(self, type=None): e = VariableExtensionPropertyValues try: return self._session.query(e).all() - except: + except Exception as e: + print("Error running Query: %s" % e) return None # ################################################################################ @@ -636,7 +660,8 @@ def getExternalIdentifiers(self, type=None): e = VariableExternalIdentifiers try: return self._session.query(e).all() - except: + except Exception as e: + print("Error running Query: %s" % e) return None # ################################################################################ @@ -720,7 +745,8 @@ def getResultValues(self, resultid, starttime=None, endtime=None): df = pd.DataFrame([dv.list_repr() for dv in vals.all()]) df.columns = vals[0].get_columns() return df - except: + except Exception as e: + print("Error running Query: %s" % e) return None # ################################################################################ @@ -731,7 +757,7 @@ def getResultValues(self, resultid, starttime=None, endtime=None): Site """ - def getSpatialReference(self, srsCodes=None): + def getSpatialReferences(self, srsCodes=None): """ getSpatialReference() * Pass a ResultID - Returns a result values object of type that is specific to the result type @@ -740,8 +766,9 @@ def getSpatialReference(self, srsCodes=None): q = self._session.query(SpatialReferences) if srsCodes: q.filter(SpatialReferences.SRSCode.in_(srsCodes)) try: - return q.first() - except: + return q.all() + except Exception as e: + print("Error running Query: %s" % e) return None @@ -762,7 +789,8 @@ def getSimulations(self, name=None, actionid=None): if actionid: s = s.filter_by(ActionID=actionid) try: return s.all() - except: + except Exception as e: + print("Error running Query: %s" % e) return None @@ -772,7 +800,8 @@ def getModels(self, codes=None): if codes: m = m.filter(Models.ModelCode.in_(codes)) try: return m.all() - except: + except Exception as e: + print("Error running Query: %s" % e) return None def getRelatedModels(self, id=None, code=None): @@ -801,12 +830,10 @@ def getRelatedModels(self, id=None, code=None): # if id: m = m.filter(RelatedModels.ModelID == id) # if code: m = m.filter(RelatedModels.ModelCode == code) - - try: return m.all() except Exception as e: - print(e) + print("Error running Query: %s" % e) return None diff --git a/odm2api/ODM2/services/readService.py.orig b/odm2api/ODM2/services/readService.py.orig deleted file mode 100644 index 38044e8..0000000 --- a/odm2api/ODM2/services/readService.py.orig +++ /dev/null @@ -1,956 +0,0 @@ -__author__ = 'jmeline' - -from sqlalchemy import func -import pandas as pd - -from odm2api.ODM2 import serviceBase -from odm2api.ODM2.models import * - - -class DetailedResult: - def __init__(self, result, - samplingFeature, - method, variable, - processingLevel, - unit): - # result.result_id etc. - self.resultID = result.ResultID - self.samplingFeatureCode = samplingFeature.SamplingFeatureCode - self.methodCode = method.MethodCode - self.variableCode = variable.VariableCode - self.processingLevelCode = processingLevel.ProcessingLevelCode - self.unitsName = unit.UnitsName - - self.samplingFeatureName = samplingFeature.SamplingFeatureName - self.methodName = method.MethodName - self.variableNameCV = variable.VariableNameCV - self.processingLevelDef = processingLevel.Definition - - -class DetailedAffiliation: - def __init__(self, affiliation, person, org): - self.affiliationID = affiliation.AffiliationID - self.name = person.PersonFirstName + \ - " " + \ - person.PersonLastName - self.organization = "(" + org.OrganizationCode + ") " + \ - org.OrganizationName - - # def __repr__(self): - # return str(self.name) + " " + str(self.organization) - - -class ReadODM2(serviceBase): - ''' - def __init__(self, session): - self._session = session - ''' - - # ################################################################################ - # Annotations - # ################################################################################ - - def getAnnotations(self, type=None): - - # TODO What keywords do I use for type - a = Annotations - if type == "action": - a = ActionAnnotations - elif type == "categoricalresultvalue": - a = CategoricalResultValueAnnotations - elif type == "equipmentannotation": - a = EquipmentAnnotations - elif type == "measurementresultvalue": - a = MeasurementResultValueAnnotations - elif type == "method": - a = MethodAnnotations - elif type == "pointcoverageresultvalue": - a = PointCoverageResultValueAnnotations - elif type == "profileresultvalue": - a = ProfileResultValueAnnotations - elif type == "result": - a = ResultAnnotations - elif type == "samplingfeature": - a = SamplingFeatureAnnotations - elif type == "sectionresultvalue": - a = SectionResultValueAnnotations - elif type == "spectraresultvalue": - a = SpectraResultValueAnnotations - elif type == "timeSeriesresultvalue": - a = TimeSeriesResultValueAnnotations - elif type == "trajectoryresultvalue": - a = TrajectoryResultValueAnnotations - elif type == "transectresultvalue": - a = TransectResultValueAnnotations - try: - return self._session.query(a).all() - except: - return None - - # ################################################################################ - # CV - # ############################################################################## - - def getCVs(self, type): - - CV = CVActionType - if type == "actiontype": - CV = CVActionType - elif type == "aggregationstatistic": - CV = CVAggregationStatistic - elif type == "annotationtype": - CV = CVAnnotationType - elif type == "censorcode": - CV = CVCensorCode - elif type == "dataqualitytype": - CV = CVDataQualityType - elif type == "dataset type": - CV = CVDataSetType - elif type == "Directive Type": - CV = CVDirectiveType - elif type == "Elevation Datum": - CV = CVElevationDatum - elif type == "Equipment Type": - CV = CVEquipmentType - elif type == "Medium": - CV = CVMediumType - elif type == "Method Type": - CV = CVMethodType - elif type == "Organization Type": - CV = CVOrganizationType - elif type == "Property Data Type": - CV = CVPropertyDataType - elif type == "Quality Code": - CV = CVQualityCode - elif type == "Relationship Type": - CV = CVRelationshipType - elif type == "Result Type": - CV = CVResultType - elif type == "Sampling Feature Geo-type": - CV = CVSamplingFeatureGeoType - elif type == "Sampling Feature Type": - CV = CVSamplingFeatureType - elif type == "Site Type": - CV = CVSiteType - elif type == "Spatial Offset Type": - CV = CVSpatialOffsetType - elif type == "Speciation": - CV = CVSpeciation - elif type == "Specimen Type": - CV = CVSpecimenType - elif type == "Status": - CV = CVStatus - elif type == "Taxonomic Classifier Type": - CV = CVTaxonomicClassifierType - elif type == "Units Type": - CV = CVUnitsType - elif type == "Variable Name": - CV = CVVariableName - elif type == "Variable Type": - CV = CVVariableType - else: - return None - return self._session.query(CV).all() - - # ################################################################################ - # Core - # ################################################################################ - - def getDetailedAffiliationInfo(self): - q = self._session.query(Affiliations, People, Organizations) \ - .filter(Affiliations.PersonID == People.PersonID) \ - .filter(Affiliations.OrganizationID == Organizations.OrganizationID) - affiliationList = [] - for a, p, o in q.all(): - detailedAffiliation = DetailedAffiliation(a, p, o) - affiliationList.append(detailedAffiliation) - return affiliationList - - def getDetailedResultInfo(self, resultTypeCV, resultID=None): - q = self._session.query(Results, SamplingFeatures, Methods, Variables, - ProcessingLevels, Units).filter(Results.VariableID == Variables.VariableID) \ - .filter(Results.UnitsID == Units.UnitsID) \ - .filter(Results.FeatureActionID == FeatureActions.FeatureActionID) \ - .filter(FeatureActions.SamplingFeatureID == SamplingFeatures.SamplingFeatureID) \ - .filter(FeatureActions.ActionID == Actions.ActionID) \ - .filter(Actions.MethodID == Methods.MethodID) \ - .filter(Results.ProcessingLevelID == ProcessingLevels.ProcessingLevelID) \ - .filter(Results.ResultTypeCV == resultTypeCV) - resultList = [] - if resultID: - for r, s, m, v, p, u in q.filter_by(ResultID=resultID).all(): - detailedResult = DetailedResult( \ - r, s, m, v, p, u) - resultList.append(detailedResult) - else: - for r, s, m, v, p, u in q.all(): - detailedResult = DetailedResult( \ - r, s, m, v, p, u) - resultList.append(detailedResult) - return resultList - - """ - Taxonomic Classifiers - """ - - def getTaxonomicClassifiers(self): - return self._session.query(TaxonomicClassifiers).all() - - """ - Variable - """ - - def getVariables(self, ids=None, codes=None): - """ - getVariables() - * Pass nothing - returns full list of variable objects - * Pass a list of VariableID - returns a single variable object - * Pass a list of VariableCode - returns a single variable object - """ - - query = self._session.query(Variables) - if ids: query = query.filter(Variables.VariableID.in_(ids)) - if codes: query = query.filter(Variables.VariableCode.in_(codes)) - try: - return query.all() - except: - return None - - """ - Method - """ - - def getMethods(self, ids=None, codes=None, type=None): - - """ - getMethods() - * Pass nothing - returns full list of method objects - * Pass a list of MethodID - returns a single method object - * Pass a list of MethodCode - returns a single method object - * Pass a MethodType - returns a list of method objects - """ - q = self._session.query(Methods) - if ids: q = q.filter(Methods.MethodID.in_(ids)) - if codes: q = q.filter(Methods.MethodCode.in_(codes)) - if type: q = q.filter_by(MethodTypeCV=type) - - try: - q.all() - except: - return None - - """ - ProcessingLevel - """ - - def getProcessingLevels(self, ids=None, codes=None): - """ - getProcessingLevels() - * Pass nothing - returns full list of ProcessingLevel objects - * Pass a list of ProcessingLevelID - returns a single processingLevel object - * Pass a list of ProcessingLevelCode - returns a single processingLevel object - """ - q = self._session.query(ProcessingLevels) - if ids: q = q.filter(ProcessingLevels.ProcessingLevels.in_(ids)) - if codes: q = q.filter(ProcessingLevels.ProcessingLevelCode.in_(codes)) - - try: -<<<<<<< HEAD - return q.all() - except: -======= - return self._session.query(ProcessingLevels).filter_by(ProcessingLevelCode=str(processingCode)).first() - except Exception as e: - print(e) ->>>>>>> origin/master - return None - - """ - Sampling Feature - """ - - def getSamplingFeatures(self, ids=None, codes=None, uuids=None, type=None, wkt=None): - """ - getSamplingFeatures - * Pass nothing - returns a list of all sampling feature objects with each object of type specific to that sampling feature - * Pass a list of SamplingFeatureID - returns a single sampling feature object - * Pass a list of SamplingFeatureCode - returns a single sampling feature object - * Pass a SamplingFeatureType - returns a list of sampling feature objects of the type passed in - * Pass a SamplingFeatureGeometry(TYPE????) - return a list of sampling feature objects - """ - - q = self._session.query(SamplingFeatures) - - if type: q = q.filter_by(SamplingFeatureTypeCV=type) - if ids: q = q.filter(SamplingFeatures.SamplingFeatureID.in_(ids)) - if codes: q = q.filter(SamplingFeatures.SamplingFeatureCode.in_(codes)) - if uuids: q = q.filter(SamplingFeatures.SamplingFeatureUUID.in_(uuids)) - if wkt: q = q.filter_by(FeatureGeometryWKT=wkt) - try: - return q.all() - except Exception as e: - print(e) - return None - -<<<<<<< HEAD - def getRelatedSamplingFeatures(self, id): - """ - - getRelatedSamplingFeatures() - * Pass a SamplingFeatureID - get a list of sampling feature objects related to the input sampling feature along with the relationship type - """ - - sf = self._session.query(SamplingFeatures).select_from(RelatedFeatures).join(RelatedFeatures.RelatedFeatureObj) - if id: sf = sf.filter(RelatedFeatures.RelatedFeatureID == id) - return sf.all() -======= - def getSamplingFeatureByGeometry(self, wkt_geometry): - - try: - # ST_Equals(geometry, geometry) - return self._session.query(SamplingFeatures).filter( - func.ST_AsText(SamplingFeatures.FeatureGeometry) == func.ST_AsText(wkt_geometry)).first() - except Exception as e: - print(e) - return None - - def getGeometryTest(self, TestGeom): - Geom = self._session.query(SamplingFeatures).first() - print("Queried Geometry: ", self._session.query(Geom.FeatureGeometry.ST_AsText()).first()) - GeomText = self._session.query( - func.ST_Union(Geom.FeatureGeometry, func.ST_GeomFromText(TestGeom)).ST_AsText()).first() - - print(GeomText) ->>>>>>> origin/master - - """ - Action - """ - - def getActions(self, ids=None, type=None, sfid=None): - - """ - getSamplingFeatures - * Pass nothing - returns a list of all Actions - * Pass a SamplingFeatureID - returns a single Action object - * Pass a list of ActionIDs - returns a single Action object - * Pass a ActionType - returns a list of Action objects of the type passed in - """ - a = Actions - if type == "equipment": - a = EquipmentActions - elif type == "calibration": - a = CalibrationActions - elif type == "maintenance": - a = MaintenanceActions - - q = self._session.query(a) - if ids: q = q.filter(a.ActionID.in_(ids)) - if sfid: - q = q.join(FeatureActions).filter(FeatureActions.SamplingFeatureID == sfid) - - try: - return q.all() - except: - return None - - def getRelatedActions(self, actionid=None): - - """ - getRelatedActions() - * Pass an ActionID - get a list of Action objects related to the input action along with the relatinship type - - """ - q = self._session.query(Actions).select_from(RelatedActions).join(RelatedActions.RelatedActionObj) - if actionid: q = q.filter(RelatedActions.ActionID == actionid) - - return q.all() - - """ - Unit - """ - - def getUnits(self, ids=None, name=None, type=None): - """ - getUnits() - * Pass nothing - returns a list of all units objects - * Pass a list of UnitsID - returns a single units object - * Pass UnitsName - returns a single units object - """ - - q = self._session.query(Units) - if ids: q = q.filter(Units.UnitsID.in_(ids)) - if name: q = q.filter(Units.UnitsName.ilike(name)) - if type: q = q.filter(Units.UnitsTypeCV.ilike(type)) - try: - return q.all() - except: - return None - - """ - Organization - """ - - def getOrganizations(self, ids=None, codes=None): - """ - getOrganizations() - * Pass nothing - returns a list of all organization objects - * Pass a list of OrganizationID - returns a single organization object - * Pass a list of OrganizationCode - returns a single organization object - """ - q = self._session.query(Organizations) - if ids: q = q.filter(Organizations.OrganizationID.in_(ids)) - if codes: q = q.filter(Organizations.OrganizationCode.in_(codes)) - try: - return q.all() - except: - return None - - """ - Person - """ - - def getPeople(self, ids=None, firstname=None, lastname=None): - """ - getPeople() - * Pass nothing - returns a list of all People objects - * Pass a list of PeopleID - returns a single People object - * Pass a First Name - returns a single People object - * Pass a Last Name - returns a single People object - """ - q = self._session.query(People) - if ids: q = q.filter(People.PersonID.in_(ids)) - if firstname: q = q.filter(People.PersonFirstName.ilike(firstname)) - if lastname: q = q.filter(People.PersonLastName.ilike(lastname)) - try: - return q.all() - except: - return None - - def getAffiliations(self, ids=None, personfirst=None, personlast=None, orgcode=None): - """ - getAffiliations() - * Pass nothing - returns a list of all Affiliation objects - * Pass a list of AffiliationID - returns a single Affiliation object - * Pass a First Name - returns a single Affiliation object - * Pass a Last Name - returns a single Affiliation object - * Pass an OrganizationCode - returns a Affiliation object - """ - q = self._session.query(Affiliations) - if ids: q = q.filter(Affiliations.AffiliationID.in_(ids)) - if orgcode: q = q.filter(Organizations.OrganizationCode.ilike(orgcode)) - if personfirst: q = q.filter(People.PersonFirstName.ilike(personfirst)) - if personlast: q = q.filter(People.PersonLastName.ilike(personlast)).first() - try: - return q.all() - except: - return None - - """ - Results - """ - - def getResults(self, ids=None, uuids= None, actionid=None, simulationid = None): - - # TODO what if user sends in both type and actionid vs just actionid - """ - getResults() - * Pass nothing - returns a list of all Results objects - * Pass a list of ResultID - returns a single Results object - * Pass an ActionID - returns a single Results object - """ - - query = self._session.query(Results) - - if actionid: query = query.join(FeatureActions).filter_by(ActionID=actionid) - if simulationid: query = query.join(FeatureActions)\ - .join(Actions)\ - .join(Simulations)\ - .filter_by(SimulationID = simulationid) - if ids: query = query.filter(Results.ResultID.in_(ids)) - if uuids: query =query.filter(Results.ResultUUID.in_(uuids)) - - try: - return query.all() - except: - return None - - # - # def getResultsBySimulationID(self, simulationid): - # try: - # return self._session.query(Results) \ - # .join(FeatureActions) \ - # .join(Actions) \ - # .join(Simulations) \ - # .filter(Simulations.SimulationID == simulationid).all() - # except Exception, e: - # print e - # return None - # - # - # def getResultValidDateTime(self, resultId): - # q = self._session.query(Results.ValidDateTime).filter(Results.ResultID == int(resultId)) - # return q.first() - # - # def getResultAndGeomByID(self, resultID): - # try: - # return self._session.query(Results, SamplingFeatures.FeatureGeometry.ST_AsText()). \ - # join(FeatureActions). \ - # join(SamplingFeatures). \ - # join(Results). \ - # filter_by(ResultID=resultID).one() - # except: - # return None - # - # def getResultAndGeomByActionID(self, actionID): - # - # try: - # return self._session.query(Results, SamplingFeatures.FeatureGeometry.ST_AsText()). \ - # join(FeatureActions). \ - # join(SamplingFeatures). \ - # join(Actions). \ - # filter_by(ActionID=actionID).all() - # except: - # return None - - """ - Datasets - """ - - def getDataSets(self, codes=None, uuids=None): - """ - getDataSets() - * Pass nothing - returns a list of all DataSet objects - * Pass a list of DataSetCode - returns a single DataSet object for each code - - """ - q = self._session.query(DataSets) - if codes: - q = q.filter(DataSets.DataSetCode.in_(codes)) - if uuids: - q.q.filter(DataSets.DataSetUUID.in_(uuids)) - try: - return q.all() - except: - return None - - # ################################################################################ - # Data Quality - # ################################################################################ - - def getDataQuality(self): - """Select all on Data Quality - - :return Dataquality Objects: - :type list: - """ - return self._session.query(DataQuality).all() - - # TODO DataQuality Schema Queries - def getReferenceMaterials(self): - return self._session.query(ReferenceMaterials).all() - - def getReferenceMaterialValues(self): - return self._session.query(ReferenceMaterialValues).all() - - def getResultNormalizationValues(self): - return self._session.query(ResultNormalizationValues).all() - - def getResultsDataQuality(self): - return self._session.query(ResultsDataQuality).all() - - # ################################################################################ - # Equipment - # ################################################################################ - - # TODO Equipment Schema Queries - def getEquipment(self, codes=None, type=None, sfid=None, actionid=None): - """ - getEquipment() - * Pass nothing - returns a list of all Equipment objects - * Pass a EquipmentType - returns a single Equipment object - * Pass a SamplingFeatureID - returns a single Equipment object - * Pass an ActionID - returns a single Equipment object - """ - e = self._session.query(Equipment) - if sfid: e = e.join(EquipmentUsed) \ - .join(Actions) \ - .join(FeatureActions) \ - .filter(FeatureActions.SamplingFeatureID == sfid) - if codes: e = e.filter(Equipment.EquipmentCode.in_(codes)) - if actionid: e = e.join(EquipmentUsed).join(Actions) \ - .filter(Actions.ActionID == actionid) - return e.all() - - def CalibrationReferenceEquipment(self): - return self._session.query(CalibrationReferenceEquipment).all() - - def CalibrationStandards(self): - return self._session.query(CalibrationStandards).all() - - def DataloggerFileColumns(self): - return self._session.query(DataLoggerFileColumns).all() - - def DataLoggerFiles(self): - return self._session.query(DataLoggerFiles).all() - - def DataloggerProgramFiles(self): - return self._session.query(DataLoggerProgramFiles).all() - - def EquipmentModels(self): - return self._session.query(EquipmentModels).all() - - def EquipmentUsed(self): - return self._session.query(EquipmentUsed).all() - - def InstrumentOutputVariables(self, modelid=None, variableid=None): - i = self._session.query(InstrumentOutputVariables) - if modelid: i = i.filter_by(ModelID=modelid) - if variableid: i = i.filter_by(VariableID=variableid) - return i.all() - - def RelatedEquipment(self, code=None): - r = self._session.query(RelatedEquipment) - if code: r = r.filter_by(EquipmentCode=code) - return r.all() - - # ################################################################################ - # Extension Properties - # ################################################################################ - - def getExtensionProperties(self, type=None): - # Todo what values to use for extensionproperties type - e = ExtensionProperties - if type == "action": - e = ActionExtensionPropertyValues - elif type == "citation": - e = CitationExtensionPropertyValues - elif type == "method": - e = MethodExtensionPropertyValues - elif type == "result": - e = ResultExtensionPropertyValues - elif type == "samplingfeature": - e = SamplingFeatureExtensionPropertyValues - elif type == "variable": - e = VariableExtensionPropertyValues - try: - return self._session.query(e).all() - except: - return None - - # ################################################################################ - # External Identifiers - # ################################################################################ - def getExternalIdentifiers(self, type=None): - e = ExternalIdentifierSystems - if type.lowercase == "citation": - e = CitationExternalIdentifiers - elif type == "method": - e = MethodExternalIdentifiers - elif type == "person": - e = PersonExternalIdentifiers - elif type == "referencematerial": - e = ReferenceMaterialExternalIdentifiers - elif type == "samplingfeature": - e = SamplingFeatureExternalIdentifiers - elif type == "spatialreference": - e = SpatialReferenceExternalIdentifiers - elif type == "taxonomicclassifier": - e = TaxonomicClassifierExternalIdentifiers - elif type == "variable": - e = VariableExternalIdentifiers - try: - return self._session.query(e).all() - except: - return None - - # ################################################################################ - # Lab Analyses - # ################################################################################ - # TODO functions for Lab Analyses - def getDirectives(self): - return self._session.query(Directives).all() - - def getActionDirectives(self): - return self._session.query(ActionDirectives).all() - - def getSpecimenBatchPositions(self): - return self._session.query(SpecimenBatchPositions).all() - - # ################################################################################ - # Provenance - # ################################################################################ - - # TODO functions for Provenance - def getAuthorLists(self): - self._session.query(AuthorLists).all() - - def getDatasetCitations(self): - self._session.query(DataSetCitations).all() - - def getDerivationEquations(self): - self._session.query(DerivationEquations).all() - - def getMethodCitations(self): - self._session.query(MethodCitations).all() - - def getRelatedAnnotations(self): - # q= read._session.query(Actions).select_from(RelatedActions).join(RelatedActions.RelatedActionObj) - self._session.query(RelatedAnnotations).all() - - def getRelatedCitations(self): - self._session.query(RelatedCitations).all() - - def getRelatedDatasets(self): - self._session.query(RelatedDataSets).all() - - def getRelatedResults(self): - self._session.query(RelatedResults).all() - - def getResultDerivationEquations(self): - self._session.query(ResultDerivationEquations).all() - - # ################################################################################ - # Results - # ################################################################################ - - """ - ResultValues - """ - - def getResultValues(self, resultid, starttime=None, endtime=None): - - """Select all on TimeSeriesResults -<<<<<<< HEAD - getResultValues() - * Pass a ResultID - Returns a result values object of type that is specific to the result type - * Pass a ResultID and a date range - returns a result values object of type that is specific to the result type with values between the input date range - """ - type= self._session.query(Results).filter_by(ResultID=resultid).first().ResultTypeCV - Result = TimeSeriesResults - if "categorical" in type.lower():Result = CategoricalResultValues - elif "measurement" in type.lower():Result = MeasurementResultValues - elif "point" in type.lower():Result = PointCoverageResultValues - elif "profile" in type.lower():Result = ProfileResultValues - elif "section" in type.lower():Result = SectionResults - elif "spectra" in type.lower():Result = SpectraResultValues - elif "time" in type.lower():Result = TimeSeriesResultValues - elif "trajectory" in type.lower():Result = TrajectoryResultValues - elif "transect" in type.lower():Result = TransectResultValues - - q = self._session.query(Result).filter_by(ResultID=resultid) - if starttime: q = q.filter(Result.ValueDateTime >= starttime) - if endtime: q = q.filter(Result.ValueDateTime <= endtime) - try: - vals = q.order_by(Result.ValueDateTime) - df = pd.DataFrame([dv.list_repr() for dv in vals.all()]) - df.columns = vals[0].get_columns() - return df -======= - - :return TimeSeriesResults Objects: - :type list: - """ - return self._session.query(TimeSeriesResults).all() - - def getTimeSeriesResultByResultId(self, resultId): - """Select by resultID on ResultID - - :param resultId: - :type Integer: - :return return matching Timeseriesresult Object filtered by resultId - """ - - try: - return self._session.query(TimeSeriesResults).filter_by(ResultID=resultId).one() - except: - return None - - def getTimeSeriesResultbyCode(self, timeSeriesCode): - """Select by time - """ - pass - - """ - TimeSeriesResultValues - """ - - def getTimeSeriesResultValues(self): - """Select all on TimeSeriesResults - - :return TimeSeriesResultsValue Objects: - :type list: - """ - - q = self._session.query(TimeSeriesResults).all() - df = pd.DataFrame([dv.list_repr() for dv in q]) - df.columns = q[0].get_columns() - return df - # return self._session.query(Timeseriesresultvalue).all() - - def getTimeSeriesResultValuesByResultId(self, resultId): - """Select by resultId - - :param timeSeriesId: - :type Integer: - :return return matching Timeseriesresultvalue Object filtered by resultId: - :type Timeseriesresultvalue: - """ - try: - q = self._session.query(TimeSeriesResultValues).filter_by(ResultID=resultId).all() - print(type(q[0]), q[0]) - df = pd.DataFrame([dv.list_repr() for dv in q]) - df.columns = q[0].get_columns() - return df - # return self._session.query(Timeseriesresultvalue).filter_by(ResultID=resultId).all() - except Exception as e: - print(e) - return None - - def getTimeSeriesResultValuesByCode(self, timeSeriesCode): - """ - - :param timeSeriesCode: - :return: - """ - pass - - def getTimeSeriesResultValuesByTime(self, resultid, starttime, endtime=None): - - # set end = start if it is None - endtime = starttime if not endtime else endtime - - try: - return self._session.query(TimeSeriesResultValues).filter_by(ResultID=resultid) \ - .filter(TimeSeriesResultValues.ValueDateTime >= starttime) \ - .filter(TimeSeriesResultValues.ValueDateTime <= endtime) \ - .order_by(TimeSeriesResultValues.ValueDateTime).all() ->>>>>>> origin/master - except: - return None - - # ################################################################################ - # SamplingFeatures - # ################################################################################ - - """ - Site - """ - - def getSpatialReference(self, srsCodes=None): - """ - getSpatialReference() - * Pass a ResultID - Returns a result values object of type that is specific to the result type - * Pass a ResultID and a date range - returns a result values object of type that is specific to the result type with values between the input date range - """ - q = self._session.query(SpatialReferences) - if srsCodes: q.filter(SpatialReferences.SRSCode.in_(srsCodes)) - try: - return q.first() - except: - return None - - - # ################################################################################ - # Simulation - # ################################################################################ - - def getSimulations(self, name=None, actionid=None): - """ - getSimulations() - * Pass nothing - get a list of all model simuation objects - * Pass a SimulationName - get a single simulation object - * Pass an ActionID - get a single simulation object - - """ - s = self._session.query(Simulations) - if name: s = s.filter(Simulations.SimulationName.ilike(name)) - if actionid: s = s.filter_by(ActionID=actionid) - try: - return s.all() - except: - return None - - - - def getModels(self, codes=None): - m = self._session.query(Models) - if codes: m = m.filter(Models.ModelCode.in_(codes)) - try: - return m.all() - except: - return None - - def getRelatedModels(self, id=None, code=None): - """ - getRelatedModels() - * Pass a ModelID - get a list of model objects related to the model having ModelID - * Pass a ModelCode - get a list of model objects related to the model having ModeCode - :param id: - :type id: - :param code: - :type code: - :return: - :rtype: - """ -# cdoe from master -#+ # note this was RelatedModels.RelatedModelID == Models.ModelID which would return all Parent models of RelatedModelID -# + self._session.query(RelatedModels).filter_by(ModelID=modelid).all() -# + self._session.query(RelatedModels).join(Models, RelatedModels.ModelID == Models.ModelID).filter(Models.ModelCode == modelcode).all() - - m = self._session.query(Models).select_from(RelatedModels).join(RelatedModels.ModelObj) - if id: m = m.filter(RelatedModels.ModelID == id) - if code: m = m.filter(Models.ModelCode == code) - -#previous version of code - # m = self._session.query(Models).select_from(RelatedModels).join(RelatedModels.RelatedModelObj) - # if id: m = m.filter(RelatedModels.ModelID == id) - # if code: m = m.filter(RelatedModels.ModelCode == code) - -<<<<<<< HEAD - -======= - def getRelatedModelsByID(self, modelid): - """ - queries the ODM2 for any models that have a relationship with the provided model id - :param modelid: id of the model to search - :return: all models related to the specified id - """ - try: - return self._session.query(RelatedModels).filter_by(RelatedModelID=modelid).all() - except Exception as e: - print(e) - return None - - def getRelatedModelsByCode(self, modelcode): - """ - queries the ODM2 for any models that have a relationship with the provided model id - :param modelcode: the code of the model to search - :return: all models related to the provided model code - """ - try: - return self._session.query(RelatedModels).join(Models, RelatedModels.RelatedModelID == Models.ModelID) \ - .filter(Models.ModelCode == modelcode).all() - except Exception as e: - print(e) - return None ->>>>>>> origin/master - - try: -<<<<<<< HEAD - return m.all() - except Exception, e: - print e - return None -======= - return self._session.query(Results) \ - .join(FeatureActions) \ - .join(Actions) \ - .join(Simulations) \ - .filter(Simulations.SimulationID == simulationID).all() - except Exception as e: - print(e) - return None ->>>>>>> origin/master - - diff --git a/odm2api/ODMconnection.py b/odm2api/ODMconnection.py index ed57a9a..767cc55 100644 --- a/odm2api/ODMconnection.py +++ b/odm2api/ODMconnection.py @@ -154,6 +154,9 @@ def __buildConnectionString(self, conn_dict): # (conn_dict['address'], conn_dict['user'], conn_dict['password'],conn_dict['db'], # )) conn_string = 'mssql+pyodbc:///?odbc_connect={}'.format(quoted) + elif conn_dict['engine']=='sqlite': + driver = 'sqlite' + conn_string = "%s:///%s" % (driver, conn_dict['address']) else: if conn_dict['engine'] == 'mssql': driver = "pyodbc" diff --git a/odm2api/base.py b/odm2api/base.py index f76ce2f..5a90953 100644 --- a/odm2api/base.py +++ b/odm2api/base.py @@ -45,6 +45,9 @@ def __tablename__(cls): def __init__(self, *args, **kwargs): for name, value in kwargs.items(): setattr(self, name, value) + def __eq__(self, other) : + return self.__dict__ == other.__dict__ + from sqlalchemy.ext.declarative import declarative_base diff --git a/requirements_tests.txt b/requirements_tests.txt index 90d3e78..2849288 100644 --- a/requirements_tests.txt +++ b/requirements_tests.txt @@ -12,3 +12,4 @@ psycopg2 #mysql-python + diff --git a/tests/test_odm2/test_createservice.py b/tests/test_odm2/test_createservice.py index ba4f856..f9aa5bb 100644 --- a/tests/test_odm2/test_createservice.py +++ b/tests/test_odm2/test_createservice.py @@ -67,10 +67,11 @@ def test_createVariable(self): v = models.Variables(VariableCode = code, VariableNameCV=name, VariableTypeCV=vType, NoDataValue= nodv, SpeciationCV = None, VariableDefinition=None) # self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=None,definition=None) - self.writer.createVariable(v) + val=self.writer.createVariable(v) # assert that this dataset has been successfully inserted res = self.engine.execute('SELECT * from Variables WHERE VariableCode = "MyVar" ORDER BY VariableID DESC').first() assert(res is not None) + assert(res[0] == val.VariableID) assert(res[1] == vType ) # vType assert(res[2] == code ) # code assert(res[3] == name ) # name @@ -81,11 +82,12 @@ def test_createVariable(self): v = models.Variables(VariableCode = code, VariableNameCV=name, VariableTypeCV=vType, NoDataValue= nodv, SpeciationCV = speciation, VariableDefinition=None) # self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=speciation,definition=None) - self.writer.createVariable(v) + val=self.writer.createVariable(v) # assert that this dataset has been successfully inserted res = self.engine.execute('SELECT * from Variables WHERE VariableCode = "MyVar" ORDER BY VariableID DESC').first() assert(res is not None) + assert(res[0] == val.VariableID) assert(res[1] == vType ) # vType assert(res[2] == code ) # code assert(res[3] == name ) # name @@ -96,12 +98,13 @@ def test_createVariable(self): v = models.Variables(VariableCode = code, VariableNameCV=name, VariableTypeCV=vType, NoDataValue= nodv, SpeciationCV = None, VariableDefinition=definition) # self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=None,definition=definition) - self.writer.createVariable(v) + val=self.writer.createVariable(v) # assert that this dataset has been successfully inserted res = self.engine.execute('SELECT * from Variables WHERE VariableCode = "MyVar" ORDER BY VariableID DESC').first() assert(res is not None) + assert(res[0] == val.VariableID) assert(res[1] == vType ) # vType assert(res[2] == code ) # code assert(res[3] == name ) # name @@ -113,12 +116,13 @@ def test_createVariable(self): v = models.Variables(VariableCode = code, VariableNameCV=name, VariableTypeCV=vType, NoDataValue= nodv, SpeciationCV = speciation, VariableDefinition=definition) # self.writer.createVariable(code = code,name = name,vType = vType,nodv =nodv,speciation=speciation,definition=definition) - self.writer.createVariable(v) + val= self.writer.createVariable(v) # assert that this dataset has been successfully inserted res = self.engine.execute('SELECT * from Variables WHERE VariableCode = "MyVar" ORDER BY VariableID DESC').first() assert(res is not None) + assert(res[0] == val.VariableID) assert(res[1] == vType ) # vType assert(res[2] == code ) # code assert(res[3] == name ) # name @@ -167,12 +171,14 @@ def test_createDataset(self): d = models.DataSets(DataSetTypeCV = type, DataSetCode =code, DataSetTitle=title, DataSetAbstract = desc, DataSetUUID = uuid.uuid4().hex) dataset = self.writer.createDataset(d) - + assert(dataset == d) + assert (dataset.DataSetID ==1) # assert that this dataset has been successfully inserted - res = self.engine.execute('SELECT * from DataSets') - assert(len(res.fetchall()) == 1) + res = self.engine.execute('SELECT * from DataSets').fetchall() + assert(len(res) == 1) + assert(res[0][0]==dataset.DataSetID) def test_createDatasetResults(self): pass @@ -241,20 +247,27 @@ def test_createTimeSeriesResult(self): ValueCount = 0, SampledMediumCV = 'unknown', ResultTypeCV = 'time series', - ResultUUID = uuid.uuid4().hex, + ResultUUID = str(uuid.uuid4()), AggregationStatisticCV = 'unknown' + ) - ) - self.writer.createResult(r) + newres=self.writer.createResult(r) + + # assert that this basic tsr exists in the database + tsr = self.engine.execute('SELECT * FROM TimeSeriesResults').first() + assert(tsr is not None) + + assert (newres == r) result = self.engine.execute('SELECT * FROM Results').first() assert(result is not None) + assert(newres.ResultID ==1) + assert(result[0] ==newres.ResultID) + + - # assert that this basic tsr exists in the database - res = self.engine.execute('SELECT * FROM TimeSeriesResults').first() - assert(res is not None) @@ -316,8 +329,10 @@ def test_createSimulation(self): ModelID = 1 ) sim = self.writer.createSimulation(s) - + assert (s == sim) + assert (s.SimulationID == 1) # assert that this record has been successfully inserted - res = self.engine.execute('SELECT * from Simulations') - assert(len(res.fetchall()) == 1) + res = self.engine.execute('SELECT * from Simulations').fetchall() + assert(len(res) == 1) + assert(res[0][0]==s.SimulationID) diff --git a/tests/test_odm2/test_readservice.py b/tests/test_odm2/test_readservice.py index 3c3d393..f6336fc 100644 --- a/tests/test_odm2/test_readservice.py +++ b/tests/test_odm2/test_readservice.py @@ -158,7 +158,8 @@ def test_getRelatedModelsByID(self): # get related models by id using the api # resapi = self.reader.getRelatedModelsByID(2) - resapi = self.reader.getRelatedModels(id = 2) + resapi = self.reader.getRelatedModels(id = 1) + # resapi = self.reader.getRelatedModels(id = 2) assert resapi is not None assert resapi[0].ModelCode == 'swat' @@ -166,22 +167,21 @@ def test_getRelatedModelsByID(self): def test_getRelatedModelsByCode(self): # get related models by id using the api - #resapi = self.reader.getRelatedModelsByCode('swmm') - resapi = self.reader.getRelatedModels(code = 'swmm') + resapi = self.reader.getRelatedModels(code = 'swat') + #resapi = self.reader.getRelatedModels(code = 'swmm') assert resapi is not None assert len(resapi) > 0 + print resapi[0].ModelCode assert resapi[0].ModelCode == 'swat' # test model code that doesn't exist - # resapi = self.reader.getRelatedModelsByCode('None') resapi= self.reader.getRelatedModels(code = 'None') assert resapi is not None assert len(resapi) == 0 # test invalid argument - # resapi = self.reader.getRelatedModelsByCode(models.ActionBy) resapi = self.reader.getRelatedModels(code = models.ActionBy) assert resapi is None diff --git a/tests/usecasesql/marchantariats/marchantariats.sql b/tests/usecasesql/marchantariats/marchantariats.sql index 2795a3b..03eb447 100644 --- a/tests/usecasesql/marchantariats/marchantariats.sql +++ b/tests/usecasesql/marchantariats/marchantariats.sql @@ -18,7 +18,7 @@ SET client_min_messages = warning; -- Name: marchantariats; Type: DATABASE; Schema: -; Owner: - -- -CREATE DATABASE marchantariats WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8'; +CREATE DATABASE marchantariats WITH TEMPLATE = template0 ENCODING = 'UTF8' ;--LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8'; \connect marchantariats