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 _find_mean(string inp_col_name, List g_rows) { IBlueRow inp_row = g_rows.ElementAt(0); IEnumerable inp_vals = BlueDataUtility.get_colvalues(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 rv = new List(); rv.Add(out_row); return rv; } } }