Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/18/13 09:47:03 (12 years ago)
Author:
ascheibe
Message:

#2031 added sorting for the chart analysis view

Location:
branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/ChartAnalysisView.cs

    r9353 r9377  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Drawing;
    2524using System.Linq;
    2625using System.Windows.Forms;
     
    3433  [View("RunCollection Chart Analysis View")]
    3534  [Content(typeof(RunCollection), false)]
    36   public sealed partial class RunCollectionStatisticalTabularView : ItemView {
    37     public RunCollectionStatisticalTabularView() {
     35  public sealed partial class ChartAnalysisView : ItemView {
     36    public new RunCollection Content {
     37      get { return (RunCollection)base.Content; }
     38      set { base.Content = value; }
     39    }
     40
     41    public override bool ReadOnly {
     42      get { return true; }
     43      set { /*not needed because results are always readonly */}
     44    }
     45
     46    public ChartAnalysisView() {
    3847      InitializeComponent();
    3948      stringConvertibleMatrixView.DataGridView.RowHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(DataGridView_RowHeaderMouseDoubleClick);
    40     }
    41 
    42     void DataGridView_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) {
    43       if (e.RowIndex >= 0) {
    44         IRun run = Content.ElementAt(e.RowIndex);
    45         IContentView view = MainFormManager.MainForm.ShowContent(run);
    46         if (view != null) {
    47           view.ReadOnly = this.ReadOnly;
    48           view.Locked = this.Locked;
    49         }
    50       }
    5149    }
    5250
     
    6361    }
    6462
    65     public new RunCollection Content {
    66       get { return (RunCollection)base.Content; }
    67       set { base.Content = value; }
    68     }
    69 
    70     public override bool ReadOnly {
    71       get { return true; }
    72       set { /*not needed because results are always readonly */}
    73     }
    74 
     63    #region Content Events
    7564    protected override void OnContentChanged() {
    7665      base.OnContentChanged();
     
    8372    }
    8473
    85     #region events
    8674    protected override void RegisterContentEvents() {
    8775      base.RegisterContentEvents();
     
    140128    #endregion
    141129
     130    #region Events
     131    void DataGridView_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) {
     132      if (e.RowIndex >= 0) {
     133        IRun run = Content.ElementAt(stringConvertibleMatrixView.GetRowIndex(e.RowIndex));
     134        IContentView view = MainFormManager.MainForm.ShowContent(run);
     135        if (view != null) {
     136          view.ReadOnly = this.ReadOnly;
     137          view.Locked = this.Locked;
     138        }
     139      }
     140    }
     141
     142    private void dataTableComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     143      UpdateDataRowComboBox();
     144    }
     145
     146    private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     147      RebuildCombinedDataTable();
     148    }
     149
     150    private void addLineToChart_Click(object sender, EventArgs e) {
     151      string resultName = (string)dataTableComboBox.SelectedItem;
     152      string rowName = (string)dataRowComboBox.SelectedItem;
     153      var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible);
     154
     155      foreach (Run run in runs) {
     156        DataTable resTable = (DataTable)run.Results[resultName];
     157        DataRow row = resTable.Rows[rowName];
     158        var values = row.Values.ToArray();
     159        double k, d;
     160        LinearLeastSquaresFitting.Calculate(values, out k, out d);
     161
     162        DataRow newRow = new DataRow(row.Name + " Fitted Line");
     163        for (int i = 0; i < values.Count(); i++) {
     164          newRow.Values.Add(k * i + d);
     165        }
     166
     167        if (!resTable.Rows.ContainsKey(newRow.Name))
     168          resTable.Rows.Add(newRow);
     169      }
     170    }
     171
     172    private void addValuesButton_Click(object sender, EventArgs e) {
     173      string resultName = (string)dataTableComboBox.SelectedItem;
     174      string rowName = (string)dataRowComboBox.SelectedItem;
     175      var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible);
     176      StringMatrix sm = (StringMatrix)stringConvertibleMatrixView.Content;
     177
     178      Content.UpdateOfRunsInProgress = true;
     179      for (int i = 0; i < runs.Count(); i++) {
     180        IRun run = runs.ElementAt(i);
     181
     182        for (int j = 0; j < sm.ColumnNames.Count(); j++) {
     183          string newResultName = resultName + " " + rowName + " " + sm.ColumnNames.ElementAt(j);
     184          if (!run.Results.ContainsKey(newResultName))
     185            run.Results.Add(new KeyValuePair<string, Core.IItem>(newResultName, new DoubleValue(double.Parse(sm[i, j]))));
     186        }
     187      }
     188      Content.UpdateOfRunsInProgress = false;
     189      //update column names of run collection
     190      Content.Modify();
     191    }
     192    #endregion
     193
    142194    private void UpdateRun(IRun run) {
    143195      //TODO: hacky di hack... this is baaaadddd
    144       RebuildCombinedDataTable();
    145     }
    146 
    147     private void dataTableComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    148       UpdateDataRowComboBox();
    149     }
    150 
    151     private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    152196      RebuildCombinedDataTable();
    153197    }
     
    181225      string resultName = (string)dataTableComboBox.SelectedItem;
    182226      string rowName = (string)dataRowComboBox.SelectedItem;
    183 
    184227      string[] columnNames = new string[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Gradient", "Relative Error", "Avg. of Upper 25 %", " Avg. of Lower 25 %", "Avg. of First 25 %", "Avg. of Last 25 %" };
    185228
     
    193236      foreach (Run run in runs) {
    194237        DataTable resTable = (DataTable)run.Results[resultName];
     238        dt.SortableView = true;
    195239        DataRow row = resTable.Rows[rowName];
    196240        var values = row.Values.AsEnumerable();
     
    234278      stringConvertibleMatrixView.Content = dt;
    235279    }
    236 
    237     private void addLineToChart_Click(object sender, EventArgs e) {
    238       string resultName = (string)dataTableComboBox.SelectedItem;
    239       string rowName = (string)dataRowComboBox.SelectedItem;
    240       var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible);
    241 
    242       foreach (Run run in runs) {
    243         DataTable resTable = (DataTable)run.Results[resultName];
    244         DataRow row = resTable.Rows[rowName];
    245         var values = row.Values.ToArray();
    246         double k, d;
    247         LinearLeastSquaresFitting.Calculate(values, out k, out d);
    248 
    249         DataRow newRow = new DataRow(row.Name + " Fitted Line");
    250         for (int i = 0; i < values.Count(); i++) {
    251           newRow.Values.Add(k * i + d);
    252         }
    253 
    254         if (!resTable.Rows.ContainsKey(newRow.Name))
    255           resTable.Rows.Add(newRow);
    256       }
    257     }
    258 
    259     private void addValuesButton_Click(object sender, EventArgs e) {
    260       string resultName = (string)dataTableComboBox.SelectedItem;
    261       string rowName = (string)dataRowComboBox.SelectedItem;
    262       var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible);
    263       StringMatrix sm = (StringMatrix)stringConvertibleMatrixView.Content;
    264 
    265       Content.UpdateOfRunsInProgress = true;
    266       for (int i = 0; i < runs.Count(); i++) {
    267         IRun run = runs.ElementAt(i);
    268 
    269         for (int j = 0; j < sm.ColumnNames.Count(); j++) {
    270           string newResultName = resultName + " " + rowName + " " + sm.ColumnNames.ElementAt(j);
    271           if (!run.Results.ContainsKey(newResultName))
    272             run.Results.Add(new KeyValuePair<string, Core.IItem>(newResultName, new DoubleValue(double.Parse(sm[i, j]))));
    273         }
    274       }
    275       Content.UpdateOfRunsInProgress = false;
    276       //update column names of run collection
    277       Content.Modify();
    278     }
    279 
    280     private void colorButton_Click(object sender, EventArgs e) {
    281       string resultName = (string)dataTableComboBox.SelectedItem;
    282       string rowName = (string)dataRowComboBox.SelectedItem;
    283       var runs = Content.Where(x => x.Results.ContainsKey(resultName) && x.Visible);
    284       Dictionary<int, double> values = new Dictionary<int, double>();
    285 
    286       if (stringConvertibleMatrixView.DataGridView.CurrentCell != null) {
    287         int curIndex = stringConvertibleMatrixView.DataGridView.CurrentCell.ColumnIndex;
    288 
    289         for (int i = 0; i < stringConvertibleMatrixView.Content.Rows; i++) {
    290           values[i] = double.Parse(stringConvertibleMatrixView.Content.GetValue(i, curIndex));
    291         }
    292 
    293         var orderedValues = values.OrderBy(x => x.Value);
    294 
    295         for (int i = 0; i < orderedValues.Count(); i++) {
    296           var row = stringConvertibleMatrixView.DataGridView.Rows[orderedValues.ElementAt(i).Key];
    297 
    298           int r = (int)Math.Round((double)i / (double)orderedValues.Count() * 255.0);
    299           int g = (int)Math.Round(((double)orderedValues.Count() - (double)i) / (double)orderedValues.Count() * 255.0);
    300 
    301           Color color = Color.FromArgb(r, g, 0);
    302           row.DefaultCellStyle.ForeColor = color;
    303         }
    304       }
    305     }
    306280  }
    307281}
  • branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/ChartAnalysisView.designer.cs

    r9355 r9377  
    2121
    2222namespace HeuristicLab.Analysis.Statistics {
    23   partial class RunCollectionStatisticalTabularView {
     23  partial class ChartAnalysisView {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    5252      this.stringConvertibleMatrixView.Location = new System.Drawing.Point(3, 59);
    5353      this.stringConvertibleMatrixView.Name = "stringConvertibleMatrixView";
    54       this.stringConvertibleMatrixView.ReadOnly = false;
     54      this.stringConvertibleMatrixView.ReadOnly = true;
    5555      this.stringConvertibleMatrixView.ShowRowsAndColumnsTextBox = true;
    5656      this.stringConvertibleMatrixView.ShowStatisticalInformation = true;
     
    122122      this.addValuesButton.Click += new System.EventHandler(this.addValuesButton_Click);
    123123      //
    124       // RunCollectionStatisticalTabularView
     124      // ChartAnalysisView
    125125      //
    126126      this.Controls.Add(this.addValuesButton);
     
    131131      this.Controls.Add(this.dataTableComboBox);
    132132      this.Controls.Add(this.stringConvertibleMatrixView);
    133       this.Name = "RunCollectionStatisticalTabularView";
     133      this.Name = "ChartAnalysisView";
    134134      this.Size = new System.Drawing.Size(498, 385);
    135135      this.ResumeLayout(false);
Note: See TracChangeset for help on using the changeset viewer.