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

35. AccessSummary.__addHit(): Register one access

webstats.py
# - - -   A c c e s s S u m m a r y . _ _ a d d H i t

    def __addHit ( self, url, when, isFar ):
        '''Register one access.

          [ (url is a URL as a string) and
            (when is the access time as a datetime.datetime) and
            (isFar is True for an off-campus access,
            False for on-campus) ->
              self  :=  self with that access added ]
        '''

The first invariant we must establish is the site-total hit count, self.sumHitCount. See Section 35, “AccessSummary.__addHit(): Register one access”.

webstats.py
        #-- 1 --
        # [ self.sumHitCount  +:=  one access with isFar=isFar ]
        self.sumHitCount.addHit ( isFar )

The next invariant is that self.oldestHit is a running minimum of all the access times.

webstats.py
        #-- 2 --
        # [ if pageGet.when < self.oldestHit ->
        #       self.oldestHit  :=  pageGet.when
        #   else -> I ]
        self.oldestHit  =  min ( self.oldestHit, when )

Next we insure that self.urlMap contains a HitCount instance for this URL, and then we register one hit with that instance. See Section 36, “AccessSummary.__addUrl(): Register one access in self.__urlMap.

webstats.py
        #-- 3 --
        # [ self.__urlMap  +:=  one access for url=url and
        #                       isFar=isFar ]
        self.__addUrl ( url, isFar )

The remaining invariants are those on the .__personalLetterMap, .__personalMap, and .__officialMap directories. See Section 37, “AccessSummary.__addCategory(): Add URL to appropriate category”.

webstats.py
        #-- 4 --
        # [ if url is "/" ->
        #     I
        #   else if url is for a personal page ->
        #     self.__personalLetterMap  +:=  entry for the third
        #         character of url
        #     self.__personalMap  +:=  entry for url
        #   else ->
        #     self.__officialLetterMap  +:=  entry for the second
        #         character of url
        #     self.__officialMap  +:=  entry for url ]
        self.__addCategory(url)