当前位置: 首页>>代码示例>>C#>>正文


C# DataStore.WriteTable方法代码示例

本文整理汇总了C#中DataStore.WriteTable方法的典型用法代码示例。如果您正苦于以下问题:C# DataStore.WriteTable方法的具体用法?C# DataStore.WriteTable怎么用?C# DataStore.WriteTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataStore的用法示例。


在下文中一共展示了DataStore.WriteTable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        /// <summary>
        /// The main run method called to fill tables in the specified DataStore.
        /// </summary>
        /// <param name="dataStore">The DataStore to work with</param>
        public void Run(DataStore dataStore)
        {
            dataStore.DeleteTable(this.Name);

            DataTable simulationData = dataStore.GetData("*", this.TableName);
            if (simulationData != null)
            {
                // Add all the necessary columns to our data table.
                DataTable probabilityData = new DataTable();
                probabilityData.Columns.Add("Probability", typeof(double));
                foreach (DataColumn column in simulationData.Columns)
                {
                    if (column.DataType == typeof(double))
                        probabilityData.Columns.Add(column.ColumnName, typeof(double));
                }

                string[] simulationNames = dataStore.SimulationNames;

                DataView view = new DataView(simulationData);
                foreach (string simulationName in simulationNames)
                {
                    view.RowFilter = "SimName = '" + simulationName + "'";

                    int startRow = probabilityData.Rows.Count;

                    // Add in a simulation column.
                    string[] simulationNameColumnValues = StringUtilities.CreateStringArray(simulationName, view.Count);
                    DataTableUtilities.AddColumn(probabilityData, "SimulationName", simulationNameColumnValues, startRow, simulationNameColumnValues.Length);

                    // Add in the probability column
                    double[] probabilityValues = MathUtilities.ProbabilityDistribution(view.Count, this.Exceedence);
                    DataTableUtilities.AddColumn(probabilityData, "Probability", probabilityValues, startRow, view.Count);

                    // Add in all other numeric columns.
                    foreach (DataColumn column in simulationData.Columns)
                    {
                        if (column.DataType == typeof(double))
                        {
                            double[] values = DataTableUtilities.GetColumnAsDoubles(view, column.ColumnName);
                            Array.Sort<double>(values);
                            DataTableUtilities.AddColumn(probabilityData, column.ColumnName, values, startRow, values.Length);
                        }
                    }
                }

                // Write the stats data to the DataStore
                dataStore.WriteTable(null, this.Name, probabilityData);
            }
        }
开发者ID:hol353,项目名称:ApsimX,代码行数:53,代码来源:Probability.cs

示例2: OnTransferData

 /// <summary>Called by the client to send its output data.</summary>
 /// <param name="sender">The sender</param>
 /// <param name="args">The command arguments</param>
 private void OnTransferData(object sender, SocketServer.CommandArgs args)
 {
     TransferData arguments = args.obj as TransferData;
     System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
     MemoryStream stream = new MemoryStream(arguments.data, 0, (int) arguments.dataLength);
     DataTable data = formatter.Deserialize(stream) as DataTable;
     DataStore store = new DataStore();
     store.Filename = Path.ChangeExtension(dbFileName, ".db");
     store.WriteTable(arguments.simulationName, arguments.tableName, data);
     server.Send(args.socket, "OK");
 }
开发者ID:hol353,项目名称:ApsimX,代码行数:14,代码来源:JobManagerMultiProcess.cs

示例3: OnTransferOutputs

        /// <summary>Called by the client to send its output data.</summary>
        /// <param name="sender">The sender</param>
        /// <param name="args">The command arguments</param>
        private void OnTransferOutputs(object sender, SocketServer.CommandArgs args)
        {
            TransferArguments arguments = args.obj as TransferArguments;

            // Read from temp file.
            byte[] bytes = File.ReadAllBytes(arguments.fileName);
            MemoryStream s = new MemoryStream(bytes);
            DataTable table = ReflectionUtilities.BinaryDeserialise(s) as DataTable;
            File.Delete(arguments.fileName);

            DataStore store = new DataStore();
            store.Filename = Path.ChangeExtension(dbFileName, ".db");
            store.WriteTable(arguments.simulationName, arguments.tableName, table);
            server.Send(args.socket, "OK");
        }
开发者ID:hol353,项目名称:ApsimX,代码行数:18,代码来源:JobManagerMultiProcess.cs

