예제 #1
0
 public RCCube Fill(RCCube source)
 {
     _source = source;
     for (int i = 0; i < source.Cols; ++i)
     {
         _target.ReserveColumn(source.ColumnAt(i), canonical: false);
     }
     _source.VisitCellsCanonical(this, 0, _source.Axis.Count);
     return(_target);
 }
예제 #2
0
 public RCCube Unplug(RCCube source)
 {
     _source = source;
     _unplug = true;
     for (int i = 0; i < _source.Cols; ++i)
     {
         _target.ReserveColumn(_source.ColumnAt(i));
     }
     _source.VisitCellsCanonical(this, 0, _source.Axis.Count);
     return(_target);
 }
예제 #3
0
        public void Format(RCCube source)
        {
            if (source.Count == 0)
            {
                if (_args.Syntax == "RCL")
                {
                    _builder.Append("[]");
                }
                return;
            }
            _names     = new List <string> ();
            _columns   = new List <List <string> > ();
            _max       = new List <int> ();
            _leftAlign = new List <bool> ();
            int  tcols    = 0;
            bool useGRows = false;

            if (source.Axis.Has("G") && _args.Showt)
            {
                _names.Add("G");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(false);
                ++tcols;
                useGRows = true;
            }
            if (source.Axis.Has("E") && _args.Showt)
            {
                _names.Add("E");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(false);
                ++tcols;
            }
            if (source.Axis.Has("T") && _args.Showt)
            {
                _names.Add("T");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(false);
                ++tcols;
            }
            if (source.Axis.Has("S"))
            {
                _names.Add("S");
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(true);
                ++tcols;
            }
            for (int i = 0; i < source.Cols; ++i)
            {
                string name = source.ColumnAt(i);
                char   type = source.GetTypeCode(name);
                _names.Add(source.NameAt(i));
                _columns.Add(new List <string> ());
                _max.Add(MIN_WIDTH);
                _leftAlign.Add(type == 'y' || type == 's');
            }
            // Populate _columns and _max.
            if (_args.CanonicalCubes)
            {
                source.VisitCellsCanonical(this, 0, source.Axis.Count);
            }
            else
            {
                source.VisitCellsForward(this, 0, source.Axis.Count);
            }
            if (_args.Syntax == "RCL")
            {
                FormatRC(tcols);
            }
            else if (_args.Syntax == "HTML")
            {
                FormatHtml(tcols, useGRows);
            }
            else if (_args.Syntax == "CSV")
            {
                FormatCsv(tcols, useGRows, CSV_ESCAPE_CHARS, true);
            }
            else if (_args.Syntax == "LOG")
            {
                FormatCsv(tcols, useGRows, LOG_ESCAPE_CHARS, false);
            }
            else
            {
                throw new Exception("Unknown syntax for format:" + _args.Syntax);
            }
        }
예제 #4
0
 protected void DoTree(TreeNode parent, RCCube right, ref double a, ref double g)
 {
     if (right.Axis.ColCount > 1)
     {
         // throw new NotImplementedException ("Cannot handle time cols on cubes yet.");
         // But we will still handle them as if the time col didn't exist.
     }
     if (right.Axis.Symbol != null)
     {
         Dictionary <RCSymbolScalar, TreeNode> map = new Dictionary <RCSymbolScalar, TreeNode> ();
         for (int i = 0; i < right.Cols; ++i)
         {
             string   colName = right.ColumnAt(i);
             TreeNode colNode = new TreeNode(parent, colName, i);
             colNode.v = colName;
             colNode.n = 0;
             ColumnBase col     = right.GetColumn(i);
             bool       numeric = typeof(long).IsAssignableFrom(col.GetElementType());
             for (int j = 0; j < col.Count; ++j)
             {
                 RCSymbolScalar symbol  = right.Axis.SymbolAt(col.Index[j]);
                 TreeNode       rowNode = new TreeNode(colNode, symbol.Key.ToString(), col.Index[j]);
                 object         box     = col.BoxCell(j);
                 if (numeric)
                 {
                     rowNode.n = (long)box;
                     rowNode.m = (long)box;
                     rowNode.g = Math.Abs((long)box);
                 }
                 else
                 {
                     rowNode.n = 1;
                     rowNode.m = 1;
                     rowNode.g = 1;
                 }
                 rowNode.v      = box.ToString();
                 colNode.n     += rowNode.n;
                 colNode.g     += Math.Abs(rowNode.n);
                 map[rowNode.s] = rowNode;
             }
             a += colNode.n;
             g += Math.Abs(colNode.g);
         }
     }
     else
     {
         for (int i = 0; i < right.Cols; ++i)
         {
             string   colName = right.ColumnAt(i);
             TreeNode colNode = new TreeNode(parent, colName, i);
             colNode.v = colName;
             colNode.n = 0;
             ColumnBase col     = right.GetColumn(i);
             bool       numeric = typeof(long).IsAssignableFrom(col.GetElementType());
             for (int j = 0; j < right.Count; ++j)
             {
                 TreeNode rowNode = new TreeNode(colNode, null, col.Index[j]);
                 object   box     = col.BoxCell(j);
                 if (numeric)
                 {
                     rowNode.n = (long)box;
                     rowNode.m = (long)box;
                     rowNode.g = Math.Abs((long)box);
                 }
                 else
                 {
                     rowNode.n = 1;
                     rowNode.m = 1;
                     rowNode.g = 1;
                 }
                 rowNode.v  = box.ToString();
                 colNode.n += rowNode.n;
                 colNode.g += Math.Abs(rowNode.n);
             }
             a += colNode.n;
             g += Math.Abs(colNode.g);
         }
     }
 }