Esempio n. 1
0
        public ValueTable Copy(IValue Rows = null, string ColumnNames = null)
        {
            ValueTable Result = CopyColumns(ColumnNames);
            List <ValueTableColumn> columns = GetProcessingColumnList(ColumnNames);

            // TODO: Переделать это убожество. Свернуть две ветки в одну, сделать соответствие объектов старых колонок и новых.

            if (Rows == null)
            {
                foreach (ValueTableRow row in _rows)
                {
                    ValueTableRow new_row = Result.Add();
                    foreach (ValueTableColumn Column in columns)
                    {
                        new_row.Set(ValueFactory.Create(Column.Name), row.Get(Column));
                    }
                }
            }
            else
            {
                ArrayImpl a_Rows = Rows as ArrayImpl;
                foreach (IValue irow in a_Rows)
                {
                    ValueTableRow row = irow as ValueTableRow;

                    ValueTableRow new_row = Result.Add();
                    foreach (ValueTableColumn Column in columns)
                    {
                        new_row.Set(ValueFactory.Create(Column.Name), row.Get(Column));
                    }
                }
            }

            return(Result);
        }
Esempio n. 2
0
        private bool CheckFilterCriteria(ValueTableRow Row, StructureImpl Filter)
        {
            foreach (KeyAndValueImpl kv in Filter)
            {
                ValueTableColumn Column = Columns.FindColumnByName(kv.Key.AsString());
                if (Column == null)
                {
                    throw RuntimeException.PropNotFoundException(kv.Key.AsString());
                }

                IValue current = Row.Get(Column);
                if (!current.Equals(kv.Value))
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 3
0
        public void GroupBy(string groupColumnNames, string aggregateColumnNames = null)
        {
            List <ValueTableColumn> GroupColumns     = GetProcessingColumnList(groupColumnNames, true);
            List <ValueTableColumn> AggregateColumns = GetProcessingColumnList(aggregateColumnNames, true);

            foreach (ValueTableColumn group_column in GroupColumns)
            {
                if (AggregateColumns.Find(x => x.Name == group_column.Name) != null)
                {
                    throw ColumnsMixedException(group_column.Name);
                }
            }

            var uniqueRows = new Dictionary <ValueTableRow, ValueTableRow>(new RowsByColumnsEqComparer(GroupColumns));
            int new_idx    = 0;

            foreach (ValueTableRow row in _rows)
            {
                if (uniqueRows.ContainsKey(row))
                {
                    ValueTableRow old_row = uniqueRows[row];

                    foreach (var Column in AggregateColumns)
                    {
                        IValue current = row.Get(Column);
                        if (current.DataType == DataType.Number)
                        {
                            decimal sum = old_row.Get(Column).AsNumber() + current.AsNumber();
                            old_row.Set(Column, ValueFactory.Create(sum));
                        }
                    }
                }
                else
                {
                    ValueTableRow new_row = _rows[new_idx++];

                    foreach (var Column in GroupColumns)
                    {
                        new_row.Set(Column, row.Get(Column));
                    }

                    foreach (var Column in AggregateColumns)
                    {
                        if (row.Get(Column).DataType != DataType.Number)
                        {
                            new_row.Set(Column, ValueFactory.Create(0));
                        }
                        else
                        {
                            new_row.Set(Column, row.Get(Column));
                        }
                    }

                    uniqueRows.Add(new_row, new_row);
                }
            }

            _rows.RemoveRange(new_idx, _rows.Count() - new_idx);

            int i = 0;

            while (i < _columns.Count())
            {
                ValueTableColumn Column = _columns.FindColumnByIndex(i);
                if (GroupColumns.IndexOf(Column) == -1 && AggregateColumns.IndexOf(Column) == -1)
                {
                    _columns.Delete(Column);
                }
                else
                {
                    ++i;
                }
            }
        }