Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
248 lines (206 sloc) 7.13 KB
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/base/jquery-ui.css"></link>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jshashtable.js"></script>
<script type="text/javascript" src="js/jquery.numberformatter-1.2.2.js"></script>
<script type="text/javascript">
// From: http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
// This function creates a new anchor element and uses location
// properties (inherent) to get the desired URL data. Some String
// operations are used (to normalize results across browsers).
function parseURL(url) {
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':',''),
host: a.hostname,
port: a.port,
query: a.search,
params: (function(){
var ret = {},
seg = a.search.replace(/^\?/,'').split('&'),
len = seg.length, i = 0, s;
for (;i<len;i++) {
if (!seg[i]) { continue; }
s = seg[i].split('=');
ret[s[0]] = s[1];
}
return ret;
})(),
file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
hash: a.hash.replace('#',''),
path: a.pathname.replace(/^([^\/])/,'/$1'),
relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
segments: a.pathname.replace(/^\//,'').split('/')
};
}
google.load("visualization", "1", {packages:["corechart", "geochart"]});
var appNames = new Array();
function buildOptions(items)
{
var options = '<option value="0">All</option>';
$.each(items.apps, function(i,item){
options += '<option value="' + i + '">' + item + '</option>';
appNames[i] = item;
});
$('#app-selection').append('<select id="app-select">' + options + '</select>');
$('#app-selection').append('<select id="download-type"><option value="0">All</option><option value="1" selected>Downloads</option><option value="7">Updates</option></select>');
}
function drawChart(items)
{
$('#app_list').empty();
var data = new google.visualization.DataTable();
data.addColumn('string', 'Day');
var appPosition = new Array();
var appName = new Array();
var totals = new Array();
var count = 1;
$.each(items.apps, function(i,item){
data.addColumn('number', item);
appPosition[i] = count;
appName[i] = item;
totals[i] = 0;
count++;
});
data.addRows(items.total);
count = 0;
$.each(items.data, function(i,dateitem){
data.setValue(count, 0, i);
$.each(dateitem, function(i,item){
data.setValue(count, appPosition[i], parseInt(item.units));
totals[i] += parseInt(item.units);
});
count++;
});
$('#from').val(items.start_date);
$('#to').val(items.end_date);
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, {width: 980, height: 480, title: items.title});
$.each(items.totals, function(i,total){
$('#app_list').append('<tr><td><div class="view_app" id="' + i + '">' + appName[i] + '</div></td><td>' + total + '</td>');
});
var proceeds = '';
$.each(items.proceeds, function(i,bought) {
proceedsSection = '<tr><td colspan="2">' + appNames[i] +'</tr>';
$.each(bought, function(currency,amount){
proceedsSection += '<tr><td>' + currency + '</td><td>' + amount +'</td></tr>';
});
proceeds += proceedsSection;
});
if (proceeds)
{
$('#proceeds').html('<table>' + proceeds + '</table>');
}
}
function drawRegionsMap(items)
{
var data = new google.visualization.DataTable();
data.addRows(items.data.length);
data.addColumn('string', 'Country');
data.addColumn('number', 'Popularity');
var count = 0;
$.each(items.data, function(i,item){
data.setValue(i, 0, item.country_code);
data.setValue(i, 1, parseInt(item.units));
count++;
});
var options = {};
var container = document.getElementById('map_canvas');
var geochart = new google.visualization.GeoChart(container);
geochart.draw(data, {width: 600, height: 480});
};
function getAppGraph(data)
{
$.getJSON('ajax/daily.php', data, function(data) {
buildOptions(data);
drawChart(data);
});
}
function updateChart()
{
var params = {apptype: $('#app-type').val(),
apple_identifier: $('#app-select').val(),
product_type_identifier:$('#download-type').val(),
from: $('#from').val(),
to: $('#to').val(),
};
$('#stats-url').val(currentUrl.protocol + '://' + currentUrl.host + currentUrl.path + '?' + decodeURIComponent($.param(params)));
$.getJSON('ajax/daily.php', params, function(data) {
drawChart(data);
});
}
$(function() {
var dates = $( "#from, #to" ).datepicker({
defaultDate: "+1w",
maxDate: "-1D",
changeMonth: true,
numberOfMonths: 1,
dateFormat: 'dd/mm/yy',
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
var currentUrl = parseURL(document.URL);
$(document).ready(function() {
$('#stats-url').val(document.URL);
getAppGraph(currentUrl.params);
/*
$.getJSON('ajax/region.php', function(data) {
drawRegionsMap(data);
});
*/
$('#app-select, #download-type, #app-type').live('change', function() {
updateChart();
});
$('#view').live('click', function() {
updateChart();
});
$('.view_app').live('click', function() {
$("#app-select").val($(this).attr('id'));
updateChart();
});
});
</script>
<style type="text/css">
.view_app {
color: blue;
cursor: pointer
}
</style>
</head>
<body>
<select id="app-type">
<option value='0'>All</option>
<option value='1'>iPhone only</option>
<option value='2'>Universal</option>
<option value='3'>iPad</option>
<option value='4'>Bundle</option>
<option value='5'>Mac</option>
<option value='6'>In-apps</option>
</select>
<div id="app-selection"></div>
<label for="from">From</label>
<input type="text" id="from" name="from"/>
<label for="to">to</label>
<input type="text" id="to" name="to"/>
<input type="button" id="view" value="View" />
<br />
URL: <input type="text" id="stats-url" name="stats-url" value="" size="100" />
<div id="chart_div"></div>
<table id="app_list"></table>
<div id="proceeds"></div>
<div id='map_canvas'></div>
</body>
</html>