Esempio n. 1
0
        //---------------------------------------

        ///-------------------------------------------------------------------------------------------------
        /// <summary> a method used to compare data for sorting
        ///            </summary>
        /// <param name="P1"> The first ChartPointsByYear. </param>
        /// <param name="P2"> The second ChartPointsByYear. </param>
        /// <returns>0 are equal, 1 P2 greater than P1,  -1 P1 greater than P2 . </returns>
        ///-------------------------------------------------------------------------------------------------

        public static int CompareForSort_UseMax(ChartPointsByYear P1, ChartPointsByYear P2)
        {
            int P1Max = P1.MaxValue();
            int P2Max = P2.MaxValue();

            if (P1Max == P2Max)
            {
                return(0);
            }
            else
            if (P1Max < P2Max)
            {
                return(1);
            }
            else
            {
                return(-1);
            }
        }
Esempio n. 2
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary> Builds an annual parameter graph. </summary>
        /// <param name="DT">           The datatable. </param>
        /// <param name="DbConnection"> The database connection. </param>
        /// <param name="Providers">    The providers to be charted. </param>
        /// <param name="fldname">      The fldname or column name to be charted. </param>
        ///-------------------------------------------------------------------------------------------------
        //public void BuildAnnualParameterGraph(DataTable DT, UniDbConnection DbConnection, string ScenarioName, List<providerinfo> Providers, string fldname, string fieldlabel)

        public void BuildAnnualParameterGraph(WaterSimManagerClass WSIM, SimulationResults SimRes, string fldname, string fieldlabel, string[] Regions)
        {
            List <string> debug = new List <string>();

            // create a lits for data
            List <ChartPointsByYear> ChartSeriesList = new List <ChartPointsByYear>();

            // ok clear up chart
            FChart.Series.Clear();
            FChart.Legends.Clear();
            FChart.ChartAreas.Clear();
            //                    ProviderPopChart.Update();

            // Setup legend

            FChart.ChartAreas.Add(FTitle);
            System.Windows.Forms.DataVisualization.Charting.Legend MyLegend = new System.Windows.Forms.DataVisualization.Charting.Legend("Default");
            FChart.Legends.Add(MyLegend);
            // get data


            int    pIndex    = -1;
            int    year      = 0;
            int    pop       = 0;
            string pcode     = "";
            int    yearCount = 0;
            int    yearIndex = 0;
            // OK, figure out the years Min Max and Count
            int MaxYear = -1;
            int MinYear = 9999;


            // There must be a way to speed this up!
            foreach (AnnualSimulationResults ASR in SimRes)
            {
                year = ASR.year;
                if (year > MaxYear)
                {
                    MaxYear = year;
                }
                if (year < MinYear)
                {
                    MinYear = year;
                }
            }


            yearCount = (MaxYear - MinYear) + 1;

            // OK can set up the dta
            int ProviderCount = SimRes[0].Outputs.ProviderOutput[0].Values.Length;

            //int ProviderCount = Providers.Count;
            // create provider value data array
            int[][] ValueData = null; // new int[ProviderCount][];
                                      // now create new arrays (years length) for each provider array
                                      //for (int i = 0; i < ProviderCount; i++)
                                      //  ValueData[i] = new int[yearCount];

            // Cycle through each record and stick data into the right slot

            // first get the parmeters index into AnnualResults arrays
            ModelParameterClass theModelParmeter = WSIM.ParamManager.Model_Parameter(fldname);
            int ModelParmIndex = SimRes[0].GetParmIndex(theModelParmeter);

            ValueData = GrabProviderDataByYear(SimRes, theModelParmeter);

            // OK create the series
            // First create a year array
            int[] allYearValues = new int[yearCount];
            for (int i = 0; i < yearCount; i++)
            {
                allYearValues[i] = MinYear + i;
            }
            for (int i = 0; i < ProviderCount; i++)
            {
                string ProviderName   = ProviderClass.ProviderNameList[i];
                bool   DoThisProvider = false;

                if ((Regions == null) || (Regions.Length == 0))
                {
                    DoThisProvider = true;
                }
                else
                {
                    foreach (string RegName in Regions)
                    {
                        if (RegName == ProviderName)
                        {
                            DoThisProvider = true;
                            break;
                        }
                    }
                }

                if (DoThisProvider)
                {
                    ChartPointsByYear points = new ChartPointsByYear(allYearValues, ValueData[i], ProviderName);
                    ChartSeriesList.Add(points);
                }
            }
            //  Now Sort By Size
            ChartSeriesList.Sort(ChartPointsByYear.CompareForSort_UseMax);


            foreach (ChartPointsByYear points in ChartSeriesList)
            {
                Series dSeries = new Series();
                int[]  Years   = points.Years;
                int[]  Values  = points.Values;
                dSeries.LegendText   = points.SeriesLabel;
                dSeries.ChartType    = FChartType;
                dSeries.BorderWidth  = 3;
                dSeries.MarkerSize   = 20;
                dSeries.LabelToolTip = points.SeriesLabel;
                for (int j = 0; j < Years.Length; j++)
                {
                    dSeries.Points.AddXY(Years[j], Values[j]);
                }
                FChart.Series.Add(dSeries);
            }


            FChart.ChartAreas[0].AxisX.Minimum  = MinYear;
            FChart.ChartAreas[0].AxisX.Maximum  = MaxYear;
            FChart.ChartAreas[0].AxisX.Interval = 5;
            // Chart Label
            bool  addTitle = false;
            Title myTitle  = null;

            if (FChart.Titles.Count > 0)
            {
                myTitle = FChart.Titles.FindByName("MAIN");
            }
            if (myTitle == null)
            {
                myTitle  = new Title();
                addTitle = true;
            }
            myTitle.Name      = "MAIN";
            myTitle.Text      = fieldlabel + " by Water Provider and Year";
            myTitle.Font      = new Font(myTitle.Font.Name, 14.0F, FontStyle.Bold, myTitle.Font.Unit);
            myTitle.Alignment = ContentAlignment.MiddleCenter;
            if (addTitle)
            {
                FChart.Titles.Add(myTitle);
            }
            // Chart Legend
            /// <summary> The second column. </summary>
            LegendCellColumn secondColumn = new LegendCellColumn();

            secondColumn.ColumnType      = LegendCellColumnType.Text;
            secondColumn.HeaderText      = "Name";
            secondColumn.Text            = "#LEGENDTEXT";
            secondColumn.HeaderBackColor = Color.WhiteSmoke;
            FChart.Legends["Default"].CellColumns.Add(secondColumn);

            // Set Min cell column attributes
            LegendCellColumn maxColumn = new LegendCellColumn();

            maxColumn.Text            = "#MAX{N1}";
            maxColumn.HeaderText      = "Max";
            maxColumn.Name            = "MaxColumn";
            maxColumn.HeaderBackColor = Color.WhiteSmoke;
            FChart.Legends["Default"].CellColumns.Add(maxColumn);
            // Add Color column
            LegendCellColumn firstColumn = new LegendCellColumn();

            firstColumn.ColumnType      = LegendCellColumnType.SeriesSymbol;
            firstColumn.HeaderText      = "Color";
            firstColumn.HeaderBackColor = Color.WhiteSmoke;
            FChart.Legends["Default"].CellColumns.Add(firstColumn);
            // OK let's see what happens

            //FChart.Update;
            //FChart.Scale(new SizeF())
        }
Esempio n. 3
0
        public void BuildAnnualProviderGraph(SimulationResults SimRes, ParameterManagerClass PM, List <string> ParameterFieldNames, int ProviderIndex, string aLabel)
        {
            // create a lits for data
            List <ChartPointsByYear> ChartSeriesList = new List <ChartPointsByYear>();

            int year      = 0;
            int parmvalue = 0;
            int yearCount = SimRes.Length;
            int yearIndex = 0;

            // OK, figure out the years Min Max and Count
            int MaxYear = -1;
            int MinYear = 9999;

            foreach (AnnualSimulationResults ASR in SimRes)
            {
                year = ASR.year;
                if (year > MaxYear)
                {
                    MaxYear = year;
                }
                if (year < MinYear)
                {
                    MinYear = year;
                }
            }

            // Count all the the parameter in first year of SimRes
            int ParameterCount = SimRes[0].Outputs.BaseOutput.Length + SimRes[0].Outputs.ProviderOutput.Length + SimRes[0].Inputs.BaseInput.Length + SimRes[0].Inputs.ProviderInput.Length;

            // Set up the Data array for that many parameters
            int[][] ValueData = new int[ParameterCount][];
            // now set up for array of years data
            for (int i = 0; i < ParameterCount; i++)
            {
                ValueData[i] = new int[yearCount];
            }

            // index for parms
            int ParmDataIndex = 0;

            // ok Build an list of parameter indexes and ModelParameters
            int ParamterCount = ParameterFieldNames.Count;

            int[] ParmIndexes = new int[ParameterCount];
            ModelParameterClass[] ModelParameters = new ModelParameterClass[ParameterCount];
            for (int i = 0; i < ParameterCount; i++)
            {
                ModelParameters[i] = PM.Model_Parameter(ParameterFieldNames[i]);
                if (ModelParameters[i] != null)
                {
                    ParmIndexes[i] = SimRes[0].GetParmIndex(ModelParameters[i]);
                }
                else
                {
                    ParmIndexes[i] = -1;
                }
            }

            foreach (AnnualSimulationResults ASR in SimRes)
            {
                year      = ASR.year;
                yearIndex = year - MinYear;
                for (int i = 0; i < ParameterCount; i++)
                {
                    if (ParmIndexes[i] >= 0)
                    {
                        if (ModelParameters[i].isBaseParam)
                        {
                            ValueData[i][yearIndex] = GrabParmBaseData(ASR, ModelParameters[i].ParamType, ParmIndexes[i]);
                        }
                        else
                        if (ModelParameters[i].isProviderParam)
                        {
                            ValueData[i][yearIndex] = GrabParmProviderData(ASR, ModelParameters[i].ParamType, ParmIndexes[i])[ProviderIndex];
                        }
                    }
                }
            }


            //bool iserr = false;
            //        string errMessage = "";
            //        year =
            //yearIndex = year - MinYear;

            //            // Fetch only records that match the scenario name or if "" then just the first scenario
            //            if (((ScenarioName == "") && (ScnStr == FirstScnName)) || (ScnStr == ScenarioName))
            //            {
            //                // fetch only records for the target provider
            //                pcode = DR[PrvdFldStr].ToString().Trim();
            //                if (pcode.ToUpper() == targetProvider.ToUpper())
            //                {
            //                    int pIndex = 0;
            //                    // Ok get all the fields requested
            //                    foreach (fieldinfo info in dbFields)
            //                    {
            //                        if (DT.Columns.Contains(info.Fieldname))
            //                        {
            //                            parmvalue = UniDB.Tools.ConvertToInt32(DR[info.Fieldname].ToString(), ref iserr, ref errMessage);
            //                            ValueData[pIndex][yearIndex] = parmvalue;
            //                            pIndex++;
            //                        }
            //                    }
            //                    // OK get a years worth of data, increment year count
            //                    YearCnt++;
            //                }
            //            }
            //            // OK, if we have read values for all the years, then break
            //            if (YearCnt == NumberOfYears) break; // from foreach


            //        if (iserr)
            //        {
            //            // Do What?
            //        }
            // OK create the series
            // First create a year array
            int[] allYearValues = new int[yearCount];
            for (int i = 0; i < yearCount; i++)
            {
                allYearValues[i] = MinYear + i;
            }
            for (int i = 0; i < ParameterCount; i++)
            {
                ChartPointsByYear points = new ChartPointsByYear(allYearValues, ValueData[i], ParameterFieldNames[i]);
                ChartSeriesList.Add(points);
            }
            //  Now Sort By Size
            ChartSeriesList.Sort(ChartPointsByYear.CompareForSort_UseMax);

            // ok clear up chart
            FChart.Series.Clear();
            FChart.Legends.Clear();
            FChart.ChartAreas.Clear();
            //                    ProviderPopChart.Update();

            // Setup legend

            FChart.ChartAreas.Add(FTitle);
            System.Windows.Forms.DataVisualization.Charting.Legend MyLegend = new System.Windows.Forms.DataVisualization.Charting.Legend("Default");
            FChart.Legends.Add(MyLegend);
            int index = 0;

            foreach (ChartPointsByYear points in ChartSeriesList)
            {
                Series dSeries = new Series();
                int[]  Years   = points.Years;
                int[]  Values  = points.Values;
                dSeries.LegendText   = points.SeriesLabel;
                dSeries.BorderWidth  = 2;
                dSeries.ChartType    = FChartType;
                dSeries.LabelToolTip = points.SeriesLabel;
                //dSeries.Label = points.SeriesLabel;
                for (int j = 0; j < Years.Length; j++)
                {
                    dSeries.Points.AddXY(Years[j], Values[j]);
                }
                FChart.Series.Add(dSeries);
                index++;
            }
            // Chart Label
            // First build field label
            string fldlabel = "";

            foreach (string str in ParameterFieldNames)
            {
                if (fldlabel != "")
                {
                    fldlabel += ", ";
                }
                fldlabel += str;
            }
            bool  addTitle = false;
            Title myTitle  = null;


            if (FChart.Titles.Count > 0)
            {
                myTitle = FChart.Titles.FindByName("MAIN");
            }
            if (myTitle == null)
            {
                myTitle  = new Title();
                addTitle = true;
            }
            myTitle.Name      = "MAIN";
            myTitle.Text      = aLabel.Trim() + " by " + fldlabel + " and Year";
            myTitle.Alignment = ContentAlignment.MiddleCenter;

            myTitle.Font = new Font(myTitle.Font.Name, 14.0F, FontStyle.Bold, myTitle.Font.Unit);
            if (addTitle)
            {
                FChart.Titles.Add(myTitle);
            }
            // Add Legend
            LegendCellColumn secondColumn = new LegendCellColumn();

            secondColumn.ColumnType      = LegendCellColumnType.Text;
            secondColumn.HeaderText      = "Name";
            secondColumn.Text            = "#LEGENDTEXT";
            secondColumn.HeaderBackColor = Color.WhiteSmoke;
            FChart.Legends["Default"].CellColumns.Add(secondColumn);

            // Set Min cell column attributes
            LegendCellColumn maxColumn = new LegendCellColumn();

            maxColumn.Text            = "#MAX{N1}";
            maxColumn.HeaderText      = "Max";
            maxColumn.Name            = "MaxColumn";
            maxColumn.HeaderBackColor = Color.WhiteSmoke;
            FChart.Legends["Default"].CellColumns.Add(maxColumn);
            // Add Color column
            LegendCellColumn firstColumn = new LegendCellColumn();

            firstColumn.ColumnType      = LegendCellColumnType.SeriesSymbol;
            firstColumn.HeaderText      = "Color";
            firstColumn.HeaderBackColor = Color.WhiteSmoke;
            FChart.Legends["Default"].CellColumns.Add(firstColumn);


            // OK let's see what happens
        }