예제 #1
0
        public void OnNext(IList <KafkaMessage> kmList)
        {
            var x = kmList;

            try
            {
                var stations = kmList.Select((x) =>
                {
                    var pir_detection_match = _pirDetectRegExp.Match(x.Payload);

                    if (pir_detection_match.Success)
                    {
                        var pir_detect_string = pir_detection_match.Groups[0].Value;

                        var station_id_match = _stationExtractorRegExp.Match(pir_detect_string);

                        if (station_id_match.Success)
                        {
                            var station_id = station_id_match.Groups[0].Value;

                            return(station_id);
                        }
                    }

                    return(string.Empty);
                })
                               .Where(x => !string.IsNullOrEmpty(x))
                               .GroupBy(x => x)
                               .Where(grp => grp.Count() >= THRESHOLD_VALUE).
                               Select(x => x.Key);

                foreach (var station in stations)
                {
                    var sta = _stationConfig.Stations.Where(x => x.Id.Equals(station)).FirstOrDefault();

                    _influxClient.WritePirDetectEvent(Guid.NewGuid().ToString(), station.Trim(), sta.Description, _timeProvider.GetCurrentTimeUtc());

                    _logger.LogInformation($"Activity detected in station {station}");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error!");
            }
        }