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

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

2.优化 CurveCollection, CurveCell 精简代码
parent cf55a664
......@@ -122,7 +122,7 @@ namespace FLY.Thick.Base.UI.UiModule
{
int index = (int)x;
double s = Interval.TotalSeconds * index * values_scale;
return $"{s:F0}s";
return $"{s:F1}s";
};
YFormatter = (y) => y.ToString("F1");
......
using System;
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;
using System.ComponentModel;
namespace FLY.Thick.Base.Common
{
......@@ -67,7 +59,7 @@ namespace FLY.Thick.Base.Common
/// <summary>
/// 曲线类型
/// </summary>
public enum CurveType
public enum CurveType
{
/// <summary>
/// 自然对数
......@@ -82,7 +74,7 @@ namespace FLY.Thick.Base.Common
/// </summary>
X2
}
public enum CurveCorrectWay
public enum CurveCorrectWay
{
/// <summary>
/// 单点校正时,比例放大
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using FLY.Thick.Base.Common;
using System.ComponentModel;
using FLY.Thick.Base.Common;
namespace FLY.Thick.Base.IService
{
......@@ -17,7 +12,7 @@ namespace FLY.Thick.Base.IService
/// <summary>
/// 标记,用于告诉 客户端,当前的曲线类型, 自然对数 / 直线拟合 / 二次拟合
/// </summary>
CurveType Flag { get; }
CurveType Flag { get; }
/// <summary>
/// 曲线
/// </summary>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;
using AutoMapper;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
using AutoMapper;
using System.IO;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace FLY.Thick.Base.Server
{
......@@ -32,11 +28,11 @@ namespace FLY.Thick.Base.Server
#endregion
public event ActiveEventHandler ActiveEvent;
public struct ExChange
{
public ExChange(int orgAd, int currAd) {
public ExChange(int orgAd, int currAd)
{
OrgAD = orgAd;
CurrAD = currAd;
}
......@@ -49,7 +45,7 @@ namespace FLY.Thick.Base.Server
List<ExChange> RevisingCurves = new List<ExChange>();
private string param_path = "curve.json";
public CurveCollection()
public CurveCollection()
{
SetDefault();
ReviseCurve();
......@@ -61,7 +57,8 @@ namespace FLY.Thick.Base.Server
this.param_path = param_path;
SetDefault();
if (!Load()) {
if (!Load())
{
Save();
}
Curves = Curves.OrderBy(c => c.Value).ToArray();
......@@ -69,7 +66,7 @@ namespace FLY.Thick.Base.Server
ReviseCurve();
}
void SetDefault()
void SetDefault()
{
CorrectWay = CurveCorrectWay.OnePointIsScale;
Flag = CurveType.E;
......@@ -82,7 +79,7 @@ namespace FLY.Thick.Base.Server
new CurveCell() { AD = 5650, Value = 440 },
new CurveCell() { AD = 3779, Value = 528 },
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)
......@@ -94,7 +91,6 @@ namespace FLY.Thick.Base.Server
ClearExChange();
ReviseCurve();
ActiveEvent?.Invoke(this);
Save();
}
......@@ -170,7 +166,8 @@ namespace FLY.Thick.Base.Server
{
c.RevisedAD = (int)(c.AD * ux);
}
} break;
}
break;
default:
//case CurveCorrectWay.OnePointIsOffset:
{
......@@ -180,7 +177,8 @@ namespace FLY.Thick.Base.Server
{
c.RevisedAD = c.AD + x;
}
} break;
}
break;
}
return true;
......@@ -201,7 +199,7 @@ namespace FLY.Thick.Base.Server
}
}
#region E
#region Ad To Value
double AD2Value_E(int ad, AD2ValueFlag flag)
{
......@@ -231,10 +229,10 @@ namespace FLY.Thick.Base.Server
break;
}
}
if (i >= Curves.Count())
if (i >= Curves.Count())
i = Curves.Count() - 1;
if (i == 0)
if (i == 0)
i = 1;
var c0 = Curves[i - 1];
......@@ -257,8 +255,8 @@ namespace FLY.Thick.Base.Server
return value;
}
#endregion
#region 线性
double AD2Value_Line(int ad, AD2ValueFlag flag)
{
int i;
......@@ -295,7 +293,8 @@ namespace FLY.Thick.Base.Server
}
}
}
else {
else
{
if (isDescending)//降序排列
{
for (i = 0; i < Curves.Count(); i++)
......@@ -317,7 +316,7 @@ namespace FLY.Thick.Base.Server
}
}
}
if (i >= Curves.Count()) i = Curves.Count() - 1;
if (i == 0) i = 1;
......@@ -338,7 +337,7 @@ namespace FLY.Thick.Base.Server
value = (ad2 - ad0) * u + c0.Value;
return value;
}
#endregion
public double AD2Value(int ad, AD2ValueFlag flag)
{
......@@ -354,6 +353,108 @@ namespace FLY.Thick.Base.Server
}
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()
......
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