提交数据

master
mzhifa 1 year ago
parent e3a1a1fb24
commit bf42d19e39

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace StartServerWPF.Assets
{
public class GlobalData
{
public static string[] StationNames { get; set; }
}
}

@ -84,6 +84,7 @@
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile Include="GlobalData.cs" />
<Compile Include="LogHelper.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>

@ -148,7 +148,8 @@ namespace StartServerWPF.Modules.Main
JsonTextReader reader = new JsonTextReader(sr);
JObject jobj = (JObject)JToken.ReadFrom(reader);
JObject jordb = JObject.Parse(jobj["channels"].ToString());
var jor = jobj["channels"].First;
JObject jordb = JObject.Parse(jor.ToString());
string sta = jordb["station"].ToString();

@ -53,6 +53,8 @@ namespace StartServerWPF.Modules.Main.ViewModels
_websocket.WebsocketError = WebSocket_Error;
_websocket.WebSocketMessageReceived = WebSocket4Net_MessageReceived;
GlobalData.StationNames = JsonParser.ReadApmsJson(sc.proApms.ProPath + sc.proApms.JsonPath);
DialogParameters param = new DialogParameters();
param.Add("type", 1);// 编辑
_dialogService.ShowDialog(

@ -25,7 +25,7 @@ namespace StartServerWPF.Modules.MseedChart.Models
//添加Z分量波形
if (item.dz.Count > 0)
{
axisY.SetRange(0, 6000);
axisY.SetRange(2000, 5000);
}
axisY.Title.Text = string.Format("Ch{0}.Z", item.Name);
axisY.Title.DistanceToAxis = distancetoX;
@ -34,7 +34,7 @@ namespace StartServerWPF.Modules.MseedChart.Models
axisY = new AxisY(curChart.ViewXY);
if (item.dn.Count > 0)
{
axisY.SetRange(0, 6000);
axisY.SetRange(2000, 5000);
}
axisY.Title.Text = string.Format("Ch{0}.N", item.Name);
axisY.Title.DistanceToAxis = distancetoX;

@ -258,10 +258,6 @@ namespace ZhaoXi.Advanced.MyRedis.Service
Console.WriteLine($"取消订阅 {c}");
Console.WriteLine();
};
subscription.OnMessage += (c, s) =>
{
// actionOnMessage(c, s, subscription);
};
subscription.OnMessageBytes += (c, s) =>
{
// ByteToFile(s, "test.mseed");
@ -275,6 +271,7 @@ namespace ZhaoXi.Advanced.MyRedis.Service
{
var subscription = base.iClient.CreateSubscription();
subscription.UnSubscribeFromChannels(channel);
//subscription.UnSubscribeFromAllChannels();
}
public static bool ByteToFile(byte[] byteArray, string fileName)

@ -39,6 +39,8 @@ using ServiceStack;
using ServiceStack.Redis;
using Arction.Licensing;
using System.Runtime.InteropServices;
using StartServerWPF.Assets;
using ServiceStack.Text;
namespace StartServerWPF.Modules.MseedChart.ViewModels
{
@ -51,7 +53,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
_dispatcher = Application.Current.Dispatcher;
_wavesModel = new WavesModel();
(Application.Current.MainWindow as System.Windows.Window).Closing += ApplicationClosingDispose;
IntervalTime=100;
IntervalTime=1000;
CreateChart();
loopCallback = new Mseed2asciiApi.LoopCallbackHandler(Mseed2AsciiEvent);
Mseed2asciiApi.MseedDatasCallFun(loopCallback);
@ -59,6 +61,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
}
#region 字段
System.Timers.Timer time=new System.Timers.Timer(1000);
Dispatcher _dispatcher;
public int CurPoints;
int _channelCount = 0;
@ -68,8 +71,6 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
public ConcurrentQueue<StationModel> smList=new ConcurrentQueue<StationModel>();
public List<AxisY> _chartAxisY=new List<AxisY>();
private DispatcherTimer dispatcherTimer=new DispatcherTimer();
#endregion
#region 属性
@ -191,7 +192,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
}
}
private int _IntervalTime=10;
private int _IntervalTime=1000;
public int IntervalTime
{
@ -200,7 +201,7 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
{
if (value >=10)
{
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(value);
// time.Interval = value;
}
SetProperty(ref _IntervalTime, value);
}
@ -263,14 +264,24 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
private void Loaded()
{
//N08,N25,N26
string station = "N02,N05,N06,N08,N09,N10,N11,N12,N13,N14,N15,N16,N19,N20,N22,N23,N24,N25,N26";//,N07,N08,N09,N10,N11,N12,N13,N14,N15,N16,N17,N18,N19,N20,N21,N22,N23,N24,N25,N26,N27";
var stations = station.Split(',');
string station = "N05,N10";
var stations = GlobalData.StationNames;// station.Split(',');
smList = _wavesModel.ReadWavesFromJson(stations);
}
private void UnLoaded()
{
time.Stop();
using (RedisListService service = new RedisListService())
{
if (subNameList != null)
{
foreach (var subName in subNameList)
{
service.UnSubscribeFromChannels(subName.Key);
}
}
}
}
private void AxesYVisible(object isCheck)
@ -495,16 +506,16 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
_lChartAll.BeginUpdate();
if (isStartRealData)
{
_data = CreateInputData(_channelCount, _samplingFrequency);
_data = new double[smList.Count * 3][];
StartChart();
//Set real-time monitoring automatic old data destruction
LChartALL.ViewXY.DropOldSeriesData = true;
_pointsAppended = LChartALL.ViewXY.XAxes[0].Minimum;
dispatcherTimer.Tick -= CompositionTarget_Rendering;
dispatcherTimer.Tick += CompositionTarget_Rendering;
LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.Scrolling;
dispatcherTimer.Start();
time.Elapsed -= CompositionTarget_Rendering;
time.Elapsed += CompositionTarget_Rendering;
LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.Scrolling;
time.Start();
using (RedisListService service = new RedisListService())
{
foreach (var subName in subNameList)
@ -521,7 +532,6 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
{
service.Subscribe(subName.Key, (c, message, iRedisSubscription) =>
{
Debug.WriteLine($"注册{1}{c}");
Mseed2asciiApi.bufferMseedData(message.Length, message);
});
}
@ -530,9 +540,9 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
}
else
{
dispatcherTimer.Stop();
time.Stop();
time.Elapsed -= CompositionTarget_Rendering;
LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.None;
dispatcherTimer.Tick -= CompositionTarget_Rendering;
using (RedisListService service = new RedisListService())
{
foreach (var subName in subNameList)
@ -548,16 +558,19 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
private void Mseed2AsciiEvent(AsciiDataStruct asciiData)
{
DateTime startTime= Convert.ToDateTime(asciiData.endtime).AddHours(8);
DateTime endTime = Convert.ToDateTime(asciiData.endtime).AddHours(8);
Debug.WriteLine($"注册{asciiData.sid}:{startTime}");
var time = endTime - startTime;
byte[] bytes = new byte[asciiData.numsamples * asciiData.samplesize];
// IntPtr bufferHandler = Marshal.AllocHGlobal((int)asciiData.datasize);
Marshal.Copy(asciiData.datasamples, bytes, 0, bytes.Length);
List<double> lines = new List<double>();
//时间添加到开始
lines.Add(startTime.ToOADate());
string[] sid = asciiData.sid.Split('_');
string name = $"HA.{sid[1]}.{sid[2]}.{sid[3]}{sid[4]}{sid[5]}";
if (asciiData.sampletype == 'i')
{
for (int index = 0; index < bytes.Length; index += 4)
@ -566,29 +579,27 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
lines.Add(a);
}
}
else if (asciiData.sampletype == 'f')
{
for (int index = 0; index < bytes.Length; index += 4)
{
var b = BitConverter.ToSingle(bytes, index);
lines.Add(b);
}
}
else if (asciiData.sampletype == 'd')
{
for (int index = 0; index < bytes.Length; index += 8)
{
var b = BitConverter.ToDouble(bytes, index);
lines.Add(b);
}
}
string lineStr= String.Join(",", lines);
//else if (asciiData.sampletype == 'f')
//{
// for (int index = 0; index < bytes.Length; index += 4)
// {
// var b = BitConverter.ToSingle(bytes, index);
// lines.Add(b);
// }
//}
//else if (asciiData.sampletype == 'd')
//{
// for (int index = 0; index < bytes.Length; index += 8)
// {
// var b = BitConverter.ToDouble(bytes, index);
// lines.Add(b);
// }
//}
using (RedisListService service = new RedisListService())
{
// string data = System.Text.Encoding.ASCII.GetString(bytes);
service.RPush(name, lineStr);
service.LPush(name, lineStr);
}
}
@ -852,66 +863,61 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
}
#region 实时数据
private void CompositionTarget_Rendering(object sender, EventArgs e)
private void CompositionTarget_Rendering(object sender, System.Timers.ElapsedEventArgs e)
{
RenderNextFrame();
}
private void RenderNextFrame()
{
Debug.WriteLine("timeFrame:{0}", DateTime.Now);
if (_lChartAll == null)
{
return;
}
_dispatcher.Invoke(() =>
using (RedisListService service = new RedisListService())
{
//FeedData(/*chartTitleText*/);
});
}
int _iRound = 0;
double _pointsAppended = 0;
double[][] _data;
int PreGenerateDataForRoundCount = 6;
//Y axis minimum
private const double YMin = 0;
//Y axis maximum
private const double YMax = 10;
private double[][] CreateInputData(int seriesCount, int appendCountPerRound)
foreach (var item in subNameList)
{
//Create input data for all series.
double[][] data = new double[seriesCount][];
// System.Threading.Tasks.Parallel.For(0, seriesCount, (seriesIndex) =>
for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++)
List<double> dataDouList = new List<double>();
var data = service.Get(item.Key, 0, 0).FirstOrDefault();
if( data != null)
{
int dataPointCount = PreGenerateDataForRoundCount * appendCountPerRound;
double[] seriesData = new double[dataPointCount];
double seriesIndexPlus1 = seriesIndex + 1;
Random rand = new Random((int)DateTime.Now.Ticks / (seriesIndex + 1));
double y = 50;
for (int i = 0; i < dataPointCount; i++)
IEnumerable<double> datasStr = data.Split(',').Select(a => Convert.ToDouble(a));
double oaTime = datasStr.First();
if (oaTime < DateTime.Now.AddSeconds(-3).ToOADate())
{
y = y - 0.05 + rand.NextDouble() / 10.0;
if (y > YMax)
//取出队列数据
service.RemoveStartFromList(item.Key);
var DouData = data.Split(',').Select(a => Convert.ToDouble(a)).ToList();
DouData.RemoveAt(0);
dataDouList.AddRange(DouData);
}
else
{
y = YMax;
break;
}
if (y < YMin)
//继续查看数据
// data = service.Get(item.Key, 0, 0).FirstOrDefault();
}
// data =service.BlockingDequeueItemFromList(item.Key, TimeSpan.FromMilliseconds(5));
if (dataDouList.Count!=0)
{
y = YMin;
_data[item.Value] =dataDouList.ToArray();
}
seriesData[i] = (float)y;
}
data[seriesIndex] = seriesData;
}//);
}
// if (_data.ToList().Any(d => d != null))
{
_dispatcher.Invoke(() =>
{
FeedData(/*chartTitleText*/);
});
}
return data;
}
int _iRound = 0;
double _pointsAppended = 0;
double[][] _data;
private void FeedData()
{
@ -920,40 +926,21 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels
_lChartAll.BeginUpdate();
//Append data to series
using (RedisListService service = new RedisListService())
{
foreach (var item in subNameList)
for (int seriesIndex = 0; seriesIndex < _channelCount; seriesIndex++)
{
string data= service.BlockingDequeueItemFromList(item.Key, TimeSpan.FromMilliseconds(500));
if(data == null)
{
System.Diagnostics.Debug.WriteLine("***********注册:{0},没有收到数据,time:{1}", item.Key, DateTime.Now);
continue;
double[] thisSeriesData = _data[seriesIndex];
if (thisSeriesData == null) continue;
_lChartAll.ViewXY.SampleDataSeries[seriesIndex].AddSamples(thisSeriesData, false);
_data[seriesIndex] = null;
System.Diagnostics.Debug.WriteLine("***********index:{0}, pointCount:{1},time:{2}", seriesIndex,
_lChartAll.ViewXY.SampleDataSeries[seriesIndex].PointCount, DateTime.Now);
}
// byte[] bytes = System.Text.Encoding.ASCII.GetBytes(data);
// List<double> thisSeriesData = new List<double>();
var thisSeriesData = data.Split(',').Select(a=>Convert.ToDouble(a)).ToArray();
// if (asciiData.sampletype == 'i')
{
//for (int index = 0; index < bytes.Length; index += 4)
//{
// int a = BitConverter.ToInt32(bytes, index);
// thisSeriesData.Add(a);
//}
}
_lChartAll.ViewXY.SampleDataSeries[subNameList[item.Key]].AddSamples(thisSeriesData, false);
System.Diagnostics.Debug.WriteLine("***********index:{0}, pointCount:{1},time:{2}", subNameList[item.Key],
_lChartAll.ViewXY.SampleDataSeries[subNameList[item.Key]].PointCount, DateTime.Now);
}
}
//System.Threading.Tasks.Parallel.For(0, _channelCount, (seriesIndex) =>
//{
// double[] thisSeriesData = _data[seriesIndex];
// double[] dataToAppendNow = new double[_samplingFrequency];
// Array.Copy(thisSeriesData, 0, dataToAppendNow, 0, _samplingFrequency);
// _lChartAll.ViewXY.SampleDataSeries[seriesIndex].AddSamples(_data[seriesIndex], false);
// System.Diagnostics.Debug.WriteLine("***********index:{0}, pointCount:{1},time:{2}", seriesIndex,
// _lChartAll.ViewXY.SampleDataSeries[seriesIndex].PointCount, DateTime.Now);
//});

@ -1,8 +1,8 @@
<Window x:Class="StartServerWPF.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
WindowStyle="None" WindowStartupLocation="CenterScreen"
xmlns:prism="http://prismlibrary.com/" WindowState="Maximized"
WindowStyle="None" WindowStartupLocation="CenterScreen" MouseDown="Window_MouseDown"
prism:ViewModelLocator.AutoWireViewModel="True" Closing="Window_Closing"
Title="{Binding Title}" Height="900" Width="1700" >
<Window.Resources>

@ -14,6 +14,7 @@ namespace StartServerWPF.Views
public MainWindow()
{
InitializeComponent();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
@ -30,5 +31,9 @@ namespace StartServerWPF.Views
//}
}
private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
this.DragMove();
}
}
}

Loading…
Cancel
Save