コード例 #1
0
ファイル: helpers.php プロジェクト: rsweetland/Lean-Charts
/**  
* Counts the total number users (of a given cohort) who who have hit an event.
* 
*  @param event (which event are we looking for)
*  @param cohort sql query returning the our target users
*  @param instances the minimum number of events for the user to be counted (for example
*  you may want to pull how many users have uploaded a photo at least 5 times.
* 
*   @example $userCohort = "SELECT uid FROM log WHERE date BETWEEN '2011-05-01' AND '2011-06-11' AND event = 'first time fut use: user record created'";
* countUsersWithEvent('first time fut use: user record created', $userCohort)
*  
*   IMPORTANT: NEVER EXPOSE 'cohort' TO END-USER AS IT EXECUTES SQL DIRECTLY WITHOUT ESCAPING
*/

function countUsersWithEvent($event, $minInstances = '', $cohort) {
    
    $event = mysql_real_escape_string($event);
    $minInstances = intval($minInstances);
    
    if($minInstances) {
        $having = "HAVING event_instances >= $minInstances";
    } else {
        $having = '';
    }

    $sql = "SELECT
    	    log.uid AS users, count(log.uid) AS event_instances
    	    FROM log
    	        INNER JOIN ($cohort) AS target_users
        	ON target_users.uid = log.uid
        	WHERE event = '$event'
        	GROUP BY log.uid
        	$having";  //group by uid to ensure that only unique users returned
    $res = SonarStatManager::dbQuery($sql);
    return mysql_num_rows($res);
}
コード例 #2
0
ファイル: hourly.php プロジェクト: rsweetland/Lean-Charts
<?
include realpath(dirname(__FILE__) . '/../init.php');

SonarStatManager::populateStatList(); //add any new stats that appeared in log files in the last hour
echo "Stat list updated from unique log entries.\n";

$stats = SonarStatManager::getStatList();

foreach($stats as $stat) {
		SonarStatManager::populateHourlyStat($stat['event']);
}
echo "Stat values updated.\n";

SonarStatManager::dbDisconnect(); 
?>
コード例 #3
0
    /**
     * gets date / value array for count('log event') in that date span. 
     *
     * @param string event 
     * @param int limit
	 * @return array ('date'=>'value');
     * 
     */

    public function getStatValues($interval = 'daily', $limit = '20') 
	{

		$from = ($interval == 'daily') ? 'sonar_stat_val_day' : 'sonar_stat_val_hr';
		
		/* get stats */
		$sql = "SELECT date, count FROM $from
				WHERE event = '" . mysql_real_escape_string($this->event) . 
				"' ORDER BY date DESC 
				LIMIT $limit;";

        SonarStatManager::dbConnect();
        $res = SonarStatManager::dbQuery($sql);
		
		$data = array();
		while (list($date, $value) = mysql_fetch_array($res)) {
			$data[$date] = $value;			
		}
		
		return $data;
	}
コード例 #4
0
ファイル: daily.php プロジェクト: rsweetland/Lean-Charts
<?php
include realpath(dirname(__FILE__) . '/../init.php');

// Specify custom stats to be run. Custom stats must be added to this
// array to be included in the daily run. 

$customStats = array(
    'example.php'
);

foreach ($customStats as $customStat) {
    include_once(APP_ROOT . 'stats/' . $customStat);
}

SonarStatManager::populateStatList(); //add any new stats that appeared in log files that day
echo "\nStat list updated from unique log entries.\n";

$stats = SonarStatManager::getStatList();

foreach($stats as $stat) {
		SonarStatManager::populateDailyStat($stat['event']);
}

echo count($stats) . " stats have been updated with yesterday's values\n";

?>
コード例 #5
0
ファイル: index.php プロジェクト: rsweetland/Lean-Charts
	.smallbox { width: 1000px; margin: 5px; height: 500px;}
	.smallbox > h4 {font-size: 13px; line-height: 1em; font-weight: bold; padding: 0; margin: 0;}
	.smallbox > ul {font-size: 9px; line-height: 1.5em; list-style: none; padding: 0; margin: 0;}
	.smallbox > p {font-size: 9px; line-height: 1.5em; padding: 0; margin: 0;}
	.smallbox > .alert {font: arial 13px bold;  color: white; background-color: red; padding: 3px;}
	.graph_data { width: 110px; float: left; font-size: 10; margin-top: 100px; text-align: right;}
</style>
</head>
<body>
<h1>Dashboard</h1>
<p>The dashboard shows all of the events your a logging, plotted over time</p>
<p>Users can generate their own custom stats in the 'stats' folder. See this
    <a href="<?= BASE_URL?>public/custom-page.php">Example Page</a></p></p>
<?php 

$stats = SonarStatManager::getStatList();

foreach($stats as $stat):
	$graph = new SonarStat($stat['event']); 
    $hourlyValues = $graph->getStatValues('hourly', 12);
	$weight = $graph->getWeight();
?>

	<div class="smallbox">
        <div style="float: left">
	    <?= $graph->renderGraph('daily', 60, 'medium') ?>
	    </div>

        <div class="graph_data">
    	<p><strong>Past 12 hours: </strong><br />
        	<? foreach($hourlyValues as $date=>$value): ?>