Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.3/SlaveStats.cs @ 6734

Last change on this file since 6734 was 6734, checked in by ascheibe, 13 years ago

#1233 some minor improvements in the Slave UI and Administrator UI

File size: 6.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Windows.Forms;
24using System.Windows.Forms.DataVisualization.Charting;
25using HeuristicLab.Common;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28
29
30namespace HeuristicLab.Clients.Hive.SlaveCore.Views {
31
32  [View("HeuristicLab Slave Stats View")]
33  [Content(typeof(SlaveItem), IsDefaultView = false)]
34  public partial class SlaveStats : ItemView {
35    private SlaveDisplayStat lastSlaveDisplayStat;
36
37
38    public new SlaveItem Content {
39      get { return (SlaveItem)base.Content; }
40      set {
41        if (base.Content != value) {
42          base.Content = value;
43        }
44      }
45    }
46
47    public SlaveStats() {
48      InitializeComponent();
49      lblSlaveState.Text = SlaveDisplayStat.NoService.ToString();
50      lastSlaveDisplayStat = SlaveDisplayStat.NoService;
51      Content_SlaveDisplayStateChanged(this, new EventArgs<SlaveDisplayStat>(lastSlaveDisplayStat));
52    }
53
54    #region Register Content Events
55    protected override void DeregisterContentEvents() {
56      Content.SlaveStatusChanged -= new System.EventHandler<EventArgs<StatusCommons>>(Content_SlaveStatusChanged);
57      Content.SlaveDisplayStateChanged -= new EventHandler<EventArgs<SlaveDisplayStat>>(Content_SlaveDisplayStateChanged);
58      Content.CoreConnectionChanged -= new EventHandler<EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
59
60      base.DeregisterContentEvents();
61    }
62
63    protected override void RegisterContentEvents() {
64      base.RegisterContentEvents();
65
66      Content.SlaveStatusChanged += new System.EventHandler<EventArgs<StatusCommons>>(Content_SlaveStatusChanged);
67      Content.SlaveDisplayStateChanged += new EventHandler<EventArgs<SlaveDisplayStat>>(Content_SlaveDisplayStateChanged);
68      Content.CoreConnectionChanged += new EventHandler<EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
69    }
70    #endregion
71
72    protected override void OnContentChanged() {
73      base.OnContentChanged();
74    }
75
76    protected override void SetEnabledStateOfControls() {
77      base.SetEnabledStateOfControls();
78    }
79
80    #region Event Handlers
81    void Content_SlaveStatusChanged(object sender, EventArgs<StatusCommons> e) {
82      RenderJobChart(e.Value);
83      RenderCoreChart(e.Value);
84    }
85
86    void Content_SlaveDisplayStateChanged(object sender, EventArgs<SlaveDisplayStat> e) {
87      lblSlaveState.Text = e.Value.ToString();
88      lastSlaveDisplayStat = e.Value;
89    }
90
91    void Content_CoreConnectionChanged(object sender, EventArgs<CoreConnection> e) {
92
93    }
94    #endregion
95
96    private void RenderJobChart(StatusCommons status) {
97      jobChart.Series[0].Points.Clear();
98      jobChart.Series[1].Points.Clear();
99      jobChart.Series[2].Points.Clear();
100      jobChart.Series[3].Points.Clear();
101      jobChart.Series[4].Points.Clear();
102
103
104      DataPoint pJobs = new DataPoint(1, status.Jobs.Count);
105      DataPoint pJobsAborted = new DataPoint(2, status.JobsAborted);
106      DataPoint pJobsDone = new DataPoint(3, status.JobsFinished);
107      DataPoint pJobsFetched = new DataPoint(4, status.JobsFetched);
108      DataPoint pJobsFailed = new DataPoint(5, status.JobsFailed);
109
110      pJobs.LegendText = "Current jobs: " + status.Jobs.Count;
111      pJobs.Color = System.Drawing.Color.Yellow;
112      pJobs.ToolTip = pJobs.LegendText;
113      jobChart.Series[0].Color = System.Drawing.Color.Yellow;
114      jobChart.Series[0].LegendText = pJobs.LegendText;
115      jobChart.Series[0].Points.Add(pJobs);
116
117      pJobsAborted.LegendText = "Aborted jobs: " + status.JobsAborted;
118      pJobsAborted.Color = System.Drawing.Color.Orange;
119      pJobsAborted.ToolTip = pJobsAborted.LegendText;
120      jobChart.Series[1].Color = System.Drawing.Color.Orange;
121      jobChart.Series[1].LegendText = pJobsAborted.LegendText;
122      jobChart.Series[1].Points.Add(pJobsAborted);
123
124      pJobsDone.LegendText = "Finished jobs: " + status.JobsFinished;
125      pJobsDone.Color = System.Drawing.Color.Green;
126      pJobsDone.ToolTip = pJobsDone.LegendText;
127      jobChart.Series[2].Color = System.Drawing.Color.Green;
128      jobChart.Series[2].LegendText = pJobsDone.LegendText;
129      jobChart.Series[2].Points.Add(pJobsDone);
130
131      pJobsFetched.LegendText = "Fetched jobs: " + status.JobsFetched;
132      pJobsFetched.ToolTip = pJobsFetched.LegendText;
133      pJobsFetched.Color = System.Drawing.Color.Blue;
134      jobChart.Series[3].Color = System.Drawing.Color.Blue;
135      jobChart.Series[3].LegendText = pJobsFetched.LegendText;
136      jobChart.Series[3].Points.Add(pJobsFetched);
137
138      pJobsFailed.LegendText = "Failed jobs: " + status.JobsFailed;
139      pJobsFailed.ToolTip = pJobsFailed.LegendText;
140      pJobsFailed.Color = System.Drawing.Color.Red;
141      jobChart.Series[4].Color = System.Drawing.Color.Red;
142      jobChart.Series[4].LegendText = pJobsFailed.LegendText;
143      jobChart.Series[4].Points.Add(pJobsFailed);
144    }
145
146    private void RenderCoreChart(StatusCommons statusCommons) {
147      int usedCores = statusCommons.TotalCores - statusCommons.FreeCores;
148      DataPoint pFreeCores = new DataPoint(statusCommons.FreeCores, statusCommons.FreeCores);
149      DataPoint pUsedCores = new DataPoint(usedCores, usedCores);
150
151      coresChart.Series[0].Points.Clear();
152
153      pFreeCores.LegendText = "Free cores: " + statusCommons.FreeCores;
154      pFreeCores.Color = System.Drawing.Color.Green;
155      pUsedCores.LegendText = "Used cores: " + usedCores;
156      pUsedCores.Color = System.Drawing.Color.Red;
157
158      coresChart.Series[0].Points.Add(pFreeCores);
159      coresChart.Series[0].Points.Add(pUsedCores);
160    }
161  }
162}
Note: See TracBrowser for help on using the repository browser.