private bool Subscribe(SubscriptionItem item, HttpTargetSite target) { bool ok = false; WireData data = null; BaseServiceNode serviceNode = _service.Children .Where((IIotNode node) => string.Equals(node.Id, item.Node, StringComparison.OrdinalIgnoreCase)).FirstOrDefault() as BaseServiceNode; if (serviceNode != null) { if (string.IsNullOrEmpty(item.Data)) { serviceNode.Subscribe(target); ok = true; } else { data = serviceNode.GetData <WireData>(item.Data); if (data != null) { data.Subscribe(target); ok = true; } } } return(ok); }
static void Main(string[] args) { var wireData = new WireData <Round>(); string file1 = @"c:\temp\losses_small_better"; string file2 = @"c:\temp\losses_small_better"; var joiner = new LossJoiner(); var limiter = new LossLimiter(); List <Round> roundsFromSource1 = wireData.ReadAll(file1); joiner.AddData(roundsFromSource1); List <Round> roundsFromSource2 = wireData.ReadAll(file2); joiner.AddData(roundsFromSource2); var allRounds = joiner.GetRounds(); var limitedRounds = limiter.Limit(allRounds, 30000); var average = RiskMeasures.Average(limitedRounds); var maxLoss = RiskMeasures.MaxLoss(limitedRounds); var tvar10 = RiskMeasures.TailValueAtRisk(limitedRounds, 0.9); Console.WriteLine($"Average: {average}"); Console.WriteLine($"maxLoss: {maxLoss}"); Console.WriteLine($"tvar10: {tvar10}"); Console.ReadKey(); }
private WireControl BuildWire(WireData wireData) { var output = FindOutputControl(wireData.Source.Id); var input = FindInputControl(wireData.Target.Id); output.IsConnected = true; input.IsConnected = true; return(new WireControl(this, input, output)); }
private void AddWire(WireData wireData) { var output = FindOutputControl(wireData.Source.Id); var input = FindInputControl(wireData.Target.Id); var wire = new WireControl(this, input, output); input.Wires.Add(wire); output.Wires.Add(wire); Wires.Add(wire); input.IsConnected = true; output.IsConnected = true; Controls.Add(wire); }
public override ObjectData Save(ObjectData dataToUse) { WireData data = (WireData)base.Save(dataToUse); //Convert the references into something serializable data.output = new List <SerializableVector3>(); for (int i = 0; i < output.Count; i++) { if (output[i] != null) { data.output.Add(output[i].transform.position); } } return(data); }
public override void Load(ObjectData dataToUse) { base.Load(dataToUse); WireData data = (WireData)dataToUse; //Grab the references from their positions output = new List <Electronic>(); for (int i = 0; i < data.output.Count; i++) { Vector3Int pos = Vector3Int.FloorToInt(data.output[i]) - GameManager.manager.tileManager.worldOrigin; if (GameManager.manager.tileManager.utilityObjects[pos.x, pos.y] != null) { output.Add(GameManager.manager.tileManager.utilityObjects[pos.x, pos.y].GetComponent <Electronic>()); } else if (GameManager.manager.tileManager.objects[pos.x, pos.y] != null) { output.Add(GameManager.manager.tileManager.objects[pos.x, pos.y].GetComponent <Electronic>()); } } }
public void Generate() { LossSimulator lossSimulator = new LossSimulator(); var fileName = @"c:\temp\losses_small_all"; var fileName2 = @"c:\temp\losses_large_all"; var losses = lossSimulator.GenerateStatic(20000, 100); var losses2 = lossSimulator.GenerateStatic(100000, 100); var betterLosses = lossSimulator.GenerateRandom(1000000, 1000); var protobufData = new ProtobufData <Trial>(); var wireData = new WireData <Trial>(); //wireData.WriteAll(betterLosses.ToList(), @"c:\temp\losses_small_better", Console.WriteLine); protobufData.WriteStreamedData(@"c:\temp\losses_large_streamed", betterLosses, Console.WriteLine); wireData.WriteStreamedData(@"c:\temp\losses_large_streamed", betterLosses, Console.WriteLine); //protobufData.WriteAll(losses.ToList(), fileName, Console.WriteLine); //protobufData.WriteAll(losses2.ToList(), fileName2, Console.WriteLine); //wireData.WriteAll(losses.ToList(), fileName, Console.WriteLine); //wireData.WriteAll(losses2.ToList(), fileName2, Console.WriteLine); List <Trial> r = protobufData.ReadAll(fileName); List <Trial> r2 = protobufData.ReadAll(fileName2); List <Trial> r3 = wireData.ReadAll(fileName); List <Trial> r4 = wireData.ReadAll(fileName2); //int roundCount = protobufData.WriteStreamedData(fileName + ".pb", losses, Console.WriteLine); //int roundCount2 = wireData.WriteStreamedData(fileName + ".wir", losses, Console.WriteLine); // IEnumerable<Trial> allData = wireData.GetStreamedData(fileName + ".wir", roundCount2); //IEnumerable<Trial> allData2 = protobufData.GetStreamedData(fileName + ".pb", roundCount); }
void drawLine() { wire = Instantiate(wirePre, start.transform); wireScript = wire.GetComponent <WireData>(); wireScript.wireConnect(start, end); }
private PartData ParsePartData(Transform trans, PartUnit partUnit, string customValue) { PartData partData; switch (partUnit.type) { case PartType.Bone: { var data = new BoneData(); for (int i = 0; i < trans.childCount; i++) { var t = trans.GetChild(i); if (!t.name.StartsWith(ModelFBXParser.GroupMark)) { continue; } var group = t; for (int j = 0; j < @group.childCount; j++) { var child = @group.GetChild(j); data.num = customValue; var childName = ModelFBXParser.ToLegalName(child.name); data.items.Add(childName); } break; } partData = data; break; } case PartType.MC: { var data = new MCData(); data.type = 1; partData = data; break; } case PartType.Wire: { var data = new WireData(); data.num = customValue; partData = data; break; } case PartType.Servo: { var data = new ServoData(); data.id = int.Parse(customValue); data.type = 1; data.angle = 120; partData = data; break; } case PartType.Motor: { var data = new MotorData(); data.id = int.Parse(customValue); partData = data; break; } case PartType.Sensor: { var data = new SensorData(); data.id = int.Parse(customValue); partData = data; break; } default: { partData = new PartData(); break; } } partData.name = trans.name; partData.source = partUnit.source; partData.transform = new DTransform(); partData.transform.position = trans.localPosition; partData.transform.angle = trans.localEulerAngles; partData.transform.scale = GetScale(trans, partData.partType); partData.parent = GetParentName(trans); return(partData); }