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 ReactiveTable() { var type = typeof(T); foreach (var propertyInfo in type.GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(p => p.GetCustomAttribute <CalculatedColumnAttribute>() == null)) { AddColumn(ReactiveColumn.Create($"{type.Name}.{propertyInfo.Name}", propertyInfo.PropertyType)); } var token = Subscribe(update => { if (update.Action == TableUpdateAction.Add) { var item = new T(); item.SetTable(this); item.SetRowIndex(update.RowIndex); ChangeNotifier.RegisterPropertyNotifiedConsumer(item, update.RowIndex); Flyweights.Add(item); } else if (update.Action == TableUpdateAction.Delete) { // TODO: Look at efficiency of this var item = Flyweights[update.RowIndex]; ChangeNotifier.UnregisterPropertyNotifiedConsumer(item, update.RowIndex); Flyweights.RemoveAt(update.RowIndex); } }); }
private static ReactiveTable GetRatesTable() { var fxRates = new ReactiveTable(); fxRates.AddColumn(new ReactiveColumn <string>(FxTableDefinitions.FxRates.CcyPairId)); fxRates.AddColumn(new ReactiveColumn <double>(FxTableDefinitions.FxRates.Bid)); fxRates.AddColumn(new ReactiveColumn <double>(FxTableDefinitions.FxRates.Ask)); fxRates.AddColumn(new ReactiveColumn <double>(FxTableDefinitions.FxRates.Open)); fxRates.AddColumn(new ReactiveColumn <double>(FxTableDefinitions.FxRates.Close)); fxRates.AddColumn(new ReactiveColumn <double>(FxTableDefinitions.FxRates.YearRangeStart)); fxRates.AddColumn(new ReactiveColumn <double>(FxTableDefinitions.FxRates.YearRangeEnd)); fxRates.AddColumn(new ReactiveColumn <double>(FxTableDefinitions.FxRates.Change)); var timeColumn = new ReactiveColumn <DateTime>(FxTableDefinitions.FxRates.Time); fxRates.AddColumn(timeColumn); // var tickColumn = new ReactiveColumn<long>(FxTableDefinitions.FxRates.Ticks); // fxRates.AddColumn(tickColumn); fxRates.AddColumn(new ReactiveCalculatedColumn1 <double, DateTime>(CalculateColumns.FxRates.LongTime, timeColumn, time => (DateTime.UtcNow - time).TotalMilliseconds)); /*fxRates.AddColumn(new ReactiveCalculatedColumn1<long, long>(CalculateColumns.FxRates.Micros, * tickColumn, * tickStart => * { * var ticksElapsed = DateTime.Now.Ticks - _start.Ticks; * return (ticksElapsed - tickStart) * 10; * }));*/ return(fxRates); }
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 CalculatedColumnTableTest() { _table = new ReactiveTable(); var idCol = new ReactiveColumn <int>("IdCol"); _table.AddColumn(idCol); var textCol = new ReactiveColumn <string>("TextCol"); _table.AddColumn(textCol); var valueCol = new ReactiveColumn <decimal>("ValueCol"); _table.AddColumn(valueCol); _table.AddColumn(new ReactiveCalculatedColumn2 <decimal, int, decimal>( "CalcCol1", idCol, valueCol, (id, val) => id * val)); _table.AddColumn(new ReactiveCalculatedColumn2 <string, int, string>( "CalcCol2", idCol, textCol, (id, text) => text + id)); }
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>()); }