[1325] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 |
|
---|
| 4 | namespace HeuristicLab.Visualization {
|
---|
[1350] | 5 | public class AvgLineAggregator : DataRowBase {
|
---|
[1325] | 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 |
|
---|
[1350] | 78 | public override void AddValue(double value) {
|
---|
[1325] | 79 | dataRow.Add(value);
|
---|
| 80 | OnValueChanged(value, dataRow.Count - 1, Action.Added);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[1350] | 83 | public override void AddValue(double value, int index) {
|
---|
| 84 | throw new NotImplementedException();
|
---|
[1325] | 85 | }
|
---|
| 86 |
|
---|
[1350] | 87 | public override void AddValues(double[] values) {
|
---|
[1325] | 88 | throw new NotSupportedException();
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[1350] | 91 | public override void AddValues(double[] values, int index) {
|
---|
[1325] | 92 | throw new NotSupportedException();
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[1350] | 95 | public override void ModifyValue(double value, int index) {
|
---|
[1325] | 96 | throw new NotSupportedException();
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[1350] | 99 | public override void ModifyValues(double[] values, int index) {
|
---|
[1325] | 100 | throw new NotSupportedException();
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[1350] | 103 | public override void RemoveValue(int index) {
|
---|
[1325] | 104 | throw new NotSupportedException();
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[1350] | 107 | public override void RemoveValues(int index, int count) {
|
---|
[1325] | 108 | throw new NotSupportedException();
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[1350] | 111 | public override int Count {
|
---|
[1383] | 112 | get { return dataRow.Count; } //return dataRowWatches.Count; }
|
---|
[1325] | 113 | }
|
---|
| 114 |
|
---|
[1350] | 115 | public override double this[int index] {
|
---|
[1325] | 116 | get { return dataRow[index]; }
|
---|
| 117 | set {
|
---|
| 118 | dataRow[index] = value;
|
---|
| 119 | OnValueChanged(value, index, Action.Modified);
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 |
|
---|
[1350] | 123 | // TODO calculate min value
|
---|
| 124 | public override double MinValue {
|
---|
| 125 | get { return 0; }
|
---|
[1327] | 126 | }
|
---|
| 127 |
|
---|
[1350] | 128 | // TODO calculate max value
|
---|
| 129 | public override double MaxValue {
|
---|
| 130 | get { return 0; }
|
---|
[1327] | 131 | }
|
---|
| 132 |
|
---|
[1325] | 133 | #endregion
|
---|
| 134 | }
|
---|
| 135 | }
|
---|