Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/AvgLineAggregator.cs @ 1383

Last change on this file since 1383 was 1383, checked in by dwagner, 15 years ago

Fixed Bug in AvgLineAggregator: Count returned dataRowWatches.Count, but should return dataRow.Count (#519)

File size: 3.7 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace HeuristicLab.Visualization {
5  public class AvgLineAggregator : DataRowBase {
6
7    private readonly List<double> dataRow = new List<double>();
8
9    #region IAggregator Members
10
11    public void AddWatch(IDataRow dataRow) {
12      dataRowWatches.Add(dataRow);
13      dataRow.ValueChanged += dataRow_ValueChanged;
14      dataRow.ValuesChanged += dataRow_ValuesChanged;
15      dataRow.DataRowChanged += dataRow_DataRowChanged;
16    }
17
18    public void RemoveWatch(IDataRow dataRow) {
19
20      dataRowWatches.Remove(dataRow);
21      dataRow.DataRowChanged -= dataRow_DataRowChanged;
22      dataRow.ValuesChanged -= dataRow_ValuesChanged;
23      dataRow.ValueChanged -= dataRow_ValueChanged;
24    }
25
26
27    #endregion
28
29    List<IDataRow> dataRowWatches = new List<IDataRow>();
30   
31    void dataRow_ValueChanged(IDataRow row, double value, int index, Action action) {
32      refreshValue(value);
33    }
34
35    void dataRow_ValuesChanged(IDataRow row, double[] values, int index, Action action) {
36      for (int i = 0; i < values.Length; i++) {
37        refreshValue(values[i]);
38      }
39    }
40
41    void dataRow_DataRowChanged(IDataRow row) {
42      refreshValue(double.MinValue);
43    }
44
45    private void refreshValue(double newVal) {
46      //alle durchlaufen und neues min berechnen; verbesserung: merken in welcher row lowest wert steckt
47
48      //curAvgValue = double.MinValue;
49      double tmpSum = 0;
50      int count = dataRowWatches.Count;
51
52      IDataRow firstRow = dataRowWatches[0];
53      int count1 = firstRow.Count;
54      System.Console.WriteLine("count: " + count1);
55
56      dataRow.Clear();
57
58      if (dataRowWatches.Count >= 2) {
59        for (int i = 0; i < count1; i++) {
60          tmpSum = 0;
61          for (int j = 0; j < count; j++) {
62            if (dataRowWatches[j].Count > i) {
63              tmpSum += dataRowWatches[j][i];
64            }
65          }
66
67          this.dataRow.Add(tmpSum/count);
68          OnValueChanged(tmpSum / count, dataRow.Count - 1, Action.Added);
69        }
70      }
71
72      // evtl nur feuern wenn sich geändert hat (jedes mal?)
73      //OnDataRowChanged(this);
74    }
75
76    #region IDataRow Members
77
78    public override void AddValue(double value) {
79      dataRow.Add(value);
80      OnValueChanged(value, dataRow.Count - 1, Action.Added);
81    }
82
83    public override void AddValue(double value, int index) {
84      throw new NotImplementedException();
85    }
86
87    public override void AddValues(double[] values) {
88      throw new NotSupportedException();
89    }
90
91    public override void AddValues(double[] values, int index) {
92      throw new NotSupportedException();
93    }
94
95    public override void ModifyValue(double value, int index) {
96      throw new NotSupportedException();
97    }
98
99    public override void ModifyValues(double[] values, int index) {
100      throw new NotSupportedException();
101    }
102
103    public override void RemoveValue(int index) {
104      throw new NotSupportedException();
105    }
106
107    public override void RemoveValues(int index, int count) {
108      throw new NotSupportedException();
109    }
110
111    public override int Count {
112      get { return dataRow.Count; } //return dataRowWatches.Count; }
113    }
114
115    public override double this[int index] {
116      get { return dataRow[index]; }
117      set {
118        dataRow[index] = value;
119        OnValueChanged(value, index, Action.Modified);
120      }
121    }
122
123    // TODO calculate min value
124    public override double MinValue {
125      get { return 0; }
126    }
127
128    // TODO calculate max value
129    public override double MaxValue {
130      get { return 0; }
131    }
132
133    #endregion
134  }
135}
Note: See TracBrowser for help on using the repository browser.