Skip to content

Commit

Permalink
added cleanup feature to make stats load faster
Browse files Browse the repository at this point in the history
  • Loading branch information
geek-at committed Feb 28, 2017
1 parent cf4557e commit 3e8f6e8
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 12 deletions.
65 changes: 65 additions & 0 deletions analyze.php
@@ -1,5 +1,7 @@
<?php
error_reporting(E_ALL & ~E_NOTICE);
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));

if(!file_exists('config.inc.php')) exit('[X] Rename example.config.inc.php to config.inc.php first and set your values');
include_once('config.inc.php');
Expand Down Expand Up @@ -189,6 +191,9 @@
closedir($handle);
}
echo "\n\n";
echo "[~] Cleaning up multiple zeros in a row\n";
cleanUp();
echo "Done\n";
}
echo "[FIN] Exiting..\n\n";

Expand Down Expand Up @@ -294,4 +299,64 @@ function sendToInflux($data,$time)
$socket = stream_socket_client("udp://".INFLUX_HOST.":".INFLUX_HOST_UDP_PORT);
stream_socket_sendto($socket, INFLUX_HOST_MEASUREMENT.','.$data.' '.$time);
stream_socket_shutdown($socket, STREAM_SHUT_RDWR);
}

function cleanUp()
{
if ($handle = opendir('cache/'))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$filepath = ROOT.DS.'cache'.DS.$file.DS.'view_log.csv';
if(is_dir('cache/'.$file) && isThatAnImage($filepath))
{
removeZeroValues($filepath);
}
}
}
closedir($handle);
}
}

function removeZeroValues($file)
{
$temp_table = fopen($file.'.tmp','w');
$lastviews = 0;
$emptycount = 0;

$handle = fopen($file,'r');
if ($handle)
{
while (($line = fgets($handle)) !== false)
{

$line = trim($line);
$a = explode(';',$line);
$traffic = $a[2];
$views = $a[3];
$count = $a[1];
if($count>0 && is_numeric($traffic) && is_numeric($views))
{
$lastviews = $views;
fwrite($temp_table,$line."\n");
}
else if($count==0)
{
$emptycount++;
}
}


fclose($handle);
}

echo " [~]Removed $emptycount zero values from $file\n";

fclose($temp_table);

//rename($file,$file.'.orig');
rename($file.'.tmp',$file);

}
6 changes: 6 additions & 0 deletions css/bootstrap.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions css/bootstrap.min.css.map

Large diffs are not rendered by default.

Binary file added css/imgs/bg.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added css/imgs/hs_logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added css/imgs/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions css/pictshare.css
@@ -0,0 +1,28 @@
body {
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 14px;
line-height: 1.42857143;
color: #333;
background-image: url('imgs/bg.png');
background-repeat: no-repeat;
background-color: #fff;
}

#headcontainer
{
padding-top:20px;
margin-left:100px;
}

.well {
min-height: 20px;
padding: 19px;
margin-bottom: 20px;
border: 1px solid #e3e3e3;
border-radius: 4px;

background: rgb(245, 245, 245); /* Fall-back for browsers that don't support rgba */
background: rgba(245, 245, 245, .8);
-webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.05);
box-shadow: inset 0 1px 1px rgba(0,0,0,.05);
}
30 changes: 18 additions & 12 deletions index.html
Expand Up @@ -9,11 +9,13 @@
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="cleartype" content="on">
<link rel="stylesheet" href="https://pictshare.net/css/normalize.css">
<link rel="stylesheet" href="https://pictshare.net/css/pictshare.css">
<script src="https://pictshare.net/js/vendor/modernizr-2.6.2.min.js"></script>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">

<!-- PictShare overwrites -->
<link href="css/pictshare.css" rel="stylesheet">
<script type="text/javascript" src="https://pictshare.net/js/jquery-2.1.0.min.js"></script>
<script src="js/pictshare.js"></script>
<script src="js/pictshare.js"></script>
<script src="js/filesize.min.js"></script>
<script type="text/javascript"
src="https://www.google.com/jsapi?autoload={
Expand All @@ -27,15 +29,19 @@

</HEAD>
<BODY>
<div class="mitte" id="overall"><span id="all_served" style="color:black;margin-left:30px;"></span>
<a href="#" onClick="resetPage();return false;"><div id="header">
<div style="padding:15px;"><div class="rechts"><?php echo $slogan; ?></div></div>
</div></a>
<div id="content">

<div class="container" id="headcontainer">
<div class="row">
<div class="col-md-8">
<a href="#" onClick="resetPage();return false;"><img src="css/imgs/logo.png" /></a>
<div id="all_served" style="color:black;"></div>
<div class="well" id="content">

</div>
</div>
</div>

</div>
<div class="content"><center>(c)2015 by<br/><a href="https://haschek.solutions" target="_blank"><img height="30" src="https://pictshare.net//css/imgs/hs_logo.png" /></a></center></div>
<div id="footer"></div>
<footer>(c)<?php echo date("y");?> by<br/><a href="https://haschek.solutions" target="_blank"><img height="30" src="css/imgs/hs_logo.png" /></a></footer>
</div>

<a href="https://github.com/chrisiaut/pictshare_stats"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://camo.githubusercontent.com/82b228a3648bf44fc1163ef44c62fcc60081495e/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png"></a>
Expand Down

0 comments on commit 3e8f6e8

Please sign in to comment.