Skip to content

Commit

Permalink
Update source code into 1.01 version
Browse files Browse the repository at this point in the history
* Reflect changes in the schema such as change Datasets into
ResourceTypes
* fix bugs in data loading
* fix bugs in the Installer (many windows didn't respond in the 1.0
version)
  • Loading branch information
Adel M. Abdallah committed Apr 4, 2018
1 parent 336de15 commit 803951f
Show file tree
Hide file tree
Showing 323 changed files with 4,582 additions and 1,065 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified WorkbookTemplates/InputData_Template/template.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes
File renamed without changes.
32 changes: 20 additions & 12 deletions src_1.0/wamdam.py → src/WaMDaM.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-#

# Wamdam.py
# Wamdam_v1.01.py
""""""

"""
WaMDaM: The Water Management Data Model Version 1.01
See the schema at http://schema.wamdam.org/diagrams/01_WaMDaM.html
Instructions at http://docs.wamdam.org/Getting_started/Steps
Adel M. Abdallah
email: [email protected]
"""


"""
Wamdam.py is the key calling/initializing function for the Wizard.
Wamdam.py is the calling/initializing function for the Wizard.
Before you start, make sure to install all the required Python libraries listed in
requirements.md text file/
Expand All @@ -27,20 +36,20 @@
dlg_ImportSpreadsheetBasic.py which exist in the viewer Folder. Then when the user
clicks at "load Data" in this dialog box, a function calls one or all the sub-data importers
for the checked boxes from the controller folder:
stp0_loadCVs.py, stp1_loadMetadata.py,
stp2_loadDataStructure.py,
stp3_loadNetworks.py,
and stp4_loadDataValues.py
stp0_loadCVs.py, stp1_loadMetadata.py,
stp2_loadDataStructure.py,
stp3_loadNetworks.py,
and stp4_loadDataValues.py
stp0_loadCVs.py, load_step_1.py, load_step_2.py, load_step_3.py, stp4_loadDataValues.py
It's important to note that the controlled vocabulary (CV) data in the stp0_loadCVs.py
are called from the online registry http://vocabulary.wamdam.org/
while the data for the rest of the steps are obtained form the provided spreadsheet template or other source of data.
It's important to note that the controlled vocabulary (CV) data in the stp0_loadCVs.py
are called from the online registry http://vocabulary.wamdam.org/
while the data for the rest of the steps are obtained form the provided spreadsheet template or other source of data.
The Wizard implements dozens of validations and checks on the imported data
The Wizard implements dozens of validations and checks on the imported data
to make sure it complies with WaMDaM business rules
The Wizard either loads all the dataset and it's metadata etc or nothing.
The Wizard either loads all the dataset and it's metadata etc or nothing.
See the software architecture in a flowchart @ https://github.com/WamdamProject/WaMDaM_Wizard
"""
Expand Down Expand Up @@ -70,4 +79,3 @@ def main():

if __name__ == '__main__':
main()

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,29 @@ def load_data(self, response_data):
self.setup.add_data()
#////////////////////////////////////////////////////////////////////#

# Add data within Datasets table
recordCountResult = self.__session.execute('SELECT COUNT(*) FROM Datasets;')
datasetID = 0
# Add data within ResourceTypes table
recordCountResult = self.__session.execute('SELECT COUNT(*) FROM ResourceTypes;')
resourceTypeID = 0
for n in recordCountResult:
datasetID = int(n[0])
datasetID += 1
resourceTypeID = int(n[0])
resourceTypeID += 1

dataset_name = "CUAHSI web service"
resource_type = "CUAHSI web service"

# Check whether same name exist in Datasets table
# Check whether same name exist in ResourceTypes table
exsting = None
try:
exsting = self.__session.query(SqlAlchemy.Datasets).filter(
SqlAlchemy.Datasets.DatasetName == dataset_name).first().DatasetID
exsting = self.__session.query(SqlAlchemy.ResourceTypes).filter(
SqlAlchemy.ResourceTypes.ResourceType == resource_type).first().ResourceTypeID
except:
pass
if exsting is None:
datasets = SqlAlchemy.Datasets()
datasets.DatasetID = datasetID
datasets.DatasetName = dataset_name
datasets.DatasetAcronym = "CUAHSI"
datasets.SourceID = sourceID
self.setup.push_data(datasets)
resourceTypes = SqlAlchemy.ResourceTypes()
resourceTypes.ResourceTypeID = resourceTypeID
resourceTypes.ResourceType = resource_type
resourceTypes.ResourceTypeAcronym = "CUAHSI"
resourceTypes.MethodID = methodID
self.setup.push_data(resourceTypes)
self.setup.add_data()
#////////////////////////////////////////////////////////////////////#

Expand All @@ -183,7 +183,7 @@ def load_data(self, response_data):
objectTypes.ObjectTypeID = objectTypeID
objectTypes.ObjectType = objecttype
objectTypes.ObjectTypologyCV = "Node"
objectTypes.DatasetID = datasetID
objectTypes.ResourceTypeID = resourceTypeID
self.setup.push_data(objectTypes)
self.setup.add_data()
#////////////////////////////////////////////////////////////////////#
Expand Down Expand Up @@ -298,16 +298,16 @@ def load_data(self, response_data):
instance_name = node_instance_name
#////////////////////////////////////////////////////////////////////#

