Beispiel #1
0
        public void LoadCompleted(DataSerie serie, ref List <pointXY> liveData, List <pointXY> dataLoggerData)
        {
            if (dataLoggerData.Count <= 0)
            {
                return;
            }

            if (liveData.Count > 0)
            {
                double lastTimeStamp = dataLoggerData[dataLoggerData.Count - 1].x;
                int    n             = 0;
                while ((n < liveData.Count) && (lastTimeStamp >= liveData[n].x))
                {
                    n++;
                }
                if (n > 0)
                {
                    liveData.RemoveRange(0, n);
                }
            }

            liveData = (List <pointXY>)dataLoggerData.Concat(liveData).ToList();


            MonitorGraph.DisableRedraw();
            serie.clear();
            serie.InsertPoints(liveData.ToArray());
            MonitorGraph.AllowRedraw();
        }
        public GraphForm(StartForm parent, XmlNode initData)
        {
            InitializeComponent();
            seriesProperties = new List <ChartSerie>();
            _cartesianChart  = new YGraph(rendererCanvas, LogManager.Log);
            _cartesianChart.getCaptureParameters = constants.getCaptureParametersCallback;
            _cartesianChart.DisableRedraw();

            noDataSourcepanel      = _cartesianChart.addMessagePanel();
            noDataSourcepanel.text = "No data source configured\n"
                                     + " 1 - Make sure you have a Yoctopuce sensor connected.\n"
                                     + " 2 - Do a right-click on this window.\n"
                                     + " 3 - Choose \"Configure this graph\" to bring up the properties editor.\n"
                                     + " 4 - Choose a data source\n";

            offLineSourcesPanel               = _cartesianChart.addMessagePanel();
            offLineSourcesPanel.bgColor       = System.Drawing.Color.FromArgb(192, 255, 192, 192);
            offLineSourcesPanel.borderColor   = System.Drawing.Color.DarkRed;
            offLineSourcesPanel.font.color    = System.Drawing.Color.DarkRed;
            offLineSourcesPanel.panelHrzAlign = MessagePanel.HorizontalAlignPos.RIGHT;
            offLineSourcesPanel.panelVrtAlign = MessagePanel.VerticalAlignPos.TOP;



            captureRunningPanel               = _cartesianChart.addMessagePanel();
            captureRunningPanel.bgColor       = System.Drawing.Color.FromArgb(240, 200, 255, 193);;
            captureRunningPanel.borderColor   = System.Drawing.Color.DarkGreen;
            captureRunningPanel.font.color    = System.Drawing.Color.DarkGreen;
            captureRunningPanel.panelHrzAlign = MessagePanel.HorizontalAlignPos.LEFT;
            captureRunningPanel.panelVrtAlign = MessagePanel.VerticalAlignPos.TOP;


            _cartesianChart.setPatchAnnotationCallback(AnnotationCallback);


            foreach (var p in typeof(YaxisDescription).GetProperties())
            {
                if (p.Name.StartsWith("zones"))
                {
                    ZoneCountPerYaxis++;
                }
            }

            foreach (var p in typeof(XaxisDescription).GetProperties())
            {
                if (p.Name.StartsWith("markers"))
                {
                    MarkerCountPerXaxis++;
                }
            }



            foreach (var p in typeof(GraphFormProperties).GetProperties())
            {
                string name = p.Name;
                if (name.StartsWith("Graph_series"))
                {
                    SeriesCount++;
                }
            }

            if (YAxisCount == 0)
            {
                AnnotationPanelCount = 0;
                foreach (var p in typeof(GraphFormProperties).GetProperties())
                {
                    string name = p.Name;
                    if (name.StartsWith("Graph_yAxes"))
                    {
                        YAxisCount++;
                    }
                    if (name.StartsWith("Graph_annotationPanel"))
                    {
                        AnnotationPanelCount++;
                    }
                }
            }


            for (int i = 0; i < YAxisCount; i++)
            {
                YAxis axis = _cartesianChart.addYAxis();
                for (int j = 0; j < ZoneCountPerYaxis; j++)
                {
                    axis.AddZone();
                }
            }

            markers = new List <Marker>();
            for (int i = 0; i < MarkerCountPerXaxis; i++)
            {
                Marker m = _cartesianChart.xAxis.AddMarker();
                m.xposition = TimeConverter.ToUnixTime(DateTime.UtcNow) + i * 60;
                markers.Add(m);
            }



            for (int i = 0; i < AnnotationPanelCount; i++)
            {
                _cartesianChart.addAnnotationPanel();
            }

            prop = new GraphFormProperties(initData, this);

            for (int i = 0; i < SeriesCount; i++)
            {
                seriesProperties.Add((ChartSerie)prop.GetType().GetProperty("Graph_series" + i.ToString()).GetValue(prop, null));
                _cartesianChart.addSerie();
            }
            _cartesianChart.yAxes[0].visible = true;

            offlineMessages = new String[SeriesCount];
            showOffline     = new bool[SeriesCount];

            manager      = new formManager(this, parent, initData, "graph", prop);
            mainForm     = parent;
            initDataNode = initData;
            prop.ApplyAllProperties(this);
            if (!manager.initForm())
            {
                Rectangle s = Screen.FromControl(this).Bounds;
                this.Location = new Point((s.Width - this.Width) >> 1, (s.Height - this.Height) >> 1);
            }

            YDataRenderer.minMaxCheckDisabled = true;
            try { prop.ApplyAllProperties(_cartesianChart); }
            catch (TargetInvocationException e) { LogManager.Log("Graph initialization raised an exception (" + e.InnerException.Message + ")"); }
            YDataRenderer.minMaxCheckDisabled = false;

            manager.configureContextMenu(this, contextMenuStrip1, showConfiguration, switchConfiguration, capture);
            _cartesianChart.proportionnalValueChangeCallback = manager.proportionalValuechanged;

            for (int i = 0; i < SeriesCount; i++)
            {
                ChartSerie s = (ChartSerie)prop.GetType().GetProperty("Graph_series" + i.ToString()).GetValue(prop, null);
                s.Init(this, i);
                if (s.DataSource_source != null)
                {
                    SourceChanged(i, s.DataSource_source);
                }
            }

            for (int i = 0; i < YAxisCount; i++)
            {
                _cartesianChart.yAxes[i].AxisChanged   = AxisParamtersChangedAutomatically;
                _cartesianChart.yAxes[i].AllowAutoShow = true;
            }
            _cartesianChart.resetRefrenceSize();
            _cartesianChart.AllowPrintScreenCapture          = true;
            _cartesianChart.proportionnalValueChangeCallback = manager.proportionalValuechanged;
            _cartesianChart.setMarkerCaptureCallbacks(MarkedCaptureStarted, MarkedCaptureStopped);
            _cartesianChart.AllowRedraw();
            deleteMarkeOption = new ToolStripMenuItem("Disable all markers", Resources.disable_marker, disableAllMarkers);
            contextMenuStrip1.Items.Insert(2, deleteMarkeOption);
            markersMenu = new ToolStripMenuItem("Place markers", Resources.add_marker);
            contextMenuStrip1.Items.Insert(2, markersMenu);
            Pen          pIcon        = new Pen(Color.DarkRed);
            SolidBrush   bIcon        = new SolidBrush(Color.LightYellow);
            StringFormat stringFormat = new StringFormat();

            stringFormat.Alignment     = StringAlignment.Center;
            stringFormat.LineAlignment = StringAlignment.Center;
            Font font1 = new Font("Arial", 9, FontStyle.Regular, GraphicsUnit.Pixel);

            for (int i = 0; i < markers.Count; i++)
            {
                int index = i;

                Bitmap   bm = new Bitmap(16, 16);
                Graphics gr = Graphics.FromImage(bm);
                gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                gr.FillEllipse(bIcon, new Rectangle(1, 1, 14, 14));
                gr.DrawEllipse(pIcon, new Rectangle(1, 1, 14, 14));
                gr.DrawString((i + 1).ToString(), font1, Brushes.Black, new Rectangle(1, 1, 16, 16), stringFormat);
                markersMenu.DropDownItems.Add(new ToolStripMenuItem("Place marker #" + (i + 1).ToString(), bm, (object sender, EventArgs e) => { startMarkerCapture(index); }));
                gr.Dispose();
            }
            pIcon.Dispose();
            bIcon.Dispose();
            markersMenu.DropDownOpening += updateMakerList;
            contextMenuStrip1.Items.Insert(2, new ToolStripSeparator());
            contextMenuStrip1.Items.Insert(2, new ToolStripMenuItem("Clear dataloggers", Resources.cleardatalogger, clearDataLogger));
            contextMenuStrip1.Items.Insert(2, new ToolStripMenuItem("Reset data view", Resources.resetdataview, resetDataView));
            contextMenuStrip1.Items.Insert(2, new ToolStripSeparator());
            contextMenuStrip1.Opening += ContextMenuStrip1_Opening;


            _cartesianChart.OnDblClick += rendererCanvas_DoubleClick;
            if (constants.OSX_Running)
            {
                _cartesianChart.OnRightClick += rendererCanvas_RightClick;
            }
        }
        public void SourceChanged(int index, CustomYSensor value)
        {
            value.registerCallback(this);

            _cartesianChart.DisableRedraw();
            ChartSerie s;

            bool noDataSource = true;

            for (int i = 0; i < SeriesCount; i++)
            {
                s = (ChartSerie)prop.GetType().GetProperty("Graph_series" + i.ToString()).GetValue(prop, null);
                if (!(s.DataSource_source is NullYSensor))
                {
                    noDataSource = false;
                }
            }
            noDataSourcepanel.enabled = noDataSource;

            if (value != null)
            {
                if (!(value is NullYSensor))
                {
                    if (value.isOnline())
                    {
                        showOffline[index] = false;
                    }
                    else
                    {
                        offlineMessages[index] = value.get_friendlyName() + " is OFFLINE";
                        showOffline[index]     = true;
                        LogManager.Log(value.get_friendlyName() + " is OFFLINE");
                    }
                }
                else
                {
                    showOffline[index] = false;
                }
            }
            else
            {
                showOffline[index] = false;
            }

            updateOfflinePanel();


            _cartesianChart.series[index].clear();
            s = (ChartSerie)prop.GetType().GetProperty("Graph_series" + index.ToString()).GetValue(prop, null);
            List <TimedSensorValue> data;

            switch (s.DataSource_datatype)
            {
            case 1: data = value.minData; break;

            case 2: data = value.maxData; break;

            default: data = value.curData; break;
            }


            List <pointXY[]> l = decomposeToSegments(data, 0, data.Count);

            for (int i = l.Count - 1; i >= 0; i--)
            {
                _cartesianChart.series[index].InsertPoints(l[i]);
            }


            _cartesianChart.AllowRedraw();
        }
Beispiel #4
0
        public void MonitorPanelDrawPanel()
        {
            int tabIndex = 0;

            SuspendLayout();
            //
            // WarningResetMessage1
            //
            if (MonitorMessage1 == null)
            {
                MonitorMessage1 = new System.Windows.Forms.Label();
            }
            MonitorMessage1.Name     = "MonitorMessage1";
            MonitorMessage1.AutoSize = false;
            MonitorMessage1.TabIndex = tabIndex++;
            MonitorMessage1.Font     = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            MonitorMessage1.Text = "Your device is gathering data at 0.1Hz, let the process run for several days to make sure that day/night temperature cycles are captured, then use this utility to analyze it and compute Temperature compensation. "
                                   + (RadioBtMonitor.Checked? " Once datalogger is loaded, you can export data at any time. ":"")
                                   + "Click on next to go back to the welcome page. You can also close this application, the capture process will still run in background.";



            MonitorMessage1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

            Controls.Add(MonitorMessage1);

            if (MonitorGraphContainer == null)
            {
                MonitorGraphContainer = new PictureBox();
            }
            MonitorGraphContainer.Name     = "MonitorGraphContainer";
            MonitorGraphContainer.TabIndex = tabIndex++;
            Controls.Add(MonitorGraphContainer);

            //
            // Export button
            //
            if (ExportButton == null)
            {
                ExportButton = new Button();
            }
            this.ExportButton.Name     = "ExportButton";
            this.ExportButton.AutoSize = false;
            this.ExportButton.Size     = new Size(75, 23);
            this.ExportButton.TabIndex = tabIndex++;
            this.ExportButton.Text     = "Export..";
            this.ExportButton.UseVisualStyleBackColor = true;

            this.ExportButton.Click += ExportButton_Click;
            ExportButton.Enabled     = false;
            Controls.Add(ExportButton);


            ResumeLayout(false);
            NextButton.Visible  = true;
            NextButton.Enabled  = true;
            PrevButton.Visible  = false;
            PrevButton.TabIndex = tabIndex++;
            NextButton.TabIndex = tabIndex++;
            MonitorPanelResize();

            MonitorGraph = new YGraph(MonitorGraphContainer, null);

            MonitorGraph.DisableRedraw();

            YAxis wAxis = MonitorGraph.addYAxis();

            wAxis.showGrid      = true;
            wAxis.visible       = true;
            wAxis.legend.title  = "Weight (" + ChoosedWeighScale.sensor.get_unit() + ")";
            wAxis.highlightZero = true;


            YAxis tAxis = MonitorGraph.addYAxis();

            tAxis.visible      = true;
            tAxis.legend.title = "Temperature (" + ChoosedWeighScale.tsensor.get_unit() + ")";
            tAxis.position     = YAxis.HrzPosition.RIGHT;



            MonitorGraph.navigator.enabled        = true;
            MonitorGraph.navigator.relativeheight = 12;
            MonitorGraph.xAxis.showGrid           = true;

            monitor_wData            = MonitorGraph.addSerie();
            monitor_wData.yAxisIndex = wAxis.index;
            monitor_wData.color      = Color.DarkBlue;
            wAxis.legend.font.color  = monitor_wData.color;

            monitor_tData            = MonitorGraph.addSerie();
            monitor_tData.yAxisIndex = tAxis.index;
            monitor_tData.color      = Color.DarkRed;
            tAxis.legend.font.color  = monitor_tData.color;


            progressPanel = MonitorGraph.addDataPanel();
            progressPanel.horizontalPosition = DataPanel.HorizontalPosition.RIGHTBORDER;
            progressPanel.verticalPosition   = DataPanel.VerticalPosition.TOPBORDER;
            progressPanel.horizontalMargin   = 5;
            progressPanel.verticalMargin     = 5;
            progressPanel.panelHrzAlign      = DataPanel.HorizontalAlign.LEFTOF;
            progressPanel.panelVrtAlign      = DataPanel.VerticalAlign.BELOW;
            progressPanel.borderColor        = Color.Black;
            progressPanel.borderthickness    = 1;

            progressPanel.enabled = true;



            MonitorGraph.AllowRedraw();
            WeightData = new List <pointXY>();
            TempData   = new List <pointXY>();

            ChoosedWeighScale.genericSensor.registerTimedReportCallback(newGenericSensorData);
            ChoosedWeighScale.tsensor.registerTimedReportCallback(newTempSensorData);

            //MonitorLoadProgress(0);
            ChoosedWeighScale.LoadDataLogger(MonitorLoadCompleted, MonitorLoadProgress, true);
        }
        public void loadFile(string fname)
        {
            FileInfo    fileInfo = new FileInfo(fname);
            DateTime    epoch    = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            CultureInfo culture  = CultureInfo.InvariantCulture;

            count = 0;

            using (var reader = new StreamReader(fname))
            {
                while (!reader.EndOfStream && count < maxPoints)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(';');

                    if (values.Length < 3)
                    {
                        break;
                    }
                    if (values[0].Contains("stamp"))
                    {
                        continue;
                    }
                    stamp[count] = (DateTime.ParseExact(values[0], "yyyy.MM.dd HH:mm:ss.ff", culture) - epoch).TotalSeconds;
                    temp[count]  = float.Parse(values[1], culture);
                    rawW[count]  = float.Parse(values[2], culture);
                    count++;
                }
            }
            if (count < 100)
            {
                count = 0;
                disable_textChangeEvents = true;
                dialogTitle.Text         = "Invalid file";
                errorMessage.Text        = "CSV file with at least 100 lines and 3 columns expected";
                errorMessage.Visible     = true;
                progressBar.Visible      = false;
                dialogButton.Text        = "Close";
                dialogPanel.Visible      = true;
                return;
            }
            fileName.Text            = fileInfo.Name;
            count                   -= 24;
            learnCount               = 3 * count / 4;
            disable_textChangeEvents = false;

            chart.DisableRedraw();
            tempData      = chart.addSerie();
            avgTempData   = chart.addSerie();
            deltaTempData = chart.addSerie();
            rawWData      = chart.addSerie();
            predData      = chart.addSerie();
            errorData     = chart.addSerie();
            for (int i = 0; i < count; i++)
            {
                tempData.AddPoint(new pointXY()
                {
                    x = stamp[i], y = temp[i]
                });
                rawWData.AddPoint(new pointXY()
                {
                    x = stamp[i], y = rawW[i]
                });
            }
            chart.xAxis.min        = stamp[count * 3 / 4];
            chart.xAxis.max        = stamp[count - 1];
            tempData.legend        = "Temperature";
            tempData.color         = Color.DarkRed;
            tempData.disabled      = !showTemp.Checked;
            avgTempData.legend     = "Avg.Temp.";
            avgTempData.color      = Color.Red;
            avgTempData.disabled   = !showAvg.Checked;
            deltaTempData.legend   = "Delta.Temp.";
            deltaTempData.color    = Color.DarkOrange;
            deltaTempData.disabled = !showDelta.Checked;
            rawWData.legend        = "Zero Drift";
            rawWData.color         = Color.DarkBlue;
            rawWData.yAxisIndex    = 1;
            rawWData.disabled      = !showRawW.Checked;
            predData.legend        = "Pred.Drift";
            predData.color         = Color.Blue;
            predData.yAxisIndex    = 1;
            predData.disabled      = !showPrediction.Checked;
            errorData.legend       = "Residual Error";
            errorData.color        = Color.Black;
            errorData.yAxisIndex   = 1;
            errorData.disabled     = !showError.Checked;
            chart.AllowRedraw();

            this.optimizeDeltaRate();
        }