public DimensionKey GetValue(T result) { string[] dimensionValues = _dimensions.Select(d => d.GetKey(result)).ToArray(); DimensionKey resultKey = new DimensionKey(dimensionValues); return(resultKey); }
/// <summary> /// Builds results into object having column names array and 2d array data grid /// </summary> public HistogramResults BuildResults() { if (_row == null) { throw new InvalidOperationException("Aggregation was never performed."); } KeyValuePair <DimensionKey, Val[]>[] results = _row .Select(r => new KeyValuePair <DimensionKey, Val[]>(r.Key, r.Value.Export().ToArray())) .ToArray(); OrderLearner orderLearner = new OrderLearner(); results.ForEach(kv => orderLearner.Learn(kv.Value.Select(v => v.Key))); string[] columnNames = Dimensions .Select(d => d.DimensionName) .Concat(orderLearner.LearnedOrder) .Except(ColumnIgnoreNames) .ToArray(); object[][] resultValues = new object[_row.Count][]; int rowIndex = 0; foreach (KeyValuePair <DimensionKey, Val[]> pair in results) { resultValues[rowIndex] = new object[columnNames.Length]; DimensionKey dimensions = pair.Key; Val[] metrics = pair.Value; for (int i = 0; i < dimensions.Values.Count; i++) { resultValues[rowIndex][i] = dimensions.Values[i]; } for (int i = 0; i < metrics.Length; i++) { int columnIndex = Array.FindIndex(columnNames, s => s == metrics[i].Key); if (columnIndex != -1) { resultValues[rowIndex][columnIndex] = metrics[i].Value; } } rowIndex++; } ReplaceNames(columnNames, ColumnAliases); return(new HistogramResults(columnNames, resultValues)); }
public void Aggregate(TData item) { DimensionKey key = _dimensionsKeyBuilder.GetValue(item); _row[key].Add(item); }