Best NBi code snippet using NBi.Core.ResultSet.Alteration.Summarization.SummarizeEngine
SummarizeEngineTest.cs
Source:SummarizeEngineTest.cs
...13using System.Data;14using System.Diagnostics;15namespace NBi.Testing.Core.ResultSet.Alteration.Summarization16{17 public class SummarizeEngineTest18 {19 private IResultSet Build()20 {21 var args = new ObjectsResultSetResolverArgs(new[] { new object[] { "alpha", 1 }, new object[] { "alpha", 2 }, new object[] { "beta", 3 }, new object[] { "alpha", 4 } });22 var resolver = new ObjectsResultSetResolver(args);23 var rs = resolver.Execute();24 rs.Columns[0].ColumnName = "keyColumn";25 rs.Columns[1].ColumnName = "valueColumn";26 return rs;27 }28 private IResultSet BuildLarge(int count)29 {30 var values = new List<object>();31 for (int i = 0; i < count; i++)32 values.Add(new object[] { i % 2 == 0 ? "alpha" : "beta", 1 });33 var args = new ObjectsResultSetResolverArgs(values);34 var resolver = new ObjectsResultSetResolver(args);35 var rs = resolver.Execute();36 rs.Columns[0].ColumnName = "keyColumn";37 rs.Columns[1].ColumnName = "valueColumn";38 return rs;39 }40 [Test]41 public void Execute_SingleKeySingleAggregation_ExpectedResultSet()42 {43 var rs = Build();44 var args = new SummarizeArgs(45 new List<ColumnAggregationArgs>()46 { new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Sum, ColumnType.Numeric, null) },47 new List<IColumnDefinitionLight>()48 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) }49 );50 var summarize = new SummarizeEngine(args);51 var result = summarize.Execute(rs);52 Assert.That(result, Is.Not.Null);53 Assert.That(result.Columns.Count, Is.EqualTo(2));54 Assert.That(result.Rows.Cast<DataRow>().Any(x => x["keyColumn"] as string == "alpha"));55 Assert.That(result.Rows.Cast<DataRow>().Any(x => x["keyColumn"] as string == "beta"));56 Assert.That(result.Rows.Count, Is.EqualTo(2));57 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["valueColumn"]) == 7);58 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["valueColumn"]) == 3);59 }60 [Test]61 public void Execute_MultipleKeySingleAggregation_ExpectedResultSet()62 {63 var rs = new ObjectsResultSetResolver(64 new ObjectsResultSetResolverArgs(65 new[] { new object[] { "alpha", "foo", 1 }, new object[] { "alpha", "foo", 2 }, new object[] { "beta", "foo", 3 }, new object[] { "alpha", "bar", 4 } })66 ).Execute();67 rs.Columns[0].ColumnName = "ColumnA";68 rs.Columns[1].ColumnName = "ColumnB";69 rs.Columns[2].ColumnName = "valueColumn";70 var args = new SummarizeArgs(71 new List<ColumnAggregationArgs>()72 { new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Sum, ColumnType.Numeric, null) },73 new List<IColumnDefinitionLight>()74 {75 Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("ColumnA") && x.Type == ColumnType.Text),76 Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("ColumnB") && x.Type == ColumnType.Text)77 }78 );79 var summarize = new SummarizeEngine(args);80 var result = summarize.Execute(rs);81 Assert.That(result, Is.Not.Null);82 Assert.That(result.Columns.Count, Is.EqualTo(3));83 Assert.That(result.Rows.Cast<DataRow>().Any(x => x["ColumnA"] as string == "alpha" && x["ColumnB"] as string == "foo"));84 Assert.That(result.Rows.Cast<DataRow>().Any(x => x["ColumnA"] as string == "beta" && x["ColumnB"] as string == "foo"));85 Assert.That(result.Rows.Cast<DataRow>().Any(x => x["ColumnA"] as string == "alpha" && x["ColumnB"] as string == "bar"));86 Assert.That(result.Rows.Count, Is.EqualTo(3));87 }88 [Test]89 public void Execute_MultipleKeyNonAlphabeticalOrderSingleAggregation_ExpectedResultSet()90 {91 var rs = new ObjectsResultSetResolver(92 new ObjectsResultSetResolverArgs(93 new[] { new object[] { "alpha", "foo", 1 }, new object[] { "alpha", "foo", 2 }, new object[] { "beta", "foo", 3 }, new object[] { "alpha", "bar", 4 } })94 ).Execute();95 rs.Columns[0].ColumnName = "ColumnB";96 rs.Columns[1].ColumnName = "ColumnA";97 rs.Columns[2].ColumnName = "valueColumn";98 var args = new SummarizeArgs(99 new List<ColumnAggregationArgs>()100 { new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Sum, ColumnType.Numeric, null) },101 new List<IColumnDefinitionLight>()102 {103 Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("ColumnB") && x.Type == ColumnType.Text),104 Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("ColumnA") && x.Type == ColumnType.Text),105 }106 );107 var summarize = new SummarizeEngine(args);108 var result = summarize.Execute(rs);109 Assert.That(result, Is.Not.Null);110 Assert.That(result.Columns.Count, Is.EqualTo(3));111 Assert.That(result.Rows.Cast<DataRow>().Any(x => x["ColumnB"] as string == "alpha" && x["ColumnA"] as string == "foo"));112 Assert.That(result.Rows.Cast<DataRow>().Any(x => x["ColumnB"] as string == "beta" && x["ColumnA"] as string == "foo"));113 Assert.That(result.Rows.Cast<DataRow>().Any(x => x["ColumnB"] as string == "alpha" && x["ColumnA"] as string == "bar"));114 Assert.That(result.Rows.Count, Is.EqualTo(3));115 }116 [Test]117 public void Execute_SingleKeyMultipleAggregations_ExpectedResultSet()118 {119 var rs = Build();120 var args = new SummarizeArgs(121 new List<ColumnAggregationArgs>()122 {123 new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Sum, ColumnType.Numeric, null),124 new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Min, ColumnType.Numeric, null),125 new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Max, ColumnType.Numeric, null),126 },127 new List<IColumnDefinitionLight>()128 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) }129 );130 var summarize = new SummarizeEngine(args);131 var result = summarize.Execute(rs);132 Assert.That(result, Is.Not.Null);133 Assert.That(result.Columns.Count, Is.EqualTo(4));134 Assert.That(result.Rows.Cast<DataRow>().Any(x => x["keyColumn"] as string == "alpha"));135 Assert.That(result.Rows.Cast<DataRow>().Any(x => x["keyColumn"] as string == "beta"));136 Assert.That(result.Rows.Count, Is.EqualTo(2));137 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["valueColumn_Sum"]) == 7);138 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["valueColumn_Min"]) == 1);139 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["valueColumn_Max"]) == 4);140 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta").ItemArray.Skip(1).Distinct().Single()) == 3);141 }142 [Test]143 public void Execute_NoKeySingleAggregations_ExpectedResultSet()144 {145 var rs = Build();146 var args = new SummarizeArgs(147 new List<ColumnAggregationArgs>()148 {149 new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Sum, ColumnType.Numeric, null),150 },151 new List<IColumnDefinitionLight>()152 );153 var summarize = new SummarizeEngine(args);154 var result = summarize.Execute(rs);155 Assert.That(result, Is.Not.Null);156 Assert.That(result.Columns.Count, Is.EqualTo(1));157 Assert.That(result.Rows.Count, Is.EqualTo(1));158 Assert.That(Convert.ToInt32(result.Rows[0][0]) == 10);159 }160 [Test]161 public void Execute_NoKeyMultipleAggregations_ExpectedResultSet()162 {163 var rs = Build();164 var args = new SummarizeArgs(165 new List<ColumnAggregationArgs>()166 {167 new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Sum, ColumnType.Numeric, null),168 new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Min, ColumnType.Numeric, null),169 new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Max, ColumnType.Numeric, null),170 },171 new List<IColumnDefinitionLight>()172 );173 var summarize = new SummarizeEngine(args);174 var result = summarize.Execute(rs);175 Assert.That(result, Is.Not.Null);176 Assert.That(result.Columns.Count, Is.EqualTo(3));177 Assert.That(result.Rows.Count, Is.EqualTo(1));178 Assert.That(Convert.ToInt32(result.Rows[0][0]) == 10);179 Assert.That(Convert.ToInt32(result.Rows[0][1]) == 1);180 Assert.That(Convert.ToInt32(result.Rows[0][2]) == 4);181 }182 [Test]183 [TestCase(100)]184 [TestCase(1000)]185 [TestCase(10000)]186 [TestCase(100000)]187 [Retry(3)]188 public void Execute_LargeResultSet_ExpectedPerformance(int count)189 {190 var rs = BuildLarge(count);191 var args = new SummarizeArgs(192 new List<ColumnAggregationArgs>()193 {194 new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Sum, ColumnType.Numeric, null),195 new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Min, ColumnType.Numeric, null),196 new ColumnAggregationArgs(new ColumnNameIdentifier("valueColumn"), AggregationFunctionType.Max, ColumnType.Numeric, null),197 },198 new List<IColumnDefinitionLight>()199 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) }200 );201 var summarize = new SummarizeEngine(args);202 var stopWatch = new Stopwatch();203 stopWatch.Start();204 var result = summarize.Execute(rs);205 stopWatch.Stop();206 Assert.That(stopWatch.Elapsed.TotalSeconds, Is.LessThan(10));207 }208 }209}...
SummarizeEngine.cs
Source:SummarizeEngine.cs
...10using System.Text;11using System.Threading.Tasks;12namespace NBi.Core.ResultSet.Alteration.Summarization13{14 class SummarizeEngine : ISummarizationEngine15 {16 private SummarizeArgs Args { get; }17 public SummarizeEngine(SummarizeArgs args)18 => Args = args;19 public IResultSet Execute(IResultSet rs)20 {21 using (var dataTable = new DataTable())22 {23 foreach (var groupBy in Args.GroupBys)24 {25 var column = groupBy.Identifier.GetColumn(rs.Table);26 dataTable.Columns.Add(new DataColumn(column.ColumnName, column.DataType));27 }28 var factory = new AggregationFactory();29 var aggregations = new List<Aggregation>();30 foreach (var aggregation in Args.Aggregations)31 {...
SummarizationFactory.cs
Source:SummarizationFactory.cs
...10 public ISummarizationEngine Instantiate(ISummarizationArgs args)11 {12 switch(args)13 {14 case SummarizeArgs x: return new SummarizeEngine(x);15 default: throw new ArgumentException();16 }17 }18 }19}...
SummarizeEngine
Using AI Code Generation
1using NBi.Core.ResultSet.Alteration.Summarization;2using NBi.Core.ResultSet;3using System;4using System.Collections.Generic;5{6 {7 static void Main(string[] args)8 {9 SummarizeEngine engine = new SummarizeEngine();10 engine.Columns.Add(new ColumnIdentifier("Column1"));11 engine.Columns.Add(new ColumnIdentifier("Column2"));12 engine.Columns.Add(new ColumnIdentifier("Column3"));13 engine.Aggregators.Add(new Aggregator("Column1", "Sum"));14 engine.Aggregators.Add(new Aggregator("Column2", "Average"));15 engine.Aggregators.Add(new Aggregator("Column3", "Count"));16 engine.Groups.Add(new Group("Column1"));17 engine.Groups.Add(new Group("Column2"));18 engine.Groups.Add(new Group("Column3"));19 engine.Apply(new ResultSet());20 }21 }22}23using NBi.Core.ResultSet;24using System;25using System.Collections.Generic;26{27 {28 static void Main(string[] args)29 {30 ResultSet rs = new ResultSet();31 rs.Columns.Add(new ColumnInfo("Column1"));32 rs.Columns.Add(new ColumnInfo("Column2"));33 rs.Columns.Add(new ColumnInfo("Column3"));34 rs.Rows.Add(new List<object>() { 1, 2, 3 });35 rs.Rows.Add(new List<object>() { 4, 5, 6 });36 rs.Rows.Add(new List<object>() { 7, 8, 9 });37 }38 }39}40using NBi.Core.ResultSet;41using System;42using System.Collections.Generic;43{44 {45 static void Main(string[] args)46 {47 ColumnIdentifier ci = new ColumnIdentifier("Column1");48 }49 }50}51using NBi.Core.ResultSet.Alteration.Summarization;52using System;53using System.Collections.Generic;54{55 {56 static void Main(string[] args)57 {58 Aggregator ag = new Aggregator("Column1", "Sum");59 }60 }61}
SummarizeEngine
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Data;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7using NBi.Core.ResultSet.Alteration.Summarization;8using NBi.Core.ResultSet;9{10 {11 static void Main(string[] args)12 {13 DataTable dt = new DataTable();14 dt.Columns.Add("id", typeof(int));15 dt.Columns.Add("name", typeof(string));16 dt.Columns.Add("value", typeof(int));17 dt.Rows.Add(1, "a", 1);18 dt.Rows.Add(1, "a", 2);19 dt.Rows.Add(1, "a", 3);20 dt.Rows.Add(2, "b", 4);21 dt.Rows.Add(2, "b", 5);22 dt.Rows.Add(2, "b", 6);23 dt.Rows.Add(3, "c", 7);24 dt.Rows.Add(3, "c", 8);25 dt.Rows.Add(3, "c", 9);26 var engine = new SummarizeEngine();27 var result = engine.Execute(dt, new SummarizationArgs("id", "value", "sum", "sum"));28 foreach (DataRow row in result.Rows)29 {30 Console.WriteLine(row[0].ToString() + " " + row[1].ToString());31 }32 Console.ReadLine();33 }34 }35}36using System;37using System.Collections.Generic;38using System.Data;39using System.Linq;40using System.Text;41using System.Threading.Tasks;42using NBi.Core.ResultSet.Alteration.Summarization;43using NBi.Core.ResultSet;
SummarizeEngine
Using AI Code Generation
1using NBi.Core.ResultSet;2using NBi.Core.ResultSet.Alteration.Summarization;3using NBi.Core.ResultSet.Resolver;4using NBi.Core.Calculation.Grouping;5using NBi.Core.Calculation;6using NBi.Core.Transformation;7using NBi.Core.Transformation.Transformer;8using System.Collections.Generic;9using System.Data;10using System.Linq;11using System;12{13 {14 static void Main(string[] args)15 {16 DataTable dt = new DataTable();17 dt.Columns.Add("col1", typeof(int));18 dt.Columns.Add("col2", typeof(string));19 dt.Columns.Add("col3", typeof(string));20 dt.Columns.Add("col4", typeof(int));21 dt.Rows.Add(1, "a", "a", 10);22 dt.Rows.Add(2, "a", "a", 20);23 dt.Rows.Add(3, "b", "b", 30);24 dt.Rows.Add(4, "b", "b", 40);25 dt.Rows.Add(5, "c", "c", 50);26 dt.Rows.Add(6, "c", "c", 60);27 var engine = new SummarizeEngine();28 var groupBy = new List<GroupBy>();29 groupBy.Add(new GroupBy("col1", new TransformationInfo(new List<ITransformer>())));30 groupBy.Add(new GroupBy("col2", new TransformationInfo(new List<ITransformer>())));31 groupBy.Add(new GroupBy("col3", new TransformationInfo(new List<ITransformer>())));32 var calculations = new List<ICalculation>();33 calculations.Add(new SumCalculation("col4", new TransformationInfo(new List<ITransformer>())));34 var args = new SummarizeArgs(groupBy, calculations);35 var result = engine.Execute(dt, args);36 foreach (DataRow r in result.Rows)37 {38 Console.WriteLine(r[0].ToString() + " " + r[1].ToString() + " " + r[2].ToString() + " " + r[3].ToString());
SummarizeEngine
Using AI Code Generation
1using NBi.Core.ResultSet.Alteration.Summarization;2using System.Collections.Generic;3using System.Data;4using System.Data.SqlClient;5using System.Linq;6using System;7{8 {9 private readonly DataTable dataTable;10 public SummarizeEngine(DataTable dataTable)11 {12 this.dataTable = dataTable;13 }14 public DataTable Execute(IEnumerable<ISummarizable> summarizables)15 {16 var result = dataTable.Clone();17 var groups = dataTable.Rows.Cast<DataRow>()18 .GroupBy(row => summarizables.Select(x => x.GetGroupingValue(row)).ToArray());19 foreach (var group in groups)20 {21 var newRow = result.NewRow();22 foreach (var summarizable in summarizables)23 summarizable.Summarize(group, newRow);24 result.Rows.Add(newRow);25 }26 return result;27 }28 }29}30using NBi.Core.ResultSet.Alteration.Summarization;31using System.Collections.Generic;32using System.Data;33using System.Data.SqlClient;34using System.Linq;35using System;36{37 {38 private readonly DataTable dataTable;39 public SummarizeEngine(DataTable dataTable)40 {41 this.dataTable = dataTable;42 }43 public DataTable Execute(IEnumerable<ISummarizable> summarizables)44 {45 var result = dataTable.Clone();46 var groups = dataTable.Rows.Cast<DataRow>()47 .GroupBy(row => summarizables.Select(x => x.GetGroupingValue(row)).ToArray());48 foreach (var group in groups)49 {50 var newRow = result.NewRow();51 foreach (var summarizable in summarizables)52 summarizable.Summarize(group, newRow);53 result.Rows.Add(newRow);54 }55 return result;56 }57 }58}59using NBi.Core.ResultSet.Alteration.Summarization;60using System.Collections.Generic;61using System.Data;62using System.Data.SqlClient;63using System.Linq;64using System;65{66 {
SummarizeEngine
Using AI Code Generation
1var engine = new SummarizeEngine();2var result = engine.Execute(resultSet, new SummarizeArgs3{4 GroupBy = new[] { "Group" }5});6var engine = new SummarizeEngine();7var result = engine.Execute(resultSet, new SummarizeArgs8{9 GroupBy = new[] { "Group" }10});11var engine = new SummarizeEngine();12var result = engine.Execute(resultSet, new SummarizeArgs13{14 GroupBy = new[] { "Group" }15});16var engine = new SummarizeEngine();17var result = engine.Execute(resultSet, new SummarizeArgs18{19 GroupBy = new[] { "Group" }20});21var engine = new SummarizeEngine();22var result = engine.Execute(resultSet, new SummarizeArgs23{24 GroupBy = new[] { "Group" }25});26var engine = new SummarizeEngine();27var result = engine.Execute(resultSet, new SummarizeArgs28{29 GroupBy = new[] { "Group" }30});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!