Commit 945d9eb7 authored by 潘栩锋's avatar 潘栩锋 🚴

1.优化 定点图 X轴,恢复 F1 格式

2.优化 CurveCollection, CurveCell 精简代码
parent cf55a664
...@@ -122,7 +122,7 @@ namespace FLY.Thick.Base.UI.UiModule ...@@ -122,7 +122,7 @@ namespace FLY.Thick.Base.UI.UiModule
{ {
int index = (int)x; int index = (int)x;
double s = Interval.TotalSeconds * index * values_scale; double s = Interval.TotalSeconds * index * values_scale;
return $"{s:F0}s"; return $"{s:F1}s";
}; };
YFormatter = (y) => y.ToString("F1"); YFormatter = (y) => y.ToString("F1");
......
using System; using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Misc;
using System.Xml;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace FLY.Thick.Base.Common namespace FLY.Thick.Base.Common
{ {
...@@ -67,7 +59,7 @@ namespace FLY.Thick.Base.Common ...@@ -67,7 +59,7 @@ namespace FLY.Thick.Base.Common
/// <summary> /// <summary>
/// 曲线类型 /// 曲线类型
/// </summary> /// </summary>
public enum CurveType public enum CurveType
{ {
/// <summary> /// <summary>
/// 自然对数 /// 自然对数
...@@ -82,7 +74,7 @@ namespace FLY.Thick.Base.Common ...@@ -82,7 +74,7 @@ namespace FLY.Thick.Base.Common
/// </summary> /// </summary>
X2 X2
} }
public enum CurveCorrectWay public enum CurveCorrectWay
{ {
/// <summary> /// <summary>
/// 单点校正时,比例放大 /// 单点校正时,比例放大
......
using System; using FLY.Thick.Base.Common;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using FLY.Thick.Base.Common;
namespace FLY.Thick.Base.IService namespace FLY.Thick.Base.IService
{ {
...@@ -17,7 +12,7 @@ namespace FLY.Thick.Base.IService ...@@ -17,7 +12,7 @@ namespace FLY.Thick.Base.IService
/// <summary> /// <summary>
/// 标记,用于告诉 客户端,当前的曲线类型, 自然对数 / 直线拟合 / 二次拟合 /// 标记,用于告诉 客户端,当前的曲线类型, 自然对数 / 直线拟合 / 二次拟合
/// </summary> /// </summary>
CurveType Flag { get; } CurveType Flag { get; }
/// <summary> /// <summary>
/// 曲线 /// 曲线
/// </summary> /// </summary>
......
using System; using AutoMapper;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;
using FLY.Thick.Base.Common; using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService; using FLY.Thick.Base.IService;
using AutoMapper;
using System.IO;
using Newtonsoft.Json; using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace FLY.Thick.Base.Server namespace FLY.Thick.Base.Server
{ {
...@@ -32,11 +28,11 @@ namespace FLY.Thick.Base.Server ...@@ -32,11 +28,11 @@ namespace FLY.Thick.Base.Server
#endregion #endregion
public event ActiveEventHandler ActiveEvent;
public struct ExChange public struct ExChange
{ {
public ExChange(int orgAd, int currAd) { public ExChange(int orgAd, int currAd)
{
OrgAD = orgAd; OrgAD = orgAd;
CurrAD = currAd; CurrAD = currAd;
} }
...@@ -49,7 +45,7 @@ namespace FLY.Thick.Base.Server ...@@ -49,7 +45,7 @@ namespace FLY.Thick.Base.Server
List<ExChange> RevisingCurves = new List<ExChange>(); List<ExChange> RevisingCurves = new List<ExChange>();
private string param_path = "curve.json"; private string param_path = "curve.json";
public CurveCollection() public CurveCollection()
{ {
SetDefault(); SetDefault();
ReviseCurve(); ReviseCurve();
...@@ -61,7 +57,8 @@ namespace FLY.Thick.Base.Server ...@@ -61,7 +57,8 @@ namespace FLY.Thick.Base.Server
this.param_path = param_path; this.param_path = param_path;
SetDefault(); SetDefault();
if (!Load()) { if (!Load())
{
Save(); Save();
} }
Curves = Curves.OrderBy(c => c.Value).ToArray(); Curves = Curves.OrderBy(c => c.Value).ToArray();
...@@ -69,7 +66,7 @@ namespace FLY.Thick.Base.Server ...@@ -69,7 +66,7 @@ namespace FLY.Thick.Base.Server
ReviseCurve(); ReviseCurve();
} }
void SetDefault() void SetDefault()
{ {
CorrectWay = CurveCorrectWay.OnePointIsScale; CorrectWay = CurveCorrectWay.OnePointIsScale;
Flag = CurveType.E; Flag = CurveType.E;
...@@ -82,7 +79,7 @@ namespace FLY.Thick.Base.Server ...@@ -82,7 +79,7 @@ namespace FLY.Thick.Base.Server
new CurveCell() { AD = 5650, Value = 440 }, new CurveCell() { AD = 5650, Value = 440 },
new CurveCell() { AD = 3779, Value = 528 }, new CurveCell() { AD = 3779, Value = 528 },
new CurveCell() { AD = 2513, Value = 616 }, new CurveCell() { AD = 2513, Value = 616 },
new CurveCell() { AD = 1660, Value = 704 } new CurveCell() { AD = 1660, Value = 704 }
}; };
} }
public void Apply(CurveCorrectWay correctWay, CurveType flag, CurveCell2[] curves) public void Apply(CurveCorrectWay correctWay, CurveType flag, CurveCell2[] curves)
...@@ -94,7 +91,6 @@ namespace FLY.Thick.Base.Server ...@@ -94,7 +91,6 @@ namespace FLY.Thick.Base.Server
ClearExChange(); ClearExChange();
ReviseCurve(); ReviseCurve();
ActiveEvent?.Invoke(this);
Save(); Save();
} }
...@@ -170,7 +166,8 @@ namespace FLY.Thick.Base.Server ...@@ -170,7 +166,8 @@ namespace FLY.Thick.Base.Server
{ {
c.RevisedAD = (int)(c.AD * ux); c.RevisedAD = (int)(c.AD * ux);
} }
} break; }
break;
default: default:
//case CurveCorrectWay.OnePointIsOffset: //case CurveCorrectWay.OnePointIsOffset:
{ {
...@@ -180,7 +177,8 @@ namespace FLY.Thick.Base.Server ...@@ -180,7 +177,8 @@ namespace FLY.Thick.Base.Server
{ {
c.RevisedAD = c.AD + x; c.RevisedAD = c.AD + x;
} }
} break; }
break;
} }
return true; return true;
...@@ -201,7 +199,7 @@ namespace FLY.Thick.Base.Server ...@@ -201,7 +199,7 @@ namespace FLY.Thick.Base.Server
} }
} }
#region E #region Ad To Value
double AD2Value_E(int ad, AD2ValueFlag flag) double AD2Value_E(int ad, AD2ValueFlag flag)
{ {
...@@ -231,10 +229,10 @@ namespace FLY.Thick.Base.Server ...@@ -231,10 +229,10 @@ namespace FLY.Thick.Base.Server
break; break;
} }
} }
if (i >= Curves.Count()) if (i >= Curves.Count())
i = Curves.Count() - 1; i = Curves.Count() - 1;
if (i == 0) if (i == 0)
i = 1; i = 1;
var c0 = Curves[i - 1]; var c0 = Curves[i - 1];
...@@ -257,8 +255,8 @@ namespace FLY.Thick.Base.Server ...@@ -257,8 +255,8 @@ namespace FLY.Thick.Base.Server
return value; return value;
} }
#endregion
#region 线性
double AD2Value_Line(int ad, AD2ValueFlag flag) double AD2Value_Line(int ad, AD2ValueFlag flag)
{ {
int i; int i;
...@@ -295,7 +293,8 @@ namespace FLY.Thick.Base.Server ...@@ -295,7 +293,8 @@ namespace FLY.Thick.Base.Server
} }
} }
} }
else { else
{
if (isDescending)//降序排列 if (isDescending)//降序排列
{ {
for (i = 0; i < Curves.Count(); i++) for (i = 0; i < Curves.Count(); i++)
...@@ -317,7 +316,7 @@ namespace FLY.Thick.Base.Server ...@@ -317,7 +316,7 @@ namespace FLY.Thick.Base.Server
} }
} }
} }
if (i >= Curves.Count()) i = Curves.Count() - 1; if (i >= Curves.Count()) i = Curves.Count() - 1;
if (i == 0) i = 1; if (i == 0) i = 1;
...@@ -338,7 +337,7 @@ namespace FLY.Thick.Base.Server ...@@ -338,7 +337,7 @@ namespace FLY.Thick.Base.Server
value = (ad2 - ad0) * u + c0.Value; value = (ad2 - ad0) * u + c0.Value;
return value; return value;
} }
#endregion
public double AD2Value(int ad, AD2ValueFlag flag) public double AD2Value(int ad, AD2ValueFlag flag)
{ {
...@@ -354,6 +353,108 @@ namespace FLY.Thick.Base.Server ...@@ -354,6 +353,108 @@ namespace FLY.Thick.Base.Server
} }
return value; return value;
} }
#endregion
#region Value To Ad
/// <summary>
/// 基本没有用
/// </summary>
/// <param name="value"></param>
/// <param name="flag"></param>
/// <returns></returns>
public int Value2Ad(double value, AD2ValueFlag flag) {
int ad;
switch (Flag)
{
case CurveType.Line:
ad = Value2Ad_Line(value, flag);
break;
default:
ad = Value2Ad_E(value, flag);
break;
}
return ad;
}
int Value2Ad_E(double value, AD2ValueFlag flag)
{
int i;
int ad;
if (Curves.Count() < 1) return -1;
for (i = 0; i < Curves.Count(); i++)
{
if (value > Curves[i].Value)
continue;
else
break;
}
if (i >= Curves.Count())
i = Curves.Count() - 1;
if (i == 0)
i = 1;
var c0 = Curves[i - 1];
var c1 = Curves[i];
double ad0, ad1, ad2;
if (flag == AD2ValueFlag.NoRevised)
{
ad0 = Math.Log(c0.AD, Math.E);
ad1 = Math.Log(c1.AD, Math.E);
//ad2 = Math.Log(ad, Math.E);
}
else
{
ad0 = Math.Log(c0.RevisedAD, Math.E);
ad1 = Math.Log(c1.RevisedAD, Math.E);
//ad2 = Math.Log(ad, Math.E);
}
double u = (c1.Value - c0.Value) / (ad1 - ad0);
ad2 = (value - c0.Value) / u + ad0;
ad = (int)Math.Round(Math.Pow(Math.E, ad2));
return ad;
}
int Value2Ad_Line(double value, AD2ValueFlag flag)
{
int i;
int ad;
if (Curves.Count() < 2) return -1;
for (i = 0; i < Curves.Count(); i++)
{
if (value > Curves[i].Value)
continue;
else
break;
}
if (i >= Curves.Count()) i = Curves.Count() - 1;
if (i == 0) i = 1;
var c0 = Curves[i - 1];
var c1 = Curves[i];
double ad0, ad1, ad2;
if (flag == AD2ValueFlag.NoRevised)
{
ad0 = c0.AD;
ad1 = c1.AD;
}
else
{
ad0 = c0.RevisedAD;
ad1 = c1.RevisedAD;
}
double u = (c1.Value - c0.Value) / (ad1 - ad0);
ad2 = (value - c0.Value) / u + ad0;
ad = (int)Math.Round(ad2);
return ad;
}
#endregion
public bool Load() public bool Load()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment