Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/12/13 15:10:06 (11 years ago)
Author:
pfleck
Message:

#2063:
Started integrating Hive statistics into statistics web project.
Added jqPlot library for charting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/Controllers/HomeController.cs

    r9604 r9617  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
     25using System.Web.Helpers;
    2226using System.Web.Mvc;
     27using HeuristicLab.Services.Hive.DataAccess;
     28using HeuristicLab.Services.Hive.Statistics.Models;
    2329
    2430namespace HeuristicLab.Services.Hive.Statistics.Controllers {
    2531  public class HomeController : Controller {
    2632    public ActionResult Index() {
    27       ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
     33      OverallStatus result = null;
    2834
    29       return View();
     35      using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString)) {
     36        var onlineSlaves = (from slave in db.Resources.OfType<Slave>()
     37                            where slave.SlaveState == SlaveState.Calculating || slave.SlaveState == SlaveState.Idle
     38                            select slave)
     39                           .ToList();
     40
     41        result = new OverallStatus {
     42          OverallCurrentlyAvailableCores = onlineSlaves.Sum(s => s.Cores ?? 0),
     43          CurrentlyAvailableCores = onlineSlaves.Where(s => s.IsAllowedToCalculate).Sum(s => s.Cores ?? 0),
     44          CurrentlyUsedCores = onlineSlaves.Sum(s => s.Cores ?? 0) - onlineSlaves.Sum(s => s.FreeCores ?? 0),
     45          CurrentlyJobsWaiting = db.Tasks.Count(x => x.State == TaskState.Waiting),
     46          OverallCpuUtilization = onlineSlaves.Any()
     47                                  ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2)
     48                                  : 0.0,
     49          AvailableCpuUtilization = onlineSlaves.Any(x => x.IsAllowedToCalculate)
     50                                    ? Math.Round(onlineSlaves.Where(x => x.IsAllowedToCalculate).Average(s => s.CpuUtilization), 2)
     51                                    : 0.0
     52        };
     53      }
     54
     55      return View(result);
    3056    }
    3157
     
    4167      return View();
    4268    }
     69
     70    public ActionResult Error() {
     71      throw new Exception();
     72    }
     73
     74    public ActionResult Test() {
     75      var data = new Dictionary<string, float>
     76        {
     77            {"test", 10.023f},
     78            {"test2", 20.020f},
     79            {"test3", 19.203f},
     80            {"test4", 4.039f},
     81            {"test5", 5.343f}
     82    };
     83
     84      var chart = new Chart(600, 400)
     85        .AddTitle("Testchart")
     86        .AddSeries(
     87          name: "13456",
     88          chartType: "Area",
     89          xValue: new[] { 1, 2, 3, 4, 5 },
     90          yValues: new[] { 10, 20, 35, 70, 50 }
     91        );
     92
     93      chart.Write("png");
     94
     95      return null;
     96    }
    4397  }
    4498}
Note: See TracChangeset for help on using the changeset viewer.