Gazelle/sections/stats/torrents.php

93 lines
2.8 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
2013-05-27 08:00:58 +00:00
if (!list($Labels, $InFlow, $OutFlow, $NetFlow, $Max) = $Cache->get_value('torrents_timeline')) {
$DB->query("
SELECT DATE_FORMAT(Time,'%b \'%y') AS Month, COUNT(ID)
FROM log
WHERE Message LIKE 'Torrent % was uploaded by %'
GROUP BY Month
ORDER BY Time DESC
LIMIT 1, 12");
2011-03-28 14:21:28 +00:00
$TimelineIn = array_reverse($DB->to_array());
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT DATE_FORMAT(Time,'%b \'%y') AS Month, COUNT(ID)
FROM log
WHERE Message LIKE 'Torrent % was deleted %'
GROUP BY Month
ORDER BY Time DESC
LIMIT 1, 12");
2011-03-28 14:21:28 +00:00
$TimelineOut = array_reverse($DB->to_array());
2013-05-27 08:00:58 +00:00
$DB->query("
SELECT DATE_FORMAT(Time,'%b \'%y') AS Month, COUNT(ID)
FROM torrents
GROUP BY Month
ORDER BY Time DESC
LIMIT 1, 12");
2011-03-28 14:21:28 +00:00
$TimelineNet = array_reverse($DB->to_array());
2013-04-30 18:18:07 +00:00
foreach ($TimelineIn as $Month) {
2013-07-02 08:01:37 +00:00
list($Label, $Amount) = $Month;
2011-03-28 14:21:28 +00:00
if ($Amount > $Max) {
$Max = $Amount;
}
}
2013-04-30 18:18:07 +00:00
foreach ($TimelineOut as $Month) {
2013-07-02 08:01:37 +00:00
list($Label, $Amount) = $Month;
2011-03-28 14:21:28 +00:00
if ($Amount > $Max) {
$Max = $Amount;
}
}
2013-04-30 18:18:07 +00:00
foreach ($TimelineNet as $Month) {
2013-07-02 08:01:37 +00:00
list($Label, $Amount) = $Month;
2011-03-28 14:21:28 +00:00
if ($Amount > $Max) {
$Max = $Amount;
}
}
2013-04-30 18:18:07 +00:00
foreach ($TimelineIn as $Month) {
2013-07-02 08:01:37 +00:00
list($Label, $Amount) = $Month;
2011-03-28 14:21:28 +00:00
$Labels[] = $Label;
2013-04-30 18:18:07 +00:00
$InFlow[] = number_format(($Amount / $Max) * 100, 4);
2011-03-28 14:21:28 +00:00
}
2013-04-30 18:18:07 +00:00
foreach ($TimelineOut as $Month) {
2013-07-02 08:01:37 +00:00
list($Label, $Amount) = $Month;
2013-04-30 18:18:07 +00:00
$OutFlow[] = number_format(($Amount / $Max) * 100, 4);
2011-03-28 14:21:28 +00:00
}
2013-04-30 18:18:07 +00:00
foreach ($TimelineNet as $Month) {
2013-07-02 08:01:37 +00:00
list($Label, $Amount) = $Month;
2013-04-30 18:18:07 +00:00
$NetFlow[] = number_format(($Amount / $Max) * 100, 4);
2011-03-28 14:21:28 +00:00
}
2013-05-27 08:00:58 +00:00
$Cache->cache_value('torrents_timeline', array($Labels, $InFlow, $OutFlow, $NetFlow, $Max), mktime(0, 0, 0, date('n') + 1, 2)); //Tested: fine for dec -> jan
2011-03-28 14:21:28 +00:00
}
2013-05-27 08:00:58 +00:00
include_once(SERVER_ROOT.'/classes/charts.class.php');
$DB->query("
SELECT tg.CategoryID, COUNT(t.ID) AS Torrents
FROM torrents AS t
2013-07-02 08:01:37 +00:00
JOIN torrents_group AS tg ON tg.ID = t.GroupID
2013-05-27 08:00:58 +00:00
GROUP BY tg.CategoryID
ORDER BY Torrents DESC");
2011-03-28 14:21:28 +00:00
$Groups = $DB->to_array();
2013-07-02 08:01:37 +00:00
$Pie = new PIE_CHART(750, 400, array('Other' => 1, 'Percentage' => 1));
2013-04-30 18:18:07 +00:00
foreach ($Groups as $Group) {
2011-03-28 14:21:28 +00:00
list($CategoryID, $Torrents) = $Group;
$CategoryName = $Categories[$CategoryID - 1];
2013-05-27 08:00:58 +00:00
$Pie->add($CategoryName, $Torrents);
2011-03-28 14:21:28 +00:00
}
$Pie->transparent();
$Pie->color('FF33CC');
$Pie->generate();
$Categories = $Pie->url();
2012-10-11 08:00:15 +00:00
View::show_header();
2011-03-28 14:21:28 +00:00
?>
<div class="box pad center">
<h1>Uploads by month</h1>
2013-07-02 08:01:37 +00:00
<img src="https://chart.googleapis.com/chart?cht=lc&amp;chs=880x160&amp;chco=000D99,99000D,00990D&amp;chg=0,-1,1,1&amp;chxt=y,x&amp;chxs=0,h&amp;chxl=1:|<?=implode('|', $Labels)?>&amp;chxr=0,0,<?=$Max?>&amp;chd=t:<?=implode(',', $InFlow)?>|<?=implode(',', $OutFlow)?>|<?=implode(',', $NetFlow)?>&amp;chls=2,4,0&amp;chdl=Uploads|Deletions|Remaining&amp;chf=bg,s,FFFFFF00" alt="User Flow Chart" />
2011-03-28 14:21:28 +00:00
</div>
<div class="box pad center">
<h1>Torrents by category</h1>
2012-08-29 08:00:17 +00:00
<img src="<?=$Categories?>" alt="" />
2011-03-28 14:21:28 +00:00
</div>
<?
2012-10-11 08:00:15 +00:00
View::show_footer();