示例#1
0
def map_null_values(table, obj):
    """
    Maps 'None' field values to appropriate CSS3.0 null field values.
    """
    from antpy import get_null_value
    for field in table.query(dbTABLE_FIELDS):
        if getattr(obj, field) == None:
           setattr(obj, field, get_null_value(table.query(dbTABLE_NAME), field))
    return obj
示例#2
0
def map_null_values(table, obj):
    """
    Update object attributes with None value to corresponding null
    value from CSS3.0 schema.

    Arguments:
    table - A Datascope database pointer to a CSS3.0 table to query for
    null values.
    obj - The object to update.

    Returns:
    obj - The updated object.

    Example:
    In [1]: import sys

    In [2]: import os

    In [3]: sys.path.append('%s/data/python' % os.environ['ANTELOPE'])

    In [4]: from antelope.datascope import closing, dbopen

    In [5]: from anfseistools.core import Origin

    In [6]: from anfseistools.ant import map_null_values

    In [7]: origin = Origin(48.4222, -123.3657, 35.0, 1267390800.000, 'white')

    In [8]: print origin
    Origin Object
    -------------
    lat:        48.4222
    lon:        -123.3657
    depth:      35.0
    time:       1267390800.0
    orid:       None
    evid:       None
    auth:       white
    jdate:      None
    nass:       None
    ndef:       None
    ndp:        None
    grn:        None
    srn:        None
    etype:      None
    review:     None
    depdp:      None
    dtype:      None
    mb:     None
    mbid:       None
    ms:     None
    msid:       None
    ml:     None
    mlid:       None
    algorithm:      None
    commid:     None
    lddate:     None
    arrivals:

    In [9]: with closing(dbopen('/Users/mcwhite/staging/dbs/June2010/June2010',
                                'r')) as db:
       ...:      tbl_origin = db.schema_tables['origin']
       ...:      origin = map_null_values(tbl_origin, origin)
       ...:

                 In [10]: print origin
                 Origin Object
                 -------------
                 lat:       48.4222
                 lon:       -123.3657
                 depth:     35.0
                 time:      1267390800.0
                 orid:      -1
                 evid:      -1
                 auth:      white
                 jdate:     -1
                 nass:      -1
                 ndef:      -1
                 ndp:       -1
                 grn:       -1
                 srn:       -1
                 etype:     -
                 review:        -
                 depdp:     -999.0
                 dtype:     -
                 mb:        -999.0
                 mbid:      -1
                 ms:        -999.0
                 msid:      -1
                 ml:        -999.0
                 mlid:      -1
                 algorithm:     -
                 commid:        -1
                 lddate:        -10000000000.0
                 arrivals:
    """
    from antelope.datascope import dbTABLE_FIELDS,\
                                   dbTABLE_NAME
    for field in table.query(dbTABLE_FIELDS):
        if getattr(obj, field) == None:
            setattr(obj,
                    field,
                    antpy.get_null_value(table.query(dbTABLE_NAME), field))
    return obj