Exemplo n.º 1
0
        private List <ValueTableColumn> GetProcessingColumnList(string ColumnNames, bool EmptyListInCaseOfNull = false)
        {
            List <ValueTableColumn> processing_list = new List <ValueTableColumn>();

            if (ColumnNames != null)
            {
                if (ColumnNames.Trim().Length == 0)
                {
                    // Передали пустую строку вместо списка колонок
                    return(processing_list);
                }

                string[] column_names = ColumnNames.Split(',');
                foreach (string name in column_names)
                {
                    ValueTableColumn Column = Columns.FindColumnByName(name.Trim());

                    if (Column == null)
                    {
                        throw RuntimeException.PropNotFoundException(name.Trim());
                    }

                    processing_list.Add(Column);
                }
            }
            else if (!EmptyListInCaseOfNull)
            {
                foreach (ValueTableColumn Column in _columns)
                {
                    processing_list.Add(Column);
                }
            }
            return(processing_list);
        }
Exemplo n.º 2
0
        public ValueTableColumn GetColumnByIIndex(IValue index)
        {
            if (index.DataType == DataType.String)
            {
                ValueTableColumn Column = FindColumnByName(index.AsString());
                if (Column == null)
                {
                    throw RuntimeException.PropNotFoundException(index.AsString());
                }
                return(Column);
            }

            if (index.DataType == DataType.Number)
            {
                int i_index = Decimal.ToInt32(index.AsNumber());
                if (i_index < 0 || i_index >= Count())
                {
                    throw RuntimeException.InvalidArgumentValue();
                }

                ValueTableColumn Column = FindColumnByIndex(i_index);
                return(Column);
            }

            if (index is ValueTableColumn)
            {
                return(index as ValueTableColumn);
            }

            throw RuntimeException.InvalidArgumentType();
        }
Exemplo n.º 3
0
        public override int FindProperty(string name)
        {
            ValueTableColumn Column = FindColumnByName(name);

            if (Column == null)
            {
                throw RuntimeException.PropNotFoundException(name);
            }
            return(Column.ID);
        }
Exemplo n.º 4
0
        private IValue TryValue(ValueTableColumn Column)
        {
            IValue Value;

            if (_data.TryGetValue(Column, out Value))
            {
                return(Value);
            }
            return(Column.ValueType.AdjustValue());
        }
Exemplo n.º 5
0
        private IValue TryValue(ValueTableColumn Column)
        {
            IValue Value;

            if (_data.TryGetValue(Column, out Value))
            {
                return(Value);
            }
            return(ValueFactory.Create()); // TODO: Определять пустое значение для типа колонки
        }
Exemplo n.º 6
0
        public IValue Find(string Name)
        {
            ValueTableColumn Column = FindColumnByName(Name);

            if (Column == null)
            {
                return(ValueFactory.Create());
            }
            return(Column);
        }
Exemplo n.º 7
0
        public void LoadColumn(IValue Values, IValue ColumnIndex)
        {
            ValueTableColumn Column = Columns.GetColumnByIIndex(ColumnIndex);
            var row_iterator        = _rows.GetEnumerator();
            var array_iterator      = (Values as ArrayImpl).GetEnumerator();

            while (row_iterator.MoveNext() && array_iterator.MoveNext())
            {
                row_iterator.Current.Set(ColumnIndex, array_iterator.Current);
            }
        }
Exemplo n.º 8
0
        public ValueTableColumn Add(string Name, IValue Type = null, string Title = null)
        {
            if (FindColumnByName(Name) != null)
            {
                throw new RuntimeException("Неверное имя колонки " + Name);
            }

            var Width = 0; // затычка

            ValueTableColumn column = new ValueTableColumn(this, ++_internal_counter, Name, Title, Type, Width);

            _columns.Add(column);

            return(column);
        }
Exemplo n.º 9
0
        public ValueTableColumn Insert(int index, string Name, IValue Type = null)
        // TODO: добавить Title и Width после того, как количество обрабатываемых параметров будет увеличено хотя бы до 5
        {
            if (FindColumnByName(Name) != null)
            {
                throw new RuntimeException("Неверное имя колонки " + Name);
            }

            var Title = Name; // TODO: Затычка
            var Width = 0;    // TODO: Затычка

            ValueTableColumn column = new ValueTableColumn(this, ++_internal_counter, Name, Title, Type, Width);

            _columns.Insert(index, column);

            return(column);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        public IValue Total(IValue columnIndex)
        {
            ValueTableColumn Column   = Columns.GetColumnByIIndex(columnIndex);
            bool             has_data = false;
            decimal          Result   = 0;

            foreach (ValueTableRow row in _rows)
            {
                IValue current_value = row.Get(Column);
                if (current_value.DataType == Machine.DataType.Number)
                {
                    has_data = true;
                    Result  += current_value.AsNumber();
                }
            }

            if (has_data)
            {
                return(ValueFactory.Create(Result));
            }

            return(ValueFactory.Create());
        }
Exemplo n.º 12
0
        private List <ValueTableColumn> GetProcessingColumnList(string ColumnNames, bool EmptyListInCaseOfNull = false)
        {
            List <ValueTableColumn> processing_list = new List <ValueTableColumn>();

            if (ColumnNames != null)
            {
                if (ColumnNames.Trim().Length == 0)
                {
                    // Передали пустую строку вместо списка колонок
                    return(processing_list);
                }

                foreach (string column_name in ColumnNames.Split(','))
                {
                    string           name   = column_name.Trim();
                    ValueTableColumn Column = Columns.FindColumnByName(name);

                    if (Column == null)
                    {
                        throw WrongColumnNameException(name);
                    }

                    if (processing_list.Find(x => x.Name == name) == null)
                    {
                        processing_list.Add(Column);
                    }
                }
            }
            else if (!EmptyListInCaseOfNull)
            {
                foreach (ValueTableColumn Column in _columns)
                {
                    processing_list.Add(Column);
                }
            }
            return(processing_list);
        }
Exemplo n.º 13
0
 public IValue Get(ValueTableColumn C)
 {
     return(TryValue(C));
 }
Exemplo n.º 14
0
 public IValue Get(ValueTableColumn c)
 {
     return(TryValue(c));
 }
Exemplo n.º 15
0
 public void Set(ValueTableColumn column, IValue value)
 {
     _data[column] = column.ValueType.AdjustValue(value);
 }
Exemplo n.º 16
0
        public override IValue GetIndexedValue(IValue index)
        {
            ValueTableColumn C = GetColumnByIIndex(index);

            return(TryValue(C));
        }
Exemplo n.º 17
0
 public void Set(ValueTableColumn Column, IValue Value)
 {
     _data[Column] = Value;
 }
Exemplo n.º 18
0
        public override void SetPropValue(int propNum, IValue newVal)
        {
            ValueTableColumn C = Owner().Columns.FindColumnByIndex(propNum);

            _data[C] = C.ValueType.AdjustValue(newVal);
        }
Exemplo n.º 19
0
        public override IValue GetPropValue(int propNum)
        {
            ValueTableColumn C = Owner().Columns.FindColumnByIndex(propNum);

            return(TryValue(C));
        }
Exemplo n.º 20
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;
                }
            }
        }
Exemplo n.º 21
0
        public override void SetPropValue(int propNum, IValue newVal)
        {
            ValueTableColumn C = Owner().Columns.FindColumnById(propNum);

            _data[C] = newVal;
        }
Exemplo n.º 22
0
 public int IndexOf(ValueTableColumn column)
 {
     return(_columns.IndexOf(column));
 }
Exemplo n.º 23
0
        public void GroupBy(string groupColumnNames, string aggregateColumnNames = null)
        {
            // TODO: Сворачиваем за N^2. Переделать на N*log(N)

            List <ValueTableColumn> GroupColumns     = GetProcessingColumnList(groupColumnNames, true);
            List <ValueTableColumn> AggregateColumns = GetProcessingColumnList(aggregateColumnNames, true);

            List <ValueTableRow> new_rows = new List <ValueTableRow>();

            foreach (ValueTableRow row in _rows)
            {
                StructureImpl search = new StructureImpl();

                foreach (ValueTableColumn Column in GroupColumns)
                {
                    search.Insert(Column.Name, row.Get(Column));
                }

                ValueTableRow new_row = null;

                foreach (ValueTableRow nrow in new_rows)
                {
                    if (CheckFilterCriteria(nrow, search))
                    {
                        new_row = nrow;
                        break;
                    }
                }

                if (new_row == null)
                {
                    new_row = new ValueTableRow(this);
                    foreach (ValueTableColumn Column in GroupColumns)
                    {
                        new_row.Set(Column, row.Get(Column));
                    }

                    new_rows.Add(new_row);
                }

                foreach (ValueTableColumn Column in AggregateColumns)
                {
                    IValue  old = new_row.Get(Column);
                    decimal d_old;

                    if (old.DataType != Machine.DataType.Number)
                    {
                        d_old = 0;
                    }
                    else
                    {
                        d_old = old.AsNumber();
                    }

                    IValue  current = row.Get(Column);
                    decimal d_current;

                    if (current.DataType != Machine.DataType.Number)
                    {
                        d_current = 0;
                    }
                    else
                    {
                        d_current = current.AsNumber();
                    }

                    new_row.Set(Column, ValueFactory.Create(d_old + d_current));
                }
            }

            _rows.Clear();
            _rows.AddRange(new_rows);

            {
                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;
                    }
                }
            }
        }
Exemplo n.º 24
0
 public void Set(ValueTableColumn Column, IValue Value)
 {
     _data[Column] = Column.ValueType.AdjustValue(Value);
 }