示例4: Run

        /// <summary>
        /// Main run method for performing our calculations and storing data.
        /// </summary>
        public void Run(DataStore dataStore)
        {
            string fullFileName = FullFileName;
            if (fullFileName != null)
            {
                Simulations simulations = Apsim.Parent(this, typeof(Simulations)) as Simulations;

                dataStore.DeleteTable(Name);
                DataTable data = GetTable();
                dataStore.WriteTable(null, this.Name, data);
            }
        }
开发者ID:kiwiroy,项目名称:ApsimX,代码行数:15,代码来源:Input.cs

示例5: Run

        /// <summary>
        /// Main run method for performing our calculations and storing data.
        /// </summary>
        /// <param name="dataStore">The data store to store the data</param>
        public void Run(DataStore dataStore)
        {
            string fullFileName = AbsoluteFileName;
            if (fullFileName != null && File.Exists(fullFileName))
            {
                dataStore.DeleteTable(this.Name);

                // Open the file
                FileStream stream = File.Open(fullFileName, FileMode.Open, FileAccess.Read);

                // Create a reader.
                IExcelDataReader excelReader;
                if (Path.GetExtension(fullFileName).Equals(".xls", StringComparison.CurrentCultureIgnoreCase))
                    throw new Exception("EXCEL file must be in .xlsx format. Filename: " + fullFileName);
                else
                {
                    // Reading from a OpenXml Excel file (2007 format; *.xlsx)
                    excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
                }

                // Read all sheets from the EXCEL file as a data set
                excelReader.IsFirstRowAsColumnNames = true;
                DataSet dataSet = excelReader.AsDataSet();

                // Write all sheets that are specified in 'SheetNames' to the data store
                foreach (DataTable table in dataSet.Tables)
                {
                    bool keep = StringUtilities.IndexOfCaseInsensitive(this.SheetNames, table.TableName) != -1;
                    if (keep)
                    {
                        dataStore.WriteTable(null, table.TableName, table);
                    }
                }

                // Close the reader and free resources.
                excelReader.Close();
            }
        }
开发者ID:hol353,项目名称:ApsimX,代码行数:42,代码来源:ExcelInput.cs

示例6: OnSimulationCompleted

        private void OnSimulationCompleted(object sender, EventArgs e)
        {
            // Get rid of old data in .db
            DataStore dataStore = new DataStore(this);
            if (this.simulation != null)
            {
                dataStore.DeleteOldContentInTable(this.simulation.Name, this.Name);
            }
            // Write and store a table in the DataStore
            if (this.columns != null && this.columns.Count > 0)
            {
                DataTable table = new DataTable();

                foreach (ReportColumn variable in this.columns)
                    variable.AddColumnsToTable(table);

                foreach (ReportColumn variable in this.columns)
                    variable.AddRowsToTable(table);

                dataStore.WriteTable(this.simulation.Name, this.Name, table);

                this.columns.Clear();
                this.columns = null;
            }

            dataStore.Disconnect();
            dataStore = null;
        }
开发者ID:kiwiroy,项目名称:ApsimX,代码行数:28,代码来源:Report.cs

示例7: Run

        /// <summary>Main run method for performing our calculations and storing data.</summary>
        /// <param name="dataStore">The data store.</param>
        /// <exception cref="ApsimXException">
        /// Could not find model data table:  + ObservedTableName
        /// or
        /// Could not find observed data table:  + ObservedTableName
        /// </exception>
        public void Run(DataStore dataStore)
        {
            if (PredictedTableName != null && ObservedTableName != null)
            {
                dataStore.DeleteTable(this.Name);

                DataTable predictedDataNames = dataStore.RunQuery("PRAGMA table_info(" + PredictedTableName + ")");
                DataTable observedDataNames  = dataStore.RunQuery("PRAGMA table_info(" + ObservedTableName + ")");

                if (predictedDataNames == null)
                    throw new ApsimXException(this, "Could not find model data table: " + ObservedTableName);

                if (observedDataNames == null)
                    throw new ApsimXException(this, "Could not find observed data table: " + ObservedTableName);

                IEnumerable<string> commonCols = from p in predictedDataNames.AsEnumerable()
                                               join o in observedDataNames.AsEnumerable() on p["name"] equals o["name"]
                                               select p["name"] as string;

                StringBuilder query = new StringBuilder("SELECT ");
                foreach (string s in commonCols)
                {
                    if (s == FieldNameUsedForMatch || s == FieldName2UsedForMatch || s == FieldName3UsedForMatch)
                        query.Append("I.'@field', ");
                    else
                        query.Append("I.'@field' AS '[email protected]', R.'@field' AS '[email protected]', ");

                    query.Replace("@field", s);
                }

                query.Append("FROM " + ObservedTableName + " I INNER JOIN " + PredictedTableName + " R USING (SimulationID) WHERE I.'@match1' = R.'@match1'");
                if (FieldName2UsedForMatch != null)
                    query.Append(" AND I.'@match2' = R.'@match2'");
                if (FieldName3UsedForMatch != null)
                    query.Append(" AND I.'@match3' = R.'@match3'");
                query.Replace(", FROM", " FROM"); // get rid of the last comma
                query.Replace("I.'SimulationID' AS 'Observed.SimulationID', R.'SimulationID' AS 'Predicted.SimulationID'", "I.'SimulationID' AS 'SimulationID'");

                query = query.Replace("@match1", FieldNameUsedForMatch);
                query = query.Replace("@match2", FieldName2UsedForMatch);
                query = query.Replace("@match3", FieldName3UsedForMatch);

                DataTable predictedObservedData = dataStore.RunQuery(query.ToString());

                if (predictedObservedData != null)
                    dataStore.WriteTable(null, this.Name, predictedObservedData);
                dataStore.Disconnect();
            }
        }
开发者ID:hol353,项目名称:ApsimX,代码行数:56,代码来源:PredictedObserved.cs

示例8: Run

        /// <summary>
        /// The main run method called to fill tables in the specified DataStore.
        /// </summary>
        /// <param name="dataStore">The DataStore to work with</param>
        public void Run(DataStore dataStore)
        {
            dataStore.DeleteTable(this.Name);

            DataTable statsData = new DataTable();
            statsData.Columns.Add("SimulationName", typeof(string));
            statsData.Columns.Add("VariableName", typeof(string));
            statsData.Columns.Add("n", typeof(string));
            statsData.Columns.Add("residual", typeof(double));
            statsData.Columns.Add("R^2", typeof(double));
            statsData.Columns.Add("RMSD", typeof(double));
            statsData.Columns.Add("%", typeof(double));
            statsData.Columns.Add("MSD", typeof(double));
            statsData.Columns.Add("SB", typeof(double));
            statsData.Columns.Add("SDSD", typeof(double));
            statsData.Columns.Add("LCS", typeof(double));

            DataTable simulationData = dataStore.GetData("*", this.TableName);
            if (simulationData != null)
            {
                DataView view = new DataView(simulationData);
                string[] columnNames = DataTableUtilities.GetColumnNames(simulationData);

                foreach (string observedColumnName in columnNames)
                {
                    if (observedColumnName.StartsWith("Observed."))
                    {
                        string predictedColumnName = observedColumnName.Replace("Observed.", "Predicted.");
                        if (simulationData.Columns.Contains(predictedColumnName))
                        {
                            DataColumn predictedColumn = simulationData.Columns[predictedColumnName];
                            DataColumn observedColumn = simulationData.Columns[observedColumnName];
                            if (predictedColumn.DataType == typeof(double) &&
                                observedColumn.DataType == typeof(double))
                            {
                                // Calculate stats for each simulation and store them in a rows in our stats table.
                                string[] simulationNames = dataStore.SimulationNames;
                                foreach (string simulationName in simulationNames)
                                {
                                    string seriesName = simulationName;
                                    view.RowFilter = "SimName = '" + simulationName + "'";
                                    CalcStatsRow(view, observedColumnName, predictedColumnName, seriesName, statsData);
                                }

                                // Calculate stats for all simulations and store in a row of the stats table.
                                string overallSeriesName = "Combined " + observedColumnName.Replace("Observed.", "");
                                view.RowFilter = null;
                                CalcStatsRow(view, observedColumnName, predictedColumnName, overallSeriesName, statsData);
                            }
                        }
                    }
                }

                // Write the stats data to the DataStore
                dataStore.WriteTable(null, this.Name, statsData);
            }
        }
开发者ID:kiwiroy,项目名称:ApsimX,代码行数:61,代码来源:TimeSeriesStats.cs


注:本文中的DataStore.WriteTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。