private void PopulateSeries(Series RainfallBar, DataTable Data, string ColumnName) { RainfallBar.Clear(); if (Data.Columns.IndexOf(ColumnName) != -1 && Data.Rows.Count > 0 && !Convert.IsDBNull(Data.Rows[0][ColumnName])) { for (int Row = 0; Row <= Data.Rows.Count - 1; Row++) { DateTime D = DataTableUtility.GetDateFromRow(Data.Rows[Row]); RainfallBar.Add(D, Convert.ToDouble(Data.Rows[Row][ColumnName])); } } }
private void PopulateSeries(Series RainfallBar, DataView Data, string ColumnName) { RainfallBar.Clear(); if (Data.Table.Columns.IndexOf(ColumnName) != -1) { for (int Row = 0; Row <= Data.Count - 1; Row++) { DateTime D = DataTableUtility.GetDateFromRow(Data[Row].Row); RainfallBar.Add(D, Convert.ToDouble(Data[Row][ColumnName])); } } }
/// <summary> /// Refresh this report. This method will create a worker thread to animate the graphs. /// </summary> public override void OnRefresh() { // Refresh the base report. base.OnRefresh(); // Make sure play is selected by default. OnPlayClick(null, null); Quit = false; Forward = true; // Find our ApsimFile.Component class. We'll need this to get the XML we're // working with and to find all DateFilter components underneath this report. OurComponent = Controller.ApsimData.Find(NodePath); // Go create a DataProcessor object. We'll need this to find some data later. Doc = new XmlDocument(); Doc.LoadXml(OurComponent.FullXMLNoShortCuts()); DataProcessor Processor = new DataProcessor(); List <string> DefaultFileNames = new List <string>(); UIUtility.OutputFileUtility.GetOutputFiles(Controller, Controller.Selection, DefaultFileNames); Processor.DefaultOutputFileNames = DefaultFileNames; // Now go and try to find some data. We need data so that we can determine the // start and end period for the animation. DataTable PlotData = null; foreach (XmlNode Child in Doc.DocumentElement.ChildNodes) { PlotData = Processor.Go(Child, ""); if (PlotData != null) { break; } } // If some data was found then work out the start and end date periods, locate // all child DataFilter nodes, and create a worker thread for the animation. if (PlotData != null && PlotData.Rows.Count > 0) { StartDate = DataTableUtility.GetDateFromRow(PlotData.Rows[0]); EndDate = DataTableUtility.GetDateFromRow(PlotData.Rows[PlotData.Rows.Count - 1]); Period = EndDate - StartDate; CurrentDate = StartDate; // Go find all DateFilter components - we'll need them later. DateFilterNodes = new List <ApsimFile.Component>(); FindAllRecursively(OurComponent, "DateFilter", ref DateFilterNodes); WorkerThread = new Thread(DoAnimation); WorkerThread.Start(); } }
public override void OnRefresh() { ContentsBox.Text = ""; string FullFileName = Controller.ToAbsolute(FileName); if (File.Exists(FullFileName)) { APSIMInputFile Metfile = new APSIMInputFile(); Metfile.Open(FullFileName); MetData = Metfile.ToTable(); Metfile.Close(); MetData.TableName = "Met"; // Get latitude for later on. if (Metfile.Constant("latitude") == null) { MessageBox.Show("A value for latitude was expected, but could not be found in this file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); Latitude = Double.NaN; } else { Latitude = Convert.ToDouble(Metfile.Constant("latitude").Value, new System.Globalization.CultureInfo("en-US")); } StartDate = DataTableUtility.GetDateFromRow(MetData.Rows[0]); EndDate = DataTableUtility.GetDateFromRow(MetData.Rows[MetData.Rows.Count - 1]); PopulateRawData(); YearStartBox.ValueChanged -= YearStartBoxChanged; NumYearsBox.ValueChanged -= NumYearsBoxChanged; YearStartBox.Value = StartDate.Year; NumYearsBox.Value = 1; if (NumYears != 0) { NumYearsBox.Value = NumYears; } if (YearStart != 0) { YearStartBox.Value = YearStart; } YearStartBox.ValueChanged += YearStartBoxChanged; NumYearsBox.ValueChanged += NumYearsBoxChanged; RefreshAllCharts(); } YearPanel.Visible = (TabControl.SelectedIndex != 0); YearPanel.Parent = this; YearPanel.Top = TabControl.SelectedTab.Top + 2; YearPanel.BringToFront(); }
private DataTable ProcessDepth(XmlNode Node) { // ------------------------------------------------- // The XmlNode is a GDDepth so go find a // nested source DataTable, add transpose the data // so that depth is a column and the depth variables // are also columns. // ------------------------------------------------- DataTable Data = GoFindChildDataTable(Node); if (Data == null || Data.Columns.Count == 0) { return(null); } DataTable NewData = new DataTable(); // copy profile fields from old datatable to new datatable and add new depth column. List <string> ProfileColumns = new List <string>(); NewData.Columns.Add("Date", Type.GetType("System.DateTime")); NewData.Columns.Add("Depth", Type.GetType("System.Single")); int NumLayers = 0; foreach (DataColumn Col in Data.Columns) { string ColumnName = Col.ColumnName; string ArraySpecString = StringManip.SplitOffBracketedValue(ref ColumnName, '(', ')'); int ArraySpec = 0; if (ArraySpecString != "") { ArraySpec = Convert.ToInt32(ArraySpecString); } if (ArraySpec == 1) { if (ColumnName.ToLower() != "dlayer") { ProfileColumns.Add(ColumnName); NewData.Columns.Add(ColumnName, Type.GetType("System.Single")); } } NumLayers = Math.Max(NumLayers, ArraySpec); } NewData.Columns.Add("Title", Type.GetType("System.String")); // Get a list of dates that we are to filter on. List <string> DateStrings = XmlHelper.Values(Node, "date"); DateTime[] Dates = new DateTime[DateStrings.Count]; for (int i = 0; i < DateStrings.Count; i++) { Dates[i] = DateTime.ParseExact(DateStrings[i], "d/M/yyyy", null); } for (int Row = 0; Row < Data.Rows.Count; Row++) { DateTime RowDate = DataTableUtility.GetDateFromRow(Data.Rows[Row]); if (Dates.Length == 0 || Array.IndexOf(Dates, RowDate) != -1) { double DepthSoFar = 0; for (int Layer = 1; Layer <= NumLayers; Layer++) { double PreviousDepth = DepthSoFar; DataRow NewRow = NewData.NewRow(); DepthSoFar += Convert.ToDouble(Data.Rows[Row]["dlayer(" + Layer.ToString() + ")"]); NewRow["Depth"] = (DepthSoFar + PreviousDepth) / 2; for (int Col = 0; Col < ProfileColumns.Count; Col++) { string ProfileColumnName = ProfileColumns[Col] + "(" + Layer.ToString() + ")"; if (Data.Columns.Contains(ProfileColumnName)) { NewRow[ProfileColumns[Col]] = Data.Rows[Row][ProfileColumnName]; } } NewRow["Date"] = RowDate; NewRow["Title"] = Data.Rows[Row]["Title"] + ", " + RowDate.ToShortDateString(); NewData.Rows.Add(NewRow); } } } return(NewData); }
private DataTable ProcessSOI(XmlNode Node) { // ------------------------------------------------- // The XmlNode is a GDSOI so go find a // nested source DataTable, add an 'SOI Phase' column // to it and return it to caller. // ------------------------------------------------- string[] DefaultPhaseNames = { "Unknown", "Negative", "Positive", "Falling", "Rising", "Zero" }; // Go find the name of the soi phase file. string PhaseFile = XmlHelper.Value(Node, "PhaseFile"); if (PhaseFile == "") { PhaseFile = Configuration.Instance.ClimateSetting("SOIFile"); } if (PhaseFile == "" || !File.Exists(PhaseFile)) { return(null); } // Go find the SOI month we're to use for the lookup. int Month = Convert.ToInt32(XmlHelper.Value(Node, "Month")); // Work out the name of the year column. // Go find source data to work with DataTable Data = GoFindChildDataTable(Node); if (Data == null || Data.Columns.Count == 0) { return(null); } // Add new SOI Phase column to Data. Data.Columns.Add("SOI Phase", Type.GetType("System.String")); // read in soi phase data. APSIMInputFile SOI = new APSIMInputFile(); SOI.Open(PhaseFile); DataTable SOIData = SOI.ToTable(); SOI.Close(); int NumRows = Data.Rows.Count; for (int Row = 0; Row < NumRows; Row++) { string RowTitle = Data.Rows[Row]["Title"].ToString(); DateTime RowDate = DataTableUtility.GetDateFromRow(Data.Rows[Row]); DataRow[] MatchingSOIData = SOIData.Select("Year = " + RowDate.Year.ToString() + " and Month = " + Month.ToString()); string PhaseName = "Unknown"; if (MatchingSOIData.Length == 1) { if (SOIData.Columns.IndexOf("PhaseName") == -1) { int PhaseNumber = Convert.ToInt32(MatchingSOIData[0]["Phase"]); if (PhaseNumber < DefaultPhaseNames.Length) { PhaseName = DefaultPhaseNames[PhaseNumber]; } } else { PhaseName = MatchingSOIData[0]["PhaseName"].ToString(); } } Data.Rows[Row]["SOI Phase"] = PhaseName; Data.Rows[Row]["Title"] = RowTitle + ", " + PhaseName; // We also want to make a duplicate of this row and label it 'AllYears' Data.ImportRow(Data.Rows[Row]); Data.Rows[Data.Rows.Count - 1]["SOI Phase"] = "AllYears"; Data.Rows[Data.Rows.Count - 1]["Title"] = RowTitle + ", AllYears"; } return(Data); }