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

45. class HitCount: Hit counts for one URL

For a discussion of the design of this class, see Section 2.1, “Data structures”. We use a new-style class with a __slots__ attribute to conserve storage, since there will be a lot of instances of this class.

webstats.py
# - - - - -   c l a s s   H i t C o u n t

class HitCount(object):
    '''Represents the access data for one URL in the report period.

      Exports:
        HitCount ( url ):
          [ url is a URL as a string ->
              return a new HitCount instance for that URL and
              zero access counts ]
        .url:         [ as passed to constructor, read-only ]
        .nTotal:      [ total hits in self as an int ]
        .nFar:        [ total off-campus hits in self as an int ]
        .addHit ( isFar ):
          [ isFar is True for off-campus, False otherwise ->
              if isFar ->
                self  :=  self with one additional total hit
                          and one additional off-campus hit
              else ->
                self  :=  self with one additional total hit ]
        .__cmp__(self, other):
          [ if self.nTotal < other.nTotal ->
              return a positive int
            else self.nTotal > other.nTotal ->
              return a negative int
            else ->
              return cmp(self.url, other.url) ]
    '''
    __slots__  =  ('nTotal', 'nFar', 'url')