using HighWayIot.Repository.domain; using HighWayIot.Repository.service.Impl; using HighWayIot.TouchSocket; using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Configuration; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RFIDSocket { public class DataAnalysis { private static readonly Lazy lazy = new Lazy(() => new DataAnalysis()); public static DataAnalysis Instance => lazy.Value; public List rFIDContents = new List(); public List NearContents = new List(); public List rFIDHeartbeats = new List(); public List HeartbeatsState = new List(); public List rFIDStates = new List(); public List AlarmState = new List(); BaseContentServiceImpl baseContentServiceImpl = new BaseContentServiceImpl(); BaseHeartbeatServiceImpl baseHeartbeatServiceImpl = new BaseHeartbeatServiceImpl(); BaseStateServiceImpl baseStateServiceImpl = new BaseStateServiceImpl(); public void GetData() { rFIDContents = baseContentServiceImpl.GetContentInfos(); NearContents = rFIDContents.Reverse().Take(200).ToList(); rFIDStates = baseStateServiceImpl.GetStateInfos(); var StateGroup = rFIDStates.GroupBy(x => x.IP); AlarmState.Clear(); foreach (var a in StateGroup) { var b = a.LastOrDefault(); if (b.LogTime > rFIDContents.Where(x => x.IP == b.IP).LastOrDefault().LogTime) { AlarmState.Add(b); } } rFIDHeartbeats = baseHeartbeatServiceImpl.GetHeartbeatInfos(); var HeartBeatGroup = rFIDHeartbeats.GroupBy(x => x.IP); HeartbeatsState.Clear(); foreach (var a in HeartBeatGroup) { var b = a.LastOrDefault(); if (DateTime.Now - b.BeatTime < TimeSpan.FromSeconds(10)) { HeartbeatsState.Add(b); } } } private string SecondToTime(int t) { int m = t / 60; int s = t % 60; if (m == 0) { return "00 分 " + s.ToString("00") + " 秒"; } return m.ToString("00") + " 分 " + s.ToString("00") + " 秒"; } } }