Changeset 9617 for branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/Controllers
- Timestamp:
- 06/12/13 15:10:06 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/Controllers/HomeController.cs
r9604 r9617 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Web.Helpers; 22 26 using System.Web.Mvc; 27 using HeuristicLab.Services.Hive.DataAccess; 28 using HeuristicLab.Services.Hive.Statistics.Models; 23 29 24 30 namespace HeuristicLab.Services.Hive.Statistics.Controllers { 25 31 public class HomeController : Controller { 26 32 public ActionResult Index() { 27 ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";33 OverallStatus result = null; 28 34 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); 30 56 } 31 57 … … 41 67 return View(); 42 68 } 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 } 43 97 } 44 98 }
Note: See TracChangeset
for help on using the changeset viewer.