Commit 402f4025 authored by sarsonl's avatar sarsonl
Browse files

Column attributes now use no m_ prefix

It was decided that it was a cleaner implementation to name the
ORM columns and ORM attributes differently.

This is cleaner without having to reference the m_ prefix all the
time, and the user should not have to know about this.

To avoid having m_ prefix on the attributes but still maintaining
prefix on column keys required an extra arg to be added to most
functions. Also fixed the bug where if an attribute was
previously called:
m_literaturesource_m_literaturesource_creator_m_\
literaturesource_creator_person_givenname

it would now be called:
m_literaturesource_literaturesource_creator_\
literaturesource_creator_person_givenname

(m_'s removed from within the name)

Question raised about whether we want the attribute to be called:
m_literaturesource_creator_person_givenname
but on attempting to modify this, an mapping error is called.
parent 9ef94f77
This diff is collapsed.
......@@ -13,6 +13,8 @@ from hydws.db.base import (ORMBase, CreationInfoMixin, RealQuantityMixin,
TimeQuantityMixin, EpochMixin,
LiteratureSourceMixin, PublicIDMixin)
KEY_PREFIX = 'm_'
# XXX(damb): The implementation of the entities below is based on the QuakeML
# and the SC3 DB model naming conventions. As a consequence,
# sub-(sub-(...)types (e.g. CreationInfo, LiteratureSource, Comment, etc. )
......@@ -22,14 +24,16 @@ from hydws.db.base import (ORMBase, CreationInfoMixin, RealQuantityMixin,
class Borehole(CreationInfoMixin('CreationInfo',
column_prefix='m_creationinfo_'),
column_prefix='creationinfo_',
key_prefix=KEY_PREFIX),
LiteratureSourceMixin('LiteratureSource',
column_prefix='m_literaturesource_'),
RealQuantityMixin('m_longitude'),
RealQuantityMixin('m_latitude'),
RealQuantityMixin('m_depth'),
RealQuantityMixin('m_bedrockdepth'),
PublicIDMixin(column_prefix='m_'),
column_prefix='literaturesource_',
key_prefix=KEY_PREFIX),
RealQuantityMixin('longitude', key_prefix=KEY_PREFIX),
RealQuantityMixin('latitude', key_prefix=KEY_PREFIX),
RealQuantityMixin('depth', key_prefix=KEY_PREFIX),
RealQuantityMixin('bedrockdepth', key_prefix=KEY_PREFIX),
PublicIDMixin(column_prefix=KEY_PREFIX),
ORMBase):
"""
ORM representation of a borehole. The attributes are in accordance with
......@@ -41,59 +45,21 @@ class Borehole(CreationInfoMixin('CreationInfo',
<https://quake.ethz.ch/quakeml>`_ quantities.
"""
_sections = relationship("BoreholeSection", back_populates="_borehole",
order_by="BoreholeSection.m_topdepth_value",
cascade='all, delete-orphan')
@hybrid_property
def m_longitude(self):
# min topdepth defines top-section
return min([s for s in self._sections],
key=lambda x: x.m_topdepth_value).m_toplongitude_value
@hybrid_property
def m_latitude(self):
# min topdepth defines top-section
return min([s for s in self._sections],
key=lambda x: x.m_topdepth_value).m_toplatitude_value
@hybrid_property
def m_depth(self):
# max bottomdepth defines bottom-section
return max([s.m_bottomdepth_value for s in self._sections])
@hybrid_property
def m_injectionpoint(self):
"""
Injection point of the borehole. It is defined by the uppermost
section's bottom with casing and an open bottom.
.. note::
The implementation requires boreholes to be linear.
"""
isection = min([s for s in self._sections
if s.m_casingdiameter_value and not s._bottomclosed],
key=lambda x: x.m_bottomdepth_value, default=None)
if not isection:
raise ValueError('Cased borehole has a closed bottom.')
return (isection.bottomlongitude_value,
isection.bottomlatitude_value,
isection.bottomdepth_value)
class BoreholeSection(EpochMixin('Epoch', epoch_type='open',
column_prefix='m_'),
RealQuantityMixin('m_toplongitude'),
RealQuantityMixin('m_toplatitude'),
RealQuantityMixin('m_topdepth'),
RealQuantityMixin('m_bottomlongitude'),
RealQuantityMixin('m_bottomlatitude'),
RealQuantityMixin('m_bottomdepth'),
RealQuantityMixin('m_holediameter'),
RealQuantityMixin('m_casingdiameter'),
PublicIDMixin(column_prefix='m_'),
RealQuantityMixin('toplongitude', key_prefix=KEY_PREFIX),
RealQuantityMixin('toplatitude', key_prefix=KEY_PREFIX),
RealQuantityMixin('topdepth', key_prefix=KEY_PREFIX),
RealQuantityMixin('bottomlongitude', key_prefix=KEY_PREFIX),
RealQuantityMixin('bottomlatitude', key_prefix=KEY_PREFIX),
RealQuantityMixin('bottomdepth', key_prefix=KEY_PREFIX),
RealQuantityMixin('holediameter', key_prefix=KEY_PREFIX),
RealQuantityMixin('casingdiameter', key_prefix=KEY_PREFIX),
PublicIDMixin(column_prefix=KEY_PREFIX),
ORMBase):
"""
ORM representation of a borehole. The attributes are in accordance with
......@@ -104,30 +70,29 @@ class BoreholeSection(EpochMixin('Epoch', epoch_type='open',
*Quantities* are implemented as `QuakeML
<https://quake.ethz.ch/quakeml>`_ quantities.
"""
m_topclosed = Column(Boolean)
m_bottomclosed = Column(Boolean)
m_sectiontype = Column(String)
m_casingtype = Column(String)
m_description = Column(String)
topclosed = Column('{}topclosed'.format(KEY_PREFIX), Boolean)
bottomclosed = Column('{}bottomclosed'.format(KEY_PREFIX), Boolean)
sectiontype = Column('{}sectiontype'.format(KEY_PREFIX), String)
casingtype = Column('{}casingtype'.format(KEY_PREFIX), String)
description = Column('{}description'.format(KEY_PREFIX), String)
m_borehole_oid = Column(Integer, ForeignKey('borehole._oid'))
borehole_oid = Column('{}borehole_oid'.format(KEY_PREFIX), Integer, ForeignKey('borehole._oid'))
_borehole = relationship("Borehole", back_populates="_sections")
_hydraulics = relationship("HydraulicSample", back_populates="_section",
order_by="HydraulicSample.m_datetime_value")
class HydraulicSample(TimeQuantityMixin('m_datetime'),
RealQuantityMixin('m_bottomtemperature'),
RealQuantityMixin('m_bottomflow'),
RealQuantityMixin('m_bottompressure'),
RealQuantityMixin('m_toptemperature'),
RealQuantityMixin('m_topflow'),
RealQuantityMixin('m_toppressure'),
RealQuantityMixin('m_fluiddensity'),
RealQuantityMixin('m_fluidviscosity'),
RealQuantityMixin('m_fluidph'),
PublicIDMixin(column_prefix='m_'),
_hydraulics = relationship("HydraulicSample", back_populates="_section")
class HydraulicSample(TimeQuantityMixin('datetime', key_prefix=KEY_PREFIX),
RealQuantityMixin('bottomtemperature', key_prefix=KEY_PREFIX),
RealQuantityMixin('bottomflow', key_prefix=KEY_PREFIX),
RealQuantityMixin('bottompressure', key_prefix=KEY_PREFIX),
RealQuantityMixin('toptemperature', key_prefix=KEY_PREFIX),
RealQuantityMixin('topflow', key_prefix=KEY_PREFIX),
RealQuantityMixin('toppressure', key_prefix=KEY_PREFIX),
RealQuantityMixin('fluiddensity', key_prefix=KEY_PREFIX),
RealQuantityMixin('fluidviscosity', key_prefix=KEY_PREFIX),
RealQuantityMixin('fluidph', key_prefix=KEY_PREFIX),
PublicIDMixin(column_prefix=KEY_PREFIX),
ORMBase):
"""
Represents an hydraulics sample. The definition is based on `QuakeML
......@@ -138,7 +103,7 @@ class HydraulicSample(TimeQuantityMixin('m_datetime'),
*Quantities* are implemented as `QuakeML
<https://quake.ethz.ch/quakeml>`_ quantities.
"""
m_fluidcomposition = Column(String)
fluidcomposition = Column('{}fluidcomposition'.format(KEY_PREFIX), String)
m_boreholesection_oid = Column(Integer, ForeignKey('boreholesection._oid'))
boreholesection_oid = Column('boreholesection_oid'.format(KEY_PREFIX), Integer, ForeignKey('boreholesection._oid'))
_section = relationship("BoreholeSection", back_populates="_hydraulics")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment