2
* Helioviewer Usage Statistics Functions
7
* Fetches the usage statistics for the specified time interval and displays summary text and graphs
9
* @param timeInterval The time interval or resolution for which the usage statistics should be displayed, e.g.
10
* hourly, daily, weekly, etc.
13
var getUsageStatistics = function(timeInterval) {
14
$.getJSON("../api/index.php", {action: "getUsageStatistics", resolution: timeInterval}, function (response) {
15
displayUsageStatistics(response, timeInterval);
20
* Handles the actual rendering of the usage statistics for the requested period
22
* @param data Usage statistics
23
* @param timeInterval Query time interval
27
var displayUsageStatistics = function (data, timeInterval) {
28
var pieChartHeight, barChartHeight, barChartMargin, summary, max;
30
// Determine how much space is available to plot charts
31
pieChartHeight = Math.min(0.4 * $(window).width(), $(window).height());
32
barChartHeight = Math.min(150, pieChartHeight / 3);
35
summary = data['summary'];
36
displaySummaryText(timeInterval, summary);
38
// Create summary pie chart
39
createPieChart('pieChart', summary, pieChartHeight);
41
// Create bar graphs for each request type
42
createColumnChart('takeScreenshot', data['takeScreenshot'], 'Screenshot', barChartHeight, "#8e305c");
43
createColumnChart('buildMovie', data['buildMovie'], 'Movie', barChartHeight, "#5d8f31");
44
createColumnChart('getJPX', data['getJPX'], 'JPX', barChartHeight, "#315d8f");
46
// Spreads bar graphs out a bit if space permits
47
barChartMargin = Math.round(($("#visualizations").height() - $("#barCharts").height()) / 6);
48
$(".columnChart").css("margin", barChartMargin + "px 0");
52
* Displays summary text to be shown at the top of the usage statistics page
54
* @param timeInterval Time interval for which the statistics are shown
55
* @param summary Total counts for each type of request
57
* @return string HTML for the overview text block
59
var displaySummaryText = function(timeInterval, summary) {
60
var humanTimes, when, html;
62
// Human readable text for the requested time intervals
64
"daily" : "two weeks",
65
"weekly" : "two months",
67
"yearly" : "three years"
70
when = humanTimes[timeInterval];
73
html = '<span id="when">During the last <b>' + when + '</b> Helioviewer.org users created</span> ' +
74
'<span id="numScreenshots" class="summaryCount">' + summary['takeScreenshot'] + ' screenshots</span>, ' +
75
'<span id="numMovies" class="summaryCount">' + summary['buildMovie'] + ' movies</span>, and ' +
76
'<span id="numJPXMovies" class="summaryCount">' + summary['getJPX'] + ' JPX movies</span>.';
78
$("#overview").html(html);
83
* Creates a bar chart representing the frequency of requests for the specified type across time
85
* @param id Id of the dom element where bar chart should be placed
86
* @param rows Data rows
87
* @param desc Description ...
88
* @param height Height of the bar chart
89
* @param color Color to use for the bars
93
var createColumnChart = function (id, rows, desc, height, color) {
95
var data = new google.visualization.DataTable();
96
data.addColumn('string', 'Time');
97
data.addColumn('number', desc);
98
data.addRows(rows.length);
100
// Set datatable values
102
$.each(rows, function (i, pair) {
103
// Grab key and value from the pair
105
data.setValue(row, 0, key);
106
data.setValue(row, 1, pair[key]);
111
$("#barCharts").append('<div id="' + id + 'Chart" class="columnChart"></div>');
113
chart = new google.visualization.ColumnChart(document.getElementById(id + "Chart"));
118
title: 'Number of ' + desc + ' requests',
119
hAxis: {slantedText: true}
124
* Creates a pie chart to show proportion of each request type made
126
* @param id Id of the dom element where pie chart should be placed
127
* @param totals Array containing counts for each type of query
128
* @param size Length of each side of the graph
132
var createPieChart = function (id, totals, size) {
133
var chart, width, data = new google.visualization.DataTable();
135
data.addColumn('string', 'Request');
136
data.addColumn('number', 'Frequency of requests');
140
data.setValue(0, 0, 'Screenshots');
141
data.setValue(0, 1, totals['takeScreenshot']);
142
data.setValue(1, 0, 'Movies');
143
data.setValue(1, 1, totals['buildMovie']);
144
data.setValue(2, 0, 'JPX Movies');
145
data.setValue(2, 1, totals['getJPX']);
147
chart = new google.visualization.PieChart(document.getElementById(id));
148
chart.draw(data, {width: size, height: size, colors: ["#8e305c", "#5d8f31", "#315d8f"], title: "Frequency of requests"});