git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Commit a9ef064b authored by Matt Pugh's avatar Matt Pugh

fixed top tracks

parent 1acb4c00
......@@ -26,9 +26,13 @@ require_once($install_path . '/data/Server.php');
require_once($install_path . '/data/Statistic.php');
/**
* Represents graph object, extended for specific implementations
*/
* Represents graph object, extended for specific implementations, currently
* acts as a data only object but intention is to delegate as much functionality
* with respect to the propagation of the graph objects themselves to this
* class. Many methods are, therefore, included with this view in mind.
*
* @see GraphTypes.php for implementations
**/
class Graph {
public $data, $data_buffer;
......@@ -46,46 +50,73 @@ class Graph {
$this->user = $user;
$this->resetData();
switch($type)
{
default:
$this->type = 0;
}
/* @todo: iterate through $type to determine renderer requirements */
switch($type){}
}
/**
* Resets internal data object.
**/
protected function resetData() {
$this->data = array(array(array()));
}
/**
* Returns the graph renderer as defined at object instantiation.
**/
public function getGraphRenderer() {
return $this->graph_types[$this->renderer];
}
/**
* Returns x-axis label.
**/
public function getXAxis() {
return $this->x_axis_label;
}
/**
* Returns y-axis label.
**/
public function getYAxis() {
return $this->y_axis_label;
}
/**
* Sets the axes labels of the current object.
* @param $x = x-axis label.
* @param $y = y-axis label.
**/
public function setAxisLabels($x = NULL, $y = NULL)
{
$this->x_axis_label = ($x === NULL) ? $this->x_axis_label : $x;
$this->y_axis_label = ($y === NULL) ? $this->y_axis_label : $y;
}
/**
* Returns the JS array built from the internal data respresentation, not
* used at present by used to hide the internal building method.
* @return String JS array.
* @see buildJsDataArray().
**/
public function getJsDataArray() {
$js_data = $this->buildJsDataArray();
return $this->buildJsDataArray();
}
/**
* Sets the internal data source to a new object.
* @param $data = new data object for the Graph
**/
public function setDataSource($data = NULL)
{
if (($data === NULL) && (! isEmpty($data))) return;
$this->data = $data;
}
/**
* Sets the maximum value of x-axis, both the maximum, rounded value of the
* x-axis ticks and also determining a round, suitable tick interval.
*/
protected function setMaxX($raw)
{
$this->max_x_axis = round($raw + 100, -2);
......@@ -93,8 +124,10 @@ class Graph {
}
/**
* Iterates through the multi-dimensional array to create a string of
* JS arrays on multiple datasets for the current plot.
* Iterates through the multi-dimensional array $data to create a string
* JS array representation of multiple series of data for the Graph object.
* @param $inverse Boolean TRUE if data is being represented horizontally.
* @return String JS multi-dimensional array.
**/
protected function buildJsDataArray($inverse = FALSE) {
......@@ -109,8 +142,8 @@ class Graph {
{
foreach ($set as $k => $node)
{
/* @TODO: Need to escape the $node if not numeric! */
$temp .= "[" . ((! is_numeric($node)) ? "'".(addslashes($node))."'" : $node);
/* Determine if the node is numeric, if not, escape. */
$temp .= "[".((! is_numeric($node)) ? "'".(addslashes($node))."'" : $node);
/* @TODO: check $node for len > 1, if so tokenise string */
if ($inverse) $temp .= "," . ++$i;
$temp .= "],";
......
......@@ -21,19 +21,36 @@
require_once($install_path . '/data/Graph.php');
/**
* Each subclass within this file extends the parent Graph object and
* correlate to individual graph data on the statistics pages.
*
* GraphTopArtists represents the Top Artists displayed on the user
* statistics page. */
class GraphTopArtists extends Graph {
public $artists, $artists_data;
public $number_of_tracks;
/**
* @param $user - the current user to build the information on.
* @param $num - the number of tracks to be included in the search,
* 20 by default.
**/
function __construct($user, $num = 20)
{
parent::__construct($user, "bar_horiz");
$this->number_of_tracks = $num;
$this->buildGraphData();
}
/**
* Parses the data internally into a format expected by the plotting
* JS libraries.
*
* Arrays are reversed to the expectation of order in the current (jqPlot)
* plotting utility.
**/
private function buildGraphData()
{
$tmp = Statistic::GeneratePlayStats('Scrobbles', 'artist',
......@@ -41,8 +58,7 @@ class GraphTopArtists extends Graph {
foreach ($tmp as $root => $node)
{
/* @TODO: check the URLs, make them work. */
$artists[] = '<a href="'.$node['artisturl'].'">'.$node['artist'].'</a>';
$artists[] = '<a href="'.$node['artisturl'].'">'.addslashes($node['artist']).'</a>';
$artists_data[] = $node['count'];
}
......@@ -55,11 +71,19 @@ class GraphTopArtists extends Graph {
}
}
/**
* Represents the Top Tracks data on the user statistic page.
**/
class GraphTopTracks extends Graph {
public $tracks, $tracks_data;
public $number_of_tracks;
/**
* @param $user - the current user to build the information on.
* @param $num - the number of tracks to be included in the search,
* 20 by default.
**/
function __construct($user, $num = 20)
{
parent::__construct($user, "bar_horiz");
......@@ -67,6 +91,13 @@ class GraphTopTracks extends Graph {
$this->buildGraphData();
}
/**
* Parses the data internally into a format expected by the plotting
* JS libraries.
*
* Arrays are reversed to the expectation of order in the current (jqPlot)
* plotting utility.
**/
private function buildGraphData()
{
$this->data_buffer = $this->user->getTopTracks($this->number_of_tracks);
......@@ -75,9 +106,10 @@ class GraphTopTracks extends Graph {
foreach($this->data_buffer as $key => $entry)
{
//$tracks[] = $entry['track'];
//$tracks[] = '<a href="'.$entry['artisturl'].'">'.$entry['artist'].'</a> - <a href="'.$entry['trackurl'].'">'.$entry['track'].'</a>';
$tmp_line = '<a href="'.$entry['artisturl'].'">'.$entry['artist'].'</a>';
$tmp_line .= ' - <a href="'.$entry['trackurl'].'">'.addslashes($entry['track']).'</a>';
$listings[] = $entry['freq'];
$tracks[] = $tmp_line;
}
$this->setMaxX($listings[0]);
......@@ -89,11 +121,19 @@ class GraphTopTracks extends Graph {
}
}
/**
* Represents the Plays By Days line graph data on the user statistic page.
**/
class GraphPlaysByDays extends Graph {
public $plays_by_days;
public $number_of_days;
/**
* @param $user - the current user to build the information on.
* @param $num - the number of tracks to be included in the search,
* 20 by default.
**/
function __construct($user, $num = 20)
{
parent::__construct($user, "line");
......@@ -101,6 +141,15 @@ class GraphPlaysByDays extends Graph {
$this->buildGraphData();
}
/**
* Parses the data internally into a format expected by the plotting
* JS libraries.
*
* Currently does not delegate the construction of the JS array to parent
* object, however it should do this. Tokenisation required in parent.
*
* @todo: tokenise build JS array functions and refactor accordingly.
**/
private function buildGraphData()
{
$this->data_buffer = Statistic::generatePlayByDays('Scrobbles',
......@@ -108,7 +157,6 @@ class GraphPlaysByDays extends Graph {
$date_line = "[";
/* @TODO: Streamline this by simply removing size from SQL... */
foreach ($this->data_buffer as $key => $entry)
{
$date_line .= "['" . $entry['date'] . "', " . $entry['count'] . "],";
......@@ -119,6 +167,5 @@ class GraphPlaysByDays extends Graph {
}
}
class GraphTrackPerformance extends Graph {
}
\ No newline at end of file
class GraphTrackPerformance extends Graph {}
\ No newline at end of file
......@@ -99,10 +99,6 @@ class Statistic {
if( $i['count'] > $max ) $max = $i['count'];
}
foreach($res as &$i){
$i['size'] = round($i['count'] / $max * $maxwidth);
}
return $res;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment