IThickHeatData.cs 7.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FLY.HeatingHelper
{
    /// <summary>
    /// IThickHeatData定义一个Thick和Heat数据的维护对象的接口,屏蔽了数据保存的方式,对于用SQLite或SQLServer或
    /// 文件等,应该用不同的类实现,但必须实现这个接口
    /// 注意:1.实现该接口的类是一个维护运行时数据的类,并不负责数据的保存
    ///       2.实现该接口的类的对象在创建时从“数据库”中提取最近数据,然后根据数据检测风环移位和加热失效问题
    /// </summary>
    public interface IThickHeatData : INotifyPropertyChanged
    {
18
        #region 用于UI的接口
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
        /// <summary>
        /// 数据库中存在的数据范围
        /// </summary>
        DateTime TotalDataFrom { get; }
        DateTime TotalDataTo { get; }

        /// <summary>
        /// DataTo和DataSpan确定数据的起始位置,对象中存在的数据范围
        /// </summary>
        DateTime DataTo { get; set; }
        TimeSpan DataSpan { get; set; }

        /// <summary>
        /// DFrom和DTo用于确定用于计算的数据
        /// </summary>
        DateTime DFrom { get; set; }
        DateTime DTo { get; set; }

        /// <summary>
        /// 风环偏差值
        /// </summary>
        int AirRingShift { get; }

42 43
        StateCode State { get; }
        #endregion
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
        /// <summary>
        /// 通知新数据产生
        /// </summary>
        bool NewDataArrived { set; }

        int CalculateFromToByClass(int selected_class, ref int from, ref int to);

        #region 一些辅助计算的函数
        /// <summary>
        /// 计算两个frame的加热和厚度差的协相关向量。
        /// </summary>
        double[] CalculateCorrelVector(double[] heats, double[] thicks);

        Tuple<int, double> CalculateAirRingShiftFromCorelVector(double[] correlVec);
        #endregion
        void SetDB(string dbname);

61
        #region 获取数据接口
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
        /// <summary>
        /// 获取厚度和加热的值
        /// </summary>
        /// <param name="idx"></param>
        /// <returns></returns>
        double[] GetThicks(int idx, int from, int to);
        double[] GetHeats(int idx, int from, int to);
        double[] GetThicks(int idx, int newResetBolt, double newAngle);
        int GetResetBolt(int idx);
        double GetRotAngle(int idx);
        int NormalBolt(int bolt, int boltcnt);

        List<DateTime> Dat_Times { get; }
        List<double> Dat_Sigmas { get; }
        List<double> Dat_Means { get; }

78 79
        int GetIndexFromID(int id);
        int GetRelativeID(int id, int relative);
80
        /// <summary>
81
        /// 依据数据ID获取数据时间
82
        /// </summary>
83 84 85 86 87
        /// <param name="id"></param>
        /// <returns></returns>
        DateTime? GetDateTimeByID(int id);
        #endregion
        int BoltCnt { get; }
88 89

        double[] HeatEffect { get; set; }
90
        #region 整体分析和局部分析的功能jiekou
91 92 93 94 95 96 97 98
        List<HeatBoltAnalystItem> SearchFeaturedBoltsItem(int startIdx, int endIdx, 
                                    int searchNum, int maxFrameInterval, int heatRating,
                                    int neglectHeatRate, int Separation, int shiftRange);
        List<HeatBoltAnalystItem> FilterFeaturedBoltsItem(List<HeatBoltAnalystItem> items, double similarityThredhold);
        void StartSearchMaxSimilarity(int startIdx, int endIdx, int searchNum, int frameInterval, MaxSimilarityResult result,
                        ProgressChangedEventHandler report,
                        RunWorkerCompletedEventHandler runcomplete,
                        int midbolt, double searchRange, bool SearchRotAngle, bool isAsync);
99 100 101 102 103 104 105 106 107 108
        /// <summary>
        /// 
        /// </summary>
        /// <param name="idxL"></param>
        /// <param name="idxB"></param>
        /// <param name="searchRange"></param>
        /// <param name="SearchRotAngle"></param>
        /// <returns>返回值:Tuple<偏转数,相关系数,旋转角度变化量></returns>
        Tuple<int, double, double> SearchMaxSimilarity(int idxL, int idxB, double searchRange, bool SearchRotAngle);
        #endregion
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125

        #region 数据库数据变化后自动运行
        List<ThickHeatEvent> AutoDetectEvents { get; }

        /// <summary>
        /// 自动运行是否旋转角度
        /// </summary>
        bool HasRotateAngleSearched { get; set; }
        /// <summary>
        /// 搜索旋转角度的范围,例如15,则在当前度数下搜索正负15度
        /// </summary>
        double SearchingAngle { get; set; }

        /// <summary>
        /// 检查数据库,当数据库有新数据时,更新DataTo属性,并读取新数据到对象中。该函数可以一定时间间隔执行。
        /// </summary>
        void RefreshData();
126 127 128 129 130
        bool IsDataReady { get; }

        bool BeginUse(bool isAsync = true);
        void EndUse();

131 132 133
        #endregion
    }

134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

    public enum StateCode
    {
        STC_NODAT,              // 没有数据
        STC_IDLE,               // 空闲
        STC_READING,            // 读取数据
        STC_UPDATING            // 检查新数据
    }

    #region 厚度加热数据自动处理结果事件
    public class ThickHeatEvent
    {
        public ThickHeatEventCode EvtCode;
        public object EvtData;
    }

    public enum ThickHeatEventCode
    {
        EVC_RingShift,
        EVC_HeatBoltItem,
    }

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
    public class MaxSimilarityResult
    {
        public int frameIdx1;
        public int frameIdx2;
        public int frameShift;
        public double similarity;
        public double deltaAngle;
        public double ThickToHeatFactor;
    }

    public class HeatBoltAnalystItem
    {
        public int FrameIdx1 { get; set; }
        public int FrameIdx2 { get; set; }
        public int StartBolt { get; set; }
        public int EndBolt { get; set; }
        /// <summary>
        /// 偏差的位置
        /// </summary>
        public int DisPos { get; set; }
        public double Similarity { get; set; }

        public void Clone(HeatBoltAnalystItem from)
        {
            FrameIdx1 = from.FrameIdx1;
            FrameIdx2 = from.FrameIdx2;
            StartBolt = from.StartBolt;
            EndBolt = from.EndBolt;
            DisPos = from.DisPos;
            Similarity = from.Similarity;
        }
    }
    #endregion

    #region DataHelper
    public class DataHelper
    {
        public static double[] VectorAdd(double[] a, double[] b)
        {
            int cnt = a.Count();
            double[] result = new double[cnt];
            for (int i = 0; i < cnt; i++)
            {
                if (double.IsNaN(a[i]) || double.IsNaN(b[i]))
                {
                    result[i] = double.NaN;
                }
                else
                {
                    result[i] = a[i] + b[i];
                }
            }
            return result;
        }
        public static double[] VectorSub(double[] a, double[] b)
        {
            int cnt = a.Count();
            double[] result = new double[cnt];
            for(int i = 0; i < cnt; i++)
            {
                if (double.IsNaN(a[i]) || double.IsNaN(b[i]))
                {
                    result[i] = double.NaN;
                }
                else
                {
                    result[i] = a[i] - b[i];
                }
            }
            return result;
        }
    }
    #endregion
}