예제 #1
0
        /// <summary>Attach the model (report) and the view (IReportView)</summary>
        public void Attach(object Model, object View, ExplorerPresenter explorerPresenter)
        {
            this.report = Model as Report;
            this.explorerPresenter = explorerPresenter;
            this.view = View as IReportView;

            this.view.VariableList.Lines = report.VariableNames;
            this.view.EventList.Lines = report.EventNames;
            this.view.VariableList.ContextItemsNeeded += OnNeedVariableNames;
            this.view.EventList.ContextItemsNeeded += OnNeedEventNames;
            this.view.VariableList.TextHasChangedByUser += OnVariableNamesChanged;
            this.view.EventList.TextHasChangedByUser += OnEventNamesChanged;
            this.explorerPresenter.CommandHistory.ModelChanged += OnModelChanged;

            Simulations simulations = Apsim.Parent(report, typeof(Simulations)) as Simulations;
            dataStore = Apsim.Child(simulations, typeof(DataStore)) as DataStore;
            this.view.VariableList.SetSyntaxHighlighter("Report");

            dataStorePresenter = new DataStorePresenter();
            dataStorePresenter.Attach(dataStore, this.view.DataStoreView, explorerPresenter);
            this.view.DataStoreView.TableList.SelectedValue = this.report.Name;

            Simulation simulation = Apsim.Parent(report, typeof(Simulation)) as Simulation;
            if (simulation != null)
            {
                if (simulation.Parent is Experiment)
                    dataStorePresenter.ExperimentFilter = simulation.Parent as Experiment;
                else
                    dataStorePresenter.SimulationFilter = simulation;
                dataStorePresenter.PopulateGrid();
            }
        }
예제 #2
0
        /// <summary>Attach the model to the view.</summary>
        /// <param name="model">The model to work with</param>
        /// <param name="view">The view to attach to</param>
        /// <param name="explorerPresenter">The parent explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.summary = model as Summary;
            this.view = view as ISummaryView;
            this.explorerPresenter = explorerPresenter;

            // populate the simulation names in the view.
            Simulation simulation = Apsim.Parent(this.summary, typeof(Simulation)) as Simulation;
            if (simulation != null)
            {
                if (simulation.Parent is Experiment)
                {
                    Experiment experiment = simulation.Parent as Experiment;
                    string[] simulationNames = experiment.Names();
                    this.view.SimulationNames = simulationNames;
                    if (simulationNames.Length > 0)
                        this.view.SimulationName = simulationNames[0];
                }
                else
                {
                    this.view.SimulationNames = new string[] { simulation.Name };
                    this.view.SimulationName = simulation.Name;
                }

                // create a data store - we'll need it later
                dataStore = new DataStore(simulation, false);

                // populate the view
                this.SetHtmlInView();

                // subscribe to the simulation name changed event.
                this.view.SimulationNameChanged += OnSimulationNameChanged;
            }
        }
예제 #3
0
        /// <summary>
        /// Attach the model to the view.
        /// </summary>
        /// <param name="model">The model object</param>
        /// <param name="view">The view used</param>
        /// <param name="explorerPresenter">The explorer presenter</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.view = view as ITestView;
            this.tests = model as Tests;
            this.explorerPresenter = explorerPresenter;

            this.dataStore = Apsim.Find(this.tests, typeof(DataStore)) as DataStore;
            this.view.Editor.IntelliSenseChars = " :";
            this.view.Editor.ContextItemsNeeded += this.OnContextItemsNeeded;
            this.view.TableNameChanged += this.OnTableNameChanged;

            this.PopulateView();
            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
예제 #4
0
        /// <summary>
        /// Attach the model and view to this presenter and populate the view.
        /// </summary>
        /// <param name="model">The data store model to work with.</param>
        /// <param name="view">Data store view to work with.</param>
        /// <param name="explorerPresenter">Parent explorer presenter.</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            this.dataStore = model as DataStore;
            this.dataStoreView = view as IDataStoreView;
            this.explorerPresenter = explorerPresenter;

            this.dataStoreView.AutoExport = dataStore.AutoExport;

            this.dataStoreView.OnTableSelected += this.OnTableSelected;
            this.dataStoreView.AutoExportClicked += OnAutoExportClicked;

            this.dataStoreView.Grid.ReadOnly = true;

            this.dataStoreView.Grid.NumericFormat = "N3";
            this.dataStoreView.TableNames = this.GetTableNames();

            this.dataStoreView.Grid.ResizeControls();
        }
