|
91 | 91 |
|
92 | 92 | // Draw the statistics graph.
|
93 | 93 | {% if results_json %}
|
94 |
| - var chart = null; |
95 |
| - function stats_graph(raw_data) { |
96 |
| - var colors = {{ results_colors_json }}; |
97 |
| - |
98 |
| - var ctx = $('#status-graph').find('canvas')[0].getContext('2d'); |
99 |
| - var font = $('body').css('font-family'); |
100 |
| - if (chart !== null) { |
101 |
| - chart.destroy(); |
102 |
| - } |
103 |
| - chart = new Chart(ctx, { |
104 |
| - type: 'pie', |
105 |
| - data: { |
106 |
| - datasets: [{ |
107 |
| - data: raw_data.categories.map(function(entry) { |
108 |
| - return entry.count; |
109 |
| - }), |
110 |
| - backgroundColor: raw_data.categories.map(function(entry) { |
111 |
| - return colors[entry.code]; |
| 94 | + $(function () { |
| 95 | + var chart = null; |
| 96 | + function stats_graph(raw_data) { |
| 97 | + var colors = {{ results_colors_json }}; |
| 98 | + |
| 99 | + var ctx = $('#status-graph').find('canvas')[0].getContext('2d'); |
| 100 | + var font = $('body').css('font-family'); |
| 101 | + if (chart !== null) { |
| 102 | + chart.destroy(); |
| 103 | + } |
| 104 | + chart = new Chart(ctx, { |
| 105 | + type: 'pie', |
| 106 | + data: { |
| 107 | + datasets: [{ |
| 108 | + data: raw_data.categories.map(function(entry) { |
| 109 | + return entry.count; |
| 110 | + }), |
| 111 | + backgroundColor: raw_data.categories.map(function(entry) { |
| 112 | + return colors[entry.code]; |
| 113 | + }), |
| 114 | + }], |
| 115 | + labels: raw_data.categories.map(function(entry) { |
| 116 | + return entry.name; |
112 | 117 | }),
|
113 |
| - }], |
114 |
| - labels: raw_data.categories.map(function(entry) { |
115 |
| - return entry.name; |
116 |
| - }), |
117 |
| - }, |
118 |
| - options: { |
119 |
| - animation: false, |
120 |
| - scaleFontFamily: font, |
121 |
| - tooltips: { |
122 |
| - titleFontFamily: font, |
123 |
| - bodyFontFamily: font, |
124 | 118 | },
|
125 |
| - legend: { |
126 |
| - display: false, |
| 119 | + options: { |
| 120 | + animation: false, |
| 121 | + scaleFontFamily: font, |
| 122 | + tooltips: { |
| 123 | + titleFontFamily: font, |
| 124 | + bodyFontFamily: font, |
| 125 | + }, |
| 126 | + legend: { |
| 127 | + display: false, |
| 128 | + }, |
127 | 129 | },
|
128 |
| - }, |
129 |
| - }); |
130 |
| - |
131 |
| - $('#total-submission-count').text(raw_data.total); |
132 |
| - } |
| 130 | + }); |
133 | 131 |
|
134 |
| - $(function () { |
| 132 | + $('#total-submission-count').text(raw_data.total); |
| 133 | + } |
135 | 134 | stats_graph(window.results_json);
|
136 | 135 | });
|
137 | 136 | {% endif %}
|
| 137 | + </script> |
| 138 | + {% endcompress %} |
138 | 139 |
|
139 |
| - function load_dynamic_update(last_msg) { |
140 |
| - var _collect = function (e) { |
141 |
| - return e.value; |
142 |
| - }; |
143 |
| - var language_filter = $.map($('select#language option[selected]'), _collect); |
144 |
| - var status_filter = $.map($('select#status option[selected]'), _collect); |
| 140 | + {% if dynamic_update and last_msg and not has_hidden_subtasks %} |
| 141 | + <script type="text/javascript"> |
| 142 | + $(function () { |
| 143 | + function load_dynamic_update(last_msg) { |
| 144 | + var _collect = function (e) { |
| 145 | + return e.value; |
| 146 | + }; |
| 147 | + var language_filter = $.map($('select#language option[selected]'), _collect); |
| 148 | + var status_filter = $.map($('select#status option[selected]'), _collect); |
| 149 | + |
| 150 | + var table = $('#submissions-table'); |
| 151 | + var statistics = $("#statistics-table"); |
| 152 | + var doing_ajax = false; |
| 153 | + var first = parseInt(table.find('>div:first-child').attr('id')); |
| 154 | + |
| 155 | + var update_submission = function (message, force) { |
| 156 | + if (language_filter.length && 'language' in message && |
| 157 | + language_filter.indexOf(message.language) == -1) |
| 158 | + return; |
| 159 | + if (status_filter.length && 'status' in message && |
| 160 | + status_filter.indexOf(message.status) == -1) |
| 161 | + return; |
| 162 | + var id = message.id; |
| 163 | + var row = table.find('div#' + id); |
| 164 | + if (row.length < 1) { |
| 165 | + if (id < first) |
| 166 | + return; |
| 167 | + first = id; |
| 168 | + row = $('<div>', {id: id, 'class': 'submission-row'}).hide().prependTo(table); |
| 169 | + if (table.find('>div').length >= {{ paginator.per_page }}) |
| 170 | + table.find('>div:last-child').hide('slow', function () { |
| 171 | + $(this).remove(); |
| 172 | + }); |
| 173 | + } |
| 174 | + if (force || !doing_ajax) { |
| 175 | + if (!force) doing_ajax = true; |
| 176 | + $.ajax({ |
| 177 | + url: '{{ url('submission_single_query') }}', |
| 178 | + data: {id: id, show_problem: show_problem} |
| 179 | + }).done(function (data) { |
| 180 | + var was_shown = row.is(':visible'); |
| 181 | + row.html(data); |
| 182 | + register_time(row.find('.time-with-rel')); |
| 183 | + if (!was_shown) { |
| 184 | + row.slideDown('slow'); |
| 185 | + } |
| 186 | + if (!force) |
| 187 | + setTimeout(function () { |
| 188 | + doing_ajax = false; |
| 189 | + }, 1000); |
| 190 | + }).fail(function () { |
| 191 | + console.log('Failed to update submission: ' + id); |
| 192 | + if (!force) doing_ajax = false; |
| 193 | + }); |
| 194 | + } |
| 195 | + }; |
145 | 196 |
|
146 |
| - var table = $('#submissions-table'); |
147 |
| - var statistics = $("#statistics-table"); |
148 |
| - var doing_ajax = false; |
149 |
| - var first = parseInt(table.find('>div:first-child').attr('id')); |
| 197 | + var stats_outdated = false; |
| 198 | + var last_stat_update = Date.now(); |
| 199 | + var stats_update_interval = {{ stats_update_interval|default(0) * 1000 }}; |
150 | 200 |
|
151 |
| - var update_submission = function (message, force) { |
152 |
| - if (language_filter.length && 'language' in message && |
153 |
| - language_filter.indexOf(message.language) == -1) |
154 |
| - return; |
155 |
| - if (status_filter.length && 'status' in message && |
156 |
| - status_filter.indexOf(message.status) == -1) |
157 |
| - return; |
158 |
| - var id = message.id; |
159 |
| - var row = table.find('div#' + id); |
160 |
| - if (row.length < 1) { |
161 |
| - if (id < first) |
| 201 | + function update_stats() { |
| 202 | + if (Date.now() - last_stat_update < stats_update_interval) |
162 | 203 | return;
|
163 |
| - first = id; |
164 |
| - row = $('<div>', {id: id, 'class': 'submission-row'}).hide().prependTo(table); |
165 |
| - if (table.find('>div').length >= {{ paginator.per_page }}) |
166 |
| - table.find('>div:last-child').hide('slow', function () { |
167 |
| - $(this).remove(); |
168 |
| - }); |
169 |
| - } |
170 |
| - if (force || !doing_ajax) { |
171 |
| - if (!force) doing_ajax = true; |
172 | 204 | $.ajax({
|
173 |
| - url: '{{ url('submission_single_query') }}', |
174 |
| - data: {id: id, show_problem: show_problem} |
| 205 | + url: '?results' |
175 | 206 | }).done(function (data) {
|
176 |
| - var was_shown = row.is(':visible'); |
177 |
| - row.html(data); |
178 |
| - register_time(row.find('.time-with-rel')); |
179 |
| - if (!was_shown) { |
180 |
| - row.slideDown('slow'); |
181 |
| - } |
182 |
| - if (!force) |
183 |
| - setTimeout(function () { |
184 |
| - doing_ajax = false; |
185 |
| - }, 1000); |
| 207 | + last_stat_update = Date.now(); |
| 208 | + stats_graph(data); |
186 | 209 | }).fail(function () {
|
187 |
| - console.log('Failed to update submission: ' + id); |
188 |
| - if (!force) doing_ajax = false; |
| 210 | + console.log('Failed to update statistics table!' + id); |
| 211 | + }).always(function () { |
| 212 | + stats_outdated = false; |
189 | 213 | });
|
190 | 214 | }
|
191 |
| - }; |
192 |
| - |
193 |
| - var stats_outdated = false; |
194 |
| - var last_stat_update = Date.now(); |
195 |
| - var stats_update_interval = {{ stats_update_interval|default(0) * 1000 }}; |
196 | 215 |
|
197 |
| - function update_stats() { |
198 |
| - if (Date.now() - last_stat_update < stats_update_interval) |
199 |
| - return; |
200 |
| - $.ajax({ |
201 |
| - url: '?results' |
202 |
| - }).done(function (data) { |
203 |
| - last_stat_update = Date.now(); |
204 |
| - stats_graph(data); |
205 |
| - }).fail(function () { |
206 |
| - console.log('Failed to update statistics table!' + id); |
207 |
| - }).always(function () { |
208 |
| - stats_outdated = false; |
| 216 | + $(window).on('dmoj:window-visible', function () { |
| 217 | + if (stats_outdated) |
| 218 | + update_stats(); |
209 | 219 | });
|
210 |
| - } |
211 |
| - |
212 |
| - $(window).on('dmoj:window-visible', function () { |
213 |
| - if (stats_outdated) |
214 |
| - update_stats(); |
215 |
| - }); |
216 | 220 |
|
217 |
| - var $body = $(document.body); |
218 |
| - var receiver = new EventReceiver( |
219 |
| - "{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}", |
220 |
| - ['submissions'], last_msg, function (message) { |
221 |
| - if (current_contest && message.contest != current_contest) |
222 |
| - return; |
223 |
| - if (dynamic_user_id && message.user != dynamic_user_id || |
224 |
| - dynamic_problem_id && message.problem != dynamic_problem_id) |
225 |
| - return; |
226 |
| - if (message.type == 'update-submission') { |
227 |
| - if (message.state == 'test-case' && $body.hasClass('window-hidden')) |
| 221 | + var $body = $(document.body); |
| 222 | + var receiver = new EventReceiver( |
| 223 | + "{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}", |
| 224 | + ['submissions'], last_msg, function (message) { |
| 225 | + if (current_contest && message.contest != current_contest) |
228 | 226 | return;
|
229 |
| - update_submission(message); |
230 |
| - } else if (message.type == 'done-submission') { |
231 |
| - update_submission(message, true); |
232 |
| - |
233 |
| - if (!statistics.length) return; |
234 |
| - if ($('body').hasClass('window-hidden')) |
235 |
| - return stats_outdated = true; |
236 |
| - update_stats(); |
| 227 | + if (dynamic_user_id && message.user != dynamic_user_id || |
| 228 | + dynamic_problem_id && message.problem != dynamic_problem_id) |
| 229 | + return; |
| 230 | + if (message.type == 'update-submission') { |
| 231 | + if (message.state == 'test-case' && $body.hasClass('window-hidden')) |
| 232 | + return; |
| 233 | + update_submission(message); |
| 234 | + } else if (message.type == 'done-submission') { |
| 235 | + update_submission(message, true); |
| 236 | + |
| 237 | + if (!statistics.length) return; |
| 238 | + if ($('body').hasClass('window-hidden')) |
| 239 | + return stats_outdated = true; |
| 240 | + update_stats(); |
| 241 | + } |
237 | 242 | }
|
238 |
| - } |
239 |
| - ); |
240 |
| - receiver.onwsclose = function (event) { |
241 |
| - if (event.code == 1001) { |
242 |
| - console.log('Navigated away'); |
243 |
| - return; |
244 |
| - } |
245 |
| - console.log('You probably should refresh?'); |
246 |
| - // $('.ws-closed').show().find('a').click(function () { |
247 |
| - // window.location.reload(); |
248 |
| - // }); |
249 |
| - }; |
250 |
| - return receiver; |
251 |
| - } |
252 |
| - </script> |
253 |
| - {% endcompress %} |
254 |
| - |
255 |
| - {% if dynamic_update and last_msg and not has_hidden_subtasks %} |
256 |
| - <script type="text/javascript"> |
257 |
| - $(function () { |
| 243 | + ); |
| 244 | + receiver.onwsclose = function (event) { |
| 245 | + if (event.code == 1001) { |
| 246 | + console.log('Navigated away'); |
| 247 | + return; |
| 248 | + } |
| 249 | + }; |
| 250 | + return receiver; |
| 251 | + } |
258 | 252 | load_dynamic_update({{last_msg}});
|
259 | 253 | });
|
260 | 254 | </script>
|
|
0 commit comments