# Load data for DataValuesMapper, Mapping, ScenarioMapping, TimeSeries and TimeSeriesValues table
# Add data for DataValuesMapper
dataValuesMapper = SqlAlchemy.DataValuesMapper()
# Load data for ValuesMapper, Mapping, ScenarioMapping, TimeSeries and TimeSeriesValues table
# Add data for ValuesMapper
valuesMapper = SqlAlchemy.ValuesMapper()
try:
dataValuesMapper.DataValuesMapperID = int(self.__session.query(SqlAlchemy.DataValuesMapper).order_by(
SqlAlchemy.DataValuesMapper.DataValuesMapperID.desc()).first().DataValuesMapperID)
dataValuesMapper.DataValuesMapperID += 1
valuesMapper.ValuesMapperID = int(self.__session.query(SqlAlchemy.ValuesMapper).order_by(
SqlAlchemy.ValuesMapper.ValuesMapperID.desc()).first().ValuesMapperID)
valuesMapper.ValuesMapperID += 1
except:
dataValuesMapper.DataValuesMapperID = 1
self.setup.push_data(dataValuesMapper)
valuesMapper.ValuesMapperID = 1
self.setup.push_data(valuesMapper)
self.setup.add_data()
#///////////////////////////////////#

Expand All @@ -323,7 +323,7 @@ def load_data(self, response_data):
dataval_map.InstanceID = instance_id
dataval_map.SourceID = source_id
dataval_map.MethodID = method_id
dataval_map.DataValuesMapperID = dataValuesMapper.DataValuesMapperID
dataval_map.ValuesMapperID = valuesMapper.ValuesMapperID
self.setup.push_data(dataval_map)
self.setup.add_data()
#///////////////////////////////////#
Expand Down Expand Up @@ -372,7 +372,7 @@ def load_data(self, response_data):
timeSeries.AggregationStatisticCV = "Average"
timeSeries.AggregationInterval = 1
timeSeries.IntervalTimeUnitCV = "day"
timeSeries.DataValuesMapperID = dataValuesMapper.DataValuesMapperID
timeSeries.ValuesMapperID = valuesMapper.ValuesMapperID

self.setup.push_data(timeSeries)
self.setup.add_data()
Expand All @@ -386,9 +386,9 @@ def load_data(self, response_data):
timeSeriesValues.DateTimeStamp = datetime(value._dateTime.year, value._dateTime.month, value._dateTime.day,
value._dateTime.hour, value._dateTime.minute, value._dateTime.second)
try:
timeSeriesValues.Value = value.value
timeSeriesValues.DataValue = value.value
except:
timeSeriesValues.Value = 0.0
timeSeriesValues.DataValue = 0.0
self.setup.push_data(timeSeriesValues)
self.setup.add_data()
#////////////////////////////////////////////////////////////////////#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

"""
The ConnectDB_ParseExcel.py file contain two very important classes used
throughout all the classes in controller. these classes are:
Expand All @@ -17,7 +16,6 @@
(the workbook is different than what it is supposed to be) .
"""


# import the database params from SqlAlchemy.py found in the Model folder
from model import SqlAlchemy

Expand All @@ -38,15 +36,17 @@

from shutil import copyfile


# Get only one copy of database class at a time and use it throughout the Wizard
class Singleton(type):
_instances = {}
_instances = {}

def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
# print "Singleton", cls._instances[cls]
return cls._instances[cls]

def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
#print "Singleton", cls._instances[cls]
return cls._instances[cls]

# ****************************************************************************************************************** #
# #
Expand All @@ -65,7 +65,7 @@ class used to setup the database and
__path = None
__type = None
__backupName = None

def __init__(self):
pass

Expand All @@ -82,12 +82,13 @@ def get_session(self):
The Data loader has a rule to load all or nothing. so if the user cancels in the middle,
then, the App, deletes the db which might have half loaded data, then it restores a backup db before
loading the new data'''

def connect(self, dbpath, db_type, sql_string=None):
self.__session = SqlAlchemy.connect(dbpath, db_type, sql_string)
print dbpath, 'path'
print db_type, 'type'
print sql_string, 'string'
self.__path = dbpath # To be used later to backup the database.
self.__path = dbpath # To be used later to backup the database.
self.__type = db_type

def add_data(self, table=None):
Expand All @@ -100,7 +101,7 @@ def add_data(self, table=None):
except e.IntegrityError as error:
self.__session.rollback()
print error
raise Exception('\nDuplicate entries found \n looks like some {} tables have already been loaded'
raise Exception('\n Duplicate entries found \n looks like some {} tables have already been loaded'
.format(table))

except e and Exception as error:
Expand Down Expand Up @@ -138,6 +139,7 @@ def close_db(self):
self.__session.close()
self.__session.bind.dispose()
self.__session = None

def getType(self):
return self.__type

Expand All @@ -151,7 +153,7 @@ def backup_db(self):
self.__backupName = dst
print 'Backing Up the DB\nsrc:{}\ndst:{}'.format(src, dst)
copyfile(src, dst)

def restore_db(self):
"""
used to restore the database after the user cancels data loading.
Expand All @@ -167,11 +169,13 @@ def restore_db(self):
copyfile(src, dst)
self.__session = SqlAlchemy.connect(dst, self.__type)


class Parse_Excel_File(object):
'''
this class is used to parse
the excel workbook
'''

def __init__(self, obj):
self.filename = None
self.__workbook = obj
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 803951f

Please sign in to comment.