Next / Previous / Contents / NM Tech homepage

9.7. transloader: addCircleYear()

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

def addCircleYear(my, db, stnd):
    '''Copy all the data for a given circle-year.

      [ (my is a MyCBC instance) and (db is a CBCData instance) and
        (stnd is a my.Stnd instance) ->
          db  :=  db + (all circle-year data for stnd) ]
    '''

This function handles the copying of new rows to the efforts and censuses tables.

The first order of business is to retrieve the Eff and AsPub instances for this count ID.

transloader
    #-- 1 --
    # [ lat  :=  latitude from stnd
    #   lon  :=  longitude from stnd
    #   year_no  :=  year number from stnd
    #   year_key  :=  year key from stnd
    #   eff  :=  Eff instance from (my) for stnd.count_id
    #   asPub  :=  AsPub instance from (my) for stnd.count_id ]
    lat = stnd.lat_lon[:4]
    lon = stnd.lat_lon[4:]
    year_no = stnd.count_id[:3]
    year_key = stnd.count_id[3:]
    eff = my.getEff(stnd.count_id)
    asPub = my.getAsPub(stnd.count_id)

Now create the new Effort instance. For the constructor, see Section 6.11, “The efforts table”.

transloader
    #-- 2 --
    # [ db.s  +:=  a new db.Effort instance representing eff and asPub ]
    asLat = asPub.as_lat_lon[:4]
    asLon = asPub.as_lat_lon[4:]
    effort = db.Effort(lat, lon, year_no, year_key, eff.yyyymmdd,
        asLat, asLon, asPub.as_name, eff.n_obs,
        eff.ph_tot, eff.ph_foot, eff.ph_car, eff.ph_o,
        eff.h_fd, eff.h_owl,
        eff.pm_tot, eff.pm_f, eff.pm_c, eff.pm_o, eff.m_owl)
    db.s.add ( effort )

Copying of records to the censuses table is handled in Section 9.8, “transloader: addCensus().

transloader
    #-- 3 --
    # [ db.s  +:=  new db.Census instances representing rows from
    #       the cen table in my for count_id (count_id) and
    #       year (year_no) ]
    for cen in my.genCens(stnd.count_id):
        #-- 3 body --
        # [ db.s  +:=  a new db.Census instance representing cen ]
        addCensus(db, lat, lon, year_no, year_key, cen)