Welcome to mirror list, hosted at ThFree Co, Russian Federation.

script.js « js - github.com/nextcloud/survey_server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2f994c74cd9f0885018a637a183b7c13565fcea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
 * @author Björn Schießle <schiessle@owncloud.com>
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

(function ($, OC) {

	$(document).ready(function () {

		/**
		 * calculate random color for the charts
		 * @returns {string}
		 */
		var getRandomColor = function() {
			var letters = '0123456789ABCDEF'.split('');
			var color = '#';
			for (var i = 0; i < 6; i++ ) {
				color += letters[Math.floor(Math.random() * 16)];
			}
			return color;
		};

		var formatNumber = function(number) {
			number = number.toString();
			return number.replace(/(\d)(?=(\d{3})+(\.|$))/g, '$1,');
		};

		/**
		 * add general statistics to the page
		 * @param instances how many instances are counted
		 * @param users statistics about the users
		 */
		var showGeneralStatistics = function(instances, users, files) {
			$('#instances span').text(formatNumber(instances));
			$('#maxUsers span').text(formatNumber(users['max']));
			$('#minUsers span').text(formatNumber(users['min']));
			$('#averageUsers span').text(formatNumber(users['average']));
			$('#maxFiles span').text(formatNumber(files['max']));
			$('#minFiles span').text(formatNumber(files['min']));
			$('#averageFiles span').text(formatNumber(files['average']));

		};

		/**
		 * add general statistics to the page
		 * @param instances how many instances are counted
		 * @param users statistics about the users
		 */
		var ocNumericStatistics = function(id, data) {
			if (id.substring(0, 3) == 'php' || id.substring(0, 8) == 'database') {
				$('#' + id + 'Max span').text(OC.Util.humanFileSize(data['max']));
				$('#' + id + 'Min span').text(OC.Util.humanFileSize(data['min']));
				$('#' + id + 'Average span').text(OC.Util.humanFileSize(data['average']));
			} else {
				$('#' + id + 'Max span').text(formatNumber(data['max']));
				$('#' + id + 'Min span').text(formatNumber(data['min']));
				$('#' + id + 'Average span').text(formatNumber(data['average']));
			}
		};

		/**
		 * draw the chart of enabled apps
		 *
		 * @param array data
		 */
		var appsChart = function (data) {
			var appLabels = new Array();
			var appValues = new Array();
			for (key in data) {
				appLabels.push(key);
				appValues.push(data[key]);
			}

			var appData = {
				labels: appLabels,
				datasets: [
					{
						label: "Enabled Apps (in %)",
						fillColor: "rgba(151,187,205,0.5)",
						strokeColor: "rgba(151,187,205,0.8)",
						highlightFill: "rgba(151,187,205,0.75)",
						highlightStroke: "rgba(151,187,205,1)",
						data: appValues
					}
				]
			};

			var ctx = document.getElementById("appChart").getContext("2d");
			var myBarChart = new Chart(ctx).Bar(appData);
		};

		/**
		 * draw the chart of ownCloud versions
		 *
		 * @param array data
		 */
		var ocChart = function (id, data) {
			var ocChartData = new Array(),
				$details = $('#' + id + 'Details');

			for (key in data) {
				$details.append($('<span>').text(key + ': ' + data[key]));
				$details.append($('<br>'));

				ocChartData.push(
					{
						value: data[key],
						color: getRandomColor(),
						label: key
					}
				);

			}
			var ctx = document.getElementById(id + 'Chart').getContext("2d");
			var myPieChart = new Chart(ctx).Pie(ocChartData);
		};

		$.get(
			OC.generateUrl('/apps/survey_server/api/v1/data'), {}
		).done(
			function (data) {
				showGeneralStatistics(data['instances'], data['categories']['stats']['num_users']['statistics'], data['categories']['stats']['num_files']['statistics']);
				appsChart(data['apps']);

				for (category in data['categories']) {
					for(key in data['categories'][category]) {
						if (key !== 'stats') {
							if (data['categories'][category][key]['presentation'] === 'diagram') {
								ocChart((category + key).replace('.', '-'), data['categories'][category][key]['statistics']);
							} else if (data['categories'][category][key]['presentation'] === 'numerical evaluation') {
								ocNumericStatistics(category + key + 'Numeric', data['categories'][category][key]['statistics']);
							}
						}
					}
				}
			}
		);

	});

})(jQuery, OC);