Files
tilde-projects/public_html/du/index.html
T

129 lines
5.4 KiB
HTML
Raw Normal View History

2015-08-24 10:04:57 -05:00
<html>
<head>
<title>Tilder Disk Usage</title>
2018-09-19 17:04:38 +00:00
<style>
body {
background-color: wheat;
}
</style>
2015-08-24 10:04:57 -05:00
</head>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.8.0/lodash.min.js"></script>
<script type="text/javascript">
2018-01-24 20:51:54 +00:00
google.load("visualization", "1.1", {packages:["corechart", "line"], callback: drawCharts});
//google.setOnLoadCallback(drawCharts);
2015-08-24 10:04:57 -05:00
function drawCharts() {
2018-01-24 20:51:54 +00:00
console.log('called drawCharts!');
2015-08-24 10:04:57 -05:00
var data = new google.visualization.DataTable();
var piechart = new google.visualization.PieChart(document.getElementById('donutchart'));
var linedata = new google.visualization.DataTable();
var linechart = new google.visualization.LineChart(document.getElementById('linechart'));
var date = new Date(0);
data.addColumn('string', 'User');
data.addColumn('number', 'Disk Usage');
data.addColumn('number', 'File Count');
var pieoptions = {
title: 'Tilder Disk Usage',
subtitle: 'in kb',
pieHole: 0.4,
2018-09-19 17:04:38 +00:00
sliceVisibilityThreshold: 0.005,
backgroundColor: 'wheat'
2015-08-24 10:04:57 -05:00
};
var lineoptions = {
title: 'Tilder Disk Usage',
subtitle: 'over time',
vAxis: {
0: {title: 'kb'},
logScale: true
2018-09-19 17:04:38 +00:00
},
backgroundColor: 'wheat'
2015-08-24 10:04:57 -05:00
};
jQuery.getJSON("/~krowbar/data/du_log.json", function(json) {
2018-01-24 20:51:54 +00:00
console.log('loaded disk usage json data!');
2015-08-24 10:04:57 -05:00
date.setUTCSeconds(json[json.length-1].date);
//Draw PieChart
data.addRows(
_.map(json[json.length-1].data, function(d) { return [d.user, d.du, d.files];})
);
piechart.draw(data, pieoptions);
//Draw LineChart
linedata.addColumn('date', 'Date');
var userData = {};
2017-08-04 12:06:58 +00:00
var userInterest = {};
2017-03-30 21:39:44 +00:00
2017-08-04 12:06:58 +00:00
var cutoffDate = new Date(); cutoffDate.setMonth(cutoffDate.getMonth() - 6); cutoffDate = cutoffDate.getTime() / 1000; //the last 3 monthsa
var interestQuotent = 0.005;
_.forEach(json, function(set, idx) { //generate the 'interest quotent' for each user as a value of change
if(set.date < cutoffDate) return;
_.forEach(set.data, function(point) {
if(!userInterest[point.user]) {
userInterest[point.user] = { absChange: 0, lastValue: point.du, count: 1 };
} else {
userInterest[point.user].absChange = userInterest[point.user].absChange
+ Math.abs(point.du - userInterest[point.user].lastValue) / userInterest[point.user].lastValue;
userInterest[point.user].lastValue = point.du;
userInterest[point.user].count = userInterest[point.user].count + 1;
}
})
})
function isInteresting(point) {
if($("#onlyInteresting").is(":checked")) {
return userInterest[point.user].absChange / userInterest[point.user].count > interestQuotent;
} else {
return point.du > 5000; //the 'interesting' threshold is set at 5000kb
}
}
2017-03-30 21:39:44 +00:00
2015-08-24 10:04:57 -05:00
_.forEach(json, function(set, idx) {
//only display 1/8 the points. (every 2 days instead of every 6 hours) page is loading too slow
//maybe i could add something to show more points but we're not losing too much granularity for the speed we gain
2017-03-30 21:39:44 +00:00
if(idx % 4 != 0 || set.date < cutoffDate) return;
2015-08-24 10:04:57 -05:00
_.forEach(set.data, function(point) {
2017-08-04 12:06:58 +00:00
if(isInteresting(point)) {
2016-09-07 15:58:36 +00:00
if(!userData[point.user]) { //if the current user has not been initialized yet
userData[point.user] = []; //create an empty array
2015-08-24 10:04:57 -05:00
var size = json.length;
2016-09-07 15:58:36 +00:00
while(size--) userData[point.user][size] = 0; //and populate it with zeros for the lenght of our entire set
linedata.addColumn('number', point.user); //then add a column of type 'number' for this user
2015-08-24 10:04:57 -05:00
}
2016-09-07 15:58:36 +00:00
userData[point.user][idx] = point.du; //add a point for this user
//if the last three data points are the same value
//if(idx > 16 && userData[point.user][idx] == userData[point.user][idx-8] && userData[point.user][idx-16]) {
// userData[point.user].splice(idx,1); //then get rid of the middle one
// if(point.user == '~vilmibm') {
// console.log('points', userData[point.user]);
// }
//}
2015-08-24 10:04:57 -05:00
}
})
})
_.forEach(json, function(set,idx) {
2017-03-30 21:39:44 +00:00
if(idx % 4 != 0) return;
var d = new Date(0);
d.setUTCSeconds(set.date);
linedata.addRow([d].concat(_.map(userData, function(user) { return user[idx];})));
2015-08-24 10:04:57 -05:00
});
console.log(linedata);
linechart.draw(linedata, lineoptions);
});
}
</script>
<body>
<div id="donutchart" style="width: 700px; height: 400px;"></div>
2017-08-04 12:06:58 +00:00
<input id="onlyInteresting" type="checkbox" onClick="drawCharts()">Only Interesting Data</input>
2017-03-30 21:39:44 +00:00
<div id="linechart" style="width: 120%; height: 130%; margin-left: -10%"></div>
2018-09-19 17:04:38 +00:00
<div>
<a href="https://github.com/RussellChamp/tilde-projects/tree/master/Code/bash">(see source)</a>
</div>
2015-08-24 10:04:57 -05:00
</body>