コード例 #1
0
        static PointPairList getData(string site_code, string var_code, DateTime dStart, DateTime dEnd, dbConnection dataObject, double lBnd, double upBnd)
        {
            PointPairList graphPoints = new PointPairList();

            DataTable values1yr = dataObject.getDVCstm(site_code, var_code, dStart, dEnd, lBnd, upBnd);
            Double NoDV = dataObject.getNoDV(var_code);

            double testBnds;
            foreach (DataRow row in values1yr.Rows)
            {
                testBnds = Convert.ToDouble(row["DataValue1"]);
                DateTime dateShowing = convDate(row["LocalDateTime"].ToString());

                try
                {
                    if (!(Convert.ToDouble(row["DataValue1"]) == NoDV || Convert.ToDouble(row["DataValue1"]) < lBnd || Convert.ToDouble(row["DataValue1"]) > upBnd))
                    {
                        graphPoints.Add((double)new XDate(dateShowing.Year, dateShowing.Month, dateShowing.Day, dateShowing.Hour, dateShowing.Minute, dateShowing.Second), Convert.ToDouble(row["DataValue1"]));
                    }
                    else
                    {
                        graphPoints.Add((double)new XDate(dateShowing.Year, dateShowing.Month, dateShowing.Day, dateShowing.Hour, dateShowing.Minute, dateShowing.Second), double.NaN);
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("found error " +ex.Message);
                }

            }
            graphPoints = cleanValues(graphPoints, values1yr);
            return graphPoints;
        }
コード例 #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new plotGen());

            //Data to fetch... parameters.
            string SITE_CODE = "LR_WaterLab_AA";
            string SEC_SITE = "LR_Mendon_AA";
            string VAR_CODE = "TurbMed";
            string VAR_NAME = "Median Turbidity";
            string VAR_UNIT = "NTU";
            DateTime dEnd = convDate(DateTime.Now.ToString("M/d/yyyy"));
            DateTime dStart = new DateTime(dEnd.Year, 1, 1);

            dbConnection dataObject = new dbConnection();
            dbConnection dataObject2 = new dbConnection();
            //dbConnection dataObject2 =

            //TurbMed
            string[] meta = { "Graph", "Date", VAR_NAME+", "+VAR_UNIT, "-5", "1650"};
            plotMeasrdAndTyp(SITE_CODE, SEC_SITE, VAR_CODE, VAR_NAME, dStart, dEnd, dataObject, meta);

            //WaterTemp_EXO
            VAR_CODE = "WaterTemp_EXO";
            VAR_NAME = "Water Temperature";
            VAR_UNIT = "Deg. C";

            meta[2] = VAR_NAME + ", " + VAR_UNIT;
            meta[3] = "-5";
            meta[4] = "40";
            plotMeasrdAndTyp(SITE_CODE, SEC_SITE, VAR_CODE, VAR_NAME, dStart, dEnd, dataObject, meta);

            //ODO
            VAR_CODE = "ODO";
            VAR_NAME = "Dissolved Oxygen";
            VAR_UNIT = "mg/L";

            meta[2] = VAR_NAME + ", " + VAR_UNIT;
            meta[3] = "2";
            meta[4] = "20";
            plotMeasrdAndTyp(SITE_CODE, SEC_SITE, VAR_CODE, VAR_NAME, dStart, dEnd, dataObject, meta);

            //Changing Connection String to the Little Bear Database ODM.

            dataObject2.Connection.ConnectionString = "name=LittleBearODMEntities";

            SITE_CODE = "USU-LBR-Paradise";
            SEC_SITE = "USU-LBR-Mendon";
            VAR_CODE = "USU6";
            VAR_NAME = "Median Turbidity";
            VAR_UNIT = "NTU";
            //TurbMed
            meta[2] = VAR_NAME + ", " + VAR_UNIT;
            meta[3] = "-5";
            meta[4] = "1650";
            plotMeasrdAndTyp(SITE_CODE, SEC_SITE, VAR_CODE, VAR_NAME, dStart, dEnd, dataObject2, meta);

            VAR_CODE = "USU36";
            VAR_NAME = "Water Temperature";
            VAR_UNIT = "Deg. C";
            //TurbMed
            meta[2] = VAR_NAME + ", " + VAR_UNIT ;
            meta[3] = "-5";
            meta[4] = "40";
            plotMeasrdAndTyp(SITE_CODE, SEC_SITE, VAR_CODE, VAR_NAME, dStart, dEnd, dataObject2, meta);

            VAR_CODE = "USU32";
            VAR_NAME = "Dissolved Oxygen";
            VAR_UNIT = "mg/L";

            //TurbMed
            meta[2] = VAR_NAME + ", " + VAR_UNIT;
            meta[3]= "2";
            meta[4] = "20";
            plotMeasrdAndTyp(SITE_CODE, SEC_SITE, VAR_CODE, VAR_NAME, dStart, dEnd, dataObject2, meta);

            System.Console.WriteLine("Done producing the graphs!");
        }
コード例 #3
0
        //meta: 0.Graph Name, 1.Labelfor X, 2.Label for Y
        static void plotMeasrdAndTyp(string site_code, string second_site, string var_code, string var_name, DateTime dStart, DateTime dEnd, dbConnection dataObject, string[] meta)
        {
            /*
             * clsRemoveDataGaps.missingValues(ref ptList);

             */
            double lBnd = Convert.ToDouble( meta[3]);
            double upBnd = Convert.ToDouble(meta[4]);
            float graphWidth = 4.0f;

            PointPairList MeasUpper = getData(site_code, var_code, dStart, dEnd, dataObject, lBnd, upBnd);
            //MeasUpper = cleanValues(MeasUpper, dataObject.getDVCstm(site_code, var_code, dStart, dEnd));
            PointPairList TypAvgUpper = getDataTyp(site_code, var_code, dataObject, lBnd, upBnd ); //getDailyAvg(MeasUpper);

            PointPairList MeasLower = getData(second_site, var_code, dStart, dEnd, dataObject, lBnd, upBnd);
            //MeasLower = cleanValues(MeasLower, dataObject.getDVCstm(site_code, var_code, dStart, dEnd));
            PointPairList TypAvgLower = getDataTyp(second_site, var_code, dataObject, lBnd, upBnd); //getDailyAvg(MeasLower);

            //Measured Graph. -- Display all data. From January 1st. --
            GraphPane graphPaneMeas = new GraphPane(new Rectangle(0, 0, 1680, 1050), "Measured Values", meta[1], meta[2]);
            graphPaneMeas.XAxis.Title.Text = "Date";
            graphPaneMeas.XAxis.Type = AxisType.Date;
            formatXaxis(ref graphPaneMeas);

            LineItem upperSite_M = new LineItem(site_code == "LR_WaterLab_AA" ? "Logan River Upper Site" : "Little Bear River Upper Site", MeasUpper, Color.Black, SymbolType.None, graphWidth);
            LineItem lowerSite_M = new LineItem(site_code == "LR_WaterLab_AA" ? "Logan River Lower Site" : "Little Bear River Lower Site", MeasLower, Color.Blue, SymbolType.None, graphWidth);
            graphPaneMeas.CurveList.Add(upperSite_M);
            graphPaneMeas.CurveList.Add(lowerSite_M);
            double miny = 99999;
            double maxy = -99999;

            foreach (CurveItem c in graphPaneMeas.CurveList)
            {

                for (int i = 0; i < c.Points.Count; i += 1)
                {
                    if (c.Points[i].Y < miny)
                        miny = c.Points[i].Y;
                    if (c.Points[i].Y > maxy)
                        maxy = c.Points[i].Y;

                }
            }
            formatYaxis(ref graphPaneMeas, maxy, miny);

            //Typical Graph. -- Daily averaged. Full Year Plotting.  --
            GraphPane graphPaneTyp = new GraphPane(new Rectangle(0, 0, 1680, 1050), "Typical Values", meta[1], meta[2]);
            graphPaneTyp.XAxis.Title.Text = "Date";
            graphPaneTyp.XAxis.Type = AxisType.Date;
            formatXaxis(ref graphPaneTyp);

            LineItem upperSite_T = new LineItem(site_code == "LR_WaterLab_AA" ? "Logan River Upper Site" : "Little Bear River Upper Site", TypAvgUpper, Color.Black, SymbolType.None, graphWidth);
            graphPaneTyp.CurveList.Add(upperSite_T);
            LineItem lowerSite_T = new LineItem(site_code == "LR_WaterLab_AA" ? "Logan River Lower Site" : "Little Bear River Lower Site", TypAvgLower, Color.Blue, SymbolType.None, graphWidth);
            graphPaneTyp.CurveList.Add(lowerSite_T);

            miny = 99999;
            maxy = -99999;
            //find the max and min values of the two series
            foreach(CurveItem c  in graphPaneTyp.CurveList){

                for ( int i =0; i < c.Points.Count; i +=1){//Point p in c.Points){
                    if (c.Points[i].Y < miny)
                        miny = c.Points[i].Y;
                    if (c.Points[i].Y > maxy)
                        maxy = c.Points[i].Y;

                }
            }

            formatYaxis(ref graphPaneTyp, maxy, miny);

            Bitmap bm = new Bitmap(1, 1);
            using (Graphics g = Graphics.FromImage(bm))
                graphPaneMeas.AxisChange(g);
            graphPaneMeas.GetImage().Save(Properties.Settings.Default.imagePath + "\\" + @"measured_" + site_code + "_" + second_site + "_" + var_code + ".png", ImageFormat.Png);

            Bitmap bm2 = new Bitmap(1, 1);
            using (Graphics g2 = Graphics.FromImage(bm2))
                graphPaneTyp.AxisChange(g2);
            graphPaneTyp.GetImage().Save(Properties.Settings.Default.imagePath + "\\"+ @"typical_" + site_code + "_" + second_site + "_" + var_code + ".png", ImageFormat.Png);
        }
コード例 #4
0
        static PointPairList getDataTyp(string site_code, string var_code,  dbConnection dataObject, double lBnd, double upBnd)
        {
            PointPairList graphPoints = new PointPairList();

            DataTable values1yr = dataObject.getDVCstmAvg(site_code, var_code, lBnd, upBnd);
            Double NoDV = dataObject.getNoDV(var_code);
            foreach (DataRow row in values1yr.Rows)
            {
                DateTime dateShowing;
                try
                {
                    dateShowing = new DateTime(DateTime.Now.Year, (int)row["Month"], (int)row["Day"]);
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine("Leap Year");
                    dateShowing = new DateTime(DateTime.Now.Year, (int)row["Month"], ((int)row["Day"]) - 1, 23, 59, 59);
                }

                try
                {
                    double? curValue = (double)row["DataValue1"];
                    double curDate = (double)new XDate(dateShowing.Year, dateShowing.Month, dateShowing.Day, dateShowing.Hour, dateShowing.Minute, dateShowing.Second);
                    graphPoints.Add(curDate, curValue.Value);

                }
                catch(Exception ex )
                {
                }
            }
            graphPoints = cleanValues(graphPoints, values1yr);
            return graphPoints;
        }