コード例 #1
0
        public override void Calculate(IDictionary <Guid, SignalDataBase> signals)
        {
            Dependencies[0].Calculate(signals);

            SignalDataBase origionalSignal = signals[Dependencies[0].UniqueId];

            SignalDataBase newSignal = TryGetSignal(m_newSignal, signals);

            if (newSignal == null || newSignal.IsComplete)
            {
                return;
            }

            int pos = 0;

            while (pos < origionalSignal.Count)
            {
                ulong  time;
                double vm;
                origionalSignal.GetData(pos, out time, out vm);
                pos++;

                newSignal.AddData(time, vm);
            }
            newSignal.Completed();
        }
コード例 #2
0
        public override void Calculate(IDictionary <Guid, SignalDataBase> signals)
        {
            Dependencies[0].Calculate(signals);
            Dependencies[1].Calculate(signals);

            SignalDataBase signal          = signals[Dependencies[0].UniqueId];
            SignalDataBase signalReference = signals[Dependencies[1].UniqueId];

            SignalDataBase newSignal = TryGetSignal(m_newSignal, signals);

            if (newSignal == null || newSignal.IsComplete)
            {
                return;
            }

            int pos    = 0;
            int posRef = 0;

            while (pos < signal.Count && posRef < signalReference.Count)
            {
                ulong  time, timeRef;
                double ang, angRef;
                signal.GetData(pos, out time, out ang);
                signalReference.GetData(posRef, out timeRef, out angRef);

                if (time == timeRef)
                {
                    pos++;
                    posRef++;

                    double delta = ang - angRef;
                    if (delta > 180.0)
                    {
                        delta -= 360.0;
                    }
                    if (delta < -180.0)
                    {
                        delta += 360.0;
                    }

                    newSignal.AddData(time, delta);
                }
                else
                {
                    if (time < timeRef)
                    {
                        pos++;
                    }
                    else
                    {
                        posRef++;
                    }
                }
            }
            newSignal.Completed();
        }
コード例 #3
0
ファイル: FrmMain.cs プロジェクト: yuwenpeng/openHistorian
        private void btnPlot_Click(object sender, EventArgs e)
        {
            List <ulong> keys = new List <ulong>(chkAllPoints.CheckedItems.OfType <ulong>());

            plot.Clear();

            plot.AddInteraction(new PlotSurface2D.Interactions.HorizontalDrag());
            plot.AddInteraction(new PlotSurface2D.Interactions.VerticalDrag());
            plot.AddInteraction(new PlotSurface2D.Interactions.AxisDrag(false));

            if (keys.Count == 0)
            {
                return;
            }
            var client = SnapClient.Connect(m_archiveFile.Host);
            var db     = client.GetDatabase <HistorianKey, HistorianValue>("");

            Dictionary <ulong, SignalDataBase> results = db.GetSignals(0, ulong.MaxValue, keys, TypeSingle.Instance);

            foreach (ulong point in keys)
            {
                List <double>  y    = new List <double>();
                List <double>  x    = new List <double>();
                SignalDataBase data = results[point];

                for (int i = 0; i < data.Count; i++)
                {
                    ulong  time;
                    double value;
                    data.GetData(i, out time, out value);

                    x.Add(time);
                    y.Add(value);
                }

                LinePlot lines = new LinePlot(y, x);

                plot.Add(lines);
            }

            plot.Refresh();
            db.Dispose();
            client.Dispose();
        }
コード例 #4
0
        private void PlotChart(QueryResultsEventArgs e, PlotSurface2D plot, List <KeyValuePair <int, Guid> > signals, bool cacheAxis)
        {
            if (cacheAxis)
            {
                double minX, maxX, minY, maxY;

                plot.Title = m_plotTitle;
                maxX       = plot.XAxis1.WorldMax;
                minX       = plot.XAxis1.WorldMin;
                maxY       = plot.YAxis1.WorldMax;
                minY       = plot.YAxis1.WorldMin;

                foreach (IDrawable drawing in plot.Drawables.ToArray())
                {
                    plot.Remove(drawing, false);
                }

                foreach (KeyValuePair <int, Guid> freq in signals)
                {
                    SignalDataBase data = e.Results[freq.Value];

                    List <double> y = new List <double>(data.Count);
                    List <double> x = new List <double>(data.Count);

                    for (int i = 0; i < data.Count; i++)
                    {
                        ulong  time;
                        double value;
                        data.GetData(i, out time, out value);

                        x.Add(time);
                        y.Add(value * m_scalingFactor);
                    }

                    LinePlot lines = new LinePlot(y, x);
                    lines.Pen = m_colorWheel.TryGetPen(freq.Key);

                    plot.Add(lines);
                }

                plot.XAxis1.WorldMax = maxX;
                plot.XAxis1.WorldMin = minX;
                plot.YAxis1.WorldMax = maxY;
                plot.YAxis1.WorldMin = minY;

                plot.Refresh();
            }
            else
            {
                plot.Clear();
                plot.Title = m_plotTitle;
                AddInteractions();

                foreach (KeyValuePair <int, Guid> freq in signals)
                {
                    SignalDataBase data = e.Results[freq.Value];

                    List <double> y = new List <double>(data.Count);
                    List <double> x = new List <double>(data.Count);

                    for (int i = 0; i < data.Count; i++)
                    {
                        ulong  time;
                        double value;
                        data.GetData(i, out time, out value);

                        x.Add(time);
                        y.Add(value * m_scalingFactor);
                    }

                    LinePlot lines = new LinePlot(y, x);
                    lines.Pen = m_colorWheel.TryGetPen(freq.Key);

                    plot.Add(lines);
                }

                if (plot.XAxis1 != null)
                {
                    plot.XAxis1.WorldMax = e.EndTime.Ticks;
                    plot.XAxis1.WorldMin = e.StartTime.Ticks;
                }
                plot.Refresh();
            }
        }
コード例 #5
0
ファイル: FrmMain.cs プロジェクト: ibgeorge/openHistorian
        private void PlotChart(QueryResultsEventArgs e, PlotSurface2D plot, List <Guid> signals, bool cacheAxis)
        {
            if (cacheAxis)
            {
                maxX = plot.XAxis1.WorldMax;
                minX = plot.XAxis1.WorldMin;
                maxY = plot.YAxis1.WorldMax;
                minY = plot.YAxis1.WorldMin;

                foreach (IDrawable drawing in plot.Drawables.ToArray())
                {
                    plot.Remove(drawing, false);
                }

                ColorWheel.Reset();
                foreach (Guid freq in signals)
                {
                    SignalDataBase data = e.Results[freq];

                    List <double> y = new List <double>(data.Count);
                    List <double> x = new List <double>(data.Count);

                    for (int i = 0; i < data.Count; i++)
                    {
                        data.GetData(i, out ulong time, out double value);

                        x.Add(time);
                        y.Add(value);
                    }

                    LinePlot lines = new LinePlot(y, x);
                    lines.Pen = ColorWheel.GetPen();

                    plot.Add(lines);
                }

                plot.XAxis1.WorldMax = maxX;
                plot.XAxis1.WorldMin = minX;
                plot.YAxis1.WorldMax = maxY;
                plot.YAxis1.WorldMin = minY;

                plot.Refresh();
            }
            else
            {
                plot.Clear();

                plot.AddInteraction(new PlotSurface2D.Interactions.HorizontalDrag());
                plot.AddInteraction(new PlotSurface2D.Interactions.VerticalDrag());
                plot.AddInteraction(new PlotSurface2D.Interactions.AxisDrag(false));

                ColorWheel.Reset();
                foreach (Guid freq in signals)
                {
                    SignalDataBase data = e.Results[freq];

                    List <double> y = new List <double>(data.Count);
                    List <double> x = new List <double>(data.Count);

                    for (int i = 0; i < data.Count; i++)
                    {
                        data.GetData(i, out ulong time, out double value);

                        x.Add(time);
                        y.Add(value);
                    }

                    LinePlot lines = new LinePlot(y, x);
                    lines.Pen = ColorWheel.GetPen();

                    plot.Add(lines);
                }
                plot.Refresh();
            }
        }
コード例 #6
0
        public override void Calculate(IDictionary <Guid, SignalDataBase> signals)
        {
            Dependencies[0].Calculate(signals);
            Dependencies[1].Calculate(signals);
            Dependencies[2].Calculate(signals);
            Dependencies[3].Calculate(signals);

            SignalDataBase pointListVM = signals[Dependencies[0].UniqueId];
            SignalDataBase pointListVA = signals[Dependencies[1].UniqueId];
            SignalDataBase pointListIM = signals[Dependencies[2].UniqueId];
            SignalDataBase pointListIA = signals[Dependencies[3].UniqueId];

            SignalDataBase pointListW    = TryGetSignal(Watt, signals);
            SignalDataBase pointListPF   = TryGetSignal(PowerFactor, signals);
            SignalDataBase pointListVAmp = TryGetSignal(VoltAmpre, signals);
            SignalDataBase pointListVAR  = TryGetSignal(VoltAmpreReactive, signals);

            if (pointListW != null && pointListW.IsComplete)
            {
                return;
            }
            if (pointListPF != null && pointListPF.IsComplete)
            {
                return;
            }
            if (pointListVAmp != null && pointListVAmp.IsComplete)
            {
                return;
            }
            if (pointListVAR != null && pointListVAR.IsComplete)
            {
                return;
            }

            int posVM = 0;
            int posVA = 0;
            int posIM = 0;
            int posIA = 0;

            while (posVM < pointListVM.Count && posVA < pointListVA.Count && posIM < pointListIM.Count &&
                   posIA < pointListIA.Count)
            {
                pointListVM.GetData(posVM, out ulong timeVM, out double vm);
                pointListVA.GetData(posVA, out ulong timeVA, out double va);
                pointListIM.GetData(posIM, out ulong timeIM, out double im);
                pointListIA.GetData(posIA, out ulong timeIA, out double ia);

                ulong time = timeVM;

                if (timeVM == timeVA && timeVM == timeIM && timeVM == timeIA)
                {
                    posVM++;
                    posVA++;
                    posIM++;
                    posIA++;

                    double angleDiffRadians = (va - ia) * TwoPieOver360;
                    double mva  = vm * im * 3;
                    double pf   = Math.Cos(angleDiffRadians);
                    double mw   = mva * pf;
                    double mvar = mva * Math.Sin(angleDiffRadians);

                    if (pointListW != null)
                    {
                        pointListW.AddData(time, mw);
                    }
                    if (pointListVAR != null)
                    {
                        pointListVAR.AddData(time, mvar);
                    }
                    if (pointListVAmp != null)
                    {
                        pointListVAmp.AddData(time, mva);
                    }
                    if (pointListPF != null)
                    {
                        pointListPF.AddData(time, pf);
                    }
                }
                else
                {
                    ulong maxTime = Math.Max(timeVM, timeVA);
                    maxTime = Math.Max(maxTime, timeIM);
                    maxTime = Math.Max(maxTime, timeIA);

                    if (timeVM < maxTime)
                    {
                        posVM++;
                    }
                    if (timeVA < maxTime)
                    {
                        posVA++;
                    }
                    if (timeIM < maxTime)
                    {
                        posIM++;
                    }
                    if (timeIA < maxTime)
                    {
                        posIA++;
                    }
                }
            }


            if (pointListW != null)
            {
                pointListW.Completed();
            }
            if (pointListPF != null)
            {
                pointListPF.Completed();
            }
            if (pointListVAmp != null)
            {
                pointListVAmp.Completed();
            }
            if (pointListVAR != null)
            {
                pointListVAR.Completed();
            }
        }