Browse Source

Remove google chart calls from torrents stat page

spaghetti 8 years ago
parent
commit
18934dddc6
1 changed files with 55 additions and 60 deletions
  1. 55
    60
      sections/stats/torrents.php

+ 55
- 60
sections/stats/torrents.php View File

@@ -1,7 +1,7 @@
1 1
 <?
2
-if (!list($Labels, $InFlow, $OutFlow, $NetFlow, $Max) = $Cache->get_value('torrents_timeline')) {
2
+if (!list($Labels, $InFlow, $OutFlow, $Max) = $Cache->get_value('torrents_timeline')) {
3 3
   $DB->query("
4
-    SELECT DATE_FORMAT(Time,'%b \'%y') AS Month, COUNT(ID)
4
+    SELECT DATE_FORMAT(Time,\"%b %Y\") AS Month, COUNT(ID)
5 5
     FROM log
6 6
     WHERE Message LIKE 'Torrent % was uploaded by %'
7 7
     GROUP BY Month
@@ -9,84 +9,79 @@ if (!list($Labels, $InFlow, $OutFlow, $NetFlow, $Max) = $Cache->get_value('torre
9 9
     LIMIT 1, 12");
10 10
   $TimelineIn = array_reverse($DB->to_array());
11 11
   $DB->query("
12
-    SELECT DATE_FORMAT(Time,'%b \'%y') AS Month, COUNT(ID)
12
+    SELECT DATE_FORMAT(Time,\"%b %Y\") AS Month, COUNT(ID)
13 13
     FROM log
14 14
     WHERE Message LIKE 'Torrent % was deleted %'
15 15
     GROUP BY Month
16 16
     ORDER BY Time DESC
17 17
     LIMIT 1, 12");
18 18
   $TimelineOut = array_reverse($DB->to_array());
19
-  $DB->query("
20
-    SELECT DATE_FORMAT(Time,'%b \'%y') AS Month, COUNT(ID)
21
-    FROM torrents
22
-    GROUP BY Month
23
-    ORDER BY Time DESC
24
-    LIMIT 1, 12");
25
-  $TimelineNet = array_reverse($DB->to_array());
26 19
 
27 20
   foreach ($TimelineIn as $Month) {
28
-    list($Label, $Amount) = $Month;
29
-    if ($Amount > $Max) {
30
-      $Max = $Amount;
31
-    }
32
-  }
33
-  foreach ($TimelineOut as $Month) {
34
-    list($Label, $Amount) = $Month;
35
-    if ($Amount > $Max) {
36
-      $Max = $Amount;
37
-    }
38
-  }
39
-  foreach ($TimelineNet as $Month) {
40
-    list($Label, $Amount) = $Month;
41
-    if ($Amount > $Max) {
42
-      $Max = $Amount;
43
-    }
44
-  }
45
-  foreach ($TimelineIn as $Month) {
46
-    list($Label, $Amount) = $Month;
47
-    $Labels[] = $Label;
48
-    $InFlow[] = number_format(($Amount / $Max) * 100, 4);
21
+    list($Labels[], $InFlow[]) = $Month;
49 22
   }
50 23
   foreach ($TimelineOut as $Month) {
51
-    list($Label, $Amount) = $Month;
52
-    $OutFlow[] = number_format(($Amount / $Max) * 100, 4);
24
+    list(, $OutFlow[]) = $Month;
53 25
   }
54
-  foreach ($TimelineNet as $Month) {
55
-    list($Label, $Amount) = $Month;
56
-    $NetFlow[] = number_format(($Amount / $Max) * 100, 4);
57
-  }
58
-  $Cache->cache_value('torrents_timeline', array($Labels, $InFlow, $OutFlow, $NetFlow, $Max), mktime(0, 0, 0, date('n') + 1, 2)); //Tested: fine for dec -> jan
26
+  $Cache->cache_value('torrents_timeline', array($Labels, $InFlow, $OutFlow, $Max), mktime(0, 0, 0, date('n') + 1, 2)); //Tested: fine for dec -> jan
59 27
 }
60 28
 
61
-include_once(SERVER_ROOT.'/classes/charts.class.php');
62
-$DB->query("
63
-  SELECT tg.CategoryID, COUNT(t.ID) AS Torrents
64
-  FROM torrents AS t
65
-    JOIN torrents_group AS tg ON tg.ID = t.GroupID
66
-  GROUP BY tg.CategoryID
67
-  ORDER BY Torrents DESC");
68
-$Groups = $DB->to_array();
69
-$Pie = new PIE_CHART(750, 400, array('Other' => 1, 'Percentage' => 1));
70
-foreach ($Groups as $Group) {
71
-  list($CategoryID, $Torrents) = $Group;
72
-  $CategoryName = $Categories[$CategoryID - 1];
73
-  $Pie->add($CategoryName, $Torrents);
29
+if (!$CategoryDistribution = $Cache->get_value('category_distribution')) {
30
+  $DB->query("
31
+    SELECT tg.CategoryID, COUNT(t.ID) AS Torrents
32
+    FROM torrents AS t
33
+      JOIN torrents_group AS tg ON tg.ID = t.GroupID
34
+    GROUP BY tg.CategoryID
35
+    ORDER BY Torrents DESC");
36
+  $CategoryDistribution = $DB->to_array();
37
+  $Cache->cache_value('category_distribution', $CategoryDistribution, 3600 * 24 * 14);
38
+}
39
+foreach ($CategoryDistribution as $i => $Category) {
40
+  list($CategoryID, $Torrents) = $Category;
41
+  $CategoryDistribution[$i]['CategoryID'] = $Categories[$CategoryID - 1];
74 42
 }
75
-$Pie->transparent();
76
-$Pie->color('FF33CC');
77
-$Pie->generate();
78
-$Categories = $Pie->url();
79 43
 
80
-View::show_header('Detailed torrent statistics');
44
+View::show_header('Detailed torrent statistics', 'chart');
81 45
 ?>
82 46
 
47
+<h3 id="Upload_Flow"><a href="#Upload_Flow">Uploads by month</a></h3>
83 48
 <div class="box pad center">
84
-  <h1>Uploads by month</h1>
85
-  <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" />
49
+  <canvas class="chart" id="chart_torrents_timeline"></canvas>
50
+  <script>
51
+    new Chart($('#chart_torrents_timeline').raw().getContext('2d'), {
52
+      type: 'line',
53
+      data: {
54
+        labels: <? print '["'.implode('","',$Labels).'"]'; ?>,
55
+        datasets: [ {
56
+          label: "New Torrents",
57
+          backgroundColor: "rgba(0,0,255,0.2)",
58
+          borderColor: "rgba(0,0,255,0.8)",
59
+          data: <? print "[".implode(",",$InFlow)."]"; ?>
60
+        }, {
61
+          label: "Deleted Torrents",
62
+          backgroundColor: "rgba(255,0,0,0.2)",
63
+          borderColor: "rgba(255,0,0,0.8)",
64
+          data: <? print "[".implode(",",$OutFlow)."]"; ?>
65
+        }]
66
+      }
67
+    })
68
+  </script>
86 69
 </div>
70
+<h3 id="Torrent_Categories"><a href="#Torrent_Categories">Torrents by category</a></h3>
87 71
 <div class="box pad center">
88
-  <h1>Torrents by category</h1>
89
-  <img src="<?=$Categories?>" alt="" />
72
+  <canvas class="chart" id="chart_torrent_categories"></canvas>
73
+  <script>
74
+    new Chart($('#chart_torrent_categories').raw().getContext('2d'), {
75
+      type: 'pie',
76
+      data: {
77
+        labels: <? print '["'.implode('","', array_column($CategoryDistribution, 'CategoryID')).'"]'; ?>,
78
+        datasets: [ {
79
+          data: <? print "[".implode(",", array_column($CategoryDistribution, 'Torrents'))."]"; ?>,
80
+          backgroundColor: ['#8a00b8','#a944cb','#be71d8','#e8ccf1', '#f3e3f9', '#fbf6fd', '#ffffff']
81
+        }]
82
+      }
83
+    })
84
+  </script>
90 85
 </div>
91 86
 <?
92 87
 View::show_footer();

Loading…
Cancel
Save