CC-4661: Listener Statistics

-backend part working
This commit is contained in:
Martin Konecny 2012-11-02 17:50:43 -04:00
parent 8b70136dd6
commit 6438b54a5f
7 changed files with 238 additions and 1 deletions

View file

@ -17,4 +17,25 @@ SQL;
return $data;
}
}
public static function insertDataPoints($p_dataPoints) {
$timestamp_sql = "INSERT INTO cc_timestamp (timestamp) VALUES (:ts::TIMESTAMP) RETURNING id;";
$stats_sql = "INSERT INTO cc_listener_count (timestamp_id, listener_count)
VALUES (:timestamp_id, :listener_count)";
foreach ($p_dataPoints as $dp) {
$timestamp_id = Application_Common_Database::prepareAndExecute($timestamp_sql,
array('ts'=> $dp['timestamp']), "column");
Application_Common_Database::prepareAndExecute($stats_sql,
array('timestamp_id' => $timestamp_id,
'listener_count' => $dp["num_listeners"])
);
}
}
}

View file

@ -129,6 +129,35 @@ class Application_Model_StreamSetting
return $data;
}
/* Similar to getStreamData, but removes all sX prefixes to
* make data easier to iterate over */
public static function getStreamDataNormalized($p_streamId)
{
$con = Propel::getConnection();
$streamId = pg_escape_string($p_streamId);
$sql = "SELECT * "
."FROM cc_stream_setting "
."WHERE keyname LIKE '{$streamId}_%'";
$stmt = $con->prepare($sql);
if ($stmt->execute()) {
$rows = $stmt->fetchAll();
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$data = array();
foreach ($rows as $row) {
list($id, $key) = explode("_", $row["keyname"], 2);
$data[$key] = $row["value"];
}
return $data;
}
public static function getStreamSetting()
{
$con = Propel::getConnection();