Merge branch 'cc-4661-listener-statistics' of dev.sourcefabric.org:airtime into cc-4661-listener-statistics
This commit is contained in:
commit
a93b588a09
8 changed files with 253 additions and 14 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,4 +35,27 @@ SQL;
|
|||
}
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
|
||||
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, mount_name)
|
||||
VALUES (:timestamp_id, :listener_count, :mount_name)";
|
||||
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"],
|
||||
'mount_name' => $dp["mount_name"],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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