Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/30/14 16:41:08 (10 years ago)
Author:
mroscoe
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/App_Code/ChartHelper.cshtml

    r11222 r11246  
    3636}
    3737
    38 @helper LineChartTime(string destinationTag, string url, string title = "", double? minY = null, double? maxY = null, string axisYFormat = null) {
     38@helper LineChartTime(string destinationTag, string url, string title = "", double? minY = null, double? maxY = null, string axisYFormat = null)
     39{
    3940  <script>
    4041    var @(destinationTag)Plot = $.jqplot("@destinationTag", "@url", {
     
    8990}
    9091
    91 @helper RefreshChart(string destinationTag, string url, string startDate, string endDate, double? minY=null, double? maxY=null) {
     92@helper RefreshChart(string destinationTag, string url, string startDate, string endDate, double? minY = null, double? maxY = null)
     93{
    9294  <text>
    9395  $.ajax({url: "@(new HtmlString(url))?start=" + @startDate + "&end=" + @endDate, datatype: "json", success: function(result) {
     
    9799    //Resets only the xaxis, still need to resize y with given min/max
    98100    @(destinationTag)Plot.replot({resetAxes:true});
    99     @if(minY != null) {
     101    @if (minY != null)
     102    {
    100103      //If min Y was provided set the plot's min Y value
    101104      @:@(destinationTag)Plot.axes.yaxis.min = @minY;
    102105    }
    103     @if(maxY != null) {
     106    @if (maxY != null)
     107    {
    104108      //If max Y was provided set the plot's max Y value
    105109      @:@(destinationTag)Plot.axes.yaxis.max = @maxY;
     
    162166  <text>
    163167    if(@(records).length > @limit) {
    164       $("#@container").append('<label class="pageTitle">Page: </label>')
     168      var appendPages = '<section class="pageContainer"><label class="pageTitle">Page: </label>';
    165169      var pages = Math.floor(@(records).length/@(limit)) + 1;
    166170      for(var i=0; i < pages; i++) {
    167         $("#" + "@container").append('<a id="@(container)Page' + (i + 1) + '" class="page">' + (i + 1) + '</a>')
    168       }
     171        appendPages += '<a id="@(container)Page' + (i + 1) + '" class="page">' + (i + 1) + '</a>';
     172      }
     173      appendPages += '</section>';
     174      $("#@container").append(appendPages);
    169175      if(@currentPage != null) {
    170176        $("#@(container)Page" + @currentPage).css('color','#F7921D');
     
    190196}
    191197
    192 @helper TasksForUser(string destinationTag, string url, string functionName, string userName, string limit, string startDate = null, string endDate = null, string jobId = null, string taskState = null, string pageNumber = null)
     198@helper TaskContainers(string destinationTag, string url, string functionName, string userName, string limit, string startDate = null, string endDate = null, string jobId = null, string taskState = null, string pageNumber = null)
    193199{
    194200  <text>
     
    235241      }
    236242      else {
    237         var waitTime;
    238         var transferTime;
    239         var runTime;
    240         var seriesDescriptions = ["Time waiting","Time transferring","Time calculating"];
    241 
    242243        //Checks if multipage display, if it is then trims results to
    243244        //the results for the page to be displayed
    244245        @ChartHelper.NumberPages("result", limit, destinationTag, functionName, pageNumber)
    245246
    246         //Globally accesible, for use when resizing, eliminates extra DB request
    247         window["numberTasks"] = result.length;
    248 
    249247        //Set display of all errors to none, errors matching the tasks will be reset below
    250248        $("#@(destinationTag)").find(".errorContainer, .errorTitle, .errorTask, .errorMessage").css('display','none');
     
    252250        //Set variable for tracking jobId and open first job grouping
    253251        var currentJob = result[0].JobId;
    254         $("#@(destinationTag)").append('<section class="jobTaskGroup" id="' + result[0].JobId + '"><h1>' + result[0].JobName + '</h1></section>');
    255252
    256253        //For each result create a seperate collapsable section with a chart and info label
    257254        for(var i = 0; i < result.length; i++){
    258           if(currentJob != result[i].JobId) {
    259             $("#@(destinationTag)").append('<section class="jobTaskGroup" id="' + result[i].JobId + '"><h1>' + result[i].JobName + '</h1></section>');
     255          if(currentJob != result[i].JobId || i == 0) {
     256            $("#@(destinationTag)").append(
     257              '<section class="jobTaskGroup" id="' + result[i].JobId + '">' +
     258                '<h1>' + result[i].JobName + '</h1>' +
     259                '<section class="chartContainer">' +
     260                  '<h1 class="title" id="@(destinationTag)' + result[i].JobId + 'PlotTitle">Job Overview - ' + result[i].JobName + '</h1>' +
     261                  '<button class="collapse" onclick="LoadJob(this)">+</button>' +
     262                  '<div id="@(destinationTag)JobOverviewPlot' + i + '"></div>' +
     263                  '<label id="@(destinationTag)JobOverviewPlotInfo' + i + '"></label>' +
     264                '</section>' +
     265              '</section>'
     266            );
     267            CollapsedByDefault(document.getElementById("@(destinationTag)JobOverviewPlot" + i));
    260268            currentJob = result[i].JobId;
    261269          }
     
    263271            '<section class="chartContainer">' +
    264272              '<h1 class="title" id="@(destinationTag)' + result[i].TaskId + 'PlotTitle">Task ' + result[i].TaskId + '</h1>' +
    265               '<button class="collapse" onclick="CollapseSection(this)">+</button>' +
     273              '<button class="collapse" onclick="LoadTask(this)">+</button>' +
    266274              '<div id="@(destinationTag)Plot' + i + '"></div>' +
    267275              '<label id="@(destinationTag)PlotInfo' + i + '"></label>' +
    268276              '<a id="' + result[i].TaskId + '" class="moreInfo" onclick="MoreTaskInfo(this)">More Info</a>' +
    269277            '</section>'
    270           )
     278          );
    271279          //Re-enables the error display if any of the tasks on the page have Ids matching
    272280          //those of errors
     
    280288            }
    281289          });
    282           waitTime = [result[i].TotalWaiting];
    283           transferTime = [result[i].TotalTransfer];
    284           runTime = [result[i].TotalRuntime];
    285           window["@(destinationTag)Plot" + i] = $.jqplot("@(destinationTag)Plot" + i, [waitTime,transferTime,runTime], {
     290          CollapsedByDefault(document.getElementById("@(destinationTag)Plot" + i));
     291        }
     292      }
     293    }});
     294  </text>
     295}
     296
     297@helper LoadJob(string url)
     298{
     299  <text>
     300    function LoadJob(caller) {
     301      CheckFilters();
     302      if($(caller).next().html()=="") {
     303        var plotName = $(caller).next().attr('id');
     304        //Set current job id
     305        var jobId = $(caller).parent().parent().attr('id');
     306        var GetRequest = "?jobId=" + jobId;
     307
     308        $.ajax({ async: false, url: "@(new HtmlString(url))" + GetRequest, datatype: "json", success: function(result) {
     309          CollapseSection(caller);
     310          var seriesDescription = ['Waiting','Transferring','Calculating','Finished','Error'];
     311          window[plotName] = $.jqplot(plotName, [[result.Wait],[result.Transfer],[result.Calculate],[result.Finish],[result.Error]], {
    286312            seriesDefaults:{
    287313              renderer:$.jqplot.BarRenderer,
    288314              shadowAngle: 135,
    289               pointLabels: {show: true, formatString: '%.3f'}
     315              pointLabels: {show: true, formatString: '%.0f'}
    290316            },
    291317            series:[
    292               {label:'Waiting'},
    293               {label:'Transferring'},
    294               {label:'Calculating'}
     318              {label:seriesDescription[0]},
     319              {label:seriesDescription[1]},
     320              {label:seriesDescription[2]},
     321              {label:seriesDescription[3]},
     322              {label:seriesDescription[4]}
    295323            ],
    296324            legend: {
     
    306334              },
    307335              yaxis: {
    308                 pad: 0
     336                padMax: 1.5
    309337              }
    310338            },
     
    315343          /* Bind a datalistener to each chart and display details of clicked
    316344            upon data in the label below the chart */
    317           $("#" + "@(destinationTag)Plot" + i).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) {
    318             $(this).next("label").html(seriesDescriptions[seriesIndex] + ": " + data[1]);
     345          $("#" + plotName).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) {
     346            $(this).next("label").html("Tasks " + seriesDescription[seriesIndex] + ": " + data[1]);
    319347          });
    320 
    321           CollapsedByDefault(document.getElementById("@(destinationTag)Plot" + i));
    322         }
    323       }
    324     }});
     348        }});
     349      }
     350      else {
     351        CollapseSection(caller);
     352      }
     353    }
     354  </text>
     355}
     356
     357@helper LoadTask(string url)
     358{
     359  <text>
     360    function LoadTask(caller) {
     361      CheckFilters();
     362      if($(caller).next().html()=="") {
     363        var plotName = $(caller).next().attr('id');
     364        //Set current slave id
     365        var currentTask = $(caller).siblings('a.moreInfo').attr('id');
     366        var GetRequest = "?taskId=" + currentTask;
     367
     368        $.ajax({ async: false, url: "@(new HtmlString(url))" + GetRequest, datatype: "json", success: function(result) {
     369          var waitTime;
     370          var transferTime;
     371          var runTime;
     372          var seriesDescriptions = ["Time waiting","Time transferring","Time calculating"];
     373          CollapseSection(caller);
     374          for(i = 0; i < result.length; i++) {
     375            waitTime = [result[i].TotalWaiting];
     376            transferTime = [result[i].TotalTransfer];
     377            runTime = [result[i].TotalRuntime];
     378            window[plotName] = $.jqplot(plotName, [waitTime,transferTime,runTime], {
     379              seriesDefaults:{
     380                renderer:$.jqplot.BarRenderer,
     381                shadowAngle: 135,
     382                pointLabels: {show: true, formatString: '%.3f'}
     383              },
     384              series:[
     385                {label:'Waiting'},
     386                {label:'Transferring'},
     387                {label:'Calculating'}
     388              ],
     389              legend: {
     390                show: true,
     391                location: 'e',
     392                placement: 'outside'
     393              },
     394              axes: {
     395                xaxis: {
     396                  renderer: $.jqplot.CategoryAxisRenderer,
     397                  showLabel: false,
     398                  pad: 0
     399                },
     400                yaxis: {
     401                  pad: 0
     402                }
     403              },
     404              cursor: {
     405                showTooltip: false
     406              }
     407            });
     408            /* Bind a datalistener to each chart and display details of clicked
     409              upon data in the label below the chart */
     410            $("#" + plotName).bind('jqplotDataClick', function (ev, seriesIndex, pointIndex, data) {
     411              $(this).next("label").html(seriesDescriptions[seriesIndex] + ": " + data[1].toFixed(4) + " seconds");
     412            });
     413          }
     414        }});
     415      }
     416      else {
     417        CollapseSection(caller);
     418      }
     419    }
    325420  </text>
    326421}
     
    467562}
    468563
    469 @helper SlaveInfoChart(string destinationTag, string url, string limit, bool singleSlave, string startDate = null, string endDate = null, string userName = null, string functionName = null, string pageNumber = null, string slaveId = null)
     564@helper SlaveContainers(string destinationTag, string url, string limit, bool singleSlave, string startDate = null, string endDate = null, string userName = null, string functionName = null, string pageNumber = null, string slaveId = null)
    470565{
    471566  <text>
     
    515610    @:}
    516611  }
    517   $.ajax({
    518     async: false, url: "@(new HtmlString(url))" + GetRequest, datatype: "json", success: function(result) {
    519 
    520     //Set chart names for use in creation below, must be set identically in
    521     //ResizeSlaves
     612  $.ajax({ async: false, url: "@(new HtmlString(url))" + GetRequest, datatype: "json", success: function(result) {
     613    //Set chart names for use in creation below, must be set identically in LoadSlave and ResizeSlaves
    522614    var slaveChartNames = ["TotalUsedCores","TotalUsedMemory","CPUUtilization"];
    523615
    524     var destTag = eval("@(destinationTag)");
    525     if(typeof eval("@(destinationTag)") != "string") {
    526       destTag = "@(destinationTag)";
     616    @if (!singleSlave) {
     617      @:$('#@(destinationTag)').html("");
     618
     619      //Checks if multipage display, if it is then trims results to
     620      //the results for the page to be displayed
     621      @ChartHelper.NumberPages("result", limit, destinationTag, functionName, pageNumber)
     622
     623     
     624      @:var destTag = "@(destinationTag)";
     625    }
     626    else {
     627      @:var destTag = @(destinationTag);
    527628    }
    528629
    529630    if(result.length == 0) {
    530       @if (!singleSlave) {
     631      @if (!singleSlave)
     632      {
    531633        @:$('#' + destTag).html("");
    532634      }
     
    537639      )
    538640    }
    539     else {
    540       var time = new Date();
    541 
    542       @if (!singleSlave)
     641
     642    for(i = 0; i < result.length; i++) {
     643      $('#' + destTag).append(
     644        '<section class="chartContainer">' +
     645          '<h1 class="title" id="' + destTag + result[i][0].SlaveID + 'PlotTitle">Slave ' + result[i][0].ClientName + '</h1>' +
     646          '<button class="collapse" onclick="LoadSlave(this)">+</button>' +
     647          '<div id="' + destTag + slaveChartNames[0] + 'Plot' + result[i][0].SlaveID + '"></div>' +
     648          '<div id="' + destTag + slaveChartNames[1] + 'Plot' + result[i][0].SlaveID + '"></div>' +
     649          '<div id="' + destTag + slaveChartNames[2] + 'Plot' + result[i][0].SlaveID + '"></div>' +
     650          '<a id="' + result[i][0].SlaveID + '" class="moreInfo" onclick="MoreSlaveInfo(this)">More Info</a>' +
     651        '</section>');
     652      for(k = 0; k < slaveChartNames.length; k++) {
     653        CollapsedByDefault(document.getElementById(destTag + slaveChartNames[k] + "Plot" + result[i][0].SlaveID));
     654      }
     655    }
     656  }});
     657  </text>
     658}
     659
     660@helper LoadSlave(string url, string limit, string startDate = null, string endDate = null, string userName = null, string pageNumber = null) {
     661  <text>
     662  function LoadSlave(caller) {
     663    CheckFilters();
     664    if($(caller).next().html()=="") {
     665      var destTag = $(caller).parent().parent().attr('id');
     666      //Set current slave id
     667      var currentSlave = $(caller).siblings('a.moreInfo').attr('id');
     668      var GetRequest = "?slaveId=" + currentSlave;
     669      @if (startDate != null)
    543670      {
    544         @:$('#' + destTag).html("");
    545 
    546         //Checks if multipage display, if it is then trims results to
    547         //the results for the page to be displayed
    548         @ChartHelper.NumberPages("result", limit, destinationTag, functionName, pageNumber)
    549       }
    550 
    551       for(i = 0; i < result.length; i++) {
     671        @:if(@(startDate)!=null) {
     672          @:GetRequest += "&start=" + @startDate;
     673        @:}
     674      }
     675      @if (endDate != null)
     676      {
     677        @:if(@(endDate)!=null) {
     678          @:GetRequest += "&end=" + @endDate;
     679        @:}
     680      }
     681      @if (userName != null)
     682      {
     683        @:if(@(userName)!=null) {
     684          @:GetRequest += "&userName=" + @userName;
     685        @:}
     686      }
     687      $.ajax({ async: false, url: "@(new HtmlString(url))" + GetRequest, datatype: "json", success: function(result) {
     688        //Set chart names for use in creation below, must be set identically in SlaveContainers and ResizeSlaves
     689        var slaveChartNames = ["TotalUsedCores","TotalUsedMemory","CPUUtilization"];
     690        CollapseSection(caller);
     691        var time = new Date();
    552692        var coreSeries = [];
    553693        coreSeries[0] = [];
     
    558698        var cpuSeries = [];
    559699        cpuSeries[0] = [];
    560         $('#' + destTag).append(
    561           '<section class="chartContainer">' +
    562             '<h1 class="title" id="' + destTag + result[i][0].SlaveID + 'PlotTitle">Slave ' + result[i][0].ClientName + '</h1>' +
    563             '<button class="collapse" onclick="CollapseSection(this)">+</button>' +
    564             '<div id="' + destTag + slaveChartNames[0] + 'Plot' + i + '"></div>' +
    565             '<div id="' + destTag + slaveChartNames[1] + 'Plot' + i + '"></div>' +
    566             '<div id="' + destTag + slaveChartNames[2] + 'Plot' + i + '"></div>' +
    567             '<a id="' + result[i][0].SlaveID + '" class="moreInfo" onclick="MoreSlaveInfo(this)">More Info</a>' +
    568           '</section>');
    569         for(j = 0; j < result[i].length; j++) {
    570           time.setTime(result[i][j].Time.replace(/\D/g,''));
    571           coreSeries[0].push([time.toUTCString(),result[i][j].TotalCores]);
    572           coreSeries[1].push([time.toUTCString(),result[i][j].UsedCores]);
    573           memorySeries[0].push([time.toUTCString(),(result[i][j].TotalMemory / 1000)]);
    574           memorySeries[1].push([time.toUTCString(),(result[i][j].UsedMemory / 1000)]);
    575           cpuSeries[0].push([time.toUTCString(),result[i][j].CPUUtilization]);
    576         }
    577         if(result[i].length > 1) {
    578           @ChartHelper.LineChartGivenSeries("destTag + slaveChartNames[0]", "i", "coreSeries", "Total/Used Cores")
    579           @ChartHelper.LineChartGivenSeries("destTag + slaveChartNames[1]", "i", "memorySeries", "Total/Used Memory", 0)
    580           @ChartHelper.LineChartGivenSeries("destTag + slaveChartNames[2]", "i", "cpuSeries", "CPU Utilization", 0, 100, "%.1f%%")
     700        for(i = 0; i < result.length; i++) {
     701          time.setTime(result[i].Time.replace(/\D/g,''));
     702          coreSeries[0].push([time.toUTCString(),result[i].TotalCores]);
     703          coreSeries[1].push([time.toUTCString(),result[i].UsedCores]);
     704          memorySeries[0].push([time.toUTCString(),(result[i].TotalMemory / 1000)]);
     705          memorySeries[1].push([time.toUTCString(),(result[i].UsedMemory / 1000)]);
     706          cpuSeries[0].push([time.toUTCString(),result[i].CPUUtilization]);
     707        }
     708        if(result.length > 1) {
     709          @ChartHelper.LineChartGivenSeries("destTag + slaveChartNames[0]", "currentSlave", "coreSeries", "Total/Used Cores")
     710          @ChartHelper.LineChartGivenSeries("destTag + slaveChartNames[1]", "currentSlave", "memorySeries", "Total/Used Memory", 0)
     711          @ChartHelper.LineChartGivenSeries("destTag + slaveChartNames[2]", "currentSlave", "cpuSeries", "CPU Utilization", 0, 100, "%.1f%%")
    581712        }
    582713        else {
    583           @ChartHelper.BarChartGivenSeries("destTag + slaveChartNames[0]", "i", "coreSeries", "Total/Used Cores")
    584           @ChartHelper.BarChartGivenSeries("destTag + slaveChartNames[1]", "i", "memorySeries", "Total/Used Memory", 0)
    585           @ChartHelper.BarChartGivenSeries("destTag + slaveChartNames[2]", "i", "cpuSeries", "CPU Utilization", 0, 100, "%.1f%%")
    586         }
    587         for(k = 0; k < slaveChartNames.length; k++) {
    588           CollapsedByDefault(document.getElementById(destTag + slaveChartNames[k] + "Plot" + i));
    589         }
    590       }
    591     }
    592   }});
     714          @ChartHelper.BarChartGivenSeries("destTag + slaveChartNames[0]", "currentSlave", "coreSeries", "Total/Used Cores")
     715          @ChartHelper.BarChartGivenSeries("destTag + slaveChartNames[1]", "currentSlave", "memorySeries", "Total/Used Memory", 0)
     716          @ChartHelper.BarChartGivenSeries("destTag + slaveChartNames[2]", "currentSlave", "cpuSeries", "CPU Utilization", 0, 100, "%.1f%%")
     717        }
     718      }});
     719    }
     720    else {
     721      CollapseSection(caller);
     722    }
     723  }
    593724  </text>
    594725}
     
    686817  </text>
    687818}
     819
     820@helper UserTasks(string url, string insertAfter, string taskState) {
     821  <text>
     822    var GetRequest = "?taskState=@(taskState)";
     823
     824    $.ajax({ async: false, url: "@(new HtmlString(url))" + GetRequest, datatype: "json", success: function(result) {
     825      if(result.length==0) {
     826        $("@(insertAfter)").after(
     827          '<section class="chartContainer">' +
     828            '<h1 class="title">No users currently have any tasks ' + @(taskState) + '!</h1>' +
     829          '</section>'
     830        )
     831      }
     832      else {
     833        $("@(insertAfter)").after(
     834          '<section class="chartContainer">' +
     835            '<h1 class="title" id="UserTask@(taskState)PlotTitle">@(taskState) Tasks</h1>' +
     836            '<button class="collapse" onclick="CollapseSection(this)">-</button>' +
     837            '<div id="UserTask@(taskState)Plot" class="noXTicks"></div>' +
     838          '</section>'
     839        );
     840      }
     841      var userTasks = [];
     842      var userNames = [];
     843      for (i=0; i < result.length; i++) {
     844        userTasks[i] = [result[i].Value];
     845        userNames[i] = { label: result[i].Key };
     846      }
     847      window["UserTask@(taskState)Plot"] = $.jqplot("UserTask@(taskState)Plot", userTasks, {
     848        title: "Users with @(taskState) Tasks",
     849        seriesDefaults:{
     850          renderer:$.jqplot.BarRenderer,
     851          shadowAngle: 135,
     852          pointLabels: {show: true, formatString: '%.3f'}
     853        },
     854        series: userNames,
     855        legend: {
     856          show: true,
     857          location: 'e',
     858          placement: 'outside'
     859        },
     860        axes: {
     861          xaxis: {
     862            renderer: $.jqplot.CategoryAxisRenderer,
     863            showTicks: false,
     864            pad: 0
     865          },
     866          yaxis: {
     867            padMax: 1.5
     868          }
     869        },
     870        cursor: {
     871          showTooltip: false
     872        }
     873      });
     874    }});
     875  </text>
     876}
Note: See TracChangeset for help on using the changeset viewer.