Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Clients.Hive.Views/3.3/StateLog/StateLogGanttChartListView.cs @ 7728

Last change on this file since 7728 was 7728, checked in by ascheibe, 12 years ago

#1722 display statelog in the correct order and show slave id in tooltip

File size: 5.0 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.Drawing;
24using System.Linq;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27using HeuristicLab.Visualization.ChartControlsExtensions;
28
29namespace HeuristicLab.Clients.Hive.Views {
30  [View("StateLogGanttChartList View")]
31  [Content(typeof(StateLogListList), true)]
32  public sealed partial class StateLogGanttChartListView : ItemView {
33    public new StateLogListList Content {
34      get { return (StateLogListList)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public StateLogGanttChartListView() {
39      InitializeComponent();
40    }
41
42    protected override void DeregisterContentEvents() {
43      // Deregister your event handlers here
44      base.DeregisterContentEvents();
45    }
46
47    protected override void RegisterContentEvents() {
48      base.RegisterContentEvents();
49      // Register your event handlers here
50    }
51
52    protected override void OnContentChanged() {
53      base.OnContentChanged();
54      if (Content == null) {
55        ganttChart.Reset();
56      } else {
57        ganttChart.Reset();
58        SetupCategories(ganttChart);
59        if (Content.Count > 0) {
60          DateTime maxValue = Content.Max(x => x.Count > 0 ? x.Max(y => y.DateTime) : DateTime.MinValue);
61          DateTime minValue = Content.Min(x => x.Count > 0 ? x.Min(y => y.DateTime) : DateTime.MinValue);
62          DateTime upperLimit;
63          if (Content.All(x => x.Count > 0 ? (x.Last().State == TaskState.Finished || x.Last().State == TaskState.Failed || x.Last().State == TaskState.Aborted) : true)) {
64            upperLimit = DateTime.FromOADate(Math.Min(DateTime.Now.AddSeconds(10).ToOADate(), maxValue.AddSeconds(10).ToOADate()));
65          } else {
66            upperLimit = DateTime.Now;
67          }
68
69          if ((upperLimit - minValue) > TimeSpan.FromDays(1)) {
70            this.ganttChart.chart.Series[0].YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Date;
71          } else {
72            this.ganttChart.chart.Series[0].YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Time;
73          }
74
75          for (int i = Content.Count - 1; i >= 0; i--) {
76            for (int j = 0; j < Content[i].Count - 1; j++) {
77              if (Content[i][j].State != TaskState.Offline)
78                AddData(ganttChart, i.ToString(), Content[i][j], Content[i][j + 1], upperLimit);
79            }
80            if (Content[i].Count > 0) {
81              AddData(ganttChart, i.ToString(), Content[i][Content[i].Count - 1], null, upperLimit);
82            }
83          }
84        }
85      }
86    }
87
88    public static void SetupCategories(GanttChart ganttChart) {
89      ganttChart.AddCategory(TaskState.Offline.ToString(), Color.Gainsboro);
90      ganttChart.AddCategory(TaskState.Waiting.ToString(), Color.NavajoWhite);
91      ganttChart.AddCategory(TaskState.Paused.ToString(), Color.PaleVioletRed);
92      ganttChart.AddCategory(TaskState.Transferring.ToString(), Color.CornflowerBlue);
93      ganttChart.AddCategory(TaskState.Calculating.ToString(), Color.DarkGreen);
94      ganttChart.AddCategory(TaskState.Finished.ToString(), Color.White);
95      ganttChart.AddCategory(TaskState.Aborted.ToString(), Color.Orange);
96      ganttChart.AddCategory(TaskState.Failed.ToString(), Color.Red);
97    }
98
99    public static void AddData(GanttChart ganttChart, string name, StateLog from, StateLog to, DateTime upperLimit) {
100      DateTime until = to != null ? to.DateTime : upperLimit;
101      TimeSpan duration = until - from.DateTime;
102      string tooltip = string.Format("Task: {0} " + Environment.NewLine + "Task Id: {1}" + Environment.NewLine + "State: {2} " + Environment.NewLine + "Duration: {3} " + Environment.NewLine + "{4} - {5}" + Environment.NewLine, from.TaskName, from.TaskId, from.State, duration, from.DateTime, until);
103
104      if (to != null && to.SlaveId != null)
105        tooltip += "Slave: " + to.SlaveId;
106
107      if (!string.IsNullOrEmpty(from.Exception))
108        tooltip += Environment.NewLine + from.Exception;
109      ganttChart.AddData(name, from.State.ToString(), from.DateTime, until, tooltip, false);
110    }
111
112    protected override void SetEnabledStateOfControls() {
113      base.SetEnabledStateOfControls();
114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.