public static (dynamic init, dynamic accum, dynamic conv) ModeToPreset(this Pivoted mode) { switch (mode) { case Pivoted.Accum: return(Presets.Accum <dynamic>()); case Pivoted.Merge: return(Presets.Accum <dynamic>()); case Pivoted.Count: return(Presets.Count <dynamic>()); case Pivoted.Sum: return(Presets.Sum <dynamic>()); case Pivoted.Average: return(Presets.Average <dynamic>()); case Pivoted.Max: return(Presets.Max <dynamic>()); case Pivoted.Min: return(Presets.Min <dynamic>()); case Pivoted.First: return(Presets.First <dynamic>()); case Pivoted.Last: return(Presets.Last <dynamic>()); default: throw new ArgumentOutOfRangeException(nameof(mode), mode, "Invalid PivotMode"); } }
public static Crostab <TO> ToCrostab <TO>( this Table <dynamic> table, string side, string head, string field, Pivoted mode, Func <dynamic, TO> formula = null, Func <object, dynamic> parser = null ) => Pivot <dynamic, dynamic, dynamic> .Build(table.CoIn(side), table.CoIn(head), table.CoIn(field), mode) .Record(table.Rows, parser) .ToCrostab(formula);
public static Crostab <T> Crostab <T>( this Table <T> table, string head, string side, string field, Pivoted mode ) { var columnX = table.Column(side); var columnY = table.Column(head); var columnZ = table.Column(field); var elementsX = columnX.AsEnumerable().Distinct().ToArray(); var elementsY = columnY.AsEnumerable().Distinct().ToArray(); var matrix = new T[elementsX.Length, elementsY.Length]; var triZipper = (Func <string, string, T, T>)((x, y, z) => default);
public static Pivot <dynamic, dynamic, dynamic> Build(int side, int head, int field, Pivoted mode) { var(init, accum, conv) = mode.ModeToPreset(); return(new Pivot <dynamic, dynamic, dynamic> { _sideIndex = side, _headIndex = head, _fieldIndex = field, _accum = (target, value) => accum(target, value), _conv = some => conv(some), Init = () => init(), Side = new string[] { }, Head = new string[] { }, Rows = new dynamic[][] { }, }); }