测试
This commit is contained in:
@@ -100,4 +100,141 @@ public static class ModbusHelper
|
|||||||
// 120 // 标准面积
|
// 120 // 标准面积
|
||||||
//);
|
//);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//计算双目视野面积
|
||||||
|
/// <summary>
|
||||||
|
/// 计算双目视野面积(左右眼同时可见)
|
||||||
|
/// </summary>
|
||||||
|
public static double CalcBinocularArea(
|
||||||
|
List<double[]> leftGroups,
|
||||||
|
List<double[]> rightGroups,
|
||||||
|
double threshold,
|
||||||
|
double standardArea)
|
||||||
|
{
|
||||||
|
// 1. 左眼平均数据
|
||||||
|
double[] leftAvg = new double[72];
|
||||||
|
for (int i = 0; i < 72; i++)
|
||||||
|
{
|
||||||
|
double sum = 0;
|
||||||
|
foreach (var g in leftGroups) sum += g[i];
|
||||||
|
leftAvg[i] = sum / leftGroups.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 右眼平均数据
|
||||||
|
double[] rightAvg = new double[72];
|
||||||
|
for (int i = 0; i < 72; i++)
|
||||||
|
{
|
||||||
|
double sum = 0;
|
||||||
|
foreach (var g in rightGroups) sum += g[i];
|
||||||
|
rightAvg[i] = sum / rightGroups.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 双目同时有效点数(左右都亮才算)
|
||||||
|
int biValid = 0;
|
||||||
|
for (int i = 0; i < 72; i++)
|
||||||
|
{
|
||||||
|
if (leftAvg[i] >= threshold && rightAvg[i] >= threshold)
|
||||||
|
biValid++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 双目视野面积
|
||||||
|
return (biValid / 72.0) * standardArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
//调用公式
|
||||||
|
|
||||||
|
// 你从Modbus拿到的20组数据
|
||||||
|
//List<double[]> left20Groups = ...;
|
||||||
|
//List<double[]> right20Groups = ...;
|
||||||
|
|
||||||
|
//double threshold = 80;
|
||||||
|
//double standardArea = 120;
|
||||||
|
|
||||||
|
//// 左眼
|
||||||
|
//double left = VisionCalculator.CalcEyeArea(left20Groups, threshold, standardArea);
|
||||||
|
|
||||||
|
//// 右眼
|
||||||
|
//double right = VisionCalculator.CalcEyeArea(right20Groups, threshold, standardArea);
|
||||||
|
|
||||||
|
//// 双目视野面积
|
||||||
|
//double binocular = VisionCalculator.CalcBinocularArea(left20Groups, right20Groups, threshold, standardArea);
|
||||||
|
|
||||||
|
//// 总视野面积
|
||||||
|
//double total = left + right - binocular;
|
||||||
|
|
||||||
|
|
||||||
|
//下方视野面积
|
||||||
|
|
||||||
|
public static double CalcLowerEyeArea(
|
||||||
|
List<double[]> eyeGroups,
|
||||||
|
double threshold,
|
||||||
|
double standardLowerArea)
|
||||||
|
{
|
||||||
|
// 1. 每个通道求20组平均
|
||||||
|
double[] avg = new double[72];
|
||||||
|
for (int i = 0; i < 72; i++)
|
||||||
|
{
|
||||||
|
double sum = 0;
|
||||||
|
foreach (var g in eyeGroups) sum += g[i];
|
||||||
|
avg[i] = sum / eyeGroups.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 只统计下半 36 个通道(下方视野)
|
||||||
|
int validCount = 0;
|
||||||
|
for (int i = 36; i < 72; i++) // 36~71 是下半区
|
||||||
|
{
|
||||||
|
if (avg[i] >= threshold)
|
||||||
|
validCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 计算下方视野面积
|
||||||
|
return (validCount / 36.0) * standardLowerArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 总下方视野面积调用
|
||||||
|
//double totalLower = leftLower + rightLower - binocularLower;
|
||||||
|
|
||||||
|
|
||||||
|
//空白视野面积计算
|
||||||
|
|
||||||
|
//空白视野面积 = 标准视野总面积 − 实测总视野面积
|
||||||
|
//总视野面积 = 左眼面积 + 右眼面积 − 双目重叠面积
|
||||||
|
// 前面已经算出来的
|
||||||
|
//double leftArea = ...;
|
||||||
|
//double rightArea = ...;
|
||||||
|
//double binocularArea = ...;
|
||||||
|
|
||||||
|
//// 总视野
|
||||||
|
//double totalVisionArea = leftArea + rightArea - binocularArea;
|
||||||
|
|
||||||
|
//// 标准总面积(设备固定值,比如 120)
|
||||||
|
//double standardTotalArea = 120;
|
||||||
|
|
||||||
|
//// 空白视野面积
|
||||||
|
//double blankArea = standardTotalArea - totalVisionArea;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//视野保存率
|
||||||
|
//double totalSaveRate = (总视野面积 / 标准总视野面积) * 100;
|
||||||
|
public static class VisionCalculator
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 计算视野保存率
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="actualArea">实测面积</param>
|
||||||
|
/// <param name="standardArea">标准面积</param>
|
||||||
|
/// <returns>保存率 %</returns>
|
||||||
|
public static double CalculateVisionSaveRate(double actualArea, double standardArea)
|
||||||
|
{
|
||||||
|
if (standardArea == 0) return 0;
|
||||||
|
return (actualArea / standardArea) * 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//double totalSaveRate = VisionCalculator.CalculateVisionSaveRate(totalVisionArea, standardTotalArea);
|
||||||
}
|
}
|
||||||
@@ -160,8 +160,8 @@ Margin="200,0,0,0" Height="194"/>
|
|||||||
Padding="25,20" Margin="0,0,0,15" >
|
Padding="25,20" Margin="0,0,0,15" >
|
||||||
<StackPanel Cursor="">
|
<StackPanel Cursor="">
|
||||||
<StackPanel Orientation="Horizontal" Margin="0,0,0,15">
|
<StackPanel Orientation="Horizontal" Margin="0,0,0,15">
|
||||||
<TextBlock Text="左目视野面积:" Style="{StaticResource LabelStyle}"/>
|
<TextBlock Text="左目视野面积:" Style="{StaticResource LabelStyle}" />
|
||||||
<TextBox Name="zmsyarea" Text="" Style="{StaticResource TextBoxStyle}"/>
|
<TextBox Name="zmsyarea" Text="" Style="{StaticResource TextBoxStyle}" />
|
||||||
<TextBlock Text="cm²" Style="{StaticResource UnitStyle}"/>
|
<TextBlock Text="cm²" Style="{StaticResource UnitStyle}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ namespace 头罩视野.Views
|
|||||||
data.VisionRetentionRate == _lastRecord.VisionRetentionRate)
|
data.VisionRetentionRate == _lastRecord.VisionRetentionRate)
|
||||||
{
|
{
|
||||||
return; // 一样就不添加
|
return; // 一样就不添加
|
||||||
}
|
}
|
||||||
// 不一样 → 插入表格
|
// 不一样 → 插入表格
|
||||||
TestDataStore.AddNewRecord(data);
|
TestDataStore.AddNewRecord(data);
|
||||||
_lastRecord = data;
|
_lastRecord = data;
|
||||||
@@ -380,17 +380,19 @@ namespace 头罩视野.Views
|
|||||||
}
|
}
|
||||||
private void dqangle_GotFocus(object sender, RoutedEventArgs e)
|
private void dqangle_GotFocus(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ma.WriteToPLCForNew(fbspeed.Text.Trim(), 202, Function.DataType.浮点型);
|
ma.WriteToPLCForNew(dqangle.Text.Trim(), 202, Function.DataType.浮点型);
|
||||||
System.Threading.Tasks.Task.Delay(50);
|
System.Threading.Tasks.Task.Delay(50);
|
||||||
fbspeed.Focus();
|
dqangle.Focus();
|
||||||
}
|
}
|
||||||
private void zdangle_GotFocus(object sender, RoutedEventArgs e)
|
private void zdangle_GotFocus(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
ma.WriteToPLCForNew(fbspeed.Text.Trim(), 310, Function.DataType.浮点型);
|
ma.WriteToPLCForNew(zdangle.Text.Trim(), 310, Function.DataType.浮点型);
|
||||||
System.Threading.Tasks.Task.Delay(50);
|
System.Threading.Tasks.Task.Delay(50);
|
||||||
fbspeed.Focus();
|
zdangle.Focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//错误信息提示
|
//错误信息提示
|
||||||
private void ShowError(string msg) => MessageBox.Show(msg, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
private void ShowError(string msg) => MessageBox.Show(msg, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
private void GoHome(object s, RoutedEventArgs e) => NavigationService.Content = null;
|
private void GoHome(object s, RoutedEventArgs e) => NavigationService.Content = null;
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ namespace 头罩视野.Views
|
|||||||
// 获取客户端
|
// 获取客户端
|
||||||
var client = ModbusHelper.TcpClient;
|
var client = ModbusHelper.TcpClient;
|
||||||
//进入页面是否要保留原来的数据????,
|
//进入页面是否要保留原来的数据????,
|
||||||
//RecordDataGrid.ItemsSource = null;
|
RecordDataGrid.ItemsSource = null;
|
||||||
RecordDataGrid.ItemsSource = TestDataStore.Records;
|
RecordDataGrid.ItemsSource = TestDataStore.Records;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user