From e8d5560c3974dc4a397b71ed424233f206e24a69 Mon Sep 17 00:00:00 2001 From: mzhifa Date: Tue, 29 Aug 2023 00:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9E=E6=97=B6=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Mseed2asciiApi.cs | 12 +- .../ViewModels/ChartPlotRealDataViewModel.cs | 168 ++++++++++-------- 2 files changed, 99 insertions(+), 81 deletions(-) diff --git a/StartServerWPF.Modules.MseedChart/Mseed2asciiApi.cs b/StartServerWPF.Modules.MseedChart/Mseed2asciiApi.cs index 78d69fe..a2e3105 100644 --- a/StartServerWPF.Modules.MseedChart/Mseed2asciiApi.cs +++ b/StartServerWPF.Modules.MseedChart/Mseed2asciiApi.cs @@ -43,16 +43,18 @@ namespace StartServerWPF.Modules.MseedChart public int Index { set; get; } public string sid { set; get; } public double samprate { set; get; } + public double StartOATime { set; get; } public Int64 numsamples { set; get; } - public Dictionary datas { get; }=new Dictionary(); + public List datas { get; }=new List(); - public void AddData(double oaTime, double[] da) + public void AddData(double aoTime, double[] da) { - if(datas.Count>=100) + StartOATime = aoTime; + if (datas.Count>=60) { - datas.RemoveKey(0); + datas.RemoveAt(0); } - datas.Add(oaTime, da); + datas.Add(da); } } } diff --git a/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs b/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs index 4c6bec1..20ff83f 100644 --- a/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs +++ b/StartServerWPF.Modules.MseedChart/ViewModels/ChartPlotRealDataViewModel.cs @@ -491,7 +491,8 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels } _lChartAll.BeginUpdate(); if (isStartRealData) - { + { + currentOATime = 0; _data = new double[smList.Count * 3][]; StartChart(); //Set real-time monitoring automatic old data destruction @@ -937,12 +938,15 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels { service.RemoveStartFromList(item.Key); tempData.Add(item.Key+ firstTime); - if (offset < 100) + if (offset < 60) { // 不能超过缓存数, 更新数据 var time = currentTime.AddSeconds(-offset); - var tem = item.Value.datas[time.ToOADate()]; - item.Value.datas[time.ToOADate()] = datasStr.ToArray(); + int iCount= item.Value.datas.Count; + if (iCount - offset > 0) + { + item.Value.datas[iCount - offset] = datasStr.ToArray(); + } } data = service.Get(item.Key, 0, 0).FirstOrDefault(); if (data == null) break; @@ -972,20 +976,27 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels //有新数据开始刷新 if (tempData.Count > 5) { - List temDou = new List(); + DateTime startTime = DateTime.Today; foreach (var item in subNameList) { - var d = item.Value.datas.Keys.OrderBy(a => a).ToArray(); - for (int i = 0; i < d.Count(); i++) + List temDou = new List(); + var number = item.Value.datas.Count; + for (int i = 0; i < number; i++) + { + temDou.AddRange(item.Value.datas[i]); + } + _data[item.Value.Index] = temDou.ToArray(); + if (startTime == DateTime.Today) { - temDou.AddRange(item.Value.datas[d[i]]); + startTime = DateTime.FromOADate(item.Value.StartOATime).AddSeconds(-item.Value.datas.Count); } - // _data[item.Value.Index] = temDou.ToArray(); - // DateTime time1 = DateTime.Now.AddMinutes(i++); - // _lChartAll.ViewXY.XAxes[0].SetRange(_lChartAll.ViewXY.XAxes[0].DateTimeToAxisValue(time1), - // _lChartAll.ViewXY.XAxes[0].DateTimeToAxisValue(time1.AddSeconds(60))); } - // isRefresh = true; + _lChartAll.ViewXY.XAxes[0].SetRange(_lChartAll.ViewXY.XAxes[0].DateTimeToAxisValue(startTime), + _lChartAll.ViewXY.XAxes[0].DateTimeToAxisValue(startTime.AddSeconds(30))); + LChartALL.ViewXY.DropOldSeriesData = true; + _pointsAppended = LChartALL.ViewXY.XAxes[0].Minimum; + + isRefresh = true; tempData.Clear(); } _dispatcher.Invoke(() => @@ -996,88 +1007,93 @@ namespace StartServerWPF.Modules.MseedChart.ViewModels double time2 = stopwatch.ElapsedMilliseconds; Debug.WriteLine("timeFrame:{0},time1:{1},time1:{2}", DateTime.FromOADate(currentOATime), time1, time2); } - int _iRound = 0; double _pointsAppended = 0; double[][] _data; - + private void FeedData(bool isRefresh) { - if (_lChartAll != null) + if (_lChartAll == null) return; + _lChartAll.BeginUpdate(); + if (isRefresh) { - _lChartAll.BeginUpdate(); - if(isRefresh) - { - for (int seriesIndex = 0; seriesIndex < _channelCount; seriesIndex++) - { - _lChartAll.ViewXY.SampleDataSeries[seriesIndex].Clear(); - } - } - //Append data to series for (int seriesIndex = 0; seriesIndex < _channelCount; seriesIndex++) { - double[] thisSeriesData = _data[seriesIndex]; - if(thisSeriesData==null) - { - - } - _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); + _lChartAll.ViewXY.SampleDataSeries[seriesIndex].Clear(); } - //System.Threading.Tasks.Parallel.For(0, _channelCount, (seriesIndex) => + + //foreach (var item in subNameList.Values) //{ - // double[] thisSeriesData = _data[seriesIndex]; - // double[] dataToAppendNow = new double[_samplingFrequency]; - // Array.Copy(thisSeriesData, 0, dataToAppendNow, 0, _samplingFrequency); - // _lChartAll.ViewXY.SampleDataSeries[seriesIndex].AddSamples(_data[seriesIndex], false); + // startTime = DateTime.FromOADate(item.StartOATime).AddSeconds(item.datas.Count); + // _lChartAll.ViewXY.XAxes[0].SetRange(_lChartAll.ViewXY.XAxes[0].DateTimeToAxisValue(startTime), + // _lChartAll.ViewXY.XAxes[0].DateTimeToAxisValue(startTime.AddSeconds(60))); + // LChartALL.ViewXY.DropOldSeriesData = true; + // _pointsAppended = LChartALL.ViewXY.XAxes[0].Minimum; + // var number = item.datas.Count; + // for (int i = 0; i < number; i++) + // { + // foreach (var d in subNameList) + // { + // double[] thisSeriesData = subNameList[d.Key].datas[i]; + // _lChartAll.ViewXY.SampleDataSeries[d.Value.Index].AddSamples(thisSeriesData, false); + // } + // _pointsAppended += 1; + // //Set X axis real-time scrolling position + // double last = _pointsAppended; + // _lChartAll.ViewXY.XAxes[0].ScrollPosition = last; + // } + // break; + //} + } + //Append data to series + for (int seriesIndex = 0; seriesIndex < _channelCount; seriesIndex++) + { + double[] thisSeriesData = _data[seriesIndex]; + _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); - //}); - _pointsAppended += 1; + // _lChartAll.ViewXY.SampleDataSeries[seriesIndex].PointCount, DateTime.Now); + } + _pointsAppended += 1; - //Set X axis real-time scrolling position - double lastX = _pointsAppended; - _lChartAll.ViewXY.XAxes[0].ScrollPosition = lastX; + //Set X axis real-time scrolling position + double lastX = _pointsAppended; + _lChartAll.ViewXY.XAxes[0].ScrollPosition = lastX; - //Update sweep bands - if (_lChartAll.ViewXY.XAxes[0].ScrollMode == XAxisScrollMode.Sweeping) + //Update sweep bands + if (_lChartAll.ViewXY.XAxes[0].ScrollMode == XAxisScrollMode.Sweeping) + { + //Dark band of old page fading away + double pageLen = _lChartAll.ViewXY.XAxes[0].Maximum - _lChartAll.ViewXY.XAxes[0].Minimum; + double sweepGapWidth = pageLen / 20.0; + _lChartAll.ViewXY.Bands[0].SetValues(lastX - pageLen, lastX - pageLen + sweepGapWidth); + if (_lChartAll.ViewXY.Bands[0].Visible == false) { - - //Dark band of old page fading away - double pageLen = _lChartAll.ViewXY.XAxes[0].Maximum - _lChartAll.ViewXY.XAxes[0].Minimum; - double sweepGapWidth = pageLen / 20.0; - _lChartAll.ViewXY.Bands[0].SetValues(lastX - pageLen, lastX - pageLen + sweepGapWidth); - if (_lChartAll.ViewXY.Bands[0].Visible == false) - { - _lChartAll.ViewXY.Bands[0].Visible = true; - } + _lChartAll.ViewXY.Bands[0].Visible = true; + } - //Bright new page band - _lChartAll.ViewXY.Bands[1].SetValues(lastX - sweepGapWidth / 6, lastX); - if (_lChartAll.ViewXY.Bands[1].Visible == false) - { - _lChartAll.ViewXY.Bands[1].Visible = true; - } - } - else + //Bright new page band + _lChartAll.ViewXY.Bands[1].SetValues(lastX - sweepGapWidth / 6, lastX); + if (_lChartAll.ViewXY.Bands[1].Visible == false) { - //Hide sweeping bands if not in sweeping mode - //if (_lChartAll.ViewXY.Bands[0].Visible == true) - //{ - // _lChartAll.ViewXY.Bands[0].Visible = false; - //} - - //if (_lChartAll.ViewXY.Bands[1].Visible == true) - //{ - // _lChartAll.ViewXY.Bands[1].Visible = false; - //} + _lChartAll.ViewXY.Bands[1].Visible = true; } - _lChartAll.EndUpdate(); + } + else + { + //Hide sweeping bands if not in sweeping mode + //if (_lChartAll.ViewXY.Bands[0].Visible == true) + //{ + // _lChartAll.ViewXY.Bands[0].Visible = false; + //} - _iRound++; + //if (_lChartAll.ViewXY.Bands[1].Visible == true) + //{ + // _lChartAll.ViewXY.Bands[1].Visible = false; + //} } + _lChartAll.EndUpdate(); + } public void OnNavigatedTo(NavigationContext navigationContext)