From: vincent@cubedesigners.com Date: Tue, 7 Nov 2017 15:25:56 +0000 (+0000) Subject: try #1761 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=7b42bce95796fcca6823ba348fbc0ef805143488;p=cubeextranet.git try #1761 @0.5 --- diff --git a/inc/ws/Controlleur/class.ws.stats.php b/inc/ws/Controlleur/class.ws.stats.php index a6bb06cb7..282579f66 100644 --- a/inc/ws/Controlleur/class.ws.stats.php +++ b/inc/ws/Controlleur/class.ws.stats.php @@ -13,12 +13,12 @@ class wsStats { $xname = self::_getXLSFile($bid, $annee, $mois); $fname = 'stats_' . $bid; if (!is_null($annee)) { - $fname.='_' . $annee; + $fname .= '_' . $annee; if (!is_null($mois)) { - $fname.='_' . $mois; + $fname .= '_' . $mois; } } - $fname.='.xlsx'; + $fname .= '.xlsx'; files::$mimeType['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; @@ -26,17 +26,18 @@ class wsStats { } protected static function _getXLSFile($bid, $annee = null, $mois = null) { + self::forceComputation($bid); $e = explode('_', $bid); $bid = $e[0]; $xname = '/home/stats/www/xls/' . $bid; if (!is_null($annee)) { - $xname.='/' . $annee; + $xname .= '/' . $annee; if (!is_null($mois)) { - $xname.='/' . $mois; + $xname .= '/' . $mois; } } - $xname.='.xlsx'; + $xname .= '.xlsx'; $dir = dirname($xname); if (!file_exists($dir)) { @@ -49,6 +50,8 @@ class wsStats { public static function display($bid, $annee = null, $mois = null) { global $core; + self::forceComputation($bid); + cubePHP::set_memory('512M'); self::$xls = new PHPExcel(); @@ -75,22 +78,22 @@ class wsStats { $listeMois = null; foreach ($years as $y) { $selectedYear = __('Toutes'); - if (!is_null($annee) && $annee == (string) $y['year']) { + if (!is_null($annee) && $annee == (string)$y['year']) { $months = $y->month; - $moiss = array('' . __('Tous') . '' => SITE_PATH . 'stats/' . $bid . '/' . (string) $y['year']); + $moiss = array('' . __('Tous') . '' => SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year']); $selectedMonth = __('Tous'); foreach ($months as $m) { - if ((string) $m['month'] == $mois) { - $selectedMonth = cubeDate::getMonth((string) $m['month']); + if ((string)$m['month'] == $mois) { + $selectedMonth = cubeDate::getMonth((string)$m['month']); } - $moiss[cubeDate::getMonth((string) $m['month'])] = SITE_PATH . 'stats/' . $bid . '/' . (string) $y['year'] . '/' . (string) $m['month']; + $moiss[cubeDate::getMonth((string)$m['month'])] = SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year'] . '/' . (string)$m['month']; } $listeMois = new commonShortcuts(__('Mois'), $moiss, $selectedMonth); } - if ((string) $y['year'] == $annee) { + if ((string)$y['year'] == $annee) { $selectedYear = $annee; } - $annees[(string) $y['year']] = SITE_PATH . 'stats/' . $bid . '/' . (string) $y['year']; + $annees[(string)$y['year']] = SITE_PATH . 'stats/' . $bid . '/' . (string)$y['year']; } $listeAnnees = new commonShortcuts(__('Année'), $annees, $selectedYear); $listeShortcuts[] = $listeAnnees; @@ -116,7 +119,7 @@ class wsStats { $writer->setPHPExcel(self::$xls); $writer->save(self::_getXLSFile($bid, $annee, $mois)); } catch (Exception $e) { - + } return $res; @@ -124,13 +127,14 @@ class wsStats { public static function getExtra($extra) { $xml = simplexml_load_string('' . $extra . ''); - if ((string) $xml->extraName != '') { - return (string) $xml->extraName; + if ((string)$xml->extraName != '') { + return (string)$xml->extraName; } return null; } public static function load_stats($bid, $annee = null, $mois = null) { + $e = explode('_', $bid, 2); $bid = $e[0]; @@ -149,7 +153,7 @@ class wsStats { $xml .= '.xml'; if ($x = @simplexml_load_file($xml)) { if (!is_null($mois)) { - + } $x = call_user_func(array('wsStats', $sort), $x); self::correctValues($x, $annee, $mois); @@ -167,7 +171,7 @@ class wsStats { foreach ($days as $day) { break; } - $visitors = (string) $day['places'] * 1.2; + $visitors = (string)$day['places'] * 1.2; $visits = $visitors * 1.1; cubeXML::removeAttribute($day, 'visitors'); cubeXML::removeAttribute($day, 'visits'); @@ -177,7 +181,7 @@ class wsStats { } public static function correctPlaces($x) { - + } public static function globalSort($xml, $root = 'stats') { @@ -187,7 +191,7 @@ class wsStats { } $years = array(); foreach ($xml->year as $year) { - $years[(string) $year['year']] = self::yearSort($year, 'year'); + $years[(string)$year['year']] = self::yearSort($year, 'year'); } ksort($years); foreach ($years as $y) { @@ -203,7 +207,7 @@ class wsStats { } $months = array(); foreach ($xml->month as $month) { - $months[(string) $month['month']] = $month; + $months[(string)$month['month']] = $month; } ksort($months); @@ -231,13 +235,13 @@ class wsStats { $x = $res->addChild('days'); $days = array(); foreach ($xml->days->day as $day) { - $days[(string) $day['day']] = $day; + $days[(string)$day['day']] = $day; } ksort($days); foreach ($days as $day) { - $places = (string) $day['places']; + $places = (string)$day['places']; if ($places == 1) { - $visitors = (string) $day['visitors']; + $visitors = (string)$day['visitors']; if ($visitors > 10) { cubeXML::removeAttribute($day, 'places'); $day->addAttribute('places', round($visitors * 0.99)); @@ -252,8 +256,8 @@ class wsStats { $pages = array(); $trans = array(); foreach ($xml->pages->page as $page) { - $pages[(string) $page['page']] = (string) $page['score']; - $trans[(string) $page['page']] = $page; + $pages[(string)$page['page']] = (string)$page['score']; + $trans[(string)$page['page']] = $page; } arsort($pages); foreach ($pages as $num => $score) { @@ -266,8 +270,8 @@ class wsStats { $links = array(); $trans = array(); foreach ($xml->links->link as $link) { - $links[(string) $link['url']] = (string) $link['click']; - $trans[(string) $link['url']] = $link; + $links[(string)$link['url']] = (string)$link['click']; + $trans[(string)$link['url']] = $link; } arsort($links); $links = array_slice($links, 0, 100, true); @@ -281,8 +285,8 @@ class wsStats { $searches = array(); $trans = array(); foreach ($xml->searches->search as $search) { - $searches[(string) $search['query']] = (string) $search['count']; - $trans[(string) $search['query']] = $search; + $searches[(string)$search['query']] = (string)$search['count']; + $trans[(string)$search['query']] = $search; } arsort($searches); $searches = array_slice($searches, 0, 100, true); @@ -296,8 +300,8 @@ class wsStats { $countries = array(); $trans = array(); foreach ($xml->countries->country as $country) { - $countries[(string) $country['code']] = (string) $country['visitors']; - $trans[(string) $country['code']] = $country; + $countries[(string)$country['code']] = (string)$country['visitors']; + $trans[(string)$country['code']] = $country; } arsort($countries); foreach ($countries as $code => $visitors) { @@ -360,7 +364,7 @@ class wsStats { /** * - * @param string $name + * @param string $name * @return PHPExcel_Worksheet */ protected static function _createSheet($name) { @@ -491,7 +495,6 @@ class wsStats { $res .= commonPage::bf(); - // . $res .= commonPage::bh('stats_detail_pages'); $res .= self::detailPages($book, $annee, $mois, $stats); @@ -607,9 +610,9 @@ class wsStats { $url .= '/' . $stats['year']; if (isset($stats['month'])) { $url .= '/' . $stats['month']; - $date = strftime('%B %Y', mktime(0, 0, 0, (string) $stats['month'], 15, (string) $stats['year'])); + $date = strftime('%B %Y', mktime(0, 0, 0, (string)$stats['month'], 15, (string)$stats['year'])); } else { - $date = (string) $stats['year']; + $date = (string)$stats['year']; } } @@ -644,18 +647,18 @@ class wsStats { $xlines = array(); foreach ($stats->days->day as $day) { - $lines[] = array(strftime('%A %d', mktime(0, 0, 0, $mois, (string) $day['day'], $annee)), - $day['places'], - $day['visitors'], - $day['visits'], - $day['views'], - $day['links']); - $xlines[] = array(strftime('%d', mktime(0, 0, 0, $mois, (string) $day['day'], $annee)), - $day['places'], - $day['visitors'], - $day['visits'], - $day['views'], - $day['links']); + $lines[] = array(strftime('%A %d', mktime(0, 0, 0, $mois, (string)$day['day'], $annee)), + $day['places'], + $day['visitors'], + $day['visits'], + $day['views'], + $day['links']); + $xlines[] = array(strftime('%d', mktime(0, 0, 0, $mois, (string)$day['day'], $annee)), + $day['places'], + $day['visitors'], + $day['visits'], + $day['views'], + $day['links']); } $time_page = mktime(0, 0, 0, $mois, 15, $annee); @@ -680,7 +683,7 @@ class wsStats { $lines = array(); foreach ($stats->pages->page as $page) { - $p = (string) $page['page']; + $p = (string)$page['page']; if ($p > $book->pages || cubeMath::isOdd($p)) { continue; } @@ -723,8 +726,8 @@ class wsStats { $xlines = array(); foreach ($stats->links->link as $link) { - $uurl = (string) $link['url']; - $nb = (string) $link['click']; + $uurl = (string)$link['url']; + $nb = (string)$link['click']; if (stristr($uurl, 'mailto:') || stristr($uurl, 'http://') || stristr($uurl, 'https://')) { $url = substr($uurl, 7); } else { @@ -796,14 +799,14 @@ class wsStats { $maxb = 0; $s = array(); foreach ($stats->month as $month) { - $maxb = max($maxb, (string) $month['visits']); - $maxp = max($maxp, (string) $month['pages']); - $maxv = max($maxv, (string) $month['visitors']); - $time = cubeDate::round(mktime(0, 0, 0, (string) $month['month'], 15, (string) $month['year']), 'm'); + $maxb = max($maxb, (string)$month['visits']); + $maxp = max($maxp, (string)$month['pages']); + $maxv = max($maxv, (string)$month['visitors']); + $time = cubeDate::round(mktime(0, 0, 0, (string)$month['month'], 15, (string)$month['year']), 'm'); $s[$time] = array(); - $s[$time]['book'] = (string) $month['visits']; - $s[$time]['page'] = (string) $month['pages']; - $s[$time]['visit'] = (string) $month['visitors']; + $s[$time]['book'] = (string)$month['visits']; + $s[$time]['page'] = (string)$month['pages']; + $s[$time]['visit'] = (string)$month['visitors']; } // . $max = max($maxb, $maxv); @@ -890,7 +893,7 @@ class wsStats { $s = array(); foreach ($stats->year as $year) { foreach ($year->month as $month) { - $time = mktime(0, 0, 0, intval((string) $month['month']), 15, (string) $month['year']); + $time = mktime(0, 0, 0, intval((string)$month['month']), 15, (string)$month['year']); $s[$time]['book'] = $month['visits']; $s[$time]['page'] = $month['pages']; $s[$time]['time'] = $time; @@ -904,9 +907,9 @@ class wsStats { $maxp = 0; $maxb = 0; foreach ($s as $time => $d) { - $maxb = max($maxb, (string) $d['book']); - $maxp = max($maxp, (string) $d['page']); - $maxv = max($maxv, (string) $d['visit']); + $maxb = max($maxb, (string)$d['book']); + $maxp = max($maxp, (string)$d['page']); + $maxv = max($maxv, (string)$d['visit']); } $max = max($maxb, $maxv); @@ -998,10 +1001,10 @@ class wsStats { $v = array(); $s = array(); foreach ($stats->days->day as $day) { - $time = mktime(0, 0, 0, $m, (string) $day['day'], $a); - $maxb = max($maxb, (string) $day['visits']); - $maxp = max($maxp, (string) $day['views']); - $maxv = max($maxv, (string) $day['visitors']); + $time = mktime(0, 0, 0, $m, (string)$day['day'], $a); + $maxb = max($maxb, (string)$day['visits']); + $maxp = max($maxp, (string)$day['views']); + $maxv = max($maxv, (string)$day['visitors']); $s[$time]['book'] = $day['visits']; $s[$time]['page'] = $day['views']; $s[$time]['visit'] = $day['visitors']; @@ -1087,6 +1090,7 @@ class wsStats { return $res; } -} - -?> \ No newline at end of file + public static function forceComputation($id) { + `/home/stats/www/FWStats.sh /home/stats/www onlybook=$id`; + } +} \ No newline at end of file