You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.3 KiB
C#

using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Txgy.EWS.Client.Common;
using Txgy.EWS.Client.FocalMechanism.Model;
using Txgy.EWS.Client.PageModule.Services;
using Txgy.Microseismic.BaseLib.Models;
using Txgy.EWS.Client.FocalMechanism.Core;
using NPOI.SS.Formula.Functions;
using FmGrid = Txgy.EWS.Client.FocalMechanism.Model.FmGrid;
namespace Txgy.EWS.Client.PageModule.Common
{
public class EventFunc
{
public static void ComputeFM(MmEvent mmEvent)
{
string downLoadStr = mmEvent.EventTimeStr;
string datePath = downLoadStr.Substring(0, 4) + downLoadStr.Substring(5, 2) + downLoadStr.Substring(8, 2);
string jsonStr = "HA." + downLoadStr.Substring(0, 4) + downLoadStr.Substring(5, 2)
+ downLoadStr.Substring(8, 2) + downLoadStr.Substring(10, 3)
+ downLoadStr.Substring(14, 2) + downLoadStr.Substring(17, 2) + ".01" + GlobalConfig.DataTypeString + ".json";
string jsonFilePath = GlobalConfig.ProjectConfig.MseedFilePath + "\\" + datePath + "\\";
if (!File.Exists(jsonFilePath + jsonStr))
{
new DownloadJsonFile().Download(downLoadStr, jsonFilePath, jsonStr, GlobalConfig.UseWaveDataTable);
}
using (StreamReader sr = System.IO.File.OpenText(jsonFilePath + jsonStr))
{
mmEvent.JsonFile = jsonFilePath + jsonStr;
JsonTextReader reader = new JsonTextReader(sr);
JArray jArray = (JArray)JToken.ReadFrom(reader);
//解析普通属性和数组混合的Json文件
//数组0是普通属性集合
JObject jobj = (JObject)jArray[0];
mmEvent.SetEnergy();
mmEvent.Phases = new Dictionary<string, int>();
JArray phaseArr = JArray.FromObject(jobj["phases"]);
for (int i = 0; i < phaseArr.Count; i++)
{
if (phaseArr[i]["first_motion_direct"] != null)
{
mmEvent.Phases.Add(phaseArr[i]["id"].ToString().Substring(3, 3),
int.Parse(phaseArr[i]["first_motion_direct"].ToString()));
}
}
}
FMMap fmMap = CreateFM(mmEvent, GlobalConfig.ProjectConfig.WorkArea.EMin, GlobalConfig.ProjectConfig.WorkArea.NMin);
ComputationResult cr = GlobalConfig.fmCore.ComputeResult(fmMap);
if (cr == null)
return;
mmEvent.FocalType = cr.FocalType;
mmEvent.Direction = cr.Direction;
}
public static FMMap CreateFM(MmEvent mmEvent, double BaseX, double BaseY)
{
FMMap fmMap = new FMMap();
fmMap.X = mmEvent.X - BaseX;
fmMap.Y = mmEvent.Y - BaseY;
fmMap.R = mmEvent.RMS;
foreach (var item in mmEvent.Phases)
{
if (item.Value == -1)
{
fmMap.negStation.Add(item.Key);
}
else
{
fmMap.posStation.Add(item.Key);
}
}
return fmMap;
}
}
}