public override void VisitScalar <T> (string name, Column <T> column, int row) { T val = column.Data[row]; int tlrow = column.Index[row]; Column <T> beforeCol = (Column <T>)_before.GetColumn(name); if (beforeCol != null) { object box; beforeCol.BoxLast(_symbol, out box); if (box != null) { if (!box.Equals(val)) { _rowChanged = true; _target.WriteCell(name, _symbol, val, -1, true, false); } } else { _rowChanged = true; _target.WriteCell(name, _symbol, val, -1, true, false); } } else { _rowChanged = true; _target.WriteCell(name, _symbol, val, -1, true, false); } }
public override void VisitNull <T> (string name, Column <T> column, int row) { if (_source.Axis.Symbol != null) { T last; RCSymbolScalar scalar = _source.Axis.Symbol[_row]; // We use the last value from the TARGET, otherwise you pull values backwards - // not good ColumnBase targetBaseColumn = _target.GetColumn(name); if (targetBaseColumn != null) { Column <T> targetColumn = (Column <T>)targetBaseColumn; if (targetColumn != null && targetColumn.Last(scalar, out last)) { _target.WriteCell(name, scalar, last, _row, true, true); } } } else { if (_last.ContainsKey(name)) { T lastVal = (T)_last[name]; _target.WriteCell(name, null, lastVal, _row, true, true); } } }
public void EvalAssert(RCRunner runner, RCClosure closure, RCBoolean right) { for (int i = 0; i < right.Count; ++i) { if (!right[i]) { RCCube target = new RCCube(new RCArray <string> ("S")); Stack <object> names = new Stack <object> (); RCBlock block = new RCBlock("", ":", closure.Code); block.Cubify(target, names); ColumnBase column = target.GetColumn("r"); string expression; if (column != null) { RCArray <string> refNames = (RCArray <string>)column.Array; // Only display the variables whose values are referenced in the assert // expression RCBlock displayVars = RCBlock.Empty; for (int j = 0; j < refNames.Count; ++j) { RCArray <string> nameParts = RCName.MultipartName(refNames[j], '.'); RCValue val = Eval.Resolve(null, closure, nameParts, null, returnNull: true); if (val != null) { displayVars = new RCBlock(displayVars, refNames[j], ":", val); } } expression = string.Format("{0}, {1}", closure.Code.ToString(), displayVars); } else { expression = string.Format("{0}", closure.Code.ToString()); } throw new RCException(closure, RCErrors.Assert, "Failed: " + expression); } } runner.Yield(closure, new RCBoolean(true)); }
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 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); } } }
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; } }