#region 程序集 Txgy.Microseismic.BaseLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// E:\mingzf\txgy\Txgy.EWS\Client\output\Txgy.Microseismic.BaseLib.dll
// Decompiled with ICSharpCode.Decompiler 7.1.0.6543
#endregion

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace mseedChart.MainModule.Models
{
    public class MmEvent : CoordBase
    {
        private bool isShow;

        public int MoniID = 0;

        public int LayerID = 0;

        public int EventID = 0;

        private int _second;

        private int _milliSecond;

        private DateTime _eventTime;

        private double _horiError;

        private double _vertError;

        private double _cnt;

        private double _ml;

        private double _rms;

        private Dictionary<string, int> _phases;

        public float[] standData;

        public float[][] nearData;

        public float minTimeDiff = 0f;

        public bool Falcone = false;

        public float errorCircularRadius = 0f;

        public float errorH = 0f;

        public int isShowed = 1;

        public float Hlen = 0f;

        public float Llen = 0f;

        public float VF = 0f;

        public List<int> SN = new List<int>();

        public List<int> PM = new List<int>();

        public List<int> GCS = new List<int>();

        public int WorkAreaID { get; set; } = 0;


        public bool IsShow
        {
            get
            {
                return isShow;
            }
            set
            {
                isShow = value;
            }
        }

        public int Second
        {
            get
            {
                return _second;
            }
            set
            {
                _second = value;
            }
        }

        public int Millisecond
        {
            get
            {
                return _milliSecond;
            }
            set
            {
                _milliSecond = value;
            }
        }

        public string EventTimeStr { get; set; }

        public DateTime EventTime
        {
            get
            {
                return _eventTime;
            }
            set
            {
                _eventTime = value;
            }
        }

        public double HoriError
        {
            get
            {
                return _horiError;
            }
            set
            {
                _horiError = value;
            }
        }

        public double VertError
        {
            get
            {
                return _vertError;
            }
            set
            {
                _vertError = value;
            }
        }

        public double Cnt
        {
            get
            {
                return _cnt;
            }
            set
            {
                _cnt = value;
            }
        }

        public double ML
        {
            get
            {
                return _ml;
            }
            set
            {
                _ml = value;
            }
        }

        public double RMS
        {
            get
            {
                return _rms;
            }
            set
            {
                _rms = value;
            }
        }

        public Dictionary<string, int> Phases
        {
            get
            {
                return _phases;
            }
            set
            {
                _phases = value;
            }
        }

        public double Stress { get; set; }

        public double Energy { get; set; }

        public int LocSta { get; set; }

        public int MLSta { get; set; }

        public string EventTpye { get; set; }

        public int SourceChara { get; set; }

        public double Direction { get; set; }

        public double StressDrop { get; set; }

        public double DominantFreq { get; set; }

        public double MW { get; set; }

        public double Amplitude { get; set; }

        public double Semiperiod { get; set; }

        public double Coda { get; set; }

        public string JsonFile { get; set; }

        public string MseedFile { get; set; }

        public string AsciiFile { get; set; }

        public float Amp { get; set; }

        public FocalMechanismType FocalType { get; set; }

        public static void SavePos(string fn, List<MmEvent> mMEvents)
        {
            StreamWriter streamWriter = new StreamWriter(fn);
            try
            {
                if (mMEvents != null && mMEvents.Count > 0)
                {
                    streamWriter.WriteLine(mMEvents.Count.ToString());
                    List<MmEvent> list = (from o in mMEvents
                                          orderby o.Second, o.Millisecond
                                          select o).ToList();
                    for (int i = 0; i < list.Count; i++)
                    {
                        MmEvent mmEvent = list[i];
                        streamWriter.WriteLine(Math.Round(mmEvent.X, 1) + "\t" + Math.Round(mmEvent.Y, 1) + "\t" + Math.Round(mmEvent.Z, 1) + "\t" + mmEvent.Second + "." + mmEvent.Millisecond);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                streamWriter.Close();
            }
        }

        public static void SaveNewPin(string fn, int layerIndex, List<MmEvent> mMEvents)
        {
            StreamWriter streamWriter = new StreamWriter(fn);
            int num = layerIndex;
            int num2 = layerIndex;
            try
            {
                List<MmEvent> list = (from o in mMEvents
                                      orderby o.Second, o.Millisecond
                                      select o).ToList();
                for (int i = 0; i < list.Count; i++)
                {
                    MmEvent mmEvent = list[i];
                    string pMStr = GetPMStr(mmEvent);
                    streamWriter.WriteLine(Math.Round(mmEvent.X, 1) + "\t" + Math.Round(mmEvent.Y, 1) + "\t" + Math.Round(mmEvent.Z, 1) + "\t" + mmEvent.Second + "." + mmEvent.Millisecond + "\t" + num + "\t" + num2 + "\t" + mmEvent.errorCircularRadius + "\t" + mmEvent.errorH + "\t" + 0 + "\t" + mmEvent.ML + pMStr);
                }

                streamWriter.Close();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                streamWriter.Close();
            }
        }

        public static void SaveOldPin(string fn, int layer, List<MmEvent> mMEvents)
        {
            StreamWriter streamWriter = new StreamWriter(fn);
            try
            {
                List<MmEvent> list = (from o in mMEvents
                                      orderby o.Second, o.Millisecond
                                      select o).ToList();
                for (int i = 0; i < list.Count; i++)
                {
                    MmEvent mmEvent = list[i];
                    string pMStr = GetPMStr(mmEvent);
                    streamWriter.WriteLine(layer + "\t" + Math.Round(mmEvent.X, 0) + "\t" + Math.Round(mmEvent.Y, 0) + "\t" + Math.Round(mmEvent.Z, 0) + "\t" + mmEvent.Second + "." + mmEvent.Millisecond + "\t" + mmEvent.ML + "\t" + mmEvent.errorCircularRadius + "\t" + mmEvent.errorH + "\t" + mmEvent.minTimeDiff + pMStr);
                }

                streamWriter.Close();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                streamWriter.Close();
            }
        }

        public static string GetPMStr(MmEvent p)
        {
            string text = "\t";
            int[] mpIndex = new int[p.SN.Count];
            for (int j = 0; j < mpIndex.Length; j++)
            {
                mpIndex[j] = p.SN[j];
            }

            for (int k = 0; k < mpIndex.Length - 1; k++)
            {
                for (int l = 0; l < mpIndex.Length - 1 - k; l++)
                {
                    if (mpIndex[l] > mpIndex[l + 1])
                    {
                        int num = mpIndex[l];
                        mpIndex[l] = mpIndex[l + 1];
                        mpIndex[l + 1] = num;
                    }
                }
            }

            int i;
            for (i = 0; i < p.PM.Count; i++)
            {
                int index = p.SN.FindIndex((int s) => s == mpIndex[i]);
                text = ((p.PM.Count - 1 != i) ? (text + p.SN[index] + ":" + p.PM[index] + "\t") : (text + p.SN[index] + ":" + p.PM[index]));
            }

            return text;
        }

        public void SetEnergy()
        {
            Energy = Math.Round(63000.0 * Math.Pow(10.0, 1.47 * ML), 2);
        }

        public static float SetAmp(List<float> amps)
        {
            amps.Sort();
            return amps[amps.Count / 2];
        }
    }
}