PYTHON   76
fcny webstats py
Guest on 10th February 2023 01:49:39 AM


  1.  
  2. # import the Webstats package
  3. import webstats, webprocessor
  4.  
  5. ####################################################################
  6. # create a subclass of WebStatistic
  7. class TestStat(webstats.WebStatistic):
  8.     def __init__(self):
  9.         self.id = 1
  10.         self.counter = 0
  11.         self.times = []
  12.         self.unique = {}
  13.    
  14.     def addSession(self, session):
  15.         for e in session:
  16.             self.times.append(e.date)
  17.             self.unique[e.date] = 1
  18.         self.counter += len(session)
  19.        
  20.     def finish(self):
  21.         line_parser = webprocessor.BaseLogEntryParser([webprocessor.LFE_REMOTE_HOST,
  22.                                                        webprocessor.LFE_RFC1413,
  23.                                                        webprocessor.LFE_USERID,
  24.                                                        webprocessor.LFE_DATE,
  25.                                                        webprocessor.LFE_URL,
  26.                                                        "uname",
  27.                                                        webprocessor.LFE_STATUS,
  28.                                                        webprocessor.LFE_SIZE,
  29.                                                        webprocessor.LFE_REFERRED,
  30.                                                        webprocessor.LFE_USER_INFO],
  31.                                                       separator = "|")
  32.         f = file('combined.ppstat')
  33.         line_count = 1
  34.         print "Entries ignored by webprocessor:"
  35.         print "line#                  url"
  36.         print "--------------------------------------------------------------------
  37.        for l in f.readlines():
  38.            entry = line_parser.parseLine(l.strip())
  39.            if entry.date not in self.times:
  40.                print line_count, "     ", entry.url
  41.            line_count += 1
  42.        print "# of requests found by webprocessor: ", self.counter
  43.         print "true requests: ", (line_counter-1)
  44.  
  45.            
  46. ####################################################################
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. # create a subclass of WebStatistic
  73. ## class Stat2(webstats.WebStatistic):
  74. ##     def __init__(self):
  75. ##         self.id = 2
  76. ##         print self.id, ": __init__ called."
  77.    
  78. ##     # This method has to be overridden by subclasses.
  79. ##     # It takes a user session as an entry. Based
  80. ##     # on this the subclass can calculate the desired statistic.
  81. ##     def addSession(self, session):
  82. ##         print self.id, ": addSession called."
  83.        
  84. ##     # When all session are processes this class is to be
  85. ##     # called to finalize the calculation of the statistic.
  86. ##     def finish(self):
  87. ##         print self.id, ": finish called."
  88.  
  89.  
  90. ## ####################################################################
  91. ## # create a subclass of WebStatistic
  92. ## class Stat3(webstats.WebStatistic):
  93. ##     def __init__(self):
  94. ##         self.id = 3
  95. ##         print self.id, ": __init__ called."
  96.    
  97. ##     # This method has to be overridden by subclasses.
  98. ##     # It takes a user session as an entry. Based
  99. ##     # on this the subclass can calculate the desired statistic.
  100. ##     def addSession(self, session):
  101. ##         print self.id, ": addSession called."
  102.        
  103. ##     # When all session are processes this class is to be
  104. ##     # called to finalize the calculation of the statistic.
  105. ##     def finish(self):
  106. ##         print self.id, ": finish called."
  107.  
  108.  
  109. ## ####################################################################
  110. ## # create a subclass of WebStatistic
  111. ## class Stat4(webstats.WebStatistic):
  112. ##     def __init__(self):
  113. ##         self.id = 4
  114. ##         print self.id, ": __init__ called."
  115.    
  116. ##     # This method has to be overridden by subclasses.
  117. ##     # It takes a user session as an entry. Based
  118. ##     # on this the subclass can calculate the desired statistic.
  119. ##     def addSession(self, session):
  120. ##         print self.id, ": addSession called."
  121.        
  122. ##     # When all session are processes this class is to be
  123. ##     # called to finalize the calculation of the statistic.
  124. ##     def finish(self):
  125. ##         print self.id, ": finish called."
  126.  
  127.  
  128. ## ####################################################################
  129. ## # create a subclass of WebStatistic
  130. ## class Stat5(webstats.WebStatistic):
  131. ##     def __init__(self):
  132. ##         self.id = 5
  133. ##         print self.id, ": __init__ called."
  134.    
  135. ##     # This method has to be overridden by subclasses.
  136. ##     # It takes a user session as an entry. Based
  137. ##     # on this the subclass can calculate the desired statistic.
  138. ##     def addSession(self, session):
  139. ##         print self.id, ": addSession called."
  140.        
  141. ##     # When all session are processes this class is to be
  142. ##     # called to finalize the calculation of the statistic.
  143. ##     def finish(self):
  144. ##         print self.id, ": finish called."
  145.  
  146.  
  147. ## ####################################################################
  148. ## # create a subclass of WebStatistic
  149. ## class Stat6(webstats.WebStatistic):
  150. ##     def __init__(self):
  151. ##         self.id = 6
  152. ##         print self.id, ": __init__ called."
  153.    
  154. ##     # This method has to be overridden by subclasses.
  155. ##     # It takes a user session as an entry. Based
  156. ##     # on this the subclass can calculate the desired statistic.
  157. ##     def addSession(self, session):
  158. ##         print self.id, ": addSession called."
  159.        
  160. ##     # When all session are processes this class is to be
  161. ##     # called to finalize the calculation of the statistic.
  162. ##     def finish(self):
  163. ##         print self.id, ": finish called."
  164.  
  165.  
  166. ## ####################################################################
  167. ## # create a subclass of WebStatistic
  168. ## class Stat7(webstats.WebStatistic):
  169. ##     def __init__(self):
  170. ##         self.id = 7
  171. ##         print self.id, ": __init__ called."
  172.    
  173. ##     # This method has to be overridden by subclasses.
  174. ##     # It takes a user session as an entry. Based
  175. ##     # on this the subclass can calculate the desired statistic.
  176. ##     def addSession(self, session):
  177. ##         print self.id, ": addSession called."
  178.        
  179. ##     # When all session are processes this class is to be
  180. ##     # called to finalize the calculation of the statistic.
  181. ##     def finish(self):
  182. ##         print self.id, ": finish called."
  183.  
  184.  
  185. ## ####################################################################
  186. ## # create a subclass of WebStatistic
  187. ## class Stat8(webstats.WebStatistic):
  188. ##     def __init__(self):
  189. ##         self.id = 8
  190. ##         print self.id, ": __init__ called."
  191.    
  192. ##     # This method has to be overridden by subclasses.
  193. ##     # It takes a user session as an entry. Based
  194. ##     # on this the subclass can calculate the desired statistic.
  195. ##     def addSession(self, session):
  196. ##         print self.id, ": addSession called."
  197.        
  198. ##     # When all session are processes this class is to be
  199. ##     # called to finalize the calculation of the statistic.
  200. ##     def finish(self):
  201. ##         print self.id, ": finish called."
  202.  
  203.  
  204. ## ####################################################################
  205. ## # create a subclass of WebStatistic
  206. ## class Stat9(webstats.WebStatistic):
  207. ##     def __init__(self):
  208. ##         self.id = 9
  209. ##         print self.id, ": __init__ called."
  210.    
  211. ##     # This method has to be overridden by subclasses.
  212. ##     # It takes a user session as an entry. Based
  213. ##     # on this the subclass can calculate the desired statistic.
  214. ##     def addSession(self, session):
  215. ##         print self.id, ": addSession called."
  216.        
  217. ##     # When all session are processes this class is to be
  218. ##     # called to finalize the calculation of the statistic.
  219. ##     def finish(self):
  220. ##         print self.id, ": finish called."
  221.  
  222.  
  223. ## ####################################################################
  224. ## # create a subclass of WebStatistic
  225. ## class Stat10(webstats.WebStatistic):
  226. ##     def __init__(self):
  227. ##         self.id = 10
  228. ##         print self.id, ": __init__ called."
  229.    
  230. ##     # This method has to be overridden by subclasses.
  231. ##     # It takes a user session as an entry. Based
  232. ##     # on this the subclass can calculate the desired statistic.
  233. ##     def addSession(self, session):
  234. ##         print self.id, ": addSession called."
  235.        
  236. ##     # When all session are processes this class is to be
  237. ##     # called to finalize the calculation of the statistic.
  238. ##     def finish(self):
  239. ##         print self.id, ": finish called."
  240.  
  241.  
  242. ## ####################################################################
  243. ## # create a subclass of WebStatistic
  244. ## class Stat11(webstats.WebStatistic):
  245. ##     def __init__(self):
  246. ##         self.id = 11
  247. ##         print self.id, ": __init__ called."
  248.    
  249. ##     # This method has to be overridden by subclasses.
  250. ##     # It takes a user session as an entry. Based
  251. ##     # on this the subclass can calculate the desired statistic.
  252. ##     def addSession(self, session):
  253. ##         print self.id, ": addSession called."
  254.        
  255. ##     # When all session are processes this class is to be
  256. ##     # called to finalize the calculation of the statistic.
  257. ##     def finish(self):
  258. ##         print self.id, ": finish called."

Raw Paste

Login or Register to edit or fork this paste. It's free.