public SimpleGroupTestViewModel() { _table1 = new ReactiveTable(); var groupColumn = new ReactiveColumn <string>(GroupColumnId); _table1.AddColumn(groupColumn); var valueColumn = new ReactiveColumn <int>(ValueColumnId); _table1.AddColumn(valueColumn); // ReactiveTable table2 = new ReactiveTable(); // table2.AddColumn(new ReactiveColumn<string>("GroupColumn2")); // table2.AddColumn(new ReactiveColumn<int>("ValueColumn2")); _groupedTable = new AggregatedTable(_table1); _groupedTable.GroupBy <string>(groupColumn.ColumnId); _groupedTable.AddAggregate(groupColumn, CountColumnId, () => new Count <string>()); _groupedTable.AddAggregate(valueColumn, SumColumnId, () => new Sum <int>()); _groupedTable.AddAggregate(valueColumn, AverageColumnId, () => new Average <int>()); _groupedTable.AddAggregate(valueColumn, MinColumnId, () => new Min <int>()); _groupedTable.AddAggregate(valueColumn, MaxColumnId, () => new Max <int>()); LoadDataCommand = new DelegateCommand(LoadData); Items = new ObservableCollection <SimpleGroupItem>(); _groupedTable.RowUpdates().Subscribe(OnRowUpdate); }
public GroupTestViewModel(IAccountBalanceDataService service) { var accountsTable = service.Accounts; _groupedAccounts = new AggregatedTable(accountsTable); _groupedAccounts.GroupBy <int>(AccountColumns.PersonId); var balanceColumn = (IReactiveColumn <decimal>)accountsTable.GetColumnByName(AccountColumns.AccountBalance); _groupedAccounts.AddAggregate(balanceColumn, SumColumnId, () => new Sum <decimal>()); _groupedAccounts.AddAggregate(balanceColumn, CountColumnId, () => new Count <decimal>()); _groupedAccounts.FinishInitialisation(); var groups = new IndexedObservableCollection <BalanceGroup, int>(g => g.RowIndex); _groupedAccounts.ReplayAndSubscribe( update => { if (update.Action == TableUpdateAction.Add) { groups.Add(new BalanceGroup(_groupedAccounts, update.RowIndex)); } else if (update.Action == TableUpdateAction.Delete) { groups.RemoveAt(groups.GetIndexForKey(update.RowIndex)); } }); var accounts = new IndexedObservableCollection <AccountViewModel, int>(a => a.RowIndex); accountsTable.ReplayAndSubscribe( update => { if (update.Action == TableUpdateAction.Add) { var accountViewModel = new AccountViewModel(accountsTable, update.RowIndex); accounts.Add(accountViewModel); Debug.WriteLine("{1},Adding,,{0},", update.RowIndex, DateTime.Now.ToLongTimeString()); } else if (update.Action == TableUpdateAction.Delete) { var indexForKey = accounts.GetIndexForKey(update.RowIndex); var accountViewModel = accounts[indexForKey]; accounts.RemoveAt(indexForKey); Debug.WriteLine("{1},Removing,{0}", accountViewModel.PersonId, DateTime.Now.ToLongTimeString()); } else { var indexForKey = accounts.GetIndexForKey(update.RowIndex); var accountViewModel = accounts[indexForKey]; Debug.WriteLine("{1},Modifying,{0},{2},{3}", accountViewModel.PersonId, DateTime.Now.ToLongTimeString(), update.RowIndex, update.Column.ColumnId); } }); Groups = groups; Accounts = accounts; }
public GroupTestViewModelSyncfusion(IAccountBalanceDataService service) { var accountsTable = service.Accounts; var groupedAccounts = new AggregatedTable(accountsTable); groupedAccounts.GroupBy <int>(AccountColumns.PersonId); var balanceColumn = (IReactiveColumn <decimal>)accountsTable.GetColumnByName(AccountColumns.AccountBalance); groupedAccounts.AddAggregate(balanceColumn, GroupTestViewModel.SumColumnId, () => new Sum <decimal>()); groupedAccounts.AddAggregate(balanceColumn, GroupTestViewModel.CountColumnId, () => new Count <decimal>()); groupedAccounts.FinishInitialisation(); SetTable(groupedAccounts); }
public void TestGrouping() { var table1 = new ReactiveTable(); var GroupColumnId = "GroupCol"; var groupColumn = new ReactiveColumn <string>(GroupColumnId); table1.AddColumn(groupColumn); var ValueColumnId = "ValueCol"; var reactiveColumn = new ReactiveColumn <int>(ValueColumnId); var valueColumn = reactiveColumn; table1.AddColumn(valueColumn); // ReactiveTable table2 = new ReactiveTable(); // table2.AddColumn(new ReactiveColumn<string>("GroupColumn2")); // table2.AddColumn(new ReactiveColumn<int>("ValueColumn2")); var groupedTable = new AggregatedTable(table1); groupedTable.GroupBy <string>(groupColumn.ColumnId); var CountColumnId = "Count"; groupedTable.AddAggregate(groupColumn, CountColumnId, () => new Count <string>()); var SumColumnId = "Sum"; groupedTable.AddAggregate(valueColumn, SumColumnId, () => new Sum <int>()); var AverageColumnId = "Average"; groupedTable.AddAggregate(valueColumn, AverageColumnId, () => new Average <int>()); var MinColumnId = "Min"; groupedTable.AddAggregate(valueColumn, MinColumnId, () => new Min <int>()); var MaxColumnId = "Max"; groupedTable.AddAggregate(valueColumn, MaxColumnId, () => new Max <int>()); RunTest( count => { for (var i = 0; i < count; i++) { var name1 = "Mendel" + i; var name2 = "Marie" + i; AddRow(name1, 42, table1, GroupColumnId, ValueColumnId); AddRow(name2, 43, table1, GroupColumnId, ValueColumnId); AddRow(name1, 44, table1, GroupColumnId, ValueColumnId); AddRow(name2, 45, table1, GroupColumnId, ValueColumnId); AddRow(name1, 46, table1, GroupColumnId, ValueColumnId); AddRow(name2, 45, table1, GroupColumnId, ValueColumnId); } }, 10000); }
public void TestGroupByOnExistingValues() { // Create group by var baseTable = TestTableHelper.CreateReactiveTable(); // Add values var row1 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row1, "Value1"); var row2 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row2, "Value2"); var row3 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row3, "Value1"); // Modify grouped columns baseTable.SetValue(TestTableColumns.StringColumn, row2, "Value1"); baseTable.SetValue(TestTableColumns.StringColumn, row3, "Value3"); // Now group it var groupedTable = new AggregatedTable(baseTable); groupedTable.GroupBy <string>(TestTableColumns.StringColumn); var countCol = "CountCol"; groupedTable.AddAggregate((IReactiveColumn <string>)baseTable.GetColumnByName(TestTableColumns.StringColumn), countCol, () => new Count <string>()); var rowUpdates = new RowUpdateHandler(); groupedTable.Subscribe(rowUpdates); var colUpdates = new ColumnUpdateHandler(); groupedTable.Subscribe(colUpdates.OnColumnUpdate); groupedTable.FinishInitialisation(); Assert.AreEqual(2, groupedTable.RowCount); Assert.AreEqual(2, rowUpdates.CurrentRowCount); Assert.AreEqual("Value1", groupedTable.GetValue <string>(TestTableColumns.StringColumn, 0)); Assert.AreEqual("Value3", groupedTable.GetValue <string>(TestTableColumns.StringColumn, 1)); Assert.AreEqual(2, groupedTable.GetValue <int>(countCol, 0)); Assert.AreEqual(1, groupedTable.GetValue <int>(countCol, 1)); // Remove rows baseTable.DeleteRow(row1); Assert.AreEqual(2, groupedTable.RowCount); Assert.AreEqual(2, rowUpdates.CurrentRowCount); baseTable.DeleteRow(row2); Assert.AreEqual(1, groupedTable.RowCount); Assert.AreEqual(1, rowUpdates.CurrentRowCount); baseTable.DeleteRow(row3); Assert.AreEqual(0, groupedTable.RowCount); Assert.AreEqual(0, rowUpdates.CurrentRowCount); }
public GroupedTableTest(int?drainTableLimit = null) { _drainTableLimit = drainTableLimit; _table1 = new ReactiveTable(); var groupColumn = new ReactiveColumn <string>(GroupColumnId); _table1.AddColumn(groupColumn); var valueColumn = new ReactiveColumn <int>(ValueColumnId); _table1.AddColumn(valueColumn); var groupedTable = new AggregatedTable(_table1); groupedTable.GroupBy <string>(groupColumn.ColumnId); groupedTable.AddAggregate(groupColumn, CountColumnId, () => new Count <string>()); groupedTable.AddAggregate(valueColumn, SumColumnId, () => new Sum <int>()); groupedTable.AddAggregate(valueColumn, AverageColumnId, () => new Average <int>()); groupedTable.AddAggregate(valueColumn, MinColumnId, () => new Min <int>()); groupedTable.AddAggregate(valueColumn, MaxColumnId, () => new Max <int>()); }
public void TestRowUpdates() { // Create group by var baseTable = TestTableHelper.CreateReactiveTable(); var groupedTable = new AggregatedTable(baseTable); var rowUpdates = new RowUpdateHandler(); groupedTable.Subscribe(rowUpdates); var colUpdates = new ColumnUpdateHandler(); groupedTable.Subscribe(colUpdates.OnColumnUpdate); groupedTable.GroupBy <string>(TestTableColumns.StringColumn); var countColumn = "Aggregate.Count"; groupedTable.AddAggregate((IReactiveColumn <string>)baseTable.GetColumnByName(TestTableColumns.StringColumn), countColumn, () => new Count <string>()); var row1 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row1, "Value1"); Assert.AreEqual(1, groupedTable.RowCount); Assert.AreEqual(1, groupedTable.GetValue <int>(countColumn, 0)); var row2 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row2, "Value1"); Assert.AreEqual(1, groupedTable.RowCount); Assert.AreEqual(2, groupedTable.GetValue <int>(countColumn, 0)); var row3 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row3, "Value2"); Assert.AreEqual(2, groupedTable.RowCount); Assert.AreEqual(2, groupedTable.GetValue <int>(countColumn, 0)); Assert.AreEqual(1, groupedTable.GetValue <int>(countColumn, 1)); baseTable.SetValue(TestTableColumns.StringColumn, row2, "Value2"); Assert.AreEqual(2, groupedTable.RowCount); Assert.AreEqual(1, groupedTable.GetValue <int>(countColumn, 0)); Assert.AreEqual(2, groupedTable.GetValue <int>(countColumn, 1)); Assert.AreEqual(2, rowUpdates.CurrentRowCount); CheckRowUpdate(rowUpdates, 0, 0, TableUpdateAction.Add); CheckRowUpdate(rowUpdates, 1, 1, TableUpdateAction.Add); CheckRowUpdate(rowUpdates, 1, 2, TableUpdateAction.Delete); CheckRowUpdate(rowUpdates, 1, 3, TableUpdateAction.Add); }
public void TestGroupByWithCount() { // Create group by var baseTable = TestTableHelper.CreateReactiveTable(); var groupedTable = new AggregatedTable(baseTable); var rowUpdates = new RowUpdateHandler(); groupedTable.Subscribe(rowUpdates); var colUpdates = new ColumnUpdateHandler(); groupedTable.Subscribe(colUpdates.OnColumnUpdate); groupedTable.GroupBy <string>(TestTableColumns.StringColumn); var countColumn = "Aggregate.Count"; groupedTable.AddAggregate((IReactiveColumn <string>)baseTable.GetColumnByName(TestTableColumns.StringColumn), countColumn, () => new Count <string>()); var row1 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row1, "Value1"); Assert.AreEqual(1, groupedTable.RowCount); Assert.AreEqual(1, groupedTable.GetValue <int>(countColumn, 0)); var row2 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row2, "Value1"); Assert.AreEqual(1, groupedTable.RowCount); Assert.AreEqual(2, groupedTable.GetValue <int>(countColumn, 0)); var row3 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row3, "Value2"); Assert.AreEqual(2, groupedTable.RowCount); Assert.AreEqual(2, groupedTable.GetValue <int>(countColumn, 0)); Assert.AreEqual(1, groupedTable.GetValue <int>(countColumn, 1)); baseTable.SetValue(TestTableColumns.StringColumn, row2, "Value2"); Assert.AreEqual(2, groupedTable.RowCount); Assert.AreEqual(1, groupedTable.GetValue <int>(countColumn, 0)); Assert.AreEqual(2, groupedTable.GetValue <int>(countColumn, 1)); // Change it to the same value again and check that nothing changes baseTable.SetValue(TestTableColumns.StringColumn, row2, "Value2"); Assert.AreEqual(2, groupedTable.RowCount); Assert.AreEqual(1, groupedTable.GetValue <int>(countColumn, 0)); Assert.AreEqual(2, groupedTable.GetValue <int>(countColumn, 1)); }
public void TestColumnsAdded() { var baseTable = TestTableHelper.CreateReactiveTable(); var groupedTable = new AggregatedTable(baseTable); groupedTable.GroupBy <string>(TestTableColumns.StringColumn); groupedTable.AddAggregate((IReactiveColumn <string>)groupedTable.GetColumnByName(TestTableColumns.StringColumn), "Test", () => new Count <string>()); Assert.AreEqual(2, groupedTable.Columns.Count); Assert.AreEqual(TestTableColumns.StringColumn, groupedTable.Columns.First().ColumnId); Assert.AreEqual("Test", groupedTable.Columns.Skip(1).First().ColumnId); }
public void TestGroupByWithAverage() { // Create group by var baseTable = TestTableHelper.CreateReactiveTable(); var groupedTable = new AggregatedTable(baseTable); var rowUpdates = new RowUpdateHandler(); groupedTable.Subscribe(rowUpdates); var colUpdates = new ColumnUpdateHandler(); groupedTable.Subscribe(colUpdates.OnColumnUpdate); groupedTable.GroupBy <string>(TestTableColumns.StringColumn); var avgColumn = "Aggregate.Sum"; groupedTable.AddAggregate((IReactiveColumn <int>)baseTable.GetColumnByName(TestTableColumns.IdColumn), avgColumn, () => new Average <int>()); var avgColumn2 = "Aggregate.DecimalSum"; groupedTable.AddAggregate((IReactiveColumn <decimal>)baseTable.GetColumnByName(TestTableColumns.DecimalColumn), avgColumn2, () => new Average <decimal>()); var row1 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row1, "Value1"); baseTable.SetValue(TestTableColumns.IdColumn, row1, 10); baseTable.SetValue(TestTableColumns.DecimalColumn, row1, 2.5m); Assert.AreEqual(1, groupedTable.RowCount); Assert.AreEqual(10.0, groupedTable.GetValue <double>(avgColumn, 0)); Assert.AreEqual(2.5, groupedTable.GetValue <double>(avgColumn2, 0)); var row2 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row2, "Value1"); baseTable.SetValue(TestTableColumns.IdColumn, row2, 20); baseTable.SetValue(TestTableColumns.DecimalColumn, row2, 4.5m); Assert.AreEqual(1, groupedTable.RowCount); Assert.AreEqual(15.0, groupedTable.GetValue <double>(avgColumn, 0)); Assert.AreEqual(3.5, groupedTable.GetValue <double>(avgColumn2, 0)); var row3 = baseTable.AddRow(); baseTable.SetValue(TestTableColumns.StringColumn, row3, "Value2"); baseTable.SetValue(TestTableColumns.IdColumn, row3, 15); baseTable.SetValue(TestTableColumns.DecimalColumn, row3, 1.5m); Assert.AreEqual(2, groupedTable.RowCount); Assert.AreEqual(15.0, groupedTable.GetValue <double>(avgColumn, 0)); Assert.AreEqual(15.0, groupedTable.GetValue <double>(avgColumn, 1)); Assert.AreEqual(3.5, groupedTable.GetValue <double>(avgColumn2, 0)); Assert.AreEqual(1.5, groupedTable.GetValue <double>(avgColumn2, 1)); baseTable.SetValue(TestTableColumns.IdColumn, row2, 25); baseTable.SetValue(TestTableColumns.DecimalColumn, row2, 5.5m); Assert.AreEqual(2, groupedTable.RowCount); Assert.AreEqual(17.5, groupedTable.GetValue <double>(avgColumn, 0)); Assert.AreEqual(4.0, groupedTable.GetValue <double>(avgColumn2, 0)); // Now change the membership in the groups baseTable.SetValue(TestTableColumns.StringColumn, row2, "Value2"); Assert.AreEqual(10, groupedTable.GetValue <double>(avgColumn, 0)); Assert.AreEqual(20, groupedTable.GetValue <double>(avgColumn, 1)); Assert.AreEqual(2.5, groupedTable.GetValue <double>(avgColumn2, 0)); Assert.AreEqual(3.5, groupedTable.GetValue <double>(avgColumn2, 1)); }