[Piwik-svn] r524 - in trunk: . modules modules/LogStats modules/LogStats/Generator

svnmaster at piwik.org svnmaster at piwik.org
Sat Jun 21 04:53:53 CEST 2008


Author: matt
Date: 2008-06-21 04:53:52 +0200 (Sat, 21 Jun 2008)
New Revision: 524

Modified:
   trunk/TODO
   trunk/modules/LogStats.php
   trunk/modules/LogStats/Generator/LogStats.php
   trunk/modules/LogStats/Generator/Visit.php
   trunk/modules/LogStats/Visit.php
   trunk/piwik.php
Log:
- adding hooks in LogStats modules, see http://dev.piwik.org/trac/wiki/Plugins/Hooks

Modified: trunk/TODO
===================================================================
--- trunk/TODO	2008-06-20 12:51:56 UTC (rev 523)
+++ trunk/TODO	2008-06-21 02:53:52 UTC (rev 524)
@@ -1,3 +1,22 @@
+delete ALL useless comments WAY TOO RISKY!!!!!!!!!!!
+review all hooks + generate auto documentation + choose good naming convention
+
+add clearpsring all widgets (create plugin)
+graph pie chart : others is -1
+check that when online archiving disabled, take the last valid archiving
+
+admin login screen should be ful screen not in ajax frame
+piwik logo should be colored logo
+text top shoudl be smaller (login, root)
+
+API request shouldnt be SO DataTable aware
+the logic of printing out nice datatable should be in some datattable class
+
+
+ACTIONS limit seem not right, seem limited to 50 instead of 200 for root
+put limit configuration in config files
+rename "Others" on a per API method basis "Other keywords" "Other websites" otherwise it's not clear at all 
+
 merge config file instead of annoying file selection?
 see if can remove translationAvailable in all plugins
 ECLIPSE WINDOWS LINE BREAKS

Modified: trunk/modules/LogStats/Generator/LogStats.php
===================================================================
--- trunk/modules/LogStats/Generator/LogStats.php	2008-06-20 12:51:56 UTC (rev 523)
+++ trunk/modules/LogStats/Generator/LogStats.php	2008-06-21 02:53:52 UTC (rev 524)
@@ -46,7 +46,9 @@
 	 */
 	protected function getNewVisitObject()
 	{
-		return new Piwik_LogStats_Generator_Visit(self::$db);
+		$visit = new Piwik_LogStats_Generator_Visit();
+		$visit->setDb(self::$db);
+		return $visit;
 	}	
 	
 	static function disconnectDb()

Modified: trunk/modules/LogStats/Generator/Visit.php
===================================================================
--- trunk/modules/LogStats/Generator/Visit.php	2008-06-20 12:51:56 UTC (rev 523)
+++ trunk/modules/LogStats/Generator/Visit.php	2008-06-21 02:53:52 UTC (rev 524)
@@ -22,11 +22,6 @@
 {
 	static protected $timestampToUse;
 	
-	function __construct( $db )
-	{
-		parent::__construct($db);
-	}
-	
 	static public function setTimestampToUse($time)
 	{
 		self::$timestampToUse = $time;

Modified: trunk/modules/LogStats/Visit.php
===================================================================
--- trunk/modules/LogStats/Visit.php	2008-06-20 12:51:56 UTC (rev 523)
+++ trunk/modules/LogStats/Visit.php	2008-06-21 02:53:52 UTC (rev 524)
@@ -9,6 +9,12 @@
  * @package Piwik_LogStats
  */
 
+
+interface Piwik_LogStats_Visit_Interface {
+	function handle();
+	function setDb($db);
+}
+
 /**
  * Class used to handle a Visit.
  * A visit is either NEW or KNOWN.
@@ -23,17 +29,15 @@
  * @package Piwik_LogStats
  */
 
-class Piwik_LogStats_Visit
+class Piwik_LogStats_Visit implements Piwik_LogStats_Visit_Interface
 {
 	protected $cookieLog = null;
 	protected $visitorInfo = array();
 	protected $userSettingsInformation = null;
-	
+	protected $db = null;
 
-	function __construct( $db )
+	function __construct()
 	{
-		$this->db = $db;
-				
 		$idsite = Piwik_Common::getRequestVar('idsite', 0, 'int');
 		if($idsite <= 0)
 		{
@@ -43,6 +47,11 @@
 		$this->idsite = $idsite;
 	}
 	
+	public function setDb($db)
+	{
+		$this->db = $db;
+	}
+	
 	/**
 	 * Returns the current date in the "Y-m-d" PHP format
 	 * @return string
@@ -67,9 +76,9 @@
 	 */
 	protected function getDatetimeFromTimestamp($timestamp)
 	{
-		return date("Y-m-d H:i:s",$timestamp);
+		return date("Y-m-d H:i:s", $timestamp);
 	}
-		
+
 	/**
 	 * Test if the current visitor is excluded from the statistics.
 	 * 
@@ -79,10 +88,10 @@
 	 * 
 	 * @return bool True if the visit must not be saved, false otherwise
 	 */
-	private function isExcluded()
+	protected function isExcluded()
 	{
 		$excluded = 0;
-		
+		Piwik_PostEvent('LogStats.Visit.isExcluded', $excluded);
 		if($excluded)
 		{
 			printDebug("Visitor excluded.");
@@ -96,7 +105,7 @@
 	 * Returns the cookie name used for the Piwik LogStats cookie
 	 * @return string
 	 */
-	private function getCookieName()
+	protected function getCookieName()
 	{
 		return Piwik_LogStats_Config::getInstance()->LogStats['cookie_name'] . $this->idsite;
 	}
@@ -131,7 +140,7 @@
 	 * 2) If the visitor doesn't have a cookie, we try to look for a similar visitor configuration.
 	 * 	  We search for a visitor with the same plugins/OS/Browser/Resolution for today for this website.
 	 */
-	private function recognizeTheVisitor()
+	protected function recognizeTheVisitor()
 	{
 		$this->visitorKnown = false;
 		
@@ -209,7 +218,7 @@
 	 * 
 	 * @return array
 	 */
-	private function getUserSettingsInformation()
+	protected function getUserSettingsInformation()
 	{
 		// we already called this method before, simply returns the result
 		if(is_array($this->userSettingsInformation))
@@ -290,7 +299,7 @@
 	 * Returns true if the last action was done during the last 30 minutes
 	 * @return bool
 	 */
-	private function isLastActionInTheSameVisit()
+	protected function isLastActionInTheSameVisit()
 	{
 		return $this->visitorInfo['visit_last_action_time'] 
 					>= ($this->getCurrentTimestamp() - Piwik_LogStats::VISIT_STANDARD_LENGTH);
@@ -299,7 +308,7 @@
 	/**
 	 * Returns true if the recognizeTheVisitor() method did recognize the visitor
 	 */
-	private function isVisitorKnown()
+	protected function isVisitorKnown()
 	{
 		return $this->visitorKnown === true;
 	}
@@ -332,7 +341,6 @@
 		}
 		
 		$this->recognizeTheVisitor();
-		
 		if( $this->isVisitorKnown() 
 			&& $this->isLastActionInTheSameVisit())
 		{
@@ -385,7 +393,7 @@
 	 * 
 	 * 2) Update the visit information
 	 */
-	private function handleKnownVisit()
+	protected function handleKnownVisit()
 	{
 		printDebug("Visit known.");		
 		
@@ -393,9 +401,7 @@
 		 * Init the action
 		 */
 		$action = $this->getActionObject();
-		
 		$actionId = $action->getActionId();
-		
 		printDebug("idAction = $actionId");
 				
 		$serverTime 	= $this->getCurrentTimestamp();
@@ -439,7 +445,7 @@
 	 * 
 	 * 2) Insert the visit information
 	 */
-	private function handleNewVisit()
+	protected function handleNewVisit()
 	{
 		printDebug("New Visit.");
 		
@@ -558,7 +564,7 @@
 	 *
 	 * @return Piwik_LogStats_Action child or fake but with same public interface
 	 */
-	private function getActionObject()
+	protected function getActionObject()
 	{
 		$action = null;
 		Piwik_PostEvent('LogStats.newAction', $action);
@@ -604,7 +610,7 @@
 	 * - referer_url : the same for all the referer types
 	 * 
 	 */
-	private function getRefererInformation()
+	protected function getRefererInformation()
 	{	
 		// default values for the referer_* fields
 		$this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_DIRECT_ENTRY;
@@ -650,7 +656,7 @@
 	/*
 	 * Search engine detection
 	 */
-	private function detectRefererSearchEngine()
+	protected function detectRefererSearchEngine()
 	{
 		/*
 		 * A referer is a search engine if the URL's host is in the SearchEngines array
@@ -708,7 +714,7 @@
 	/*
 	 * Newsletter analysis
 	 */
-	private function detectRefererNewsletter()
+	protected function detectRefererNewsletter()
 	{
 		if(isset($this->currentUrlParse['query']))
 		{
@@ -728,7 +734,7 @@
 	/*
 	 * Partner analysis
 	 */
-	private function detectRefererPartner()
+	protected function detectRefererPartner()
 	{
 		if(isset($this->currentUrlParse['query']))
 		{		
@@ -748,7 +754,7 @@
 	/*
 	 * Campaign analysis
 	 */
-	private function detectRefererCampaign()
+	protected function detectRefererCampaign()
 	{	
 		if(isset($this->currentUrlParse['query']))
 		{		
@@ -779,7 +785,7 @@
 	 * so it can only be a direct access
 	 */
 	
-	private function detectRefererDirectEntry()
+	protected function detectRefererDirectEntry()
 	{
 		if(isset($this->currentUrlParse['host']))
 		{
@@ -798,7 +804,7 @@
 	 * Returns a MD5 of all the configuration settings
 	 * @return string
 	 */
-	private function getConfigHash( $os, $browserName, $browserVersion, $resolution, $colorDepth, $plugin_Flash, $plugin_Director, $plugin_RealPlayer, $plugin_Pdf, $plugin_WindowsMedia, $plugin_Java, $plugin_Cookie, $ip, $browserLang)
+	protected function getConfigHash( $os, $browserName, $browserVersion, $resolution, $colorDepth, $plugin_Flash, $plugin_Director, $plugin_RealPlayer, $plugin_Pdf, $plugin_WindowsMedia, $plugin_Java, $plugin_Cookie, $ip, $browserLang)
 	{
 		return md5( $os . $browserName . $browserVersion . $resolution . $colorDepth . $plugin_Flash . $plugin_Director . $plugin_RealPlayer . $plugin_Pdf . $plugin_WindowsMedia . $plugin_Java . $plugin_Cookie . $ip . $browserLang );
 	}
@@ -808,7 +814,7 @@
 	 * - "-1" for a known visitor
 	 * - a unique 32 char identifier @see Piwik_Common::generateUniqId()
 	 */
-	private function getVisitorUniqueId()
+	protected function getVisitorUniqueId()
 	{
 		if($this->isVisitorKnown())
 		{

Modified: trunk/modules/LogStats.php
===================================================================
--- trunk/modules/LogStats.php	2008-06-20 12:51:56 UTC (rev 523)
+++ trunk/modules/LogStats.php	2008-06-21 02:53:52 UTC (rev 524)
@@ -190,7 +190,20 @@
 	 */
 	protected function getNewVisitObject()
 	{
-		return new Piwik_LogStats_Visit(self::$db);
+		$visit = null;
+		Piwik_PostEvent('LogStats.getNewVisitObject', $visit);
+	
+		if(is_null($visit))
+		{
+			$visit = new Piwik_LogStats_Visit();
+		}
+		elseif(!($visit instanceof Piwik_LogStats_Visit_Interface ))
+		{
+			throw new Exception("The Visit object set in the plugin must implement Piwik_LogStats_Visit_Interface");
+		}
+		
+		$visit->setDb(self::$db);
+		return $visit;
 	}
 	
 	// main algorithm 

Modified: trunk/piwik.php
===================================================================
--- trunk/piwik.php	2008-06-20 12:51:56 UTC (rev 523)
+++ trunk/piwik.php	2008-06-21 02:53:52 UTC (rev 524)
@@ -7,25 +7,6 @@
  * @version $Id$
  */
 
-/**
- * Misc Thoughts about optimization
- * 
- * - after a day is archived, we delete all the useless information from the log table, keeping only the useful data for weeks/month
- *   maybe we create a new table containing only these aggregate and we can delete the rows of the day in the log table
- */
- 
-/*
- * Some benchmarks
- * 
- * - with the config parsing + db connection
- * Requests per second:    471.91 [#/sec] (mean)
- * 
- * - with the main algorithm working + one visitor requesting 5000 times
- * Requests per second:    155.00 [#/sec] (mean)
- * 
- * - august 28th, main algo + files in place + one visitor requesting 5000 times
- * Requests per second:    118.55 [#/sec] (mean)
- */
 error_reporting(E_ALL|E_NOTICE);
 define('PIWIK_INCLUDE_PATH', '.');
 @ignore_user_abort(true);



More information about the Piwik-svn mailing list