IDisposable bigbang3() { var ticks = Observable.Interval(TimeSpan.FromMilliseconds(20), new EventLoopScheduler()); var sunOrbitStream = DDSObservable.FromKeyedTopic <string, ShapeType>( DefaultParticipant.Instance, "Square", shape => shape.color, Scheduler.Default); return(sunOrbitStream.Select(sunOrbit => { //var mercuryOrbit = planetOrbit(ticks, sunOrbit, "Mercury"); //var venusOrbit = planetOrbit(ticks, sunOrbit, "Venus"); var earthOrbit = planetOrbit(ticks, sunOrbit, "Earth").Publish().RefCount(); //var marsOrbit = planetOrbit(ticks, sunOrbit, "Mars"); //var jupiterOrbit = planetOrbit(ticks, sunOrbit, "Jupiter"); double moonDegree = 0; var moonOrbit = earthOrbit.Select(earthLoc => { moonDegree += 3; Console.WriteLine("moonDegree = {0}", moonDegree); return planetLocation(earthLoc, moonDegree, "Moon"); }); var instance = new ShapeType { color = sunOrbit.Key }; return new CompositeDisposable(new IDisposable[] { //mercuryOrbit.DisposeAtEnd(circleWriter, instance).Subscribe(), //venusOrbit .DisposeAtEnd(circleWriter, instance).Subscribe(), earthOrbit.DisposeAtEnd(circleWriter, instance).Subscribe(), //marsOrbit .DisposeAtEnd(circleWriter, instance).Subscribe(), //jupiterOrbit.DisposeAtEnd(circleWriter, instance).Subscribe(), moonOrbit.DisposeAtEnd(triangleWriter, instance).Subscribe() }); }).Subscribe()); }
// Space and Time were born here! IDisposable bigbang2() { // The beginning of time! var ticks = Observable.Interval(TimeSpan.FromMilliseconds(20), new EventLoopScheduler()); // The Sun was born here! var sunOrbit = DDSObservable.FromTopic <ShapeType>(DefaultParticipant.Instance, "Square", Scheduler.Default); // planets were born here! var mercuryOrbit = planetOrbitLinq(ticks, sunOrbit, "Mercury"); var venusOrbit = planetOrbitLinq(ticks, sunOrbit, "Venus"); var earthOrbit = planetOrbitLinq(ticks, sunOrbit, "Earth").Publish().RefCount(); var marsOrbit = planetOrbitLinq(ticks, sunOrbit, "Mars"); var jupiterOrbit = planetOrbitLinq(ticks, sunOrbit, "Jupiter"); // The Moon was born here! double moonDegree = 0; var moonOrbit = earthOrbit.Select(earthLoc => { moonDegree += 7; return(planetLocation(earthLoc, moonDegree, "Moon")); }); // begin orbiting but be ready for the big crunch! return(new CompositeDisposable(new IDisposable[] { mercuryOrbit.Subscribe(circleWriter), venusOrbit.Subscribe(circleWriter), earthOrbit.Subscribe(circleWriter), marsOrbit.Subscribe(circleWriter), jupiterOrbit.Subscribe(circleWriter), moonOrbit.Subscribe(triangleWriter) })); }
IDisposable bigbang() { // The Sun was born here! var sunOrbit = DDSObservable.FromTopic <ShapeType>(DefaultParticipant.Instance, "Square", Scheduler.Default); // Earth was born here! double earthDegree = 0; IObservable <ShapeType> earthOrbit = sunOrbit.Select(sunLoc => { earthDegree += 2; return(planetLocation(sunLoc, earthDegree, "Earth")); }) .Publish() .RefCount(); // The Moon was born here! double moonDegree = 0; IObservable <ShapeType> moonOrbit = earthOrbit.Select(earthLoc => { moonDegree += 7; return(planetLocation(earthLoc, moonDegree, "Moon")); }); var assumedInstance = new ShapeType { color = "BLUE" }; // begin orbiting! return(new CompositeDisposable(new IDisposable[] { earthOrbit.DisposeAtEnd(circleWriter, assumedInstance).Subscribe(), moonOrbit.DisposeAtEnd(triangleWriter, assumedInstance).Subscribe() })); }
/** * Entry point of program */ public static void Main(string[] args) { Console.WriteLine("Running QueryProcessor. Press Enter to exit..."); if (args.Length != 1) { Console.WriteLine("Usage: soccer.exe <domain-id>"); return; } else { DefaultParticipant.DomainId = Int32.Parse(args[0]); } try { //initialize player information MetaData.initializePlayerData(); //create Sensor mapping to player name MetaData.createSensorMap(); //create Player mapping to sensor_ids MetaData.createPlayerMap(); //create Player mapping to team_ids MetaData.createTeamMap(); //get an instance of default domain participant DDS.DomainParticipant participant = DefaultParticipant.Instance; //Register types that will be used in application registerTypes(); Soccer prog = new Soccer(); //initialize dataWriters prog.initializeDataWriters(); IDisposable disposable = null; Console.WriteLine("******************Initialization is Complete**************"); //eventInfoStream subject is used to convey intermediate output from query-2 to query-4 var eventInfoStream = new Subject <BallPossessionQuery.EventInfo>(); //heatMapSub subject is used to integrate HeatMap data for 17*4=68 streams. (17 players * 4 grid types) var heatMapSub = new Subject <HeatMapProcessor.HeatMapData>(); //create rawSensorStream from data received on DDS topic "Raw SensorData" DDS.Duration_t timeout; timeout.nanosec = 0; timeout.sec = 10; /*var dict = * MetaData.PLAYER_MAP * .SelectMany((KeyValuePair<string, List<int>> keyValue, int index) => * { * return keyValue.Value; * }) * .ToDictionary(sensor_id => sensor_id, * sensor_id => new DDSKeyedSubject<int, SensorData>(sensor_id)); */ IObservable <SensorData> rawSensorStream = DDSObservable .FromTopicWaitSet <SensorData>(participant, "Raw SensorData", timeout); /*IObservable<IGroupedObservable<int, SensorData>> rawSensorStream = DDSObservable * .FromKeyedTopicWaitSet<int, SensorData>( * participant, * "Raw SensorData", * (sensor) => sensor.sensor_id, * dict, * timeout);*/ //used to keep track of number of output samples produced from a query. int output_count = 0; //initialize PerformanceTest.ptArray that stores a PerformanceTest obj for each player stream PerformanceTest.initializePtArr(); //set AvgProcessorStatus equal to true to compute performance metrics for AverageProcessor. PerformanceTest.AvgProcessorStatus = false; PerformanceTest.CurrRunningStatus = false; PerformanceTest.AggRunningStatus = true; //start throughput timer before query PerformanceTest.startThroughputSW(); int input_count = 0; var countedStream = rawSensorStream.Do(data => ++ input_count) .Publish(); //query-1 AverageProcessor /*disposable= countedStream * //.ObserveOn(new EventLoopScheduler()) * .averageProcessor() * .Merge() * //if PerformanceTest.AvgProcessorStatus is true, then perform Do side-effect. * .DoIf(() => PerformanceTest.AvgProcessorStatus, * d => output_count++, * () => * { * if (PerformanceTest.AvgProcessorStatus) * { * PerformanceTest.postProcess("averageProcessor_stats.txt"); * Console.WriteLine("Inputs = {0}. Output count = {1} ", input_count, output_count); * } * }) * //.Subscribe(prog.mPlayerDataWriter); * .Subscribe();*/ //Query-1 CurrentRunningProcessor /*disposable = countedStream.Average() * .CurrentRunningAnalysis() * .Merge() * //.Subscribe(prog.mCurrentRunningDataWriter); * .Subscribe();*/ //Query-1 AggregateRunningProcessor disposable = countedStream.Average() //disposable = AverageProcessor.Average(dict) .CurrentRunningAnalysis() .FullGameAggregateRunningDataAnalysis() .Merge() .DoIf(() => PerformanceTest.AggRunningStatus, d => output_count++, () => { if (PerformanceTest.AggRunningStatus) { PerformanceTest.postProcess("AggRunning_stats.txt"); Console.WriteLine("Inputs = {0}. Output count = {1} ", input_count, output_count); } }) .Subscribe(); //Query2 //disposable= countedStream.ballPossessionProcessor(ref eventInfoStream).Subscribe(prog.mPlayerBallPossessionDataWriter); /*//Query3 * countedStream.averageProcessor().heatMapProcessor(heatMapSub); * disposable= heatMapSub.Subscribe();*/ //Query4 //disposable= countedStream.shotOnGoalProcessor(ref eventInfoStream).Subscribe(prog.mshotOnGoalDataWriter); countedStream.Connect(); //rawSensorStream.Subscribe(); Console.ReadLine(); while (disposable != null) { ConsoleKeyInfo info = Console.ReadKey(true); if (info.Key == ConsoleKey.Enter) { disposable.Dispose(); break; } } } catch (DDS.Exception e) { Console.WriteLine("Error: {0}", e); } Console.WriteLine("Quitting..."); DefaultParticipant.Shutdown(); }