Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/Controllers/HomeController.cs @ 9617

Last change on this file since 9617 was 9617, checked in by pfleck, 11 years ago

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

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Web.Helpers;
26using System.Web.Mvc;
27using HeuristicLab.Services.Hive.DataAccess;
28using HeuristicLab.Services.Hive.Statistics.Models;
29
30namespace HeuristicLab.Services.Hive.Statistics.Controllers {
31  public class HomeController : Controller {
32    public ActionResult Index() {
33      OverallStatus result = null;
34
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);
56    }
57
58    public ActionResult About() {
59      ViewBag.Message = "Your app description page.";
60
61      return View();
62    }
63
64    public ActionResult Contact() {
65      ViewBag.Message = "Your contact page.";
66
67      return View();
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    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.