예제 #5
0
        /// <summary>Attach the model and view to this presenter and populate the view.</summary>
        /// <param name="model">The data store model to work with.</param>
        /// <param name="view">Data store view to work with.</param>
        /// <param name="explorerPresenter">Parent explorer presenter.</param>
        public void Attach(object model, object view, ExplorerPresenter explorerPresenter)
        {
            dataStore = model as DataStore;
            this.view = view as IDataStoreView;
            this.explorerPresenter = explorerPresenter;

            this.view.TableList.IsEditable = false;
            this.view.Grid.ReadOnly = true;
            this.view.Grid.NumericFormat = "N3";
            this.view.TableList.Values = this.GetTableNames();
            if (dataStore != null && dataStore.MaximumResultsPerPage > 0)
                this.view.MaximumNumberRecords.Value = dataStore.MaximumResultsPerPage.ToString();

            this.view.Grid.ResizeControls();
            this.view.TableList.Changed += this.OnTableSelected;
            this.view.ColumnFilter.Changed += OnColumnFilterChanged;
            this.view.MaximumNumberRecords.Changed += OnMaximumNumberRecordsChanged;
            PopulateGrid();
        }
예제 #6
0
        /// <summary>
        /// Attach the model to the view.
        /// </summary>
        public void Attach(object Model, object View, ExplorerPresenter explorerPresenter)
        {
            Graph             = Model as Graph;
            GraphView         = View as GraphView;
            ExplorerPresenter = explorerPresenter;

            GraphView.OnAxisClick      += OnAxisClick;
            GraphView.OnPlotClick      += OnPlotClick;
            GraphView.OnLegendClick    += OnLegendClick;
            GraphView.OnTitleClick     += OnTitleClick;
            GraphView.OnCaptionClick   += OnCaptionClick;
            GraphView.OnHoverOverPoint += OnHoverOverPoint;
            ExplorerPresenter.CommandHistory.ModelChanged += OnGraphModelChanged;
            this.GraphView.AddContextAction("Copy graph XML to clipboard", CopyGraphXML);

            // Connect to a datastore.
            DataStore = new Models.DataStore(Graph);

            DrawGraph();
        }
예제 #7
0
        /// <summary>
        /// Attach the model (report) and the view (IReportView)
        /// </summary>
        public void Attach(object Model, object View, ExplorerPresenter explorerPresenter)
        {
            this.Report = Model as Report;
            this.ExplorerPresenter = explorerPresenter;
            this.View = View as IReportView;

            this.View.VariableList.Lines = Report.VariableNames;
            this.View.EventList.Lines = Report.EventNames;
            this.View.VariableList.ContextItemsNeeded += OnNeedVariableNames;
            this.View.EventList.ContextItemsNeeded += OnNeedEventNames;
            this.View.VariableList.TextHasChangedByUser += OnVariableNamesChanged;
            this.View.EventList.TextHasChangedByUser += OnEventNamesChanged;
            ExplorerPresenter.CommandHistory.ModelChanged += CommandHistory_ModelChanged;

            Simulation simulation = Apsim.Parent(Report, typeof(Simulation)) as Simulation;
            DataStore = new DataStore(Report);
            this.View.VariableList.SetSyntaxHighlighter("Report");

            PopulateDataGrid();
            this.View.DataGrid.ResizeControls();
        }
예제 #8
0
        /// <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;
        }
예제 #9
0
파일: Summary.cs 프로젝트: hol353/ApsimX
 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();
 }
예제 #10
0
파일: Summary.cs 프로젝트: hol353/ApsimX
        /// <summary>
        /// Create a message table ready for writing.
        /// </summary>
        /// <param name="dataStore">The data store to read the message table from</param>
        /// <param name="simulationName">The simulation name to get messages for</param>
        /// <returns>The filled message table</returns>
        private static DataTable GetMessageTable(DataStore dataStore, string simulationName)
        {
            DataTable messageTable = new DataTable();
            DataTable messages = dataStore.GetData(simulationName, "Messages");
            if (messages != null && messages.Rows.Count > 0)
            {
                messageTable.Columns.Add("Date", typeof(string));
                messageTable.Columns.Add("Message", typeof(string));
                string previousCol1Text = null;
                string previousMessage = null;
                foreach (DataRow row in messages.Rows)
                {
                    // Work out the column 1 text.
                    string modelName = (string)row[1];

                    string col1Text;
                    if (row[2].GetType() == typeof(DateTime))
                    {
                        DateTime date = (DateTime)row[2];
                        col1Text = date.ToString("yyyy-MM-dd") + " " + modelName;
                    }
                    else
                        col1Text = row[2].ToString();

                    // If the date and model name have changed then write a row.
                    if (col1Text != previousCol1Text)
                    {
                        if (previousCol1Text != null)
                        {
                            messageTable.Rows.Add(new object[] { previousCol1Text, previousMessage });
                        }

                        previousMessage = string.Empty;
                        previousCol1Text = col1Text;
                    }
                    else
                    {
                        col1Text = null;
                    }

                    string message = (string)row[3];
                    Models.DataStore.ErrorLevel errorLevel = (Models.DataStore.ErrorLevel)Enum.Parse(typeof(Models.DataStore.ErrorLevel), row[4].ToString());

                    if (errorLevel == DataStore.ErrorLevel.Error)
                    {
                        previousMessage += "FATAL ERROR: " + message;
                    }
                    else if (errorLevel == DataStore.ErrorLevel.Warning)
                    {
                        previousMessage += "WARNING: " + message;
                    }
                    else
                    {
                        previousMessage += message;
                    }

                    previousMessage += "\r\n";
                }
                if (previousMessage != null)
                {
                    messageTable.Rows.Add(new object[] { previousCol1Text, previousMessage });
                }
            }

            return messageTable;
        }
예제 #11
0
파일: Summary.cs 프로젝트: hol353/ApsimX
        /// <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();
        }
