statistics dialog: add 'last 30 days' and 'top 30 days'

This commit is contained in:
rolux 2012-10-05 11:19:58 +00:00
parent 2e628bb1b6
commit b51508ed4f

View file

@ -88,8 +88,6 @@ pandora.ui.statisticsDialog = function() {
$tabPanel; $tabPanel;
//Ox.getJSON('/static/json/deleteme.json', function(result) {
///*
pandora.api.findUsers({ pandora.api.findUsers({
keys: ['browser', 'firstseen', 'lastseen', 'level', 'location', 'system'], keys: ['browser', 'firstseen', 'lastseen', 'level', 'location', 'system'],
query: { query: {
@ -99,7 +97,6 @@ pandora.ui.statisticsDialog = function() {
range: [0, 1000000], range: [0, 1000000],
sort: [{key: 'username', operator: '+'}] sort: [{key: 'username', operator: '+'}]
}, function(result) { }, function(result) {
//*/
var data = {}, var data = {},
flagCountry = {}, flagCountry = {},
@ -111,6 +108,7 @@ pandora.ui.statisticsDialog = function() {
year: {}, year: {},
month: {}, month: {},
day: {}, day: {},
weekday: {},
hour: {}, hour: {},
continent: {}, continent: {},
region: {}, region: {},
@ -130,13 +128,15 @@ pandora.ui.statisticsDialog = function() {
['firstseen', 'lastseen'].forEach(function(key, i) { ['firstseen', 'lastseen'].forEach(function(key, i) {
var year = item[key].slice(0, 4) + '-' + key, var year = item[key].slice(0, 4) + '-' + key,
month = item[key].slice(0, 7) + '-' + key, month = item[key].slice(0, 7) + '-' + key,
day = Ox.formatDate(item[key], '%u'), day = item[key].slice(0, 10),
weekday = Ox.formatDate(item[key], '%u'),
hour = item[key].slice(11, 13); hour = item[key].slice(11, 13);
data[mode].year[year] = data[mode].year[year] || {}; data[mode].year[year] = data[mode].year[year] || {};
data[mode].year[year][month] = (data[mode].year[year][month] || 0) + 1; data[mode].year[year][month] = (data[mode].year[year][month] || 0) + 1;
data[mode].month[month] = (data[mode].month[month] || 0) + 1; data[mode].month[month] = (data[mode].month[month] || 0) + 1;
data[mode].day[day] = data[mode].day[day] || {}; data[mode].day[day] = (data[mode].day[day] || 0) + 1;
data[mode].day[day][hour] = (data[mode].day[day][hour] || 0) + 1; data[mode].weekday[weekday] = data[mode].weekday[weekday] || {};
data[mode].weekday[weekday][hour] = (data[mode].weekday[weekday][hour] || 0) + 1;
data[mode].hour[hour] = (data[mode].hour[hour] || 0) + 1; data[mode].hour[hour] = (data[mode].hour[hour] || 0) + 1;
}); });
if (item.location) { if (item.location) {
@ -262,13 +262,16 @@ pandora.ui.statisticsDialog = function() {
: 'rgb(16, 16, 16)' : 'rgb(16, 16, 16)'
}); });
if (id == 'seen') { if (id == 'seen') {
['year', 'month', 'day', 'hour'].forEach(function(key) { ['year', 'month', 'lastdays', 'topdays', 'weekday', 'hour'].forEach(function(key) {
var isYearOrMonth = ['year', 'month'].indexOf(key) > -1; var isDate = ['year', 'month'].indexOf(key) > -1,
isDay = ['lastdays', 'topdays'].indexOf(key) > -1;
Ox.Chart({ Ox.Chart({
color: function(value) { color: function(value) {
var split = value.split('-'), var split = value.split('-'),
color = isYearOrMonth ? Ox.rgb( color = isDate ? Ox.rgb(
Ox.mod(8 - parseInt(split[1], 10), 12) * 30, 1, 0.5 Ox.mod(8 - parseInt(split[1], 10), 12) * 30, 1, 0.5
) : isDay ? Ox.rgb(
Math.abs(parseInt(Ox.formatDate(value, '%w')) * 360 / 7), 1, 0.5
) : Ox.rgb( ) : Ox.rgb(
(Math.abs(11.5 - parseInt(split[0], 10)) - 0.5) * -11, 1, 0.5 (Math.abs(11.5 - parseInt(split[0], 10)) - 0.5) * -11, 1, 0.5
); );
@ -279,16 +282,21 @@ pandora.ui.statisticsDialog = function() {
} }
return color; return color;
}, },
data: data[mode][key], data: data[mode][isDay ? 'day' : key],
formatKey: function(value) { formatKey: function(value) {
var ret, split; var ret, split;
if (isYearOrMonth) { if (isDate) {
split = value.split('-'); split = value.split('-');
ret = (split.pop() == 'firstseen' ? 'First' : 'Last') + ': ' ret = (split.pop() == 'firstseen' ? 'First' : 'Last') + ': '
+ (key == 'year' ? '' : Ox.MONTHS[parseInt(split[1], 10) - 1]) + (key == 'year' ? '' : Ox.MONTHS[parseInt(split[1], 10) - 1])
+ ' ' + split[0]; + ' ' + split[0];
} else if (isDay) {
split = value.split('-');
ret = Ox.SHORT_WEEKDAYS[parseInt(Ox.formatDate(value, '%u')) - 1] + ', '
+ Ox.SHORT_MONTHS[parseInt(split[1], 10) - 1] + ' '
+ parseInt(split[2], 10) + ', ' + split[0];
} else { } else {
ret = key == 'day' ret = key == 'weekday'
? Ox.WEEKDAYS[parseInt(value, 10) - 1] ? Ox.WEEKDAYS[parseInt(value, 10) - 1]
: value + ':00'; : value + ':00';
} }
@ -296,9 +304,15 @@ pandora.ui.statisticsDialog = function() {
}, },
keyAlign: 'right', keyAlign: 'right',
keyWidth: 128, keyWidth: 128,
rows: isYearOrMonth ? 2 : 1, limit: isDay ? 30 : 0,
sort: {key: 'key', operator: isYearOrMonth ? '-' : '+'}, rows: isDate ? 2 : 1,
title: Ox.toTitleCase(key) + 's', sort: {
key: key == 'topdays' ? 'value' : 'key',
operator: isDate || isDay ? '-' : '+'
},
title: key == 'lastdays' ? 'Last 30 Days'
: key == 'topdays' ? 'Top 30 Days'
: Ox.toTitleCase(key) + 's',
width: chartWidth width: chartWidth
}) })
.css({ .css({
@ -307,7 +321,7 @@ pandora.ui.statisticsDialog = function() {
top: top + 'px' top: top + 'px'
}) })
.appendTo($content); .appendTo($content);
top += Ox.len(data[mode][key]) * 16 + 32; top += (isDay ? 30 : Ox.len(data[mode][key])) * 16 + 32;
}); });
} else if (id == 'locations') { } else if (id == 'locations') {
['continent', 'region', 'country', 'city'].forEach(function(key) { ['continent', 'region', 'country', 'city'].forEach(function(key) {