private Dictionary <string, TimeSpan> GetStateDurations(List <ActuatorHistoryEntry> historyEntries) { var durations = new Dictionary <string, TimeSpan>(); ActuatorHistoryEntry previousEntry = null; foreach (var historyEntry in historyEntries.OrderBy(e => e.Timestamp)) { if (previousEntry == null) { previousEntry = historyEntry; continue; } ////if (historyEntry.OldState != previousEntry.NewState) ////{ //// _notificationHandler.Warning("Detected wrong states between history entries of actuator '" + _actuator.Id + "'."); ////} TimeSpan durationOfState = historyEntry.Timestamp - previousEntry.Timestamp; TimeSpan totalDuration; if (!durations.TryGetValue(previousEntry.NewState, out totalDuration)) { durations.Add(previousEntry.NewState, durationOfState); } else { durations[previousEntry.NewState] = totalDuration + durationOfState; } previousEntry = historyEntry; } return(durations); }
public void AddEntry(ActuatorHistoryEntry entry) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } lock (_syncRoot) { if (entry.Timestamp.Month != DateTime.Now.Month) { _entriesOfThisMonth.Clear(); _logger.Verbose("Cleared rolling history due to month change."); } _entriesOfThisMonth.Add(entry); string directory = Path.GetDirectoryName(_filename); if (!Directory.Exists(directory)) { _logger.Verbose("Creating directory... " + directory); Directory.CreateDirectory(directory); } File.AppendAllText(_filename, entry.ToCsv()); } }
private void QueueEntry(IActuator actuator, string newState) { var entry = new ActuatorHistoryEntry(DateTime.Now, actuator.Id, newState); _actuatorHistory[actuator].AddEntry(entry); lock (_queuedEntries) { _queuedEntries.Add(entry); } }