<?php
$scandir = scandir('c:/keycounter');
$stats = array();
foreach($scandir as $filename){
if(substr($filename, -4) !== '.day') continue;
$date = substr($filename, 0, -4);
$stats[$date]= array('k' => 0, 'm' => 0);
$content = file_get_contents('c:/keycounter/'.$filename);
$lines = explode("\n", $content);
foreach($lines as $line){
if($line === '') {
continue;
}
$exp2 = explode(",", $line);
$stats[$date]['k']+=intval($exp2[0]);
$stats[$date]['m']+=intval($exp2[1]);
}
}
$kplot = array();
$mplot = array();
foreach($stats as $date => $stat){
$kplot[$date] = $stat['k'];
$mplot[$date] = $stat['m'];
}
function time_flot($data){
ksort($data);
$rand = md5(rand(100000,10000000));
$dt = '';
foreach ($data as $key => $val) {
$dt.='[' . date('U', strtotime($key)) * 1000 .','. $val . '],';
}
ob_start();
?>
<div id="flot-<?php echo $rand ?>" style="height:100%; width: 100%; min-height: 200px; min-width: 300px;"></div>
<script type="text/javascript">
$(function() {
var d = [<?php echo $dt ?>];
// helper for returning the weekends in a period
function weekendAreas(axes) {
var markings = [],
d = new Date(axes.xaxis.min);
// go to the first Saturday
d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 1) % 7));
d.setUTCSeconds(0);
d.setUTCMinutes(0);
d.setUTCHours(0);
var i = d.getTime();
// when we dont set yaxis, the rectangle automatically
// extends to infinity upwards and downwards
do {
markings.push({ xaxis: { from: i, to: i + 24 * 60 * 60 * 1000 } });
i += 7 * 24 * 60 * 60 * 1000;
} while (i < axes.xaxis.max);
return markings;
}
var options = {
xaxis: {
mode: "time",
tickLength: 5,
timeformat: "%d %b",
monthNames: ["jan", "feb", "mar", "apr", "mai", "jun", "jul", "aug", "sep", "okt", "nov", "des"]
},
selection: {
mode: "x"
},
grid: {
markings: weekendAreas,
hoverable: true,
},
};
$("<div id='flot-<?php echo $rand ?>-tooltip'></div>").css({
position: "absolute",
display: "none",
border: "1px solid #ddd",
padding: "2px",
"background-color": "#eee",
opacity: 0.80
}).appendTo("body");
var plot = $.plot("#flot-<?php echo $rand ?>", [d], options);
$("#flot-<?php echo $rand ?>").bind("plothover", function (event, pos, item) {
if (item) {
var x = item.datapoint[0].toFixed(),
y = item.datapoint[1].toFixed();
var date = new Date(x * 1);
$("#flot-<?php echo $rand ?>-tooltip").html(date.getFullYear()+ "/" + (date.getMonth() + 1) + "/" + date.getDate() + " ("+ y + ")")
.css({top: item.pageY+0, left: item.pageX+25})
.fadeIn(200);
} else {
$("#flot-<?php echo $rand ?>-tooltip").hide();
}
});
// now connect the two
});
</script>
<?php
$str = ob_get_contents();
ob_end_clean();
return $str;
}
?>
<script language="javascript" type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script language="javascript" type="text/javascript" src="jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="jquery.flot.time.js"></script>
<style>
.flot{
background: white;
border-radius: 10px;
border: 1px solid orange;
padding: 10px;
margin-bottom: 10px;
}
</style>
<?php echo 'avg_k: ' . intval(array_sum($kplot) / count($kplot)) . '<br/>'; ?>
<div class="plot" style="width: 1500px; height: 400px;">
<?php echo time_flot($kplot);?>
</div>
<br/>
<?php echo 'avg_m: ' . intval(array_sum($mplot) / count($mplot)) . '<br/>'; ?>
<div class="plot" style="width: 1500px; height: 400px;">
<?php echo time_flot($mplot);?>
</div>
Abusive script
This script was stopped while abusing our resources
preferences:
37.54 ms | 402 KiB | 5 Q