public AlertData Process(CustomAlert alert, StreamlabsEvent streamEvent) { AlertData data = new AlertData { canSpawn = false }; if (alert == null || alert.Descriptor == null || alert.GameObject == null) { return(data); } AlertValue value = _config.Alerts.FirstOrDefault(a => a.Enabled && a.AlertType == alert.AlertType && (a.Value == alert.Descriptor.alertName || a.Value == alert.Descriptor.channelPointsName)); if (value != null) { data.canSpawn = true; if (value.AlertType == AlertType.ChannelPoints && streamEvent != null) { data.canSpawn = alert.Descriptor.channelPointsName.ToLower().Trim() == streamEvent.Message[0].ChannelPointsName.ToLower().Trim(); } data.delay = value.OverrideDelay ? value.DelayOverrideTime : _config.AlertDelay; data.volume = value.Volume; } return(data); }
public AlertValue GetAlertValue(string id) { AlertValue alert = new AlertValue(); if (int.TryParse(id, out int _id)) { alert = _db.AlertValues.SingleOrDefault(a => a.AlertValueID == _id); alert.SensorName = _db.SensorGroups.SingleOrDefault(g => g.GroupID == alert.GroupID).GroupName.ToString(); } return(alert); }
public async Task <AlertValue> Edit(AlertValue model) { var isUpdated = await _alertValueRepository.Update(model); if (isUpdated) { return(await _alertValueRepository.Read(model.Id)); } throw new Exception($"Failed to update alert value {model.Id}"); }
public static void LoadAlerts() { foreach (AlertDescriptor.AlertType alertType in (AlertDescriptor.AlertType[])Enum.GetValues(typeof(AlertDescriptor.AlertType))) { AlertValue alertValue = new AlertValue(); alertValue.alertType = alertType; alertValue.value = Plugin.config.GetString("StreamlabsAlerts", alertType.ToString() + "Value", "Disabled"); alerts.Add(alertValue); //int savedAlertValue = Plugin.config.GetInt("Streamlabs", "SelectedFollowAlert", SelectedFollowAlert); } }
public AlertValue ValueFromAlert(CustomAlert alert) { AlertValue value = _config.Alerts.FirstOrDefault(a => a.AlertType == alert.AlertType && a.Value == (string.IsNullOrEmpty(alert.Descriptor.channelPointsName) ? alert.Descriptor.alertName : alert.Descriptor.channelPointsName)); if (value == null) { value = new AlertValue { Enabled = false, OverrideDelay = false, AlertType = alert.AlertType, DelayOverrideTime = _config.AlertDelay, Value = string.IsNullOrEmpty(alert.Descriptor.channelPointsName) ? alert.Descriptor.alertName : alert.Descriptor.channelPointsName }; _config.Alerts.Add(value); } return(value); }
public async Task <AlertValue> Create(AlertValue model) { var createdId = await _alertValueRepository.Create(model); return(await _alertValueRepository.Read(createdId)); }
private async Task <IEnumerable <AlertValue> > GenerateAlertsNonConstantValue(IList <NormalizedLog> logs, IList <Alert> alerts) { var componentId = logs.First().ComponentId; var alertValues = new List <AlertValue>(); if (alerts.Any()) { var longestTimespan = alerts.Select(elem => elem.Timespan).Max(); var firstLogTime = logs.Select(elem => elem.DateTime).Min(); var lastLogTime = logs.Select(elem => elem.DateTime).Max(); var startDateTime = firstLogTime - longestTimespan; var endDateTime = lastLogTime + longestTimespan; var materializedLogs = (await _normalizedLogRepository.WithinTimeFrameForComponents(new[] { componentId }, startDateTime, endDateTime, null)).OrderBy(elem => elem.DateTime).ToArray(); foreach (var alert in alerts) { var earliestEvent = firstLogTime - alert.Timespan; var latestEvent = lastLogTime + alert.Timespan; var rule = alert.GeneralRule; var valueMatcher = alert.Value; var logsWithinTimeFrame = materializedLogs.Where(elem => elem.DateTime >= earliestEvent && elem.DateTime <= latestEvent).ToArray(); NormalizedLog startLog = null; var eventCount = 0; foreach (var log in logsWithinTimeFrame) { var isMatch = IsMatch(rule.Id, log, valueMatcher, out var matchedValue); if (startLog == null) { if (isMatch) { startLog = log; eventCount++; } } else { if (isMatch) { eventCount++; } if (eventCount >= alert.Threshold) { // create new alert value and save it to db var alertValue = new AlertValue { Id = 0, AlertId = alert.Id, TimespanStart = startLog.DateTime, TimespanEnd = log.DateTime, ConstantValue = null }; var createdId = await _alertValueRepository.Create(alertValue); alertValues.Add(await _alertValueRepository.Read(createdId)); // reset event count eventCount = 0; // start search for new window beginning startLog = null; } else { var diff = startLog.DateTime - log.DateTime; if (diff > alert.Timespan) { // find next start, search until new positive match is found or until end of current windows is found var nextLogStart = logsWithinTimeFrame.FirstOrDefault(elem => elem.DateTime > startLog.DateTime && elem.DateTime <= log.DateTime && IsMatch(rule.Id, elem, valueMatcher, out var nextConstantValue)); // current window is closed, we restart search if (nextLogStart == null || nextLogStart.Id == log.Id) { eventCount = 0; startLog = null; } // we found middle match else { // we lost previous first match eventCount--; startLog = nextLogStart; } } } } } } } return(alertValues); }