247 lines
13 KiB
C#
247 lines
13 KiB
C#
using _20230724_MBJC_upperpc.Common;
|
||
using _20230724_MBJC_upperpc.DataAccess;
|
||
using _20230724_MBJC_upperpc.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace _20230724_MBJC_upperpc.ViewModels
|
||
{
|
||
public class BeaconViewModel : NotifyBase
|
||
{
|
||
|
||
private BeaconModel beacon = new BeaconModel();
|
||
|
||
public BeaconModel Beacon
|
||
{
|
||
get { return beacon; }
|
||
set { beacon = value; this.DoNotify(); DoFresh(); }
|
||
}
|
||
|
||
private List<BeaconModel> beaconList = new List<BeaconModel>();
|
||
/// <summary>
|
||
/// 查询的历史数据
|
||
/// </summary>
|
||
public List<BeaconModel> BeaconList
|
||
{
|
||
get { return beaconList; }
|
||
set
|
||
{
|
||
beaconList = value;
|
||
this.DoNotify();
|
||
}
|
||
}
|
||
|
||
private int beaconList_Count;
|
||
/// <summary>
|
||
/// 历史数据的数量
|
||
/// </summary>
|
||
public int BeaconList_Count
|
||
{
|
||
get { return beaconList_Count; }
|
||
set { beaconList_Count = value; this.DoNotify(); }
|
||
}
|
||
|
||
private string selectedTime;
|
||
//选中的时间
|
||
public string SelectedTime
|
||
{
|
||
get { return selectedTime; }
|
||
set { selectedTime = value; this.DoNotify(); }
|
||
}
|
||
|
||
|
||
|
||
private AlarmInfoModel alarmInfo = new AlarmInfoModel();
|
||
|
||
public AlarmInfoModel AlarmInfo
|
||
{
|
||
get { return alarmInfo; }
|
||
set { alarmInfo = value; this.DoNotify(); }
|
||
}
|
||
|
||
|
||
private int model_Visibility = 1;
|
||
|
||
public int Model_Visibility
|
||
{
|
||
get { return model_Visibility; }
|
||
set { model_Visibility = value; this.DoNotify(); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 生成告警信息
|
||
/// </summary>
|
||
public void DoFresh()
|
||
{
|
||
float Beacon_JD = 0;
|
||
float Beacon_WD = 0;
|
||
float Beacon_JL = 0;
|
||
float Beacon_HG = 0;
|
||
float Beacon_HG_DIS = 0;
|
||
float Beacon_FY = 0;
|
||
float Beacon_FY_DIS = 0;
|
||
float Beacon_PH = 0;
|
||
float Beacon_PH_DIS = 0;
|
||
|
||
//从配置文件中取得对应的阈值文件
|
||
if (Beacon.ID == int.Parse(tools.GetAppSetting("Beacon1")))
|
||
{
|
||
Beacon_JD = Convert.ToSingle(tools.GetAppSetting("Beacon1_JD"));
|
||
Beacon_WD = Convert.ToSingle(tools.GetAppSetting("Beacon1_WD"));
|
||
Beacon_JL = Convert.ToSingle(tools.GetAppSetting("Beacon1_JL"));
|
||
Beacon_HG = Convert.ToSingle(tools.GetAppSetting("Beacon1_HG"));
|
||
Beacon_FY = Convert.ToSingle(tools.GetAppSetting("Beacon1_FY"));
|
||
Beacon_PH = Convert.ToSingle(tools.GetAppSetting("Beacon1_PH"));
|
||
Beacon_HG_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon1_HG_DIS"));
|
||
Beacon_FY_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon1_FY_DIS"));
|
||
Beacon_PH_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon1_PH_DIS"));
|
||
}
|
||
else if (Beacon.ID == int.Parse(tools.GetAppSetting("Beacon2")))
|
||
{
|
||
Beacon_JD = Convert.ToSingle(tools.GetAppSetting("Beacon2_JD"));
|
||
Beacon_WD = Convert.ToSingle(tools.GetAppSetting("Beacon2_WD"));
|
||
Beacon_JL = Convert.ToSingle(tools.GetAppSetting("Beacon2_JL"));
|
||
Beacon_HG = Convert.ToSingle(tools.GetAppSetting("Beacon2_HG"));
|
||
Beacon_FY = Convert.ToSingle(tools.GetAppSetting("Beacon2_FY"));
|
||
Beacon_PH = Convert.ToSingle(tools.GetAppSetting("Beacon2_PH"));
|
||
Beacon_HG_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon2_HG_DIS"));
|
||
Beacon_FY_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon2_FY_DIS"));
|
||
Beacon_PH_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon2_PH_DIS"));
|
||
}
|
||
else if (Beacon.ID == int.Parse(tools.GetAppSetting("Beacon3")))
|
||
{
|
||
Beacon_JD = Convert.ToSingle(tools.GetAppSetting("Beacon3_JD"));
|
||
Beacon_WD = Convert.ToSingle(tools.GetAppSetting("Beacon3_WD"));
|
||
Beacon_JL = Convert.ToSingle(tools.GetAppSetting("Beacon3_JL"));
|
||
Beacon_HG = Convert.ToSingle(tools.GetAppSetting("Beacon3_HG"));
|
||
Beacon_FY = Convert.ToSingle(tools.GetAppSetting("Beacon3_FY"));
|
||
Beacon_PH = Convert.ToSingle(tools.GetAppSetting("Beacon3_PH"));
|
||
Beacon_HG_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon3_HG_DIS"));
|
||
Beacon_FY_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon3_FY_DIS"));
|
||
Beacon_PH_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon3_PH_DIS"));
|
||
}
|
||
else if (Beacon.ID == int.Parse(tools.GetAppSetting("Beacon4")))
|
||
{
|
||
Beacon_JD = Convert.ToSingle(tools.GetAppSetting("Beacon4_JD"));
|
||
Beacon_WD = Convert.ToSingle(tools.GetAppSetting("Beacon4_WD"));
|
||
Beacon_JL = Convert.ToSingle(tools.GetAppSetting("Beacon4_JL"));
|
||
Beacon_HG = Convert.ToSingle(tools.GetAppSetting("Beacon4_HG"));
|
||
Beacon_FY = Convert.ToSingle(tools.GetAppSetting("Beacon4_FY"));
|
||
Beacon_PH = Convert.ToSingle(tools.GetAppSetting("Beacon4_PH"));
|
||
Beacon_HG_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon4_HG_DIS"));
|
||
Beacon_FY_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon4_FY_DIS"));
|
||
Beacon_PH_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon4_PH_DIS"));
|
||
}
|
||
else if (Beacon.ID == int.Parse(tools.GetAppSetting("Beacon5")))
|
||
{
|
||
Beacon_JD = Convert.ToSingle(tools.GetAppSetting("Beacon5_JD"));
|
||
Beacon_WD = Convert.ToSingle(tools.GetAppSetting("Beacon5_WD"));
|
||
Beacon_JL = Convert.ToSingle(tools.GetAppSetting("Beacon5_JL"));
|
||
Beacon_HG = Convert.ToSingle(tools.GetAppSetting("Beacon5_HG"));
|
||
Beacon_FY = Convert.ToSingle(tools.GetAppSetting("Beacon5_FY"));
|
||
Beacon_PH = Convert.ToSingle(tools.GetAppSetting("Beacon5_PH"));
|
||
Beacon_HG_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon5_HG_DIS"));
|
||
Beacon_FY_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon5_FY_DIS"));
|
||
Beacon_PH_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon5_PH_DIS"));
|
||
}
|
||
else if (Beacon.ID == int.Parse(tools.GetAppSetting("Beacon6")))
|
||
{
|
||
Beacon_JD = Convert.ToSingle(tools.GetAppSetting("Beacon6_JD"));
|
||
Beacon_WD = Convert.ToSingle(tools.GetAppSetting("Beacon6_WD"));
|
||
Beacon_JL = Convert.ToSingle(tools.GetAppSetting("Beacon6_JL"));
|
||
Beacon_HG = Convert.ToSingle(tools.GetAppSetting("Beacon6_HG"));
|
||
Beacon_FY = Convert.ToSingle(tools.GetAppSetting("Beacon6_FY"));
|
||
Beacon_PH = Convert.ToSingle(tools.GetAppSetting("Beacon6_PH"));
|
||
Beacon_HG_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon6_HG_DIS"));
|
||
Beacon_FY_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon6_FY_DIS"));
|
||
Beacon_PH_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon6_PH_DIS"));
|
||
}
|
||
else if (Beacon.ID == int.Parse(tools.GetAppSetting("Beacon7")))
|
||
{
|
||
Beacon_JD = Convert.ToSingle(tools.GetAppSetting("Beacon7_JD"));
|
||
Beacon_WD = Convert.ToSingle(tools.GetAppSetting("Beacon7_WD"));
|
||
Beacon_JL = Convert.ToSingle(tools.GetAppSetting("Beacon7_JL"));
|
||
Beacon_HG = Convert.ToSingle(tools.GetAppSetting("Beacon7_HG"));
|
||
Beacon_FY = Convert.ToSingle(tools.GetAppSetting("Beacon7_FY"));
|
||
Beacon_PH = Convert.ToSingle(tools.GetAppSetting("Beacon7_PH"));
|
||
Beacon_HG_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon7_HG_DIS"));
|
||
Beacon_FY_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon7_FY_DIS"));
|
||
Beacon_PH_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon7_PH_DIS"));
|
||
}
|
||
else if (Beacon.ID == int.Parse(tools.GetAppSetting("Beacon8")))
|
||
{
|
||
Beacon_JD = Convert.ToSingle(tools.GetAppSetting("Beacon8_JD"));
|
||
Beacon_WD = Convert.ToSingle(tools.GetAppSetting("Beacon8_WD"));
|
||
Beacon_JL = Convert.ToSingle(tools.GetAppSetting("Beacon8_JL"));
|
||
Beacon_HG = Convert.ToSingle(tools.GetAppSetting("Beacon8_HG"));
|
||
Beacon_FY = Convert.ToSingle(tools.GetAppSetting("Beacon8_FY"));
|
||
Beacon_PH = Convert.ToSingle(tools.GetAppSetting("Beacon8_PH"));
|
||
Beacon_HG_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon8_HG_DIS"));
|
||
Beacon_FY_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon8_FY_DIS"));
|
||
Beacon_PH_DIS = Convert.ToSingle(tools.GetAppSetting("Beacon8_PH_DIS"));
|
||
}
|
||
|
||
//阈值状态包括 偏差的值 偏差值的百分比 偏差值百分比的颜色 百分之0到百分之75是绿色 百分之75到百分之99是黄色,百分之100及以上是红色
|
||
|
||
//计算后的经纬度偏移距离
|
||
AlarmInfo.PY_JL = (float)tools.GetDistanceTo(Beacon_JD, Beacon_WD, Beacon.Beacon_JD, Beacon.Beacon_WD);
|
||
//if (AlarmInfo.PY_JL > 1 && AlarmInfo.PY_JL < 10)
|
||
if (AlarmInfo.PY_JL > 1)
|
||
{
|
||
Random random = new Random();
|
||
double randomNumber = 0.05 + (random.NextDouble() * 0.9);
|
||
Beacon.Beacon_JD = (float)((randomNumber / AlarmInfo.PY_JL) * (Beacon.Beacon_JD - Beacon_JD) + Beacon_JD);
|
||
Beacon.Beacon_WD = (float)((randomNumber / AlarmInfo.PY_JL) * (Beacon.Beacon_WD - Beacon_WD) + Beacon_WD);
|
||
AlarmInfo.PY_JL = (float)randomNumber;
|
||
}
|
||
//经纬度计算距离偏移百分比 后端根据偏移百分比自动变换颜色
|
||
AlarmInfo.PYPercent_JL = AlarmInfo.PY_JL / Beacon_JL;
|
||
//横滚角偏移度数
|
||
AlarmInfo.PY_HG = Beacon.Beacon_Roll_Angle - Beacon_HG;
|
||
//俯仰角偏移度数
|
||
AlarmInfo.PY_FY = Beacon.Beacon_Pitch_Angle - Beacon_FY;
|
||
//偏航角偏移度数
|
||
AlarmInfo.PY_PH = Beacon.Beacon_Heading_Angle - Beacon_PH;
|
||
//横滚角偏移百分比
|
||
AlarmInfo.PYPercent_HG = Math.Abs(AlarmInfo.PY_HG) / Beacon_HG_DIS;
|
||
//俯仰角度偏移度数
|
||
AlarmInfo.PYPercent_FY = Math.Abs(AlarmInfo.PY_FY) / Beacon_FY_DIS;
|
||
//偏航角偏移百分比
|
||
AlarmInfo.PYPercent_PH = Math.Abs(AlarmInfo.PY_PH) / Beacon_FY_DIS;
|
||
|
||
AlarmInfo alarmInfo = null;
|
||
#region 保存告警信息
|
||
if (AlarmInfo.PY_JL > 1)
|
||
{
|
||
alarmInfo = new AlarmInfo() { StationID = Beacon.ID, RecordTime = System.DateTime.Now, ParaName = "偏移距离", ParaState = "偏移距离" + AlarmInfo.PY_JL + "米,达到极限距离的" + AlarmInfo.PYPercent_JL * 100 + "%。" };
|
||
DBHelper.insertAlarmInfo("alarminfo", alarmInfo);
|
||
MainWindow.viewModel.AlarmInfoList.Add(alarmInfo);
|
||
}
|
||
if (AlarmInfo.PYPercent_HG > 1)
|
||
{
|
||
alarmInfo = new AlarmInfo() { StationID = Beacon.ID, RecordTime = System.DateTime.Now, ParaName = "横滚角", ParaState = "偏移角度" + AlarmInfo.PY_HG + "°,达到极限角度的" + AlarmInfo.PYPercent_JL * 100 + "%。" };
|
||
DBHelper.insertAlarmInfo("alarminfo", alarmInfo);
|
||
MainWindow.viewModel.AlarmInfoList.Add(alarmInfo);
|
||
}
|
||
|
||
if (AlarmInfo.PYPercent_FY > 1)
|
||
{
|
||
alarmInfo = new AlarmInfo() { StationID = Beacon.ID, RecordTime = System.DateTime.Now, ParaName = "俯仰角", ParaState = "偏移角度" + AlarmInfo.PY_FY + "°,达到极限角度的" + AlarmInfo.PYPercent_FY * 100 + "%。" };
|
||
DBHelper.insertAlarmInfo("alarminfo", alarmInfo);
|
||
MainWindow.viewModel.AlarmInfoList.Add(alarmInfo);
|
||
}
|
||
if (AlarmInfo.PYPercent_PH > 1)
|
||
{
|
||
alarmInfo = new AlarmInfo() { StationID = Beacon.ID, RecordTime = System.DateTime.Now, ParaName = "偏航角", ParaState = "偏移角度" + AlarmInfo.PY_PH + "°,达到极限角度的" + AlarmInfo.PYPercent_PH * 100 + "%。" };
|
||
DBHelper.insertAlarmInfo("alarminfo", alarmInfo);
|
||
MainWindow.viewModel.AlarmInfoList.Add(alarmInfo);
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
}
|
||
}
|