Next / Previous / Contents / TCC Help System / NM Tech homepage

10.12. hist.cgi: findEfforts(): Locate selected effort records

# - - -   f i n d E f f o r t s

def findEfforts(db, circleList):
    '''Locate effort records for circles in circleList, if any.

      [ (db is a pycbc.CbcDatabase instance) and
        (circleList is a list of pycbc.Circle instances) ->
          if the circles in circleList have any efforts in db for
          years selected by HistArgs() ->
            effKeyList  :=  EffortKey values from those effort records ]
          else -> raise ScriptError ]

For each of the selected circles, we retrieve the associated effort records (a one-to-many relation) and filter out the ones outside the year range of interest. The ordering of the resulting list is unimportant; the ColumnLayout instance will worry about the ordering of the columns.

    #-- 1
    # [ effKeyList  :=  Effort instances related to circle,
    #       excluding those outside the years selected by HistArgs() ]
    effKeyList = []
    for circle in circleList:
        for effort in circle.efforts:
            if ((effort.year_no >= HistArgs().firstYear) and
                (effort.year_no <= HistArgs().lastYear)):
                effKey = lib.EffortKey(effort.year_no, effort.year_key)

If this list is empty, there is no point in continuing.

    #-- 2
    # [ if effKeyList is empty ->
    #     raise ScriptError
    #   else -> return effKeyList ]
    if len(effKeyList) == 0:
        raise lib.ScriptError("The selected circle(s) had no data for "
            "the selected years.")
        return effKeyList