Modifica tabella e codice per stats
This commit is contained in:
parent
9f7a337a3b
commit
b48253094f
3 changed files with 72 additions and 20 deletions
|
@ -147,7 +147,7 @@ if ($opts['updstats']) {
|
|||
'ffffffffffffffffffffffffffffffff'
|
||||
);
|
||||
$langs=array('ca','en','es','fr','it');
|
||||
$urls=array('home','instances','about','stats','contribute','404');
|
||||
$urls=array('home','instances','about','statistics','contribute','404');
|
||||
for ($i=0; $i<1460; $i++) mysqli_query($link,'INSERT INTO ZHits (UID,URL,Lang,TS) VALUES ("'.$uids[rand(0,count($uids)-1)].'","'.$urls[rand(0,count($urls)-1)].'","'.$langs[rand(0,count($langs)-1)].'",'.rand($now-365*24*60*60,$tdstart).')');
|
||||
}
|
||||
$res=mysqli_query($link,'SELECT * FROM ZHits WHERE TS < '.$tdstart.' ORDER BY TS ASC') or mexit(__LINE__.': '.mysqli_error($link).N,2);
|
||||
|
@ -165,23 +165,32 @@ if ($opts['updstats']) {
|
|||
//echo('-------- '.gmdate('d M Y H:i:s',$dstart).' ---------'.N);
|
||||
$inserts++;
|
||||
// questo qui sotto dev'essere sincronizzato con le lingue supportate e le url che serviamo (vedi index.php)
|
||||
$hits=array('tot'=>0, 'ca'=>0, 'en'=>0, 'es'=>0, 'fr'=>0, 'it'=>0, 'home'=>0, 'instances'=>0, 'about'=>0, 'stats'=>0, 'contribute'=>0, '404'=>0);
|
||||
$hits=0;
|
||||
$hitslang=array('ca'=>0, 'en'=>0, 'es'=>0, 'fr'=>0, 'it'=>0);
|
||||
$hitspage=array('home'=>0, 'instances'=>0, 'about'=>0, 'statistics'=>0, 'contribute'=>0, '404'=>0);
|
||||
$visits=0;
|
||||
$buf=array();
|
||||
$res=mysqli_query($link,'SELECT * FROM ZHits WHERE TS >= '.$dstart.' AND TS < '.($dstart+$day).' ORDER BY TS ASC') or mexit(__LINE__.': '.mysqli_error($link).N,2);
|
||||
while ($row=mysqli_fetch_assoc($res)) {
|
||||
//echo($row['UID'].' '.$row['URL'].' '.$row['Lang'].' '.$row['TS'].N);
|
||||
$hits['tot']++;
|
||||
$hits[$row['Lang']]++;
|
||||
$hits[$row['URL']]++;
|
||||
$hits++;
|
||||
$hitslang[$row['Lang']]++;
|
||||
$hitspage[$row['URL']]++;
|
||||
if (!in_array($row['UID'],$buf)) {
|
||||
$buf[]=$row['UID'];
|
||||
$visits++;
|
||||
}
|
||||
}
|
||||
//echo('>>> hits: '.$hits['tot'].', visits: '.$visits.' <<<'.N);
|
||||
$hits=implode(', ',$hits);
|
||||
mysqli_query($link,'INSERT INTO ZStats (TS, Hits, HitsCa, HitsEn, HitsEs, HitsFr, HitsIt, HitsHome, HitsInst, HitsAbout, HitsStats, HitsContrib, Hits404, Visits) VALUES ('.$dstart.', '.$hits.', '.$visits.')') or mexit(__LINE__.': '.mysqli_error($link).N,2);
|
||||
$buf='';
|
||||
foreach ($hitslang as $key=>$val) $buf.=$key.':'.$val.';';
|
||||
$hitslang=substr($buf,0,-1);
|
||||
$buf='';
|
||||
foreach ($hitspage as $key=>$val) $buf.=$key.':'.$val.';';
|
||||
$hitspage=substr($buf,0,-1);
|
||||
//echo('>>> hits: '.$hits.', hitslang: '.$hitslang.', hitspage: '.$hitspage.', visits: '.$visits.' <<<'.N);
|
||||
$query='INSERT INTO ZStats (TS, Hits, HitsLang, HitsPage, Visits) VALUES ('.$dstart.', '.$hits.', "'.$hitslang.'", "'.$hitspage.'", '.$visits.')';
|
||||
//echo($query.N);
|
||||
mysqli_query($link,$query) or mexit(__LINE__.': '.mysqli_error($link).N,2);
|
||||
$dstart+=$day;
|
||||
}
|
||||
mysqli_query($link,'DELETE FROM ZHits WHERE TS < '.$tdstart) or mexit(__LINE__.': '.mysqli_error($link).N,2);
|
||||
|
|
|
@ -16,8 +16,24 @@ $link=mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_adm
|
|||
or mexit('Impossibile connettersi al database: '.mysqli_connect_error().' ['.mysqli_connect_errno().']'.N,1);
|
||||
mysqli_set_charset($link,'utf8mb4');
|
||||
|
||||
/*mysqli_query($link,"ALTER TABLE `ZStats` CHANGE `HitsTrans` `HitsContrib` INT(10) UNSIGNED NOT NULL;")
|
||||
or mexit(mysqli_error($link).N,2);*/
|
||||
mysqli_query($link,"ALTER TABLE `ZStats` ADD `HitsLang` VARCHAR(5000) NOT NULL AFTER `Hits`;")
|
||||
or mexit(mysqli_error($link).N,2);
|
||||
mysqli_query($link,"ALTER TABLE `ZStats` ADD `HitsPage` VARCHAR(5000) NOT NULL AFTER `HitsLang`;")
|
||||
or mexit(mysqli_error($link).N,2);
|
||||
|
||||
$res=mysqli_query($link,"SELECT * FROM `ZStats`")
|
||||
or mexit(mysqli_error($link).N,2);
|
||||
|
||||
$hlang;
|
||||
$hpage;
|
||||
while ($row=mysqli_fetch_assoc($res)) {
|
||||
$hlang='ca:'.$row['HitsCa'].';en:'.$row['HitsEn'].';es:'.$row['HitsEs'].';fr:'.$row['HitsFr'].';it:'.$row['HitsIt'];
|
||||
$hpage='home:'.$row['HitsHome'].';inst:'.$row['HitsInst'].';about:'.$row['HitsAbout'].';stats:'.$row['HitsStats'].';contrib:'.$row['HitsContrib'].';404:'.$row['Hits404'];
|
||||
mysqli_query($link,"UPDATE `ZStats` SET HitsLang='".$hlang."', HitsPage='".$hpage."' WHERE TS=".$row['TS']);
|
||||
}
|
||||
|
||||
mysqli_query($link,"ALTER TABLE `ZStats` DROP `HitsCa`, DROP `HitsEn`, DROP `HitsEs`, DROP `HitsFr`, DROP `HitsIt`, DROP `HitsHome`, DROP `HitsInst`, DROP `HitsAbout`, DROP `HitsStats`, DROP `HitsContrib`, DROP `Hits404`;")
|
||||
or mexit(mysqli_error($link).N,2);
|
||||
|
||||
mysqli_close($link);
|
||||
|
||||
|
|
|
@ -30,20 +30,47 @@ $now=time();
|
|||
$tdstart=gmmktime(0,0,0,gmdate('n',$now),gmdate('j',$now),gmdate('Y',$now));
|
||||
$limit=$tdstart-(30*24*60*60);
|
||||
$res=mysqli_query($link,'SELECT * FROM ZStats WHERE TS >= '.$limit.' ORDER BY TS DESC') or muorimeglio(__LINE__.': '.mysqli_error($link),true);
|
||||
$hlmap=array(
|
||||
'ca'=>_('Catalan'),
|
||||
'en'=>_('English'),
|
||||
'es'=>_('Spanish'),
|
||||
'fr'=>_('French'),
|
||||
'it'=>_('Italian')
|
||||
);
|
||||
$hpmap=array(
|
||||
'home'=>_('Guide'),
|
||||
'instances'=>_('Instances'),
|
||||
'about'=>_('About'),
|
||||
'statistics'=>_('Statistics'),
|
||||
'contribute'=>_('Contribute'),
|
||||
'404'=>'404'
|
||||
);
|
||||
while ($row=mysqli_fetch_assoc($res)) {
|
||||
$buf=array(_('Catalan')=>$row['HitsCa'], _('English')=>$row['HitsEn'], _('Spanish')=>$row['HitsEs'], _('French')=>$row['HitsFr'], _('Italian')=>$row['HitsIt']);
|
||||
$hl=explode(';',$row['HitsLang']);
|
||||
$buf=array();
|
||||
foreach($hl as $key=>$val) {
|
||||
$val=explode(':',$val);
|
||||
$buf[$hlmap[$val[0]]]=$val[1];
|
||||
}
|
||||
arsort($buf);
|
||||
$langs='';
|
||||
foreach ($buf as $key=>$val) $langs.=$key.': '.$val.', ';
|
||||
$langs=_('Hits per language').': '.substr($langs,0,-2);
|
||||
$buf=array(_('Guide')=>$row['HitsHome'], _('Instances')=>$row['HitsInst'], _('About')=>$row['HitsAbout'], _('Stats')=>$row['HitsStats'], _('Contribute')=>$row['HitsContrib'], '404'=>$row['Hits404']);
|
||||
$hl='';
|
||||
foreach($buf as $key=>$val) $hl.=$key.': '.$val.'; ';
|
||||
$hl=_('Hits per language').': '.substr($hl,0,-2);
|
||||
|
||||
$hp=explode(';',$row['HitsPage']);
|
||||
$buf=array();
|
||||
foreach($hp as $key=>$val) {
|
||||
$val=explode(':',$val);
|
||||
$buf[$hpmap[$val[0]]]=$val[1];
|
||||
}
|
||||
arsort($buf);
|
||||
$pages='';
|
||||
foreach ($buf as $key=>$val) $pages.=$key.': '.$val.', ';
|
||||
$pages=_('Hits per page').': '.substr($pages,0,-2);
|
||||
$hp='';
|
||||
foreach($buf as $key=>$val) $hp.=$key.': '.$val.'; ';
|
||||
$hp=_('Hits per page').': '.substr($hp,0,-2);
|
||||
|
||||
echo('<div class="info">'.gmdate('d/m/Y',$row['TS']).': '.$row['Visits'].' <span class="visitslab">'.sp($row['Visits'],_('visit'),_('visits')).'</span>, '.$row['Hits'].' <span class="hitslab">'.sp($row['Hits'],_('hit'),_('hits')).'</span></div>'.N);
|
||||
echo('<div class="info">'.$langs.'</div>'.N);
|
||||
echo('<div class="info">'.$pages.'</div>'.N);
|
||||
echo('<div class="info">'.$hl.'</div>'.N);
|
||||
echo('<div class="info">'.$hp.'</div>'.N);
|
||||
echo('<div class="visits" style="width:'.(100/$maxvisits*$row['Visits']).'%"></div>'.N);
|
||||
echo('<div class="hits" style="width:'.(100/$maxhits*$row['Hits']).'%"></div>'.N);
|
||||
echo('<div class="sep"></div>'.N);
|
||||
|
|
Loading…
Reference in a new issue