Next / Previous / Contents / NM Tech homepage

9.6. transloader: addCircle()

transloader
# - - -   a d d C i r c l e

def addCircle(my, db, cir):
    '''Add rows to the circles, cir_reg, and cir_physio tables.

      [ (my is a MyCBC instance) and (db is a CBCData instance) and
        (cir is a db.Cir instance) ->
          db  :=  db with a circle row and related cir_reg
                  and cir_physio rows added, made from cir ]
    '''

First we assemble a db.Circle instance. For the constructor, see Section 6.8, “The circles table”.

transloader
    #-- 1 --
    # [ db  +:=  a db.Circle instance made from cir ]
    lat = cir.lat_lon[:4]
    lon = cir.lat_lon[4:]
    name = unicode(cir.name)
    circle = db.Circle(lat, lon, cir.water, cir.odd, name)
    db.s.add ( circle )
    db.s.commit()

Next, create cir_reg instances for each region code. The number of region codes is the length of the old database's regions field divided by two. For the constructor, see Section 6.9, “The cir_reg table”.

transloader
    #-- 2--
    # [ db  +:=  db.CirReg instances made from cir's regions,
    #              if any ]
    nRegs = len(cir.regions.strip())/2
    for regx in range(nRegs):
        regCode = cir.regions[regx*2:regx*2+2]
        cirReg = db.CirReg(lat, lon, regx, regCode)
        db.s.add ( cirReg )

Similarly, create cir_physio instances for the physiographic strata, if any. For the CirPhysio constructor, see Section 6.10, “The cir_physio table”.

transloader
    #-- 3 --
    # [ db.s  +:=  db.CirPhysio instances made from cir's
    #              physio codes, if any ]
    nPhysios = len(cir.physio.strip())/2
    for physx in range(nPhysios):
        physioCode = cir.physio[physx*2:physx*2+2]
        cirPhysio = db.CirPhysio(lat, lon, physx, physioCode)
        db.s.add ( cirPhysio )

    #-- 4 --
    db.s.commit()