private void OnSimulationCompleted(object sender, EventArgs e) { DataStore dataStore = new DataStore(this); dataStore.WriteTable(this.messagesTable); dataStore.Disconnect(); }
/// <summary>Write all outputs to a text file (.csv)</summary> public void WriteToTextFiles() { string originalFileName = Filename; try { // Write the output CSV file. Open(forWriting: false); WriteAllTables(this, Filename + ".csv"); // Write the summary file. WriteSummaryFile(this, Filename + ".sum"); // If the baseline file exists then write the .CSV and .SUM files string baselineFileName = Filename + ".baseline"; if (File.Exists(baselineFileName)) { DataStore baselineDataStore = new DataStore(this, baseline: true); // Write the CSV output file. WriteAllTables(baselineDataStore, baselineFileName + ".csv"); // Write the SUM file. WriteSummaryFile(baselineDataStore, baselineFileName + ".sum"); baselineDataStore.Disconnect(); } } finally { Filename = originalFileName; Disconnect(); } }
/// <summary> /// Create an initial conditions table in the DataStore. /// </summary> /// <param name="simulation">The simulation to create an table for</param> private static void CreateInitialConditionsTable(Simulation simulation) { // Create our initial conditions table. DataTable initialConditionsTable = new DataTable("InitialConditions"); initialConditionsTable.Columns.Add("ModelPath", typeof(string)); initialConditionsTable.Columns.Add("Name", typeof(string)); initialConditionsTable.Columns.Add("Description", typeof(string)); initialConditionsTable.Columns.Add("DataType", typeof(string)); initialConditionsTable.Columns.Add("Units", typeof(string)); initialConditionsTable.Columns.Add("DisplayFormat", typeof(string)); initialConditionsTable.Columns.Add("Total", typeof(int)); initialConditionsTable.Columns.Add("Value", typeof(string)); initialConditionsTable.Rows.Add( new object[] { Apsim.FullPath(simulation), "Simulation name", "Simulation name", "String", string.Empty, string.Empty, false, simulation.Name }); // Get all model properties and store in 'initialConditionsTable' foreach (Model model in Apsim.FindAll(simulation)) { string relativeModelPath = Apsim.FullPath(model).Replace(Apsim.FullPath(simulation) + ".", string.Empty); List <VariableProperty> properties = new List <VariableProperty>(); FindAllProperties(model, properties); foreach (VariableProperty property in properties) { string value = property.ValueWithArrayHandling.ToString(); if (value != string.Empty) { if (value != null && property.DataType == typeof(DateTime)) { value = ((DateTime)property.Value).ToString("yyyy-MM-dd hh:mm:ss"); } bool showTotal = !double.IsNaN(property.Total); initialConditionsTable.Rows.Add(new object[] { relativeModelPath, property.Name, property.Description, property.DataType.Name, property.Units, property.Format, showTotal, value }); } } } // Write to data store. DataStore dataStore = new DataStore(simulation); dataStore.DeleteOldContentInTable(simulation.Name, "InitialConditions"); dataStore.WriteTable(simulation.Name, "InitialConditions", initialConditionsTable); dataStore.Disconnect(); }
private void OnSimulationCompleted(object sender, EventArgs e) { DataStore dataStore = new DataStore(this); dataStore.DeleteOldContentInTable(this.Simulation.Name, "Messages"); dataStore.WriteTable(this.Simulation.Name, "Messages", this.messagesTable); dataStore.Disconnect(); }
/// <summary> /// Format the grid. /// </summary> private void FormatGrid() { string[] fieldNames = null; for (int i = 0; i < this.properties.Count; i++) { IGridCell cell = this.grid.GetCell(1, i); if (this.properties[i].DisplayType == DisplayAttribute.DisplayTypeEnum.TableName) { DataStore dataStore = new DataStore(this.model); cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = dataStore.TableNames; if (cell.Value != null && cell.Value.ToString() != string.Empty) { DataTable data = dataStore.RunQuery("SELECT * FROM " + cell.Value.ToString() + " LIMIT 1"); if (data != null) fieldNames = DataTableUtilities.GetColumnNames(data); } dataStore.Disconnect(); } else if (this.properties[i].DisplayType == DisplayAttribute.DisplayTypeEnum.CultivarName) { cell.EditorType = EditorTypeEnum.DropDown; ICrop crop = GetCrop(properties); if (crop != null) { cell.DropDownStrings = GetCultivarNames(crop); } } else if (this.properties[i].DisplayType == DisplayAttribute.DisplayTypeEnum.FileName) { cell.EditorType = EditorTypeEnum.Button; } else if (this.properties[i].DisplayType == DisplayAttribute.DisplayTypeEnum.FieldName) { cell.EditorType = EditorTypeEnum.DropDown; if (fieldNames != null) cell.DropDownStrings = fieldNames; } else { object cellValue = this.properties[i].ValueWithArrayHandling; if (cellValue is DateTime) { cell.EditorType = EditorTypeEnum.DateTime; } else if (cellValue is bool) { cell.EditorType = EditorTypeEnum.Boolean; } else if (cellValue.GetType().IsEnum) { cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = StringUtilities.EnumToStrings(cellValue); } else if (cellValue.GetType() == typeof(ICrop)) { cell.EditorType = EditorTypeEnum.DropDown; List<string> cropNames = new List<string>(); foreach (Model crop in Apsim.FindAll(this.model, typeof(ICrop))) { cropNames.Add(crop.Name); } cell.DropDownStrings = cropNames.ToArray(); } else if (this.properties[i].DataType == typeof(ICrop)) { List<string> plantNames = Apsim.FindAll(this.model, typeof(ICrop)).Select(m => m.Name).ToList(); cell.EditorType = EditorTypeEnum.DropDown; cell.DropDownStrings = plantNames.ToArray(); } else { cell.EditorType = EditorTypeEnum.TextBox; } } } IGridColumn descriptionColumn = this.grid.GetColumn(0); descriptionColumn.Width = -1; descriptionColumn.ReadOnly = true; IGridColumn valueColumn = this.grid.GetColumn(1); valueColumn.Width = -1; }
private void OnSimulationCompleted(object sender, EventArgs e) { DataStore dataStore = new DataStore(this); dataStore.DeleteOldContentInTable(this.Simulation.Name, "Messages"); dataStore.WriteTable(this.Simulation.Name, "Messages", this.messagesTable); dataStore.Disconnect(); }
/// <summary> /// Create an initial conditions table in the DataStore. /// </summary> /// <param name="simulation">The simulation to create an table for</param> private static void CreateInitialConditionsTable(Simulation simulation) { // Create our initial conditions table. DataTable initialConditionsTable = new DataTable("InitialConditions"); initialConditionsTable.Columns.Add("ModelPath", typeof(string)); initialConditionsTable.Columns.Add("Name", typeof(string)); initialConditionsTable.Columns.Add("Description", typeof(string)); initialConditionsTable.Columns.Add("DataType", typeof(string)); initialConditionsTable.Columns.Add("Units", typeof(string)); initialConditionsTable.Columns.Add("DisplayFormat", typeof(string)); initialConditionsTable.Columns.Add("Total", typeof(int)); initialConditionsTable.Columns.Add("Value", typeof(string)); initialConditionsTable.Rows.Add( new object[] { Apsim.FullPath(simulation), "Simulation name", "Simulation name", "String", string.Empty, string.Empty, false, simulation.Name }); initialConditionsTable.Rows.Add( new object[] { Apsim.FullPath(simulation), "APSIM version", "APSIM version", "String", string.Empty, string.Empty, false, simulation.ApsimVersion }); initialConditionsTable.Rows.Add( new object[] { Apsim.FullPath(simulation), "Run on", "Run on", "String", string.Empty, string.Empty, false, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); // Get all model properties and store in 'initialConditionsTable' foreach (Model model in Apsim.FindAll(simulation)) { string relativeModelPath = Apsim.FullPath(model).Replace(Apsim.FullPath(simulation) + ".", string.Empty); List<VariableProperty> properties = new List<VariableProperty>(); FindAllProperties(model, properties); foreach (VariableProperty property in properties) { string value = property.ValueWithArrayHandling.ToString(); if (value != string.Empty) { if (value != null && property.DataType == typeof(DateTime)) { value = ((DateTime)property.Value).ToString("yyyy-MM-dd HH:mm:ss"); } bool showTotal = !double.IsNaN(property.Total); initialConditionsTable.Rows.Add(new object[] { relativeModelPath, property.Name, property.Description, property.DataType.Name, property.Units, property.Format, showTotal, value }); } } } // Write to data store. DataStore dataStore = new DataStore(simulation); dataStore.DeleteOldContentInTable(simulation.Name, "InitialConditions"); dataStore.WriteTable(simulation.Name, "InitialConditions", initialConditionsTable); dataStore.Disconnect(); }
/// <summary> /// Populate the views series editor with the current selected series. /// </summary> private void PopulateView() { // Populate the editor with a list of data sources. DataStore dataStore = new DataStore(series); List<string> dataSources = new List<string>(); foreach (string tableName in dataStore.TableNames) { if (tableName != "Messages" && tableName != "InitialConditions") dataSources.Add(tableName); } dataSources.Sort(); this.seriesView.SetDataSources(dataSources.ToArray()); // Populate other controls. this.seriesView.SeriesType = series.Type.ToString(); this.seriesView.SeriesLineType = series.Line.ToString(); this.seriesView.SeriesMarkerType = series.Marker.ToString(); this.seriesView.Colour = series.Colour; this.seriesView.XOnTop = series.XAxis == Axis.AxisType.Top; this.seriesView.YOnRight = series.YAxis == Axis.AxisType.Right; this.seriesView.ShowInLegend = series.ShowInLegend; this.seriesView.CumulativeX = series.CumulativeX; this.seriesView.CumulativeY = series.Cumulative; this.seriesView.DataSource = series.TableName; PopulateFieldNames(dataStore); dataStore.Disconnect(); this.seriesView.X = series.XFieldName; this.seriesView.Y = series.YFieldName; this.seriesView.X2 = series.X2FieldName; this.seriesView.Y2 = series.Y2FieldName; this.seriesView.ShowX2Y2(series.Type == SeriesType.Area); }
/// <summary> /// User has changed the data source. /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event arguments</param> private void OnDataSourceChanged(object sender, EventArgs e) { if (series.TableName != this.seriesView.DataSource) { this.SetModelProperty("TableName", this.seriesView.DataSource); DataStore dataStore = new DataStore(series); PopulateFieldNames(dataStore); dataStore.Disconnect(); } }
/// <summary> /// Create an initial conditions table in the DataStore. /// </summary> private void CreateInitialConditionsTable() { ReportColumnWithValues modelPath = new ReportColumnWithValues("ModelPath"); ReportColumnWithValues name = new ReportColumnWithValues("Name"); ReportColumnWithValues description = new ReportColumnWithValues("Description"); ReportColumnWithValues dataType = new ReportColumnWithValues("DataType"); ReportColumnWithValues units = new ReportColumnWithValues("Units"); ReportColumnWithValues displayFormat = new ReportColumnWithValues("DisplayFormat"); ReportColumnWithValues showTotal = new ReportColumnWithValues("Total"); ReportColumnWithValues value = new ReportColumnWithValues("Value"); ReportTable table = new Report.ReportTable(); table.FileName = Path.ChangeExtension(Simulation.FileName, ".db"); table.SimulationName = Simulation.Name; table.TableName = "InitialConditions"; table.Columns.Add(modelPath); table.Columns.Add(name); table.Columns.Add(description); table.Columns.Add(dataType); table.Columns.Add(units); table.Columns.Add(displayFormat); table.Columns.Add(showTotal); table.Columns.Add(value); modelPath.Add(Apsim.FullPath(Simulation)); name.Add("Simulation name"); description.Add("Simulation name"); dataType.Add("String"); units.Add(string.Empty); displayFormat.Add(string.Empty); showTotal.Add(0); value.Add(Simulation.Name); modelPath.Add(Apsim.FullPath(Simulation)); name.Add("APSIM version"); description.Add("APSIM version"); dataType.Add("String"); units.Add(string.Empty); displayFormat.Add(string.Empty); showTotal.Add(0); value.Add(Simulation.ApsimVersion); modelPath.Add(Apsim.FullPath(Simulation)); name.Add("Run on"); description.Add("Run on"); dataType.Add("String"); units.Add(string.Empty); displayFormat.Add(string.Empty); showTotal.Add(0); value.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); // Get all model properties and store in 'initialConditionsTable' foreach (Model model in Apsim.FindAll(Simulation)) { string relativeModelPath = Apsim.FullPath(model).Replace(Apsim.FullPath(Simulation) + ".", string.Empty); List <VariableProperty> properties = new List <VariableProperty>(); FindAllProperties(model, properties); foreach (VariableProperty property in properties) { string propertyValue = property.ValueWithArrayHandling.ToString(); if (propertyValue != string.Empty) { if (propertyValue != null && property.DataType == typeof(DateTime)) { propertyValue = ((DateTime)property.Value).ToString("yyyy-MM-dd HH:mm:ss"); } modelPath.Add(relativeModelPath); name.Add(property.Name); description.Add(property.Description); dataType.Add(property.DataType.Name); units.Add(property.Units); displayFormat.Add(property.Format); if (double.IsNaN(property.Total)) { showTotal.Add(0); } else { showTotal.Add(1); } value.Add(propertyValue); } } } // Write to data store. DataStore dataStore = new DataStore(Simulation); dataStore.WriteTable(table); dataStore.Disconnect(); }
/// <summary>Populate the views series editor with the current selected series.</summary> private void PopulateView() { // Populate the editor with a list of data sources. DataStore dataStore = new DataStore(series); List<string> dataSources = new List<string>(); foreach (string tableName in dataStore.TableNames) { if (tableName != "Messages" && tableName != "InitialConditions") dataSources.Add(tableName); } dataSources.Sort(); this.seriesView.DataSource.Values = dataSources.ToArray(); PopulateMarkerDropDown(); PopulateLineDropDown(); PopulateColourDropDown(); // Populate line thickness drop down. List<string> thicknesses = new List<string>(Enum.GetNames(typeof(LineThicknessType))); seriesView.LineThickness.Values = thicknesses.ToArray(); seriesView.LineThickness.SelectedValue = series.LineThickness.ToString(); // Populate marker size drop down. List<string> sizes = new List<string>(Enum.GetNames(typeof(MarkerSizeType))); seriesView.MarkerSize.Values = sizes.ToArray(); seriesView.MarkerSize.SelectedValue = series.MarkerSize.ToString(); this.seriesView.SeriesType.Values = new string[] { "Scatter", "Bar", "Area" }; // Populate other controls. this.seriesView.SeriesType.SelectedValue = series.Type.ToString(); this.seriesView.XOnTop.IsChecked = series.XAxis == Axis.AxisType.Top; this.seriesView.YOnRight.IsChecked = series.YAxis == Axis.AxisType.Right; this.seriesView.ShowInLegend.IsChecked = series.ShowInLegend; this.seriesView.IncludeSeriesNameInLegend.IsChecked = series.IncludeSeriesNameInLegend; this.seriesView.XCumulative.IsChecked = series.CumulativeX; this.seriesView.YCumulative.IsChecked = series.Cumulative; this.seriesView.DataSource.SelectedValue = series.TableName; this.seriesView.Filter.Value = series.Filter; PopulateFieldNames(dataStore); dataStore.Disconnect(); this.seriesView.X.SelectedValue = series.XFieldName; this.seriesView.Y.SelectedValue = series.YFieldName; this.seriesView.X2.SelectedValue = series.X2FieldName; this.seriesView.Y2.SelectedValue = series.Y2FieldName; this.seriesView.ShowX2Y2(series.Type == SeriesType.Area); }
/// <summary>Write all outputs to a text file (.csv)</summary> public void WriteToTextFiles() { string originalFileName = Filename; try { // Write the output CSV file. Open(forWriting: false); WriteAllTables(this, Filename + ".csv"); // Write the summary file. WriteSummaryFile(this, Filename + ".sum"); // If the baseline file exists then write the .CSV and .SUM files string baselineFileName = Filename + ".baseline"; if (File.Exists(baselineFileName)) { DataStore baselineDataStore = new DataStore(this, baseline: true); // Write the CSV output file. WriteAllTables(baselineDataStore, baselineFileName + ".csv"); // Write the SUM file. WriteSummaryFile(baselineDataStore, baselineFileName + ".sum"); baselineDataStore.Disconnect(); } } finally { Filename = originalFileName; Disconnect(); } }