forked from andig/videodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.php
170 lines (141 loc) · 5.2 KB
/
stats.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* Statistics
*
* Shows general statistics about the database
*
* @package videoDB
* @author Andreas Gohr <a.gohr@web.de>
* @version $Id: stats.php,v 2.25 2009/04/04 16:22:56 andig2 Exp $
*/
require_once './core/functions.php';
/*
* Helper function for comparing an associative array by it's 'count' values
*/
function compare_count($a, $b)
{
return strnatcasecmp($b['count'], $a['count']);
}
/*
* De-uniquify multi-language statistics
*
* Makes sure videos with mulitple languages are count once for each language
* contained instead of once for a unique combination
*
* @param array $langs array of all languages from
*/
function collapse_multiple_languages($langs)
{
$templangs = array();
foreach($langs as $key => $val)
{
$lang_ary = preg_split('/,\s*/', $val['language']);
foreach($lang_ary as $numid => $lang)
{
// take care of english vs. English
$lang = ucwords($lang);
$templangs[$lang]['language'] = $lang;
$templangs[$lang]['count'] += $val['count'];
}
}
usort($templangs, 'compare_count');
return $templangs;
}
/**
* input
*/
$owner = req_string('owner');
$WHERES = null; // init
if ($config['multiuser'])
{
// get owner from session- or use current user
session_default_owner();
// build html select box
$all = strtoupper($lang['radio_all']);
$smarty->assign('owners', out_owners(array($lang['filter_any'] => $lang['filter_any']), PERM_READ));
$smarty->assign('owner', $owner);
// further limit to single owner
if ($owner == $lang['filter_any'])
$WHERES .= " AND owner_id IN (".get_owner_ids(PERM_READ).")";
else
$WHERES .= " AND owner_id = '".get_userid($owner)."'";
}
// Don't count movies which are on the wishlist
$WHERES .= ' AND mediatype != '.MEDIA_WISHLIST;
$result = runSQL('SELECT COUNT(*) AS count FROM '.TBL_DATA.' WHERE 1=1'.$WHERES);
$stats['count_all'] = $result[0]['count'];
$result = runSQL('SELECT COUNT(*) AS count FROM '.TBL_DATA.' WHERE istv = 1'.$WHERES);
$stats['count_tv'] = $result[0]['count'];
$result = runSQL('SELECT DISTINCT diskid FROM '.TBL_DATA.' WHERE 1=1'.$WHERES);
$stats['count_disk'] = count($result);
$result = runSQL('SELECT AVG(filesize) AS afs FROM '.TBL_DATA.' WHERE filesize > 0'.$WHERES);
$stats['avg_size'] = round(($result[0]['afs'])/(1024*1024), 2);
$result = runSQL('SELECT SUM(filesize) AS sfs,
AVG(runtime) AS art,
SUM(runtime) AS srt
FROM '.TBL_DATA.' WHERE 1=1'.$WHERES);
$stats['sum_size'] = round(($result[0]['sfs'])/(1024*1024*1024), 2);
$stats['avg_time'] = round($result[0]['art'], 2);
$stats['sum_time'] = round(($result[0]['srt'])/60, 2);
$result = runSQL('SELECT SUM(runtime) AS srt FROM '.TBL_DATA.'
LEFT JOIN '.TBL_USERSEEN.' ON '.TBL_DATA.'.id = '.TBL_USERSEEN.'.video_id AND '.TBL_USERSEEN.'.user_id = '.get_current_user_id().'
WHERE !ISNULL('.TBL_USERSEEN.'.video_id)'.$WHERES);
$stats['seen_time'] = round($result[0]['srt']/60, 2);
$result = runSQL('SELECT A.name, COUNT(*) AS count, A.id
FROM '.TBL_GENRES.' A, '.TBL_VIDEOGENRE.' B, '.TBL_DATA.' C
WHERE B.genre_id = A.id
AND B.video_id = C.id'.$WHERES.'
GROUP BY A.name, A.id
ORDER BY count DESC');
$stats['count_genre'] = $result;
$result = runSQL('SELECT A.name, COUNT(*) AS count, A.id
FROM '.TBL_MEDIATYPES.' A, '.TBL_DATA.' B
WHERE B.mediatype = A.id'.$WHERES.'
GROUP BY A.name, A.id
ORDER BY count DESC');
$stats['count_media'] = $result;
$result = runSQL('SELECT language, COUNT(*) AS count
FROM '.TBL_DATA.' WHERE 1=1'.$WHERES.'
GROUP BY language
ORDER BY count DESC');
$stats['count_lang'] = collapse_multiple_languages($result);
$result = runSQL('SELECT video_codec, COUNT(*) AS count
FROM '.TBL_DATA.' WHERE 1=1'.$WHERES.'
GROUP BY video_codec
ORDER BY count DESC');
$stats['count_vcodec'] = $result;
$result = runSQL('SELECT audio_codec, COUNT(*) AS count
FROM '.TBL_DATA.' WHERE 1=1'.$WHERES.'
GROUP BY audio_codec
ORDER BY count DESC');
$stats['count_acodec'] = $result;
// year statistics
$result = runSQL('SELECT year, COUNT(*) AS count
FROM '.TBL_DATA.'
WHERE year > 0'.$WHERES.'
GROUP BY year
ORDER BY year');
$minyear = $result[0]['year'];
$maxyear = $result[count($result)-1]['year'];
for ($i = $minyear; $i <= $maxyear; $i++)
{
$years[$i] = 0;
}
$maxcount = 0;
if (is_array($result))
{
foreach ($result AS $year)
{
$years[$year['year']] = $year['count'];
if ($year['count'] > $maxcount) $maxcount = $year['count'];
}
}
$stats['count_year'] = $years;
$stats['first_year'] = $minyear;
$stats['last_year'] = $maxyear;
$stats['max_count'] = $maxcount;
// prepare templates
tpl_page();
$smarty->assign('stats', $stats);
// display templates
tpl_display('stats.tpl');