Beispiel #1
0
        public IEnumerator StreamData()
        {
            var wait = new WaitForSeconds(1 / 10f);

            while (true)
            {
                SimManager.GetData(this);
                if (TimeKeeper.DeltaFrame() > Constants.CoroutineTimeSlice)
                {
                    yield return(null);
                }

                yield return(wait);
            }
        }
        private IEnumerator SimLog()
        {
            if (!IsLogging)
            {
                yield break;
            }
            yield return(new WaitUntil(() => TimeKeeper.TimeSpeed != TimeSpeed.Pause));

            if (!Directory.Exists(_logPath))
            {
                Directory.CreateDirectory(_logPath);
            }
            var filepath = Path.Combine(_logPath, "Simulation Log.csv");

            if (!File.Exists(filepath))
            {
                string[] headers = { "Timestamp",
                                     "time (s)",
                                     "Total Drones",
                                     "Active Drones",
                                     "Crashed Drones",
                                     "Job Queue Length",
                                     "Jobs Delayed in Queue",
                                     "Jobs Completed",
                                     "Jobs Delayed",
                                     "Jobs Failed",
                                     "Revenue ($)",
                                     "Delay (s)",
                                     "Audibility (s)",
                                     "Energy (kWh)" };
                WriteTupleToMemory(ref simCache, headers);
                Flush(filepath, ref simCache);
            }
            var time = TimeKeeper.Chronos.Get();
            var wait = new WaitUntil(() => time.Timer() > LoggingPeriod);

            while (true)
            {
                SimManager.GetData(this, time);
                WriteTupleToMemory(ref simCache, _simulationData);
                yield return(wait);

                time.Now();
            }
        }