1 | @* HeuristicLab
|
---|
2 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
3 | *
|
---|
4 | * This file is part of HeuristicLab.
|
---|
5 | *
|
---|
6 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation, either version 3 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
18 | *@
|
---|
19 |
|
---|
20 | @helper AjaxDataRenderer()
|
---|
21 | {
|
---|
22 | <script>
|
---|
23 | var ajaxDataRenderer = function (url, plot, options) {
|
---|
24 | var ret = null;
|
---|
25 | $.ajax({
|
---|
26 | async: false,
|
---|
27 | url: url,
|
---|
28 | dataType: "json",
|
---|
29 | success: function (data) {
|
---|
30 | ret = data;
|
---|
31 | }
|
---|
32 | });
|
---|
33 | return ret;
|
---|
34 | };
|
---|
35 | </script>
|
---|
36 | }
|
---|
37 |
|
---|
38 | @helper LineChartTime(string destinationTag, string url, string title = "", double? minY = null, double? maxY = null, string axisYFormat = null)
|
---|
39 | {
|
---|
40 | <script>
|
---|
41 | var @(destinationTag)Plot = $.jqplot("@destinationTag", "@url", {
|
---|
42 | title: "@title",
|
---|
43 | highlighter: {
|
---|
44 | show: true,
|
---|
45 | sizeAdjust: 7.5
|
---|
46 | },
|
---|
47 | seriesDefaults: {
|
---|
48 | markerOptions: { show: false }
|
---|
49 | },
|
---|
50 | dataRenderer: ajaxDataRenderer,
|
---|
51 | axes: {
|
---|
52 | xaxis: {
|
---|
53 | renderer: $.jqplot.DateAxisRenderer,
|
---|
54 | pad: 0
|
---|
55 | },
|
---|
56 | yaxis: {
|
---|
57 | @if (axisYFormat != null)
|
---|
58 | {<text>
|
---|
59 | tickOptions: {
|
---|
60 | formatString: "@axisYFormat",
|
---|
61 | },
|
---|
62 | </text>}
|
---|
63 | autoscale: true,
|
---|
64 | pad: 0,
|
---|
65 | @if (minY != null)
|
---|
66 | {
|
---|
67 | @:min: @minY,
|
---|
68 | }
|
---|
69 | @if (maxY != null)
|
---|
70 | {
|
---|
71 | @:max: @maxY,
|
---|
72 | }
|
---|
73 | },
|
---|
74 | },
|
---|
75 | gridPadding: { left: 50, right: 10 },
|
---|
76 | cursor: {
|
---|
77 | show: true,
|
---|
78 | showTooltip: false,
|
---|
79 | zoom: true,
|
---|
80 | clickReset: false,
|
---|
81 | dblClickReset: false,
|
---|
82 | constrainZoomTo: 'x'
|
---|
83 | }
|
---|
84 | });
|
---|
85 |
|
---|
86 | @(destinationTag)Plot.replot({ resetAxes: true });
|
---|
87 |
|
---|
88 | $('#@destinationTag').contextmenu(function() {
|
---|
89 | @(destinationTag)Plot.resetZoom();
|
---|
90 | @(destinationTag)Plot.replot({ resetAxes: true });
|
---|
91 | return false;
|
---|
92 | });
|
---|
93 |
|
---|
94 | $(window).resize(function() {
|
---|
95 | @(destinationTag)Plot.replot({ resetAxes: true });
|
---|
96 | });
|
---|
97 | </script>
|
---|
98 | }
|
---|
99 |
|
---|
100 | @helper RefreshChart(string destinationTag, string url, string startDateVar, string endDateVar)
|
---|
101 | {
|
---|
102 | <text>
|
---|
103 | $.ajax({url: "@(new HtmlString(url))?start=" + @startDateVar + "&end=" + @endDateVar, datatype: "json", success: function(result) {
|
---|
104 | for (var i = 0; i < result.length; i++) {
|
---|
105 | @(destinationTag)Plot.series[i].data = result[i];
|
---|
106 | }
|
---|
107 | @(destinationTag)Plot.replot({ resetAxes: true })
|
---|
108 | }});
|
---|
109 | </text>
|
---|
110 | }
|
---|
111 |
|
---|
112 | @helper TasksForUser(string container, string destinationTag, string pageUrl, string taskUrl, string functionName, string userName, string limit, string startDate = null, string endDate = null, string jobId=null, string taskState=null, string pageNumber=null)
|
---|
113 | {
|
---|
114 | <text>
|
---|
115 | var GetRequest = "?userName=" + @(userName) + "&limit=" + @(limit);
|
---|
116 | @if(startDate!=null) {
|
---|
117 | @:if(@(startDate)!=null) {
|
---|
118 | @:GetRequest += "&start=" + @startDate;
|
---|
119 | @:}
|
---|
120 | }
|
---|
121 | @if(endDate!=null) {
|
---|
122 | @:if(@(endDate)!=null) {
|
---|
123 | @:GetRequest += "&end=" + @endDate;
|
---|
124 | @:}
|
---|
125 | }
|
---|
126 | @if(jobId!=null) {
|
---|
127 | @:if(@(jobId)!=null) {
|
---|
128 | @:GetRequest += "&jobId=" + @jobId;
|
---|
129 | @:}
|
---|
130 | }
|
---|
131 | @if(taskState!=null) {
|
---|
132 | @:if(@(taskState)!=null) {
|
---|
133 | @:GetRequest += "&taskState=" + @taskState;
|
---|
134 | @:}
|
---|
135 | }
|
---|
136 | $.ajax({async: false, url: "@(new HtmlString(pageUrl))" + GetRequest, datatype: "json", success: function(result) {
|
---|
137 | if(result > 1) {
|
---|
138 | $("#@container").append('<label class="pageTitle">Page: </label>')
|
---|
139 | for(var i=0; i < result; i++) {
|
---|
140 | $("#" + "@container").append('<a id="Page' + (i + 1) + '" class="page">' + (i + 1) + '</a>')
|
---|
141 | }
|
---|
142 | if(@pageNumber != null) {
|
---|
143 | $("#Page" + @pageNumber).css('color','#F7921D');
|
---|
144 | }
|
---|
145 | else {
|
---|
146 | $("#Page1").css('color','#F7921D');
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }});
|
---|
150 | @if(pageNumber!=null) {
|
---|
151 | @:if(@(pageNumber)!=null) {
|
---|
152 | @:GetRequest += "¤tPage=" + @pageNumber;
|
---|
153 | @:}
|
---|
154 | }
|
---|
155 | $.ajax({url: "@(new HtmlString(taskUrl))" + GetRequest, datatype: "json", success: function(result) {
|
---|
156 | if(result.Key.length==0) {
|
---|
157 | $("#@container").append(
|
---|
158 | '<section class="chartContainer"><h1 class="title">' + @userName + ' has no tasks for the specified filters!</h1></section>'
|
---|
159 | )
|
---|
160 | }
|
---|
161 | var waitTime;
|
---|
162 | var transferTime;
|
---|
163 | var runTime;
|
---|
164 | var seriesDescriptions = ["Time waiting","Time transferring","Time calculating"];
|
---|
165 |
|
---|
166 | //Globally accesible, for use when resizing, eliminates extra DB request
|
---|
167 | window["numberTasks"] = result.Key.length;
|
---|
168 |
|
---|
169 | //Set display of all errors to none, errors matching the tasks will be reset below
|
---|
170 | $(".errorContainer, .errorTitle, .errorTask, .errorMessage").css('display','none');
|
---|
171 |
|
---|
172 | //For each result create a seperate collapsable section with a chart and info label
|
---|
173 | for(var i = 0; i < result.Key.length; i++){
|
---|
174 | $("#" + "@container").append(
|
---|
175 | '<section class="chartContainer"><h1 class="title" id="' + result.Key[i] + '">Task ' + result.Key[i] +
|
---|
176 | '</h1><button class="collapse" onclick="collapseSection(this)">+</button><div id="@(destinationTag)' + i +
|
---|
177 | '"></div><label id="@(destinationTag)' + i + 'Info"></label></section>'
|
---|
178 | )
|
---|
179 | $(".errorTask").each(function() {
|
---|
180 | if($(this).html()==result.Key[i]) {
|
---|
181 | $("#" + result.Key[i]).css("color","red");
|
---|
182 | $("#" + result.Key[i]).append(" - ERROR");
|
---|
183 | $(".errorContainer, .errorTitle, .underline").css('display','inline-block');
|
---|
184 | $(this).css('display','inline-block');
|
---|
185 | $(this).next().css('display','inline-block');
|
---|
186 | }
|
---|
187 | });
|
---|
188 | waitTime = [result.Value[0][i]];
|
---|
189 | transferTime = [result.Value[1][i]];
|
---|
190 | runTime = [result.Value[2][i]];
|
---|
191 | window["@(destinationTag)Plot" + i] = $.jqplot("@destinationTag" + i, [waitTime,transferTime,runTime], {
|
---|
192 | seriesDefaults:{
|
---|
193 | renderer:$.jqplot.BarRenderer,
|
---|
194 | shadowAngle: 135,
|
---|
195 | pointLabels: {show: true, formatString: '%.3f'}
|
---|
196 | },
|
---|
197 | series:[
|
---|
198 | {label:'Waiting'},
|
---|
199 | {label:'Transferring'},
|
---|
200 | {label:'Calculating'}
|
---|
201 | ],
|
---|
202 | legend: {
|
---|
203 | show: true,
|
---|
204 | location: 'e',
|
---|
205 | placement: 'outside'
|
---|
206 | },
|
---|
207 | axes: {
|
---|
208 | xaxis: {
|
---|
209 | renderer: $.jqplot.CategoryAxisRenderer,
|
---|
210 | showLabel: false,
|
---|
211 | pad: 0
|
---|
212 | },
|
---|
213 | yaxis: {
|
---|
214 | pad: 0
|
---|
215 | }
|
---|
216 | },
|
---|
217 | cursor: {
|
---|
218 | showTooltip: false
|
---|
219 | }
|
---|
220 | });
|
---|
221 | /* Bind a datalistener to each chart and display details of clicked
|
---|
222 | upon data in the label below the chart */
|
---|
223 | $("#" + "@(destinationTag)" + i).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) {
|
---|
224 | $("#" + $(this).attr('id') + "Info").html(seriesDescriptions[seriesIndex] + ': ' + data[1]);
|
---|
225 | });
|
---|
226 |
|
---|
227 | window["@(destinationTag)Plot" + i].replot({ resetAxes: true });
|
---|
228 |
|
---|
229 | $('#@destinationTag' + i).contextmenu(function() {
|
---|
230 | window["@(destinationTag)Plot" + i].resetZoom();
|
---|
231 | window["@(destinationTag)Plot" + i].replot({ resetAxes: true });
|
---|
232 | return false;
|
---|
233 | });
|
---|
234 |
|
---|
235 | collapsedByDefault(document.getElementById("@(destinationTag)" + i));
|
---|
236 | }
|
---|
237 | }});
|
---|
238 |
|
---|
239 | $(".page").click(function () {
|
---|
240 | pageNumber = $(this).html();
|
---|
241 | @(functionName)();
|
---|
242 | });
|
---|
243 | </text>
|
---|
244 | }
|
---|
245 |
|
---|
246 | @helper ResizeTasks(string destinationTag)
|
---|
247 | {
|
---|
248 | <text>
|
---|
249 | $(window).resize(function() {
|
---|
250 | for(var i = 0; i < numberTasks; i++) {
|
---|
251 | $.each(window[ "@(destinationTag)Plot" + i].series, function(index, series) {
|
---|
252 | series.barWidth = undefined;
|
---|
253 | });
|
---|
254 | window["@(destinationTag)Plot" + i].replot({ resetAxes: true });
|
---|
255 | }
|
---|
256 | });
|
---|
257 | </text>
|
---|
258 | }
|
---|
259 |
|
---|
260 | @helper SetStreamingProperties(int refresh, int chartLength, int upperY) {
|
---|
261 | <text>
|
---|
262 | //Refresh time (in millisec)
|
---|
263 | var refreshRate = @(refresh);
|
---|
264 | //Number of data points on chart
|
---|
265 | var chartSize = @(chartLength);
|
---|
266 | //Amount to add to max Y value
|
---|
267 | var upperYBuffer = @(upperY);
|
---|
268 |
|
---|
269 | //Used to return a string containing the names of the series
|
---|
270 | //to be used in plot creation
|
---|
271 | function getSeries(numberData,dataName){
|
---|
272 | var result = "[";
|
---|
273 | for(i=0; i < numberData; i++) {
|
---|
274 | if(i < numberData -1) {
|
---|
275 | result += dataName + i + ",";
|
---|
276 | }
|
---|
277 | else {
|
---|
278 | result += dataName + i + "]";
|
---|
279 | }
|
---|
280 | }
|
---|
281 | return result;
|
---|
282 | }
|
---|
283 | </text>
|
---|
284 | }
|
---|
285 |
|
---|
286 | @helper CreateStreamChart(string dataName, string destinationTag, string url, string title, string format = null, double? maxY = null) {
|
---|
287 | <text>
|
---|
288 | //Get current time, used to create initial values
|
---|
289 | var @(dataName)CurrentDate = (new Date()).getTime();
|
---|
290 |
|
---|
291 | var @(dataName)Data = [];
|
---|
292 | var @(dataName)CurrentValue = [];
|
---|
293 |
|
---|
294 | //Get the most recent value(s) from the given URL
|
---|
295 | $.ajax({
|
---|
296 | async: false, url: '@(url)', datatype: "json", success: function (result) {
|
---|
297 | for(i = 0; i < result.length; i++) {
|
---|
298 | @(dataName)CurrentValue[i] = result[i];
|
---|
299 | }
|
---|
300 | }
|
---|
301 | });
|
---|
302 |
|
---|
303 | //Create a chartSize worth of data using CurrentDate and CurrentValue
|
---|
304 | //for each CurrentValue
|
---|
305 | for(i = 0; i < @(dataName)CurrentValue.length; i++) {
|
---|
306 | window["@(dataName)Data" + i] = [];
|
---|
307 | for (j = 0; j < chartSize; j++) {
|
---|
308 | window[ "@(dataName)Data" + i].push([@(dataName)CurrentDate - (chartSize - 1 - j) * refreshRate, @(dataName)CurrentValue[i]]);
|
---|
309 | }
|
---|
310 | }
|
---|
311 |
|
---|
312 | //Options for the chart to be created
|
---|
313 | var @(destinationTag)PlotOptions = {
|
---|
314 | title: "@title",
|
---|
315 | axes: {
|
---|
316 | xaxis: {
|
---|
317 | numberTicks: 4,
|
---|
318 | renderer: $.jqplot.DateAxisRenderer,
|
---|
319 | tickOptions: { formatString: '%H:%M:%S' },
|
---|
320 | min: window["@(dataName)Data" + 0][0][0],
|
---|
321 | max: window["@(dataName)Data" + 0][window["@(dataName)Data" + 0].length - 1][0]
|
---|
322 | },
|
---|
323 | yaxis: {
|
---|
324 | @if (format != null)
|
---|
325 | {<text>
|
---|
326 | tickOptions: {
|
---|
327 | formatString: "@format",
|
---|
328 | },
|
---|
329 | </text>}
|
---|
330 | min: 0,
|
---|
331 | @if (maxY != null) {
|
---|
332 | @:max: @maxY,
|
---|
333 | }
|
---|
334 | else{
|
---|
335 | @:max: window["@(dataName)Data" + 0][window["@(dataName)Data" + 0].length - 1][1] + upperYBuffer,
|
---|
336 | }
|
---|
337 | numberTicks: 6
|
---|
338 | }
|
---|
339 | },
|
---|
340 | seriesDefaults: {
|
---|
341 | rendererOptions: { smooth: true },
|
---|
342 | markerOptions: {
|
---|
343 | show: false
|
---|
344 | }
|
---|
345 | }
|
---|
346 | };
|
---|
347 |
|
---|
348 | //Declares the jqPlot variable, evals the string of series returned
|
---|
349 | //from getSeries which allows for any number of series
|
---|
350 | window[ "@(destinationTag)Plot"] = $.jqplot('@destinationTag', eval(getSeries(@(dataName)CurrentValue.length,"@(dataName)Data")), @(destinationTag)PlotOptions);
|
---|
351 | </text>
|
---|
352 | }
|
---|
353 |
|
---|
354 | @helper UpdateStreamChart(string dataName, string destinationTag, string url, string fixedY = null)
|
---|
355 | {
|
---|
356 | <text>
|
---|
357 | //If the data is beyond chartSize use shift to trim one off the end
|
---|
358 | for(i = 0; i < @(dataName)CurrentValue.length; i++) {
|
---|
359 | if (window["@(dataName)Data" + i].length > chartSize - 1) {
|
---|
360 | window["@(dataName)Data" + i].shift();
|
---|
361 | }
|
---|
362 | }
|
---|
363 |
|
---|
364 | //Get the up-to-date data, each result assigned to it's own array
|
---|
365 | $.ajax({
|
---|
366 | async: false, url: '@(url)', datatype: "json", success: function (result) {
|
---|
367 | for(i = 0; i < result.length; i++) {
|
---|
368 | window[ "@(dataName)Data" + i].push([(new Date()).getTime(), result[i]]);
|
---|
369 | }
|
---|
370 | }
|
---|
371 | });
|
---|
372 |
|
---|
373 | //If the plot exists currently destroy it
|
---|
374 | if ( @(destinationTag)Plot) {
|
---|
375 | @(destinationTag)Plot.destroy();
|
---|
376 | }
|
---|
377 |
|
---|
378 | //Assign series
|
---|
379 | for(i = 0; i < @(dataName)CurrentValue.length; i++) {
|
---|
380 | @(destinationTag)Plot.series[i].data = window["@(dataName)Data" + i];
|
---|
381 | }
|
---|
382 |
|
---|
383 | //Recalculate x and possibly y axis max and mins
|
---|
384 | @(destinationTag)PlotOptions.axes.xaxis.min = window["@(dataName)Data" + 0][0][0];
|
---|
385 | @(destinationTag)PlotOptions.axes.xaxis.max = window["@(dataName)Data" + 0][window["@(dataName)Data" + 0].length - 1][0];
|
---|
386 | @if (fixedY == null) {
|
---|
387 | @:@(destinationTag)PlotOptions.axes.yaxis.max = window["@(dataName)Data" + 0][window["@(dataName)Data" + 0].length - 1][1] + upperYBuffer;
|
---|
388 | }
|
---|
389 |
|
---|
390 | //Re-assigns the jqPlot variable, evals the string of series returned
|
---|
391 | //from getSeries which allows for any number of series
|
---|
392 | @(destinationTag)Plot = $.jqplot('@destinationTag', eval(getSeries(@(dataName)CurrentValue.length,"@(dataName)Data")), @(destinationTag)PlotOptions);
|
---|
393 | </text>
|
---|
394 | } |
---|