-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.php
109 lines (103 loc) · 2.78 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
<?php
require_once('config.inc.php');
ob_start();
$dirnames=array(
'*',
'__others/*',
);
$dirnames_excludes=array(
array('__others','__old'),
NULL,
);
$filenames=array(
''=>'*.htm',
'gz'=>'*.htm.gz',
);
function readable($value) {
static $units=array('','k','m','g','t','p','e','z','y');
if($value==0) return '0';
$s=floor(log($value)/log(1024));
$text=number_format( ($value/pow(1024,$s)), 2).$units[$s];
return $text;
}
echo '<pre>';
$counts=array();
$stats=array();
$sizes=array();
$globals=array(
'count'=>0,'chapters'=>0,'size'=>0,'avg'=>0,
);
$avgs=array();
foreach($dirnames as $k1 => $dirpattern)
{ // 2
$dirs=glob($dirpattern);
$dirs=array_filter($dirs, 'is_dir');
if(array_key_exists($k1, $dirnames_excludes) && is_array($dirnames_excludes[$k1])) {
$dirs=array_diff($dirs, $dirnames_excludes[$k1]);
}
echo 'dirs'.$k1.'=';var_dump(count($dirs));
foreach($filenames as $k2=>$filepattern)
{ // 2
$key=$k1.$k2;
$stats[$key]=array();
$sizes[$key]=array();
$global=array(
'count'=>0,'chapters'=>0,'size'=>0,'avg'=>0,
);
foreach($dirs as $a => $dir)
{ //loop dirs
$files=glob($dir.'/'.$filepattern);
$sizesf=array_map('filesize', $files);
$counts[$key][$dir]=count($files);
$sizes[$key][$dir]=array_sum($sizesf);
$s=0;
$nb=0;
$avg=0;
foreach($files as $b => $file) {
//loop files
$s+=$sizesf[$b];
$ch=explode('/',$file);
$ch=array_pop($ch);
$ch=explode('.',$ch);
$ch=$ch[0];
$ch=explode('-',$ch);
$ch=array_map('trim',$ch);
if(count($ch)==1) ++$nb;
else {
$nb_=($ch[1]-$ch[0]+1);
if($nb_<=0) var_dump($file,$ch,$nb_);
$nb+=$nb_;
}
}//files
if($s==0 || $nb==0) $avg=0;
else $avg=($s/$nb);
$stat=array(
'count'=>$counts[$key][$dir],'chapters'=>$nb,'size'=>$s, 'avg'=>$avg,
);
$stats[$key][$dir]=$stat;
foreach($global as $k=>$v) $global[$k]+=$stat[$k];
if($k2=='') {
foreach($global as $k=>$v) $globals[$k]+=$stat[$k];
$avgs[$dir]=$stat['avg'];
}
}//dirs
if(array_sum($counts[$key])==0) continue;
echo 'pastes'.$key.'=';var_dump(array_sum($counts[$key]));
echo 'sizes'.$key.'=';var_dump(readable(array_sum($sizes[$key])));
if($global['chapters']!=0) $global['avg']=$global['size']/$global['chapters'];
else $global['avg']=0;
echo 'stats'.$key.'=';var_dump($global);
}//2
}//2
if($globals['chapters']>0)
{
if($globals['chapters']!=0) $globals['avg']=$globals['size']/$globals['chapters'];
else $globals['avg']=0;
echo 'globalstats=';var_dump($globals);
echo 'avgs=';var_dump(array('min'=>min($avgs),'max'=>max($avgs)));
}
echo '</pre>';
$data=ob_get_flush();
if(SAVESTAT) file_put_contents('stats.htm',$data);
echo '<br/>'.date('Y-m-d H:i:s');
?>