예제 #12
0
파일: Summary.cs 프로젝트: hol353/ApsimX
        /// <summary>
        /// Write the summary report to the specified writer.
        /// </summary>
        /// <param name="dataStore">The data store to write a summary report from</param>
        /// <param name="simulationName">The simulation name to produce a summary report for</param>
        /// <param name="writer">Text writer to write to</param>
        /// <param name="apsimSummaryImageFileName">The file name for the logo. Can be null</param>
        /// <param name="outtype">Indicates the format to be produced</param>
        public static void WriteReport(
            DataStore dataStore,
            string simulationName,
            TextWriter writer,
            string apsimSummaryImageFileName,
            OutputType outtype)
        {
            Document document = null;
            RtfDocumentRenderer renderer = null;

            if (outtype == OutputType.html)
            {
                writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                writer.WriteLine("<html>");
                writer.WriteLine("<head>");
                writer.WriteLine("<meta content='text/html; charset=UTF-8; http-equiv='content-type'>");
                writer.WriteLine("<style>");
                writer.WriteLine("h2 { color:darkblue; } ");
                writer.WriteLine("h3 { color:darkblue; } ");
                writer.WriteLine("table { border:1px solid black; border-collapse:collapse; width:100%; table-layout:fixed; text-align:left; }");
                writer.WriteLine("table.headered {text-align:right; }");
                writer.WriteLine("tr.total { color:darkorange; font-weight:bold; }");
                writer.WriteLine("table.headered td.col1 { text-align:left; font-weight:bold; }");
                writer.WriteLine("td { border:1px solid; }");
                writer.WriteLine("th { border:1px solid; text-align:right; background-color: palegoldenrod}");
                writer.WriteLine("th.col1 { text-align:left; }");
                writer.WriteLine("</style>");
                writer.WriteLine("</head>");
                writer.WriteLine("<body>");
            }
            else if (outtype == OutputType.rtf)
            {
                document = new Document();
                renderer = new RtfDocumentRenderer();

                // Get the predefined style Normal.
                Style style = document.Styles["Normal"];

                // Because all styles are derived from Normal, the next line changes the
                // font of the whole document. Or, more exactly, it changes the font of
                // all styles and paragraphs that do not redefine the font.
                style.Font.Name = "Arial";

                // Heading1 to Heading9 are predefined styles with an outline level. An outline level
                // other than OutlineLevel.BodyText automatically creates the outline (or bookmarks)
                // in PDF.
                style = document.Styles["Heading2"];
                style.Font.Size = 14;
                style.Font.Bold = true;
                style.Font.Color = Colors.DarkBlue;
                style.ParagraphFormat.PageBreakBefore = false;
                style.ParagraphFormat.SpaceAfter = 3;
                style.ParagraphFormat.SpaceBefore = 16;

                style = document.Styles["Heading3"];
                style.Font.Size = 12;
                style.Font.Bold = true;
                style.Font.Color = Colors.DarkBlue;
                style.ParagraphFormat.SpaceBefore = 10;
                style.ParagraphFormat.SpaceAfter = 2;

                // Create a new style called Monospace based on style Normal
                style = document.Styles.AddStyle("Monospace", "Normal");
                System.Drawing.FontFamily monoFamily = new System.Drawing.FontFamily(System.Drawing.Text.GenericFontFamilies.Monospace);
                style.Font.Name = monoFamily.Name;
                Section section = document.AddSection();
            }

            // Get the initial conditions table.
            DataTable initialConditionsTable = dataStore.GetData(simulationName, "InitialConditions");
            if (initialConditionsTable != null)
            {
                // Convert the 'InitialConditions' table in the DataStore to a series of
                // DataTables for each model.
                List<DataTable> tables = new List<DataTable>();
                ConvertInitialConditionsToTables(initialConditionsTable, tables);

                // Now write all tables to our report.
                for (int i = 0; i < tables.Count; i += 2)
                {
                    // Only write something to the summary file if we have something to write.
                    if (tables[i].Rows.Count > 0 || tables[i + 1].Rows.Count > 0)
                    {
                        string heading = tables[i].TableName;
                        WriteHeading(writer, heading, outtype, document);

                        // Write the manager script.
                        if (tables[i].Rows.Count == 1 && tables[i].Rows[0][0].ToString() == "Script code: ")
                        {
                            WriteScript(writer, tables[i].Rows[0], outtype, document);
                        }
                        else
                        {
                            // Write the properties table if we have any properties.
                            if (tables[i].Rows.Count > 0)
                            {
                                WriteTable(writer, tables[i], outtype, "PropertyTable", document);
                            }

                            // Write the general data table if we have any data.
                            if (tables[i + 1].Rows.Count > 0)
                            {
                                WriteTable(writer, tables[i + 1], outtype, "ApsimTable", document);
                            }
                        }

                        if (outtype == OutputType.html)
                            writer.WriteLine("<br/>");
                    }
                }
            }

            // Write out all messages.
            WriteHeading(writer, "Simulation log:", outtype, document);
            DataTable messageTable = GetMessageTable(dataStore, simulationName);
            WriteMessageTable(writer, messageTable, outtype, false, "MessageTable", document);

            if (outtype == OutputType.html)
            {
                writer.WriteLine("</body>");
                writer.WriteLine("</html>");
            }
            else if (outtype == OutputType.rtf)
            {
                string rtf = renderer.RenderToString(document, Path.GetTempPath());
                writer.Write(rtf);
            }
        }
예제 #13
0
        /// <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);
        }
예제 #14
0
        /// <summary>
        /// Write the summary report to a file
        /// </summary>
        /// <param name="baseline">Indicates whether the baseline data store should be used.</param>
        private void WriteSummaryFiles(DataStore dataStoreToUse)
        {
            string fileName = dataStoreToUse.Filename + ".sum";

            StreamWriter report = report = new StreamWriter(fileName);
            foreach (string simulationName in dataStoreToUse.SimulationNames)
            {
                Summary.WriteReport(dataStoreToUse, simulationName, report, null, outtype: Summary.OutputType.html);
                report.WriteLine();
                report.WriteLine();
                report.WriteLine("############################################################################");
            }
            report.Close();
        }
예제 #15
0
 /// <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();
     }
 }
예제 #16
0
파일: DataStore.cs 프로젝트: hut104/ApsimX
        /// <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();
            }
        }
예제 #17
0
        public DataStore ExportStore()
        {
            var store = new DataStore();
            using (var exporter = new DatabaseExporter(this.GetStatelessSession()))
            {
                store.IngredientForms = exporter.IngredientForms();
                store.IngredientMetadata = exporter.IngredientMetadata();
                store.Ingredients = exporter.Ingredients();
                store.NlpAnomalousIngredients = exporter.NlpAnomalousIngredients();
                store.NlpDefaultPairings = exporter.NlpDefaultPairings();
                store.NlpFormSynonyms = exporter.NlpFormSynonyms();
                store.NlpIngredientSynonyms = exporter.NlpIngredientSynonyms();
                store.NlpPrepNotes = exporter.NlpPrepNotes();
                store.NlpUnitSynonyms = exporter.NlpUnitSynonyms();
                store.Recipes = exporter.Recipes();
                store.RecipeMetadata = exporter.RecipeMetadata();
                store.RecipeIngredients = exporter.RecipeIngredients();
                store.Favorites = exporter.Favorites();
                store.Menus = exporter.Menus();
                store.QueuedRecipes = exporter.QueuedRecipes();
                store.RecipeRatings = exporter.RecipeRatings();
                store.ShoppingLists = exporter.ShoppingLists();
                store.ShoppingListItems = exporter.ShoppingListItems();
            }

            return store;
        }
예제 #18
0
        /// <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);
        }
예제 #19
0
        /// <summary>Populates the field names in the view.</summary>
        /// <param name="dataStore">The data store.</param>
        private void PopulateFieldNames(DataStore dataStore)
        {
            Graph parentGraph = series.Parent as Graph;
            if (this.seriesView.DataSource != null &&
                this.seriesView.DataSource.SelectedValue != string.Empty &&
                this.seriesView.DataSource.SelectedValue != null &&
                parentGraph != null)
            {
                DataTable data = parentGraph.GetBaseData(this.seriesView.DataSource.SelectedValue);
                if (data != null)
                {

                    List<string> fieldNames = new List<string>();
                    foreach (DataColumn column in data.Columns)
                    {
                        if (column.DataType.Name != "Object")
                            fieldNames.Add(column.ColumnName);
                    }

                    fieldNames.Sort();

                    this.seriesView.X.Values = fieldNames.ToArray();
                    this.seriesView.Y.Values = fieldNames.ToArray();
                    this.seriesView.X2.Values = fieldNames.ToArray();
                    this.seriesView.Y2.Values = fieldNames.ToArray();
                }
            }
        }
예제 #20
0
        /// <summary>Populates the field names in the view.</summary>
        /// <param name="dataStore">The data store.</param>
        private void PopulateFieldNames(DataStore dataStore)
        {
            Graph parentGraph = series.Parent as Graph;
            if (this.seriesView.DataSource != null &&
                this.seriesView.DataSource.SelectedValue != string.Empty &&
                this.seriesView.DataSource.SelectedValue != null &&
                parentGraph != null)
            {
                List<string> fieldNames = new List<string>();
                fieldNames.Add("SimulationName");
                fieldNames.AddRange(dataStore.ColumnNames(seriesView.DataSource.SelectedValue));
                fieldNames.Sort();

                this.seriesView.X.Values = fieldNames.ToArray();
                this.seriesView.Y.Values = fieldNames.ToArray();
                this.seriesView.X2.Values = fieldNames.ToArray();
                this.seriesView.Y2.Values = fieldNames.ToArray();
            }
        }
예제 #21
0
파일: DataStore.cs 프로젝트: hut104/ApsimX
        /// <summary>Create a text report from tables in this data store.</summary>
        /// <param name="dataStore">The data store.</param>
        /// <param name="fileName">Name of the file.</param>
        private static void WriteAllTables(DataStore dataStore, string fileName)
        {
            // Write out each table for this simulation.
            foreach (string tableName in dataStore.TableNames)
            {
                if (tableName != "Messages" && tableName != "InitialConditions")
                {
                    DataTable firstRowOfTable = dataStore.RunQuery("SELECT * FROM " + tableName + " LIMIT 1");
                    if (firstRowOfTable != null)
                    {
                        string fieldNamesString = "";
                        for (int i = 1; i < firstRowOfTable.Columns.Count; i++)
                        {
                            if (i > 1)
                                fieldNamesString += ", ";
                            fieldNamesString += "[" + firstRowOfTable.Columns[i].ColumnName + "]";
                        }

                        string sql = String.Format("SELECT Name, {0} FROM Simulations, {1} " +
                                                   "WHERE Simulations.ID = {1}.SimulationID " +
                                                   "ORDER BY Name",
                                                   fieldNamesString, tableName);
                        DataTable data = dataStore.RunQuery(sql);
                        if (data != null && data.Rows.Count > 0)
                        {
                            StreamWriter report = new StreamWriter(Path.ChangeExtension(fileName, "." + tableName + ".csv"));
                            report.Write(DataTableUtilities.DataTableToText(data, 0, ",", true));
                            report.Close();
                        }
                    }
                }
            }
        }
예제 #22
0
 /// <summary>Populates the field names in the view.</summary>
 /// <param name="dataStore">The data store.</param>
 private void PopulateFieldNames(DataStore dataStore)
 {
     if (this.seriesView.DataSource != null)
     {
         DataTable data = dataStore.RunQuery("SELECT * FROM " + this.seriesView.DataSource + " LIMIT 1");
         if (data != null)
             this.seriesView.SetFieldNames(DataTableUtilities.GetColumnNames(data));
     }
 }
예제 #23
0
        /// <summary>Populates the field names in the view.</summary>
        /// <param name="dataStore">The data store.</param>
        private void PopulateFieldNames(DataStore dataStore)
        {
            Graph parentGraph = series.Parent as Graph;
            if (this.seriesView.DataSource != null &&
                this.seriesView.DataSource.SelectedValue != string.Empty &&
                this.seriesView.DataSource.SelectedValue != null &&
                parentGraph != null)
            {
                DataTable data = null;
                int i = 0;
                while (i < graphPresenter.seriesDefinitions.Count && graphPresenter.seriesDefinitions[i].data == null)
                    i++;
                if (i < graphPresenter.seriesDefinitions.Count)
                    data = graphPresenter.seriesDefinitions[i].data;

                List<string> fieldNames = new List<string>();
                if (data == null)
                    fieldNames.AddRange(dataStore.ColumnNames(seriesView.DataSource.SelectedValue));
                else
                {
                    foreach (DataColumn column in data.Columns)
                    {
                        if (column.DataType.Name != "Object")
                            fieldNames.Add(column.ColumnName);
                    }
                }

                fieldNames.Sort();

                this.seriesView.X.Values = fieldNames.ToArray();
                this.seriesView.Y.Values = fieldNames.ToArray();
                this.seriesView.X2.Values = fieldNames.ToArray();
                this.seriesView.Y2.Values = fieldNames.ToArray();
            }
        }
예제 #24
0
파일: DataStore.cs 프로젝트: hut104/ApsimX
 /// <summary>Write a single summary file.</summary>
 /// <param name="dataStore">The data store containing the data</param>
 /// <param name="fileName">The file name to create</param>
 private static void WriteSummaryFile(DataStore dataStore, string fileName)
 {
     StreamWriter report = new StreamWriter(fileName);
     foreach (string simulationName in dataStore.SimulationNames)
     {
         Summary.WriteReport(dataStore, simulationName, report, null, outtype: Summary.OutputType.html);
         report.WriteLine();
         report.WriteLine();
         report.WriteLine("############################################################################");
     }
     report.Close();
 }