#region License Information
/* HeuristicLab
* Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Helpers;
using System.Web.Mvc;
using HeuristicLab.Services.Hive.DataAccess;
using HeuristicLab.Services.Hive.Statistics.Models;
namespace HeuristicLab.Services.Hive.Statistics.Controllers {
public class HomeController : Controller {
public ActionResult Index() {
OverallStatus result = null;
using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString)) {
var onlineSlaves = (from slave in db.Resources.OfType()
where slave.SlaveState == SlaveState.Calculating || slave.SlaveState == SlaveState.Idle
select slave)
.ToList();
result = new OverallStatus {
OverallCurrentlyAvailableCores = onlineSlaves.Sum(s => s.Cores ?? 0),
CurrentlyAvailableCores = onlineSlaves.Where(s => s.IsAllowedToCalculate).Sum(s => s.Cores ?? 0),
CurrentlyUsedCores = onlineSlaves.Sum(s => s.Cores ?? 0) - onlineSlaves.Sum(s => s.FreeCores ?? 0),
CurrentlyJobsWaiting = db.Tasks.Count(x => x.State == TaskState.Waiting),
OverallCpuUtilization = onlineSlaves.Any()
? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2)
: 0.0,
AvailableCpuUtilization = onlineSlaves.Any(x => x.IsAllowedToCalculate)
? Math.Round(onlineSlaves.Where(x => x.IsAllowedToCalculate).Average(s => s.CpuUtilization), 2)
: 0.0
};
}
return View(result);
}
public ActionResult About() {
ViewBag.Message = "Your app description page.";
return View();
}
public ActionResult Contact() {
ViewBag.Message = "Your contact page.";
return View();
}
public ActionResult Error() {
throw new Exception();
}
public ActionResult Test() {
var data = new Dictionary
{
{"test", 10.023f},
{"test2", 20.020f},
{"test3", 19.203f},
{"test4", 4.039f},
{"test5", 5.343f}
};
var chart = new Chart(600, 400)
.AddTitle("Testchart")
.AddSeries(
name: "13456",
chartType: "Area",
xValue: new[] { 1, 2, 3, 4, 5 },
yValues: new[] { 10, 20, 35, 70, 50 }
);
chart.Write("png");
return null;
}
}
}