Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Clients.Hive.Slave.Views/3.3/SlaveStats.cs @ 12747

Last change on this file since 12747 was 12009, checked in by ascheibe, 10 years ago

#2212 updated copyright year

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