Skip to content

Commit

Permalink
Merge pull request #78 from ODM2/renameObject
Browse files Browse the repository at this point in the history
Rename Reference Object
  • Loading branch information
sreeder authored May 6, 2017
2 parents 7d820e8 + 9e0fd51 commit 76b0dcd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 65 deletions.
84 changes: 20 additions & 64 deletions odm2api/ODM2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
BigIntegerType = BigIntegerType.with_variant(mysql.BIGINT(), 'mysql')





def is_hex(s):
try:
int(s, base=16)
Expand Down Expand Up @@ -777,7 +774,8 @@ class Annotations(Base):
AnnotatorID = Column('annotatorid', ForeignKey(People.PersonID))
CitationID = Column('citationid', ForeignKey(Citations.CitationID))

PersonObj = relationship(People)
# PersonObj = relationship(People)
AnnotatorObj = relationship(People)
CitationObj = relationship(Citations)


Expand Down Expand Up @@ -889,7 +887,6 @@ class ReferenceMaterials(Base):

class CalibrationStandards(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ActionID = Column('actionid', Integer, ForeignKey(Actions.ActionID), nullable=False)
ReferenceMaterialID = Column('referencematerialid', Integer, ForeignKey(ReferenceMaterials.ReferenceMaterialID),
Expand All @@ -898,18 +895,9 @@ class CalibrationStandards(Base):
ActionObj = relationship(Actions)
ReferenceMaterialObj = relationship(ReferenceMaterials)

# ResultNormalizationValues = Table(
# u'resultnormalizationvalues', Base.metadata,
# Column(u'resultid', ForeignKey(Results.ResultID), primary_key=True),
# Column(u'normalizedbyreferencematerialvalueid', ForeignKey('odm2.referencematerialvalues.referencematerialvalueid'),
# nullable=False),
# schema='odm2'
# )


class ReferenceMaterialValues(Base):


ReferenceMaterialValueID = Column('referencematerialvalueid', Integer, primary_key=True, nullable=False)
ReferenceMaterialID = Column('referencematerialid', ForeignKey(ReferenceMaterials.ReferenceMaterialID),
nullable=False)
Expand All @@ -923,12 +911,10 @@ class ReferenceMaterialValues(Base):
ReferenceMaterialObj = relationship(ReferenceMaterials)
UnitObj = relationship(Units)
VariableObj = relationship(Variables)
#ResultsObj = relationship(Results, secondary=ResultNormalizationValues)


class ResultNormalizationValues(Base):


ResultID = Column(u'resultid', ForeignKey(Results.ResultID), primary_key=True)
ReferenceMaterialValueID = Column(u'referencematerialvalueid',
ForeignKey(ReferenceMaterialValues.ReferenceMaterialValueID),
Expand All @@ -940,7 +926,6 @@ class ResultNormalizationValues(Base):

class ResultsDataQuality(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ResultID = Column('resultid', ForeignKey(Results.ResultID), nullable=False)
DataQualityID = Column('dataqualityid', ForeignKey(DataQuality.DataQualityID), nullable=False)
Expand All @@ -954,7 +939,6 @@ class ResultsDataQuality(Base):
# ################################################################################
class ExtensionProperties(Base):


PropertyID = Column('propertyid', Integer, primary_key=True, nullable=False)
PropertyName = Column('propertyname', String(255), nullable=False)
PropertyDescription = Column('propertydescription', String(500))
Expand All @@ -978,7 +962,6 @@ class ActionExtensionPropertyValues(Base):

class CitationExtensionPropertyValues(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
CitationID = Column('citationid', ForeignKey(Citations.CitationID), nullable=False)
PropertyID = Column('propertyid', ForeignKey(ExtensionProperties.PropertyID), nullable=False)
Expand Down Expand Up @@ -1226,6 +1209,7 @@ class MethodCitations(Base):
RelationshipTypeCV = Column('relationshiptypecv', ForeignKey(CVRelationshipType.Name), nullable=False,
index=True)
CitationID = Column('citationid', ForeignKey(Citations.CitationID), nullable=False)

CitationObj = relationship(Citations)
MethodObj = relationship(Methods)

Expand Down Expand Up @@ -1292,7 +1276,6 @@ class RelatedResults(Base):
# ################################################################################
class PointCoverageResults(Results):


ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
ZLocation = Column('zlocation', Float(53))
ZLocationUnitsID = Column('zlocationunitsid', ForeignKey(Units.UnitsID))
Expand All @@ -1310,12 +1293,11 @@ class PointCoverageResults(Results):
IntendedYSpacingUnitsObj = relationship(Units, primaryjoin='PointCoverageResults.IntendedYSpacingUnitsID == Units.UnitsID')
SpatialReferenceObj = relationship(SpatialReferences)
ZLocationUnitsObj = relationship(Units, primaryjoin='PointCoverageResults.ZLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='PointCoverageResults.ResultID == Results.ResultID')
__mapper_args__ = {'polymorphic_identity':'Point coverage'}

__mapper_args__ = {'polymorphic_identity': 'Point coverage'}

class ProfileResults(Results):

class ProfileResults(Results):

ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
XLocation = Column('xlocation', Float(53))
Expand All @@ -1335,12 +1317,11 @@ class ProfileResults(Results):
SpatialReferenceObj = relationship(SpatialReferences)
XLocationUnitsObj = relationship(Units, primaryjoin='ProfileResults.XLocationUnitsID == Units.UnitsID')
YLocationUnitsObj = relationship(Units, primaryjoin='ProfileResults.YLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='ProfileResults.ResultID == Results.ResultID')
__mapper_args__ = {'polymorphic_identity':'Profile Coverage'}

__mapper_args__ = {'polymorphic_identity': 'Profile Coverage'}

class CategoricalResults(Results):

class CategoricalResults(Results):

ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
XLocation = Column('xlocation', Float(53))
Expand All @@ -1357,8 +1338,7 @@ class CategoricalResults(Results):
YLocationUnitsObj = relationship(Units, primaryjoin='CategoricalResults.YLocationUnitsID == Units.UnitsID')
ZLocationUnitsObj = relationship(Units, primaryjoin='CategoricalResults.ZLocationUnitsID == Units.UnitsID')

# ResultObj = relationship(Results, primaryjoin='CategoricalResults.ResultID == Results.ResultID')
__mapper_args__ = {'polymorphic_identity':'Category coverage'}
__mapper_args__ = {'polymorphic_identity':' Category coverage'}


class TransectResults(Results):
Expand All @@ -1379,12 +1359,11 @@ class TransectResults(Results):
IntendedTransectSpacingUnitsObj = relationship(Units, primaryjoin='TransectResults.IntendedTransectSpacingUnitsID == Units.UnitsID')
SpatialReferenceObj = relationship(SpatialReferences)
ZLocationUnitsObj = relationship(Units, primaryjoin='TransectResults.ZLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='TransectResults.ResultID == Results.ResultID')
__mapper_args__ = {'polymorphic_identity':'Transect Coverage'}

__mapper_args__ = {'polymorphic_identity': 'Transect Coverage'}

class SpectraResults(Results):

class SpectraResults(Results):

ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
XLocation = Column('xlocation', Float(53))
Expand All @@ -1404,7 +1383,7 @@ class SpectraResults(Results):
XLocationUnitsObj = relationship(Units, primaryjoin='SpectraResults.XLocationUnitsID == Units.UnitsID')
YLocationUnitsObj = relationship(Units, primaryjoin='SpectraResults.YLocationUnitsID == Units.UnitsID')
ZLocationUnitsObj = relationship(Units, primaryjoin='SpectraResults.ZLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='SpectraResults.ResultID == Results.ResultID')

__mapper_args__ = {'polymorphic_identity':'Spectra coverage'}


Expand All @@ -1423,14 +1402,13 @@ class TimeSeriesResults(Results):
AggregationStatisticCV = Column('aggregationstatisticcv', ForeignKey(CVAggregationStatistic.Name),
nullable=False, index=True)

# ResultObj = relationship(Results)
IntendedTimeSpacingUnitsObj = relationship(Units,
primaryjoin='TimeSeriesResults.IntendedTimeSpacingUnitsID == Units.UnitsID')
primaryjoin='TimeSeriesResults.IntendedTimeSpacingUnitsID == Units.UnitsID')
SpatialReferenceObj = relationship(SpatialReferences)
XLocationUnitsObj = relationship(Units, primaryjoin='TimeSeriesResults.XLocationUnitsID == Units.UnitsID')
YLocationUnitsObj = relationship(Units, primaryjoin='TimeSeriesResults.YLocationUnitsID == Units.UnitsID')
ZLocationUnitsObj = relationship(Units, primaryjoin='TimeSeriesResults.ZLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='TimeSeriesResults.ResultID == Results.ResultID')

__mapper_args__ = {'polymorphic_identity':'Time series coverage'}


Expand All @@ -1454,13 +1432,12 @@ class SectionResults(Results):
IntendedZSpacingUnitsObj = relationship(Units, primaryjoin='SectionResults.IntendedZSpacingUnitsID == Units.UnitsID')
SpatialReferenceObj = relationship(SpatialReferences)
YLocationUnitsObj = relationship(Units, primaryjoin='SectionResults.YLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='SectionResults.ResultID == Results.ResultID')

__mapper_args__ = {'polymorphic_identity':'Section coverage'}


class TrajectoryResults(Results):


ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
SpatialReferenceID = Column('spatialreferenceid', ForeignKey(SpatialReferences.SpatialReferenceID))
IntendedTrajectorySpacing = Column('intendedtrajectoryspacing', Float(53))
Expand All @@ -1474,13 +1451,12 @@ class TrajectoryResults(Results):
IntendedTrajectorySpacingUnitsObj = relationship(Units,
primaryjoin='TrajectoryResults.IntendedTrajectorySpacingUnitsID == Units.UnitsID')
SpatialReferenceObj = relationship(SpatialReferences)
# ResultObj = relationship(Results, primaryjoin='TrajectoryResults.ResultID == Results.ResultID')

__mapper_args__ = {'polymorphic_identity':'Trajectory coverage'}


class MeasurementResults(Results):


ResultID = Column('resultid', ForeignKey(Results.ResultID), primary_key=True)
XLocation = Column('xlocation', Float(53))
XLocationUnitsID = Column('xlocationunitsid', ForeignKey(Units.UnitsID))
Expand All @@ -1502,7 +1478,7 @@ class MeasurementResults(Results):
XLocationUnitsObj = relationship(Units, primaryjoin='MeasurementResults.XLocationUnitsID == Units.UnitsID')
YLocationUnitsObj = relationship(Units, primaryjoin='MeasurementResults.YLocationUnitsID == Units.UnitsID')
ZLocationUnitsObj = relationship(Units, primaryjoin='MeasurementResults.ZLocationUnitsID == Units.UnitsID')
# ResultObj = relationship(Results, primaryjoin='MeasurementResults.ResultID == Results.ResultID')

__mapper_args__ = {'polymorphic_identity':'Measurement'}


Expand Down Expand Up @@ -1531,7 +1507,6 @@ class MeasurementResultValues(Base):

class PointCoverageResultValues(Base):


ValueID = Column('valueid', BigIntegerType, primary_key=True)
ResultID = Column('resultid', ForeignKey(PointCoverageResults.ResultID), nullable=False)
DataValue = Column('datavalue', BigInteger, nullable=False)
Expand Down Expand Up @@ -1648,7 +1623,6 @@ def list_repr(self):

class TrajectoryResultValues(Base):


ValueID = Column('valueid', BigIntegerType, primary_key=True)
ResultID = Column('resultid', ForeignKey(TrajectoryResults.ResultID), nullable=False)
DataValue = Column('datavalue', Float(53), nullable=False)
Expand Down Expand Up @@ -1679,7 +1653,6 @@ class TrajectoryResultValues(Base):

class TransectResultValues(Base):


ValueID = Column('valueid', BigIntegerType, primary_key=True)
ResultID = Column('resultid', ForeignKey(TransectResults.ResultID), nullable=False)
DataValue = Column('datavalue', Float(53), nullable=False)
Expand Down Expand Up @@ -1709,7 +1682,6 @@ class TransectResultValues(Base):

class CategoricalResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(CategoricalResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand All @@ -1720,7 +1692,6 @@ class CategoricalResultValueAnnotations(Base):

class MeasurementResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(MeasurementResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand All @@ -1731,7 +1702,6 @@ class MeasurementResultValueAnnotations(Base):

class PointCoverageResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(PointCoverageResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand All @@ -1752,7 +1722,6 @@ class ProfileResultValueAnnotations(Base):

class SectionResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(SectionResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand All @@ -1763,7 +1732,6 @@ class SectionResultValueAnnotations(Base):

class SpectraResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(SpectraResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand All @@ -1774,7 +1742,6 @@ class SpectraResultValueAnnotations(Base):

class TimeSeriesResultValueAnnotations(Base):


BridgeID = Column('bridgeid', Integer, primary_key=True, nullable=False)
ValueID = Column('valueid', BigInteger, ForeignKey(TimeSeriesResultValues.ValueID), nullable=False)
AnnotationID = Column('annotationid', ForeignKey(Annotations.AnnotationID), nullable=False)
Expand Down Expand Up @@ -1806,28 +1773,19 @@ class TransectResultValueAnnotations(Base):
def _changeSchema(schema):
import inspect
import sys
#get a list of all of the classes in the module
# get a list of all of the classes in the module
clsmembers = inspect.getmembers(sys.modules[__name__],
lambda member: inspect.isclass(member) and member.__module__ == __name__)

for name, Tbl in clsmembers:
import sqlalchemy.ext.declarative.api as api

if isinstance(Tbl, api.DeclarativeMeta):
#check to see if the schema is already set correctly
if Tbl.__table__.schema ==schema:
# check to see if the schema is already set correctly
if Tbl.__table__.schema == schema:
return
Tbl.__table__.schema = schema
Tbl.__table_args__["schema"]=schema


# def _changeSchema(schema):
# # check to see if the schema is already set correctly
# # if Base.__table__.schema == schema:
# # return
# # Base.__table__.schema = schema
# Base.__table_args__["schema"] = schema
# print schema
Tbl.__table_args__["schema"]= schema


def _getSchema(engine):
Expand All @@ -1844,8 +1802,6 @@ def _getSchema(engine):
def setSchema(engine):

s = _getSchema(engine)
# if s is None:
# s = ''
_changeSchema(s)


6 changes: 5 additions & 1 deletion odm2api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def __eq__(self, other):
return self.__dict__ == other.__dict__

def __repr__(self):
return "<%s(%s)>" % (self.__class__.__name__, str(self.__dict__))
valuedict = self.__dict__.copy()
for v in valuedict.keys():
if "obj" in v.lower():
del valuedict[v]
return "<%s(%s)>" % (self.__class__.__name__, str(valuedict))


from sqlalchemy.ext.declarative import declarative_base
Expand Down

0 comments on commit 76b0dcd

Please sign in to comment.