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); } }
protected RCCube SortCubeByDirectionAndColumn(RCSymbol left, RCCube right) { if (right.Count == 0) { return(right); } SortDirection direction = Sort.ToDir(left); string name = (string)left[0].Part(1); ColumnBase sortCol = right.GetColumn(name); RCArray <ColumnBase> columns = new RCArray <ColumnBase> ((int)right.Cols); long[] rank; if (sortCol == null) { switch (name) { case "G": rank = RankUtils.DoRank <long> (direction, 'l', right.Axis.Global); break; case "E": rank = RankUtils.DoRank <long> (direction, 'l', right.Axis.Event); break; case "T": rank = RankUtils.DoRank <RCTimeScalar> (direction, 't', right.Axis.Time); break; case "S": rank = RankUtils.DoRank <RCSymbolScalar> (direction, 's', right.Axis.Symbol); break; default: throw new Exception("Unknown timeline column: " + name); } } else { switch (sortCol.TypeCode) { case 'x': rank = RankUtils.DoRank <byte> (direction, sortCol.TypeCode, (RCArray <byte>)sortCol.Array); break; case 'l': rank = RankUtils.DoRank <long> (direction, sortCol.TypeCode, (RCArray <long>)sortCol.Array); break; case 'd': rank = RankUtils.DoRank <double> (direction, sortCol.TypeCode, (RCArray <double>)sortCol.Array); break; case 'm': rank = RankUtils.DoRank <decimal> (direction, sortCol.TypeCode, (RCArray <decimal>)sortCol.Array); break; case 's': rank = RankUtils.DoRank <string> (direction, sortCol.TypeCode, (RCArray <string>)sortCol.Array); break; case 'b': rank = RankUtils.DoRank <bool> (direction, sortCol.TypeCode, (RCArray <bool>)sortCol.Array); break; case 'y': rank = RankUtils.DoRank <RCSymbolScalar> (direction, sortCol.TypeCode, (RCArray <RCSymbolScalar>)sortCol.Array); break; case 't': rank = RankUtils.DoRank <RCTimeScalar> (direction, sortCol.TypeCode, (RCArray <RCTimeScalar>)sortCol.Array); break; default: throw new Exception("Type:" + sortCol.TypeCode + " is not supported by sort"); } } int[] rowRank = new int[rank.Length]; if (sortCol == null) { for (int i = 0; i < rowRank.Length; ++i) { rowRank[i] = (int)rank[i]; } } else { for (int i = 0; i < rowRank.Length; ++i) { rowRank[i] = sortCol.Index[(int)rank[i]]; } } Dictionary <long, int> map = new Dictionary <long, int> (); for (int i = 0; i < rowRank.Length; ++i) { map[rowRank[i]] = i; } Timeline axis = ApplyAxisRank(right.Axis, map); int lastRow = map.Count; for (int i = 0; i < axis.Count; ++i) { if (!map.ContainsKey(i)) { map[i] = lastRow; ++lastRow; } } for (int col = 0; col < right.Cols; ++col) { ColumnBase oldcol = right.GetColumn(col); ColumnBase newcol = null; switch (oldcol.TypeCode) { case 'x': newcol = DoColumn <byte> (oldcol, map, axis); break; case 'l': newcol = DoColumn <long> (oldcol, map, axis); break; case 'd': newcol = DoColumn <double> (oldcol, map, axis); break; case 'm': newcol = DoColumn <decimal> (oldcol, map, axis); break; case 's': newcol = DoColumn <string> (oldcol, map, axis); break; case 'b': newcol = DoColumn <bool> (oldcol, map, axis); break; case 'y': newcol = DoColumn <RCSymbolScalar> (oldcol, map, axis); break; case 't': newcol = DoColumn <RCTimeScalar> (oldcol, map, axis); break; case '0': newcol = oldcol; break; default: throw new Exception("Type:" + newcol.TypeCode + " is not supported by sort"); } columns.Write(newcol); } RCArray <string> names = new RCArray <string> (columns.Count); for (int i = 0; i < right.Cols; ++i) { names.Write(right.NameAt(i)); } RCCube result = new RCCube(axis, names, columns); return(result); }
protected void DoChart(RCCube result, RCSymbolScalar name, ref long row, long col, RCCube cube) { for (int i = 0; i < cube.Cols; ++i) { string colname = cube.NameAt(i); ColumnBase data = cube.GetColumn(i); RCSymbolScalar cell = RCSymbolScalar.From(row, (long)col, 0L); RCSymbolScalar parent = new RCSymbolScalar(name, colname); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, parent); result.WriteCell("v", cell, colname); result.Write(cell); for (int j = 0; j < data.Count; ++j) { string val = data.BoxCell(j).ToString(); cell = RCSymbolScalar.From(row, (long)col + data.Index[j] + 1, 0L); RCSymbolScalar child = new RCSymbolScalar(parent, (long)j); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col + data.Index[j] + 1); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, child); result.WriteCell("v", cell, val); result.Write(cell); } ++row; } if (cube.Axis.Global != null) { RCSymbolScalar cell = RCSymbolScalar.From(row, col, 0L); RCSymbolScalar parent = new RCSymbolScalar(name, "G"); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, parent); result.WriteCell("v", cell, "G"); result.Write(cell); for (int i = 0; i < cube.Axis.Global.Count; ++i) { string val = cube.Axis.Global[i].ToString(); cell = RCSymbolScalar.From(row, col + i + 1, 0L); RCSymbolScalar child = new RCSymbolScalar(parent, (long)i); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col + i + 1); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, child); result.WriteCell("v", cell, val); result.Write(cell); } ++row; } if (cube.Axis.Event != null) { RCSymbolScalar cell = RCSymbolScalar.From(row, col, 0L); RCSymbolScalar parent = new RCSymbolScalar(name, "E"); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, parent); result.WriteCell("v", cell, "E"); result.Write(cell); for (int i = 0; i < cube.Axis.Event.Count; ++i) { string val = cube.Axis.Event[i].ToString(); cell = RCSymbolScalar.From(row, col + i + 1, 0L); RCSymbolScalar child = new RCSymbolScalar(parent, (long)i); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col + i + 1); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, child); result.WriteCell("v", cell, val); result.Write(cell); } ++row; } if (cube.Axis.Time != null) { RCSymbolScalar cell = RCSymbolScalar.From(row, col, 0L); RCSymbolScalar parent = new RCSymbolScalar(name, "T"); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, parent); result.WriteCell("v", cell, "T"); result.Write(cell); for (int i = 0; i < cube.Axis.Time.Count; ++i) { string val = cube.Axis.Time[i].ToString(); cell = RCSymbolScalar.From(row, col + i + 1, 0L); RCSymbolScalar child = new RCSymbolScalar(parent, (long)i); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col + i + 1); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, child); result.WriteCell("v", cell, val); result.Write(cell); } ++row; } if (cube.Axis.Symbol != null) { RCSymbolScalar cell = RCSymbolScalar.From(row, col, 0L); RCSymbolScalar parent = new RCSymbolScalar(name, "S"); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, parent); result.WriteCell("v", cell, "S"); result.Write(cell); for (int i = 0; i < cube.Axis.Symbol.Count; ++i) { string val = cube.Axis.Symbol[i].ToString(); cell = RCSymbolScalar.From(row, col + i + 1, 0L); RCSymbolScalar child = new RCSymbolScalar(parent, (long)i); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col + i + 1); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, child); result.WriteCell("v", cell, val); result.Write(cell); } ++row; } }