예제 #1
0
        private IEnumerator HubLog(Objects.Hub hub)
        {
            if (!IsLogging)
            {
                yield break;
            }
            yield return(new WaitUntil(() => TimeKeeper.TimeSpeed != TimeSpeed.Pause));

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

            while (true)
            {
                hub.GetData(this, time);
                WriteTupleToMemory(ref hub.dataCache, _hubData);
                yield return(wait);

                time.Now();
            }
        }