Public Member Functions | |
__construct () | |
update () | |
updateOneshot ($minutes=60, $interval=300) | |
Protected Member Functions | |
_getSummaryTypes () | |
_update ($type) | |
Protected Attributes | |
$_visitorTable | |
$_customerTable | |
$_urlTable | |
$_summaryTable | |
$_summaryTypeTable | |
$_read | |
$_write |
Definition at line 33 of file Aggregator.php.
__construct | ( | ) |
Definition at line 84 of file Aggregator.php.
00085 { 00086 $resource = Mage::getSingleton('core/resource'); 00087 00088 $this->_visitorTable = $resource->getTableName('log/visitor'); 00089 $this->_urlTable = $resource->getTableName('log/url_table'); 00090 $this->_customerTable = $resource->getTableName('log/customer'); 00091 $this->_summaryTable = $resource->getTableName('log/summary_table'); 00092 $this->_summaryTypeTable= $resource->getTableName('log/summary_type_table'); 00093 00094 $this->_read = $resource->getConnection('log_read'); 00095 $this->_write = $resource->getConnection('log_write'); 00096 }
_getSummaryTypes | ( | ) | [protected] |
Definition at line 106 of file Aggregator.php.
00107 { 00108 $types = $this->_read->fetchAll("SELECT type_id, period, period_type FROM {$this->_summaryTypeTable}"); 00109 return $types; 00110 }
_update | ( | $ | type | ) | [protected] |
Definition at line 112 of file Aggregator.php.
00113 { 00114 $countSelect = $this->_read->select() 00115 ->from($this->_summaryTable, 'summary_id') 00116 ->where('type_id=?', $type['type_id']) 00117 ->having("('".now()."' - INTERVAL {$type['period']} {$type['period_type']}) <= MAX(add_date)"); 00118 00119 $summaryIds = $this->_read->fetchCol($countSelect); 00120 00121 $customerSelect = $this->_read->select() 00122 ->from($this->_customerTable, 'visitor_id') 00123 ->where("? - INTERVAL {$type['period']} {$type['period_type']} <= login_at", now()) 00124 ->where("logout_at IS NULL OR logout_at <= ? - INTERVAL {$type['period']} {$type['period_type']}", now()); 00125 00126 $customers = $this->_read->fetchCol($customerSelect); 00127 00128 $customerCount = count($customers); 00129 00130 $customers = ( $customerCount > 0 ) ? $customers : 0; 00131 00132 $customersCondition = $this->_read->quoteInto('visitor_id NOT IN(?)', $customers); 00133 $visitorCount = $this->_read->fetchOne("SELECT COUNT(visitor_id) FROM {$this->_visitorTable} WHERE ('".now()."' - INTERVAL {$type['period']} {$type['period_type']}) <= first_visit_at OR (NOW() - INTERVAL {$type['period']} {$type['period_type']}) <= last_visit_at AND {$customersCondition}"); 00134 00135 if( $customerCount == 0 && $visitorCount == 0 ) { 00136 return; 00137 } 00138 00139 $data = array( 00140 'type_id' => $type['type_id'], 00141 'visitor_count' => $visitorCount, 00142 'customer_count' => $customerCount, 00143 'add_date' => now() 00144 ); 00145 00146 00147 if(count($summaryIds)==0) { 00148 $this->_write->insert($this->_summaryTable, $data); 00149 } else { 00150 $conditionSql = $this->_write->quoteInto('summary_id in (?)', $summaryIds); 00151 $this->_write->update($this->_summaryTable, $data, $conditionSql); 00152 } 00153 00154 }
update | ( | ) |
Definition at line 98 of file Aggregator.php.
00099 { 00100 $types = $this->_getSummaryTypes(); 00101 foreach( $types as $type ) { 00102 $this->_update($type); 00103 } 00104 }
updateOneshot | ( | $ | minutes = 60 , |
|
$ | interval = 300 | |||
) |
Definition at line 156 of file Aggregator.php.
00157 { 00158 $last_update = $this->_read->fetchOne("SELECT UNIX_TIMESTAMP(MAX(add_date)) FROM {$this->_summaryTable} WHERE type_id IS NULL"); 00159 $next_update = $last_update + $interval; 00160 00161 if( time() >= $next_update ) { 00162 $stats = $this->_read->fetchAssoc("SELECT 00163 u.visit_time, 00164 v.visitor_id, 00165 c.customer_id, 00166 ROUND( (UNIX_TIMESTAMP(u.visit_time) - UNIX_TIMESTAMP(".now()." - INTERVAL {$minutes} MINUTE )) / {$interval} ) as _diff, 00167 COUNT(DISTINCT(v.visitor_id)) as visitor_count, 00168 COUNT(DISTINCT(c.customer_id)) as customer_count 00169 FROM 00170 {$this->_urlTable} u 00171 LEFT JOIN {$this->_visitorTable} v ON(v.visitor_id = u.visitor_id) 00172 LEFT JOIN {$this->_customerTable} c on(c.visitor_id = v.visitor_id) 00173 WHERE 00174 UNIX_TIMESTAMP(u.visit_time) > {$next_update} 00175 group by _diff"); 00176 00177 foreach( $stats as $stat ) { 00178 $data = array( 00179 'type_id' => new Zend_Db_Expr('NULL'), 00180 'visitor_count' => $stat['visitor_count'], 00181 'customer_count' => $stat['customer_count'], 00182 'add_date' => $stat['visit_time'] 00183 ); 00184 $this->_write->insert($this->_summaryTable, $data); 00185 } 00186 } 00187 00188 }
$_customerTable [protected] |
Definition at line 47 of file Aggregator.php.
$_read [protected] |
Definition at line 75 of file Aggregator.php.
$_summaryTable [protected] |
Definition at line 61 of file Aggregator.php.
$_summaryTypeTable [protected] |
Definition at line 68 of file Aggregator.php.
$_urlTable [protected] |
Definition at line 54 of file Aggregator.php.
$_visitorTable [protected] |
Definition at line 40 of file Aggregator.php.
$_write [protected] |
Definition at line 82 of file Aggregator.php.