|
|
|
|
using HighWayIot.Repository.domain;
|
|
|
|
|
using HighWayIot.Repository.service.Impl;
|
|
|
|
|
using HighWayIot.TouchSocket;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace RFIDSocket
|
|
|
|
|
{
|
|
|
|
|
public class DataAnalysis
|
|
|
|
|
{
|
|
|
|
|
private static readonly Lazy<DataAnalysis> lazy = new Lazy<DataAnalysis>(() => new DataAnalysis());
|
|
|
|
|
|
|
|
|
|
public static DataAnalysis Instance => lazy.Value;
|
|
|
|
|
|
|
|
|
|
public List<RFIDContent> rFIDContents = new List<RFIDContent>();
|
|
|
|
|
public List<RFIDContent> NearContents = new List<RFIDContent>();
|
|
|
|
|
public List<RFIDHeartbeat> rFIDHeartbeats = new List<RFIDHeartbeat>();
|
|
|
|
|
public List<RFIDHeartbeat> HeartbeatsState = new List<RFIDHeartbeat>();
|
|
|
|
|
public List<RFIDState> rFIDStates = new List<RFIDState>();
|
|
|
|
|
public List<RFIDState> AlarmState = new List<RFIDState>();
|
|
|
|
|
BaseContentServiceImpl baseContentServiceImpl = new BaseContentServiceImpl();
|
|
|
|
|
BaseHeartbeatServiceImpl baseHeartbeatServiceImpl = new BaseHeartbeatServiceImpl();
|
|
|
|
|
BaseStateServiceImpl baseStateServiceImpl = new BaseStateServiceImpl();
|
|
|
|
|
|
|
|
|
|
public void GetData()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
rFIDContents = baseContentServiceImpl.GetContentInfos();
|
|
|
|
|
|
|
|
|
|
NearContents = rFIDContents.Reverse<RFIDContent>().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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<string> GetAllIP()
|
|
|
|
|
{
|
|
|
|
|
var groups = baseContentServiceImpl.GetContentInfos().GroupBy(x => x.IP);
|
|
|
|
|
List<string> result = new List<string>();
|
|
|
|
|
foreach (var group in groups)
|
|
|
|
|
{
|
|
|
|
|
result.Add(group.Key);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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") + " 秒";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|