public RCCube Delta() { HashSet <RCSymbolScalar> removeSyms = new HashSet <RCSymbolScalar> (); for (int i = 0; i < _before.Axis.Count; ++i) { removeSyms.Add(_before.Axis.Symbol[i]); } HashSet <RCSymbolScalar> afterSyms = new HashSet <RCSymbolScalar> (); for (int i = 0; i < _after.Axis.Count; ++i) { afterSyms.Add(_after.Axis.Symbol[i]); } removeSyms.ExceptWith(afterSyms); if (removeSyms.Count > 0) { foreach (RCSymbolScalar sym in removeSyms) { // Still unsure whether I really want to hardcode "i" here... _target.WriteCell("i", sym, RCIncrScalar.Delete, -1, true, false); _target.Write(-1, -1, new RCTimeScalar(DateTime.UtcNow.Ticks, RCTimeType.Timestamp), sym); } } _after.VisitCellsForward(this, 0, _after.Count); return(_target); }
public static void ListExec(RCRunner runner, RCClosure closure) { RCArray <Exec> modules = new RCArray <Exec> (); RCArray <long> keys = new RCArray <long> (); lock (runner._botLock) { foreach (KeyValuePair <long, RCBot> kv in runner._bots) { keys.Write(kv.Key); modules.Write((Exec)runner._bots[kv.Key].GetModule(typeof(Exec))); } } RCCube result = new RCCube("S"); for (int i = 0; i < modules.Count; ++i) { lock (modules[i]._lock) { foreach (KeyValuePair <long, Exec.ChildProcess> kv in modules[i]._process) { RCSymbolScalar sym = RCSymbolScalar.From("exec", keys[i], kv.Key); result.WriteCell("bot", sym, keys[i]); result.WriteCell("handle", sym, (long)kv.Key); result.WriteCell("pid", sym, (long)kv.Value._pid); result.WriteCell("program", sym, kv.Value._program); result.WriteCell("arguments", sym, kv.Value._arguments); result.WriteCell("exit", sym, kv.Value._exitCode); result.Write(sym); } } } runner.Yield(closure, result); }
/* * public static void ListFibers (RCRunner runner, RCClosure closure) * { * RCArray<Fiber> modules = new RCArray<Fiber> (); * RCArray<long> keys = new RCArray<long> (); * lock (runner._botLock) * { * foreach (KeyValuePair<long, RCBot> kv in runner._bots) * { * keys.Write (kv.Key); * modules.Write ((Fiber) runner._bots[kv.Key].GetModule (typeof (Fiber))); * } * } * RCArray<long> bots = new RCArray<long> (); * RCArray<long> fibers = new RCArray<long> (); * RCArray<string> states = new RCArray<string> (); * for (int i = 0; i < modules.Count; ++i) * { * lock (modules[i]._fiberLock) * { * foreach (KeyValuePair<long, Fiber.FiberState> kv in modules[i]._fibers) * { * bots.Write (keys[i]); * fibers.Write (kv.Key); * states.Write (kv.Value.State); * } * } * } * RCBlock result = RCBlock.Empty; * if (states.Count > 0) * { * result = new RCBlock (result, "bot", ":", new RCLong (bots)); * result = new RCBlock (result, "fiber", ":", new RCLong (fibers)); * result = new RCBlock (result, "state", ":", new RCString (states)); * } * * runner.Yield (closure, result); * } */ public static void ListFibers(RCRunner runner, RCClosure closure) { RCArray <Fiber> modules = new RCArray <Fiber> (); RCArray <long> keys = new RCArray <long> (); lock (runner._botLock) { foreach (KeyValuePair <long, RCBot> kv in runner._bots) { keys.Write(kv.Key); modules.Write((Fiber)runner._bots[kv.Key].GetModule(typeof(Fiber))); } } RCCube result = new RCCube("S"); for (int i = 0; i < modules.Count; ++i) { lock (modules[i]._fiberLock) { foreach (KeyValuePair <long, Fiber.FiberState> kv in modules[i]._fibers) { RCSymbolScalar sym = RCSymbolScalar.From("fiber", keys[i], kv.Key); result.WriteCell("bot", sym, keys[i]); result.WriteCell("fiber", sym, kv.Key); result.WriteCell("state", sym, kv.Value.State); result.Write(sym); } } } runner.Yield(closure, result); }
public static void ListRequest(RCRunner runner, RCClosure closure) { RCArray <HttpServer> modules = new RCArray <HttpServer> (); RCArray <long> keys = new RCArray <long> (); lock (runner._botLock) { foreach (KeyValuePair <long, RCBot> kv in runner._bots) { keys.Write(kv.Key); modules.Write((HttpServer)runner._bots[kv.Key].GetModule(typeof(HttpServer))); } } RCCube result = new RCCube("S"); for (int i = 0; i < modules.Count; ++i) { lock (modules[i]._lock) { foreach (KeyValuePair <int, HttpServer.RequestInfo> kv in modules[i]._contexts) { RCSymbolScalar urlsym = RCSymbolScalar.From("request", keys[i], (long)kv.Key); result.WriteCell("bot", urlsym, keys[i]); result.WriteCell("handle", urlsym, (long)kv.Key); result.WriteCell("url", urlsym, kv.Value.Context.Request.RawUrl); result.Write(urlsym); } } } runner.Yield(closure, result); }
public override void Cubify(RCCube target, Stack <object> names) { object[] array = names.ToArray(); System.Array.Reverse(array); RCSymbolScalar symbol = RCSymbolScalar.From(array); target.WriteCell(this.TypeCode.ToString(), symbol, Name, -1, true, false); target.Write(symbol); }
public override void AfterRow(long e, RCTimeScalar t, RCSymbolScalar s, int row) { if (_indicator) { long g = -1; _target.Write(g, e, t, s); } _indicator = false; }
public override void AfterRow(long e, RCTimeScalar t, RCSymbolScalar s, int row) { if (_indicator[row]) { // g needs to be included in the signature above. long g = -1; _target.Write(g, e, t, s); } }
public override void Cubify(RCCube target, Stack <object> names) { object[] array = names.ToArray(); System.Array.Reverse(array); RCSymbolScalar symbol = RCSymbolScalar.From(array); for (int i = 0; i < Count; ++i) { T val = this[i]; RCSymbolScalar symboli = new RCSymbolScalar(symbol, (long)i); // Do not try to evaluate incrs during cubification target.WriteCell(this.TypeCode.ToString(), symboli, val, -1, true, false); target.Write(symboli); } }
public override void AfterRow(long e, RCTimeScalar t, RCSymbolScalar s, int row) { if (!_accept) { return; } // Do this after writing the individual cells, // the correct behavior of WriteCell depends on it. // Do not pass the counter here. long g = row; if (_source.Axis.Global != null) { g = _source.Axis.Global[row]; } _target.Write(g, e, t, s); }
public override void Cubify(RCCube target, Stack <object> names) { if (this.Left != null) { names.Push("L"); this.Left.Cubify(target, names); names.Pop(); } names.Push("R"); this.Right.Cubify(target, names); names.Pop(); object[] array = names.ToArray(); System.Array.Reverse(array); RCSymbolScalar symbol = RCSymbolScalar.From(array); target.WriteCell("o", symbol, Name); target.Write(symbol); }
protected void DoChart <T> (RCCube result, RCSymbolScalar name, long row, long col, RCVector <T> right) { for (int i = 0; i < right.Count; ++i) { string val = right[i].ToString(); RCSymbolScalar s = RCSymbolScalar.From(row, (long)col + i, 0L); RCSymbolScalar k = new RCSymbolScalar(name, (long)i); result.WriteCell("r", s, row); result.WriteCell("c", s, (long)col + i); result.WriteCell("l", s, 0L); result.WriteCell("k", s, k); result.WriteCell("v", s, val); result.Write(s); } }
public static void ListVars(RCRunner runner, RCClosure closure) { RCArray <Variable> modules = new RCArray <Variable> (); RCArray <long> keys = new RCArray <long> (); lock (runner._botLock) { foreach (KeyValuePair <long, RCBot> kv in runner._bots) { keys.Write(kv.Key); modules.Write((Variable)runner._bots[kv.Key].GetModule(typeof(Variable))); } } RCCube result = new RCCube("S"); for (int i = 0; i < modules.Count; ++i) { lock (modules[i]._lock) { foreach (KeyValuePair <object, Dictionary <RCSymbolScalar, RCValue> > section in modules[i]._sections) { RCSymbolScalar botsym = RCSymbolScalar.From("var", keys[i]); foreach (KeyValuePair <RCSymbolScalar, RCValue> kv in section.Value) { RCSymbolScalar varsym = RCSymbolScalar.From(botsym, kv.Key); result.WriteCell("bot", varsym, keys[i]); result.WriteCell("section", varsym, section.Key); result.WriteCell("name", varsym, kv.Key); result.WriteCell("value", varsym, kv.Value.ToString()); result.Write(varsym); } } } } runner.Yield(closure, 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; } }
protected void DoChart(RCCube result, RCSymbolScalar parent, ref long row, long col, RCBlock right) { for (int i = 0; i < right.Count; ++i) { RCBlock current = right.GetName(i); object shortName = current.Name; if (shortName.Equals("")) { shortName = (long)i; } RCSymbolScalar name = new RCSymbolScalar(parent, shortName); RCSymbolScalar cell = RCSymbolScalar.From(row, col, 0L); result.WriteCell("r", cell, row); result.WriteCell("c", cell, col); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, name); result.WriteCell("v", cell, shortName is long?shortName.ToString() : shortName); result.Axis.Write(cell); RCVectorBase vector = current.Value as RCVectorBase; if (vector != null) { ++col; switch (vector.TypeCode) { case 'l': DoChart <long> (result, name, row, col, (RCVector <long>)vector); break; case 'd': DoChart <double> (result, name, row, col, (RCVector <double>)vector); break; case 'm': DoChart <decimal> (result, name, row, col, (RCVector <decimal>)vector); break; case 's': DoChart <string> (result, name, row, col, (RCVector <string>)vector); break; case 'x': DoChart <byte> (result, name, row, col, (RCVector <byte>)vector); break; case 'y': DoChart <RCSymbolScalar> (result, name, row, col, (RCVector <RCSymbolScalar>)vector); break; case 'b': DoChart <bool> (result, name, row, col, (RCVector <bool>)vector); break; default: throw new Exception("Unknown typecode: " + vector.TypeCode); } --col; ++row; continue; } RCBlock block = current.Value as RCBlock; if (block != null) { ++col; ++row; DoChart(result, name, ref row, col, block); --col; continue; } RCOperator oper = current.Value as RCOperator; if (oper != null) { ++col; string val = oper.ToString(); cell = RCSymbolScalar.From(row, col, 0L); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, new RCSymbolScalar(name, 0L)); result.WriteCell("v", cell, val); result.Write(cell); ++row; --col; continue; } RCReference reference = current.Value as RCReference; if (reference != null) { ++col; string val = reference.ToString(); cell = RCSymbolScalar.From(row, col, 0L); result.WriteCell("r", cell, (long)row); result.WriteCell("c", cell, (long)col); result.WriteCell("l", cell, 0L); result.WriteCell("k", cell, new RCSymbolScalar(name, 0L)); result.WriteCell("v", cell, val); result.Write(cell); ++row; --col; continue; } RCCube cube = current.Value as RCCube; if (cube != null) { ++col; ++row; DoChart(result, name, ref row, col, cube); ++row; --col; continue; } } }