Beispiel #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Summary()
        {
            // Create our Messages table.
            componentNameColumn = new ReportColumnWithValues("ComponentName");
            dateColumn          = new ReportColumnWithValues("Date");
            messageColumn       = new ReportColumnWithValues("Message");
            messageTypeColumn   = new ReportColumnWithValues("MessageType");

            messagesTable.Columns.Add(componentNameColumn);
            messagesTable.Columns.Add(dateColumn);
            messagesTable.Columns.Add(messageColumn);
            messagesTable.Columns.Add(messageTypeColumn);
        }
Beispiel #2
0
        /// <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();
        }