FireFly Media Server › Firefly Media Server Forums › Firefly Media Server › Add-on Software › FireStats – Top 40 php script (now with added charts) › Reply To: FireStats – Top 40 php script (now with added charts)
26/11/2007 at 3:42 PM
#14693
sonichouse
Participant
@fizze wrote:
Nice chart 😉
Glad you liked it, the latest version has a dependency on libchart.php from http://naku.dohcrew.com/libchart/pages/introduction/
The code is
<?php
if(isset($_GET))
$mode = $_GET;
else
$mode = "Tracks";
try {
if($mode=="Tracks") {
$limit=40;
$Target = "Albums";
} else {
$limit=10;
$Target = "Tracks";
}
$query="
select Artist,Album,title as Track,play_count,track as No
from songs
where play_count >= 1
group by 4,1,2,3,5
order by 4 desc,1 asc,2 asc,5
limit $limit";
$album_query="
select Album,Artist,sum(play_count) as Played
from songs
where play_count > 0 and album''
group by 1,2
having sum(play_count) >= 1
order by 3 desc,1 asc,2 asc
limit $limit";
$dbh = new PDO('sqlite:/opt/var/mt-daapd/songs3.db');
$dbh->exec('SET CHARACTER SET UTF8');
print "nnn";
print "th{font-size: 7pt}td{font-size: 7pt; padding: 2 1em 0 1em;border-right: thin solid; border-bottom: thin dotted;}n";
print "Firefly - Top $limit $mode
n";
print "nShow $Target";print "
";
if($mode=="Tracks")
{
print "ntPlayed Artist Album Track Title Track # nn";
foreach ($dbh->query($query) as $row)
{
print "t";
print "$row[play_count] ";
print "$row[Artist] ";
print "$row[Album] ";
print "$row[Track] ";
print "$row[No] ";
print " n";
}
print "
n";
}
if($mode=="Albums")
{
include "./libchart-1.2/libchart/classes/libchart.php";
$chart = new PieChart(800,300);
$dataSet = new XYDataSet();
print "
";
print "
ntTracks Played Album Artist nn";
foreach ($dbh->query($album_query) as $row)
{
$n = "$row[Played]";
print "t";
print "$row[Played] ";
print "$row[Album] ";
print "$row[Artist] ";
print " n";
$dataSet->addPoint(new Point("$row[Album] - $row[Artist] ( $n )", $n));
}
print "
n";
/**
* Pie chart demonstration
*
*/
$chart->setDataSet($dataSet);
$chart->setTitle("Top $limit $mode");
$chart->render("$mode.png");
}
print "nn";
$dbh = null;
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "
";
die();
}
?>