31 lines
1.3 KiB
C#
31 lines
1.3 KiB
C#
namespace bts.SilverPine {
|
|
using BCG;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
[DataStreamUserRespresentation("Average")]
|
|
public class AverageNonIncGroupsStream : ViewStream {
|
|
public AverageNonIncGroupsStream(ViewStream parent_stream, string inp_col_name, params string[] group_by_cols) {
|
|
NonIncGroupByStream rs = new NonIncGroupByStream(parent_stream, () => group_by_cols,
|
|
(g_rows) => _find_mean(inp_col_name, g_rows));
|
|
mySetRealSource(rs);
|
|
}
|
|
|
|
private List<IBlueRow> _find_mean(string inp_col_name, List<IBlueRow> g_rows) {
|
|
IBlueRow inp_row = g_rows.ElementAt(0);
|
|
IEnumerable<double> inp_vals = BlueDataUtility.get_colvalues<double>(g_rows, inp_col_name);
|
|
double sum = 0.0;
|
|
inp_vals.ToList().ForEach(d => sum += d);
|
|
string out_col_name = $"average_{inp_col_name}";
|
|
double average = sum / inp_vals.Count();
|
|
IBlueTableSchema schema_out = inp_row.schema.add_column(TypeCode.Double, out_col_name);
|
|
MutableBlueRow out_row = new MutableBlueRow(schema_out, inp_row);
|
|
out_row.setValue(out_col_name, average);
|
|
List<IBlueRow> rv = new List<IBlueRow>();
|
|
rv.Add(out_row);
|
|
return rv;
|
|
}
|
|
}
|
|
} |