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

11. addSummaryTable(): Generate the table summarizing all accesses

webstats.py
# - - -   a d d S u m m a r y T a b l e

def addSummaryTable ( parent, accessSummary ):
    '''Add the overall summary of accesses.

      [ (parent is an et.Element) and
        (accessSummary is an AccessSummary) ->
          parent  +:=  (summary of total hits in accessSummary) ]
    '''

We'll use the TABLE_ATTRS dictionary defined in Section 6.4, “Constants for HTML generation” to decorate our table.

webstats.py
    #-- 1 --
    # [ parent  +:=  a new 'table' element with attributes TABLE_ATTRS
    #   table  :=  that element ]
    table  =  E.table ( TABLE_ATTRS )
    parent.append ( table )

The first line shows the current time. The second line shows, not the beginning of the report interval, but the time of the oldest actual observed access.

webstats.py
    #-- 2 --
    # [ table  +:=  row showing the current time from accessSummary.now ]
    timeFormat  =  "%Y-%m-%dT%H:%M %z"
    table.append (
      E.tr (
        E.th ( L_ALIGN, "This report generated" ),
        E.td ( R_ALIGN, accessSummary.now.strftime ( timeFormat ) ) ) )

    #-- 3 --
    # [ table  +:=  row showing start time accessSummary.oldestHit ]
    utcZone  =  FixedTimeZone(0, "UTC")
    oldestZulu  =  accessSummary.oldestHit.astimezone(utcZone)
    table.append (
      E.tr (
        E.th ( L_ALIGN, "Accesses since" ),
        E.td ( R_ALIGN, oldestZulu.strftime ( timeFormat ) ) ) )

The remaining rows show off-campus, on-campus, and grand total hits.

webstats.py
    #-- 4 --
    # [ table  +:=  rows showing total off-campus hits, total
    #       on-campus hits, and total hits from accessSummary ]
    nFar  =  accessSummary.sumHitCount.nFar
    nTotal  =  accessSummary.sumHitCount.nTotal
    table.append (
      E.tr (
        E.th ( L_ALIGN, "Requests from off-campus" ),
        E.td ( R_ALIGN, str(nFar) ) ) )
    table.append (
      E.tr (
        E.th ( L_ALIGN, "Requests from on-campus" ),
        E.td ( R_ALIGN, str(nTotal-nFar) ) ) )
    table.append (
      E.tr (
        E.th ( L_ALIGN, "Total requests" ),
        E.td ( R_ALIGN, str(nTotal) ) ) )