示例#1
0
        }//end

        private void formsPlot1_Load(object sender, EventArgs e)
        {
            classWXstnChk WXchk = new classWXstnChk();                                                         //make an object WXck

            WXchk.cnxstring("192.168.1.15", "DAWES_SQL2008", "WeatherStation", "WeatherStation", "Esp32a.b."); //a constructor - no arguments

            Globals.fieldname = "TEMP";
            Globals.tempDataS = WXchk.getTemperatureData(Globals.pointcount, Globals.tname1);  //this gets the data as an XY pair

            Globals.fieldname    = "TIME";
            Globals.tempDataDate = WXchk.getTemperatureData(Globals.pointcount, Globals.tname1);  //this gets the data as an XY pair



            formsPlot1.plt.PlotScatter(Globals.tempDataS, Globals.tempDataDate, lineWidth: 1, color: Color.Red); //   (Globals.tempDataS, sampleRate:1,xOffset:0,yOffset:0,color:Color.Red,lineWidth:1,markerSize:4,label:null,maxRenderIndex:null);
                                                                                                                 // formsPlot1.plt.PlotScatter()
            formsPlot1.Render();                                                                                 //draw the chart on the PC screen
        }//end
示例#2
0
        private void formsPlot1_Load(object sender, EventArgs e)
        {
            // this is the plotting place - all in the Load

            //           string tname1 = "WXROVER";
            //           string tname2 = "WXIN";
            //           int pointcount = 5000;
            //           double[,] tempData;

            int cnt = 0;
            //            double[] t1 = new double[Globals.pointcount];
            //            double[] t2 = new double[Globals.pointcount];

            // a couple of local lists
            List <double> orgs = new List <double> {
            };
            List <double> chks = new List <double> {
            };



            classWXstnChk WXchk = new classWXstnChk();                                                         //make an object WXck

            WXchk.cnxstring("192.168.1.15", "DAWES_SQL2008", "WeatherStation", "WeatherStation", "Esp32a.b."); //a constructor - no arguments

            //go get the data
            Globals.tempData = WXchk.getTemperatureData(Globals.pointcount, Globals.tname1, Globals.tname2);  //this gets the data as an XY pair
                                                                                                              //there will be a lot of duplcates in this array.  Lets remove the dupes - done in the SQL



            //for scotterplot to work, these need to be in two separate Arrays, so we seperate them out in
            //this loop and we might as well get rid of the empty slots
            //maybe this would also work
            // double [] tab1 = new double[tempData.Length];

            for (int i = 0; i < pointcount - 1; i++)
            {
                if (Globals.tempData[i, 0] > 0)
                {
                    t1[i]   = tempData[i, 0];
                    t2[i]   = tempData[i, 1];
                    t1qq[i] = tempData[i, 0];
                    t2qq[i] = tempData[i, 1];

                    //might as well put the data in the grid
                    dgXY.Rows.Add();
                    try
                    {
                        dgXY.Rows[i].Cells["dgXYrecord"].Value = i.ToString(); //puts the record no on the dgXY
                        dgXY.Rows[i].Cells["dgXYx"].Value      = t1[i];
                        dgXY.Rows[i].Cells["dgXYy"].Value      = t2[i];
                    }
                    catch { }

                    cnt += 1;
                }
            }//end of for loop

            // we have two arrays lets sort them to form a QQ plot
            Array.Sort(t1qq);
            Array.Sort(t2qq);



            // the arrays are declared a certain size and are now full of 0's
            //this will reduce them down to just data.
            // if there is no data in the arrays then cnt will = 0
            if (cnt == 0)
            {
                MessageBox.Show("No Data in your selection.", "No data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }


            Array.Resize(ref t1, cnt);
            Array.Resize(ref t2, cnt);
            cntG = cnt;

            // int aa = cnt;
            int ab = t2.GetLength(0);
            // create a Population object from the data
            var popt1 = new ScottPlot.Statistics.Population(t1);
            var popt2 = new ScottPlot.Statistics.Population(t2);

            // now lets fill the stats box
            lblT1.Text       = tname1;
            lblT2.Text       = tname2;
            lblMeanT1.Text   = Math.Round(popt1.mean, 2).ToString();
            lblMeanT2.Text   = Math.Round(popt2.mean, 2).ToString();
            lblMedT1.Text    = Math.Round(popt1.median, 2).ToString();
            lblMedT2.Text    = Math.Round(popt2.median, 2).ToString();
            lblQ3T1.Text     = popt1.Q3.ToString();
            lblq3table2.Text = popt1.Q3.ToString();
            lblQ1t1.Text     = popt1.Q1.ToString();
            lblQ1T2.Text     = popt2.Q1.ToString();
            lblstderrT1.Text = Math.Round(popt1.stdErr, 2).ToString();
            lblstderrT2.Text = Math.Round(popt2.stdErr, 2).ToString();
            lblstdevT1.Text  = Math.Round(popt1.stDev, 2).ToString();
            lblstdevT2.Text  = Math.Round(popt2.stDev, 2).ToString();
            lblIQRt1.Text    = Math.Round(popt1.IQR, 2).ToString();
            lblIQRt2.Text    = Math.Round(popt2.IQR, 2).ToString();
            lblNtn1.Text     = cnt.ToString(); //opt1.aa.ToString();
                                               // lblNtn2.Text = ab.ToString(); // popt2.count.ToString();


            //this gives us the regression line and the correlation coeficient
            var    model = new ScottPlot.Statistics.LinearRegressionLine(t1, t2);
            string line  = $"Y={model.slope:0.0000}X + {model.offset:0.0}";

            lblLine.Text   = line;
            lblCorrel.Text = $"R² = {model.rSquared:0.0000}";

            formsPlot1.plt.Title($"ScarpWeather Temperature XY Plot");
            formsPlot1.plt.XLabel(tname1);
            formsPlot1.plt.YLabel(tname2);
            //formsPlot1.plt.AxisAuto(horizontalMargin: 0, verticalMargin: 0.5);
            //                 xmin,xmax,ymin,ymax

            int axisMin, axisMax;

            axisMin = (int)popt1.min - 2;  //get some data from the arrays
            //axisMin = 0;
            axisMax = (int)popt1.max + 2;

            formsPlot1.plt.Axis(axisMin, axisMax, axisMin, axisMax); //defines the min and max of the chart
                                                                     //            formsPlot1.plt.Axis(15,40,15,40);


            formsPlot1.plt.Legend();  // got ot have this be we toggle it with hte context menu

            //this draws the scatter plot
            XYplotPoints = formsPlot1.plt.PlotScatter(t1, t2, Color.DarkCyan, lineWidth: 0, markerSize: 5, label: "XYData");
            //draw the QQ plot
            QQplotPoints         = formsPlot1.plt.PlotScatter(t1qq, t2qq, Color.DarkGreen, lineWidth: 0, markerSize: 5, label: "QQData");
            QQplotPoints.visible = false;

            // draws the regresion line
            //if (plotRegression)
            regLine = formsPlot1.plt.PlotLine(model.slope, model.offset, (axisMin, axisMax), lineWidth: 2, label: "Regression", color: Color.BlueViolet);

            //plot a 45 degree line = X=Y
            XequalsYLine = formsPlot1.plt.PlotLine(1.0, 0.0, (0, 100), Color.Goldenrod, lineWidth: 2, label: "X=Y", lineStyle: ScottPlot.LineStyle.Dot); //uses the equation of the line to plot

            //the 10% error lines
            errorLineA = formsPlot1.plt.PlotLine(0, 0, 100.0 - 0.1 * 100, 100, color: Color.OrangeRed, lineWidth: 2, label: "10%error", lineStyle: ScottPlot.LineStyle.Dash);
            errorLineB = formsPlot1.plt.PlotLine(0, 0, 100, 100.0 - 0.1 * 100, color: Color.OrangeRed, lineWidth: 2, lineStyle: ScottPlot.LineStyle.Dash);

            formsPlot1.Render();//draw the chart on the PC screen
        }//end function