CC-4661: Listener Statistics
-backend part working
This commit is contained in:
parent
8b70136dd6
commit
6438b54a5f
7 changed files with 238 additions and 1 deletions
|
@ -40,6 +40,8 @@ class ApiController extends Zend_Controller_Action
|
|||
->addActionContext('get-files-without-replay-gain' , 'json')
|
||||
->addActionContext('reload-metadata-group' , 'json')
|
||||
->addActionContext('notify-webstream-data' , 'json')
|
||||
->addActionContext('get-stream-parameters' , 'json')
|
||||
->addActionContext('push-stream-stats' , 'json')
|
||||
->initContext();
|
||||
}
|
||||
|
||||
|
@ -957,4 +959,22 @@ class ApiController extends Zend_Controller_Action
|
|||
$this->view->media_id = $media_id;
|
||||
}
|
||||
|
||||
public function getStreamParametersAction() {
|
||||
$streams = array("s1", "s2", "s3");
|
||||
$stream_params = array();
|
||||
foreach ($streams as $s) {
|
||||
$stream_params[$s] =
|
||||
Application_Model_StreamSetting::getStreamDataNormalized($s);
|
||||
}
|
||||
$this->view->stream_params = $stream_params;
|
||||
}
|
||||
|
||||
public function pushStreamStatsAction() {
|
||||
$request = $this->getRequest();
|
||||
$data = json_decode($request->getParam("data"), true);
|
||||
|
||||
Application_Model_ListenerStat::insertDataPoints($data);
|
||||
$this->view->data = $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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"])
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue