コード例 #1
0
        public XYZMeshedColumnPlotData(Altaxo.Data.DataColumnCollection coll, IAscendingIntegerCollection selected)
        {
            m_XColumn = new Altaxo.Data.IndexerColumn();
            m_YColumn = new Altaxo.Data.IndexerColumn();

            int len = selected == null ? coll.ColumnCount : selected.Count;

            m_DataColumns = new Altaxo.Data.IReadableColumn[len];
            for (int i = 0; i < len; i++)
            {
                int idx = null == selected ? i : selected[i];
                m_DataColumns[i] = coll[idx];

                // set the event chain
                if (m_DataColumns[i] is Altaxo.Data.DataColumn)
                {
                    ((Altaxo.Data.DataColumn)m_DataColumns[i]).Changed += new EventHandler(EhColumnDataChangedEventHandler);
                }
            }


            this.SetXBoundsFromTemplate(new FiniteNumericalBoundaries());
            this.SetYBoundsFromTemplate(new FiniteNumericalBoundaries());
            this.SetVBoundsFromTemplate(new FiniteNumericalBoundaries());
        }
コード例 #2
0
 /// <summary>
 /// This function searches for patterns like aaa=bbb in the items of the text column. If it finds such a item, it creates a column named aaa
 /// and stores the value bbb at the same position in it as in the text column.
 /// </summary>
 /// <param name="col">The column where to search for the patterns described above.</param>
 /// <param name="store">The column collection where to store the newly created columns of properties.</param>
 public static void ExtractPropertiesFromColumn(Altaxo.Data.DataColumn col, Altaxo.Data.DataColumnCollection store)
 {
     for (int nRow = 0; nRow < col.Count; nRow++)
     {
         ExtractPropertiesFromString(col[nRow].ToString(), store, nRow);
     }
 }
コード例 #3
0
 public void ZeroColumns()
 {
   DataColumnCollection d = new DataColumnCollection();
   Assert.AreEqual(0, d.ColumnCount);
   Assert.AreEqual(0, d.RowCount);
   Assert.AreEqual(false, d.IsDirty);
   Assert.AreEqual(false, d.IsSuspended);
 }
コード例 #4
0
			public TableNode(DataTable table)
				: base(true)
			{
				_collection = table.DataColumns;
				_firstColumn = 0;
				_columnCount = table.DataColumns.ColumnCount;
				Text = table.ShortName;
				Tag = table;
			}
コード例 #5
0
 public DataColumnToColumnMatrixWrapper(Altaxo.Data.DataColumnCollection collection, Altaxo.Collections.IAscendingIntegerCollection selectedColumns, Altaxo.Collections.IAscendingIntegerCollection selectedRows)
     : base(collection, selectedColumns, selectedRows)
 {
     /*
      * // check the writeability
      * for(int i=selectedColumns.Count-1;i>=0;i--)
      * if(!(collection[selectedColumns[i]] is IWriteableColumn))
      *  throw new ArgumentException(string.Format("Column not writeable! Index in matrix: {0}, index in data column collection: {1}, column name: {2}",i,selectedColumns[i],collection[selectedColumns[i]].Name));
      */
 }
コード例 #6
0
            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="collection">Collection of <see cref="DataColumn" />s.</param>
            /// <param name="selectedColumns">Set set of indices into the collection that are part of the matrix.</param>
            /// <param name="selectedRows">The set of rows that are part of the matrix. This collection is not cloned here, therefore it must not be subsequently changed!</param>
            public DataColumnToColumnROMatrixWrapper(Altaxo.Data.DataColumnCollection collection, Altaxo.Collections.IAscendingIntegerCollection selectedColumns, Altaxo.Collections.IAscendingIntegerCollection selectedRows)
            {
                _columns = new Altaxo.Data.INumericColumn[selectedColumns.Count];
                for (int i = selectedColumns.Count - 1; i >= 0; i--)
                {
                    _columns[i] = (Altaxo.Data.INumericColumn)collection[selectedColumns[i]];
                }

                _rows = selectedRows;
            }
コード例 #7
0
    public void TenEmptyColumns()
    {
      DataColumnCollection d = new DataColumnCollection();

      DataColumn[] cols = new DataColumn[10];
      for(int i=0;i<10;i++)
      {
        cols[i] = new DoubleColumn();
        d.Add(cols[i]);
      }

      Assert.AreEqual(10, d.ColumnCount);
      Assert.AreEqual(0, d.RowCount);
      Assert.AreEqual(false, d.IsDirty);
      Assert.AreEqual(false, d.IsSuspended);

      Assert.AreEqual("A", d.GetColumnName(0));
      Assert.AreEqual("A", d[0].Name);

      Assert.AreEqual("J", d.GetColumnName(9));
      Assert.AreEqual("J", d[9].Name);


      // Test index to column resolution
      for(int i=0;i<10;i++)
        Assert.AreEqual(cols[i], d[i]);

      // test name to column resolution

      for(int i=0;i<10;i++)
      {
        char name = (char)('A'+i);
        Assert.AreEqual(cols[i], d[name.ToString()],"Column to name resolution of col " + name.ToString());
      }
      // test column to number resolution
      for(int i=0;i<10;i++)
        Assert.AreEqual(i, d.GetColumnNumber(cols[i]));

    }
コード例 #8
0
        /// <summary>
        /// This function searches for patterns like aaa=bbb in the provided string. If it finds such a item, it creates a column named aaa
        /// and stores the value bbb at the same position in it as in the text column.
        /// </summary>
        /// <param name="strg">The string where to search for the patterns described above.</param>
        /// <param name="store">The column collection where to store the newly created columns of properties.</param>
        /// <param name="index">The index into the column where to store the property value.</param>
        public static void ExtractPropertiesFromString(string strg, Altaxo.Data.DataColumnCollection store, int index)
        {
            string pat;

            pat = @"(\S+)=(\S+)";

            var r = new Regex(pat, RegexOptions.Compiled | RegexOptions.IgnoreCase);

            for (Match m = r.Match(strg); m.Success; m = m.NextMatch())
            {
                string propname  = m.Groups[1].ToString();
                string propvalue = m.Groups[2].ToString();

                // System.Diagnostics.Trace.WriteLine("Found the pair " + propname + " : " + propvalue);

                if (!store.ContainsColumn(propname))
                {
                    Altaxo.Data.DataColumn col;
                    if (Altaxo.Serialization.DateTimeParsing.IsDateTime(propvalue))
                    {
                        col = new Altaxo.Data.DateTimeColumn();
                    }
                    else if (Altaxo.Serialization.NumberConversion.IsNumeric(propvalue))
                    {
                        col = new Altaxo.Data.DoubleColumn();
                    }
                    else
                    {
                        col = new Altaxo.Data.TextColumn();
                    }

                    store.Add(col, propname); // add the column to the collection
                }

                // now the column is present we can store the value in it.
                store[propname][index] = new Altaxo.Data.AltaxoVariant(propvalue);
            }
        }
コード例 #9
0
 /// <summary>
 /// Constructor. Besides the table, the current selections must be provided. Only the areas that corresponds to the selections are
 /// serialized. The serialization process has to occur immediately after this constructor, because only a reference
 /// to the table is hold by this object.
 /// </summary>
 /// <param name="collection">The collection to serialize.</param>
 /// <param name="selectedColumns">The selected data columns.</param>
 /// <param name="selectedRows">The selected data rows.</param>
 /// <param name="useOnlySelections">If true, only the selections are serialized. If false and there is no selection, the whole collection is serialized.</param>
 public ClipboardMemento(
   DataColumnCollection collection,
   IAscendingIntegerCollection selectedColumns, 
   IAscendingIntegerCollection selectedRows,
   bool useOnlySelections)
 {
   this._collection          = collection;
   this._selectedColumns     = selectedColumns;
   this._selectedRows        = selectedRows;
   this._useOnlySelections   = useOnlySelections;
 }
コード例 #10
0
ファイル: StatisticCommands.cs プロジェクト: Altaxo/Altaxo
		private static void AppendStatisticalData(DataColumnCollection destinationTable, Data.DoubleColumn colMean, Data.DoubleColumn colSd, Data.DoubleColumn colSe, Data.DoubleColumn colSum, Data.DoubleColumn colSumSqr, Data.DoubleColumn colN, Data.DoubleColumn fracOneSigma, Data.DoubleColumn fracTwoSigma, Data.DoubleColumn fracThreeSigma, DoubleColumn minimum, DoubleColumn maximum)
		{
			destinationTable.EnsureExistence(DefaultMeanColumnName, typeof(DoubleColumn), ColumnKind.V, 0).Append(colMean);
			destinationTable.EnsureExistence(DefaultStandardErrorColumnName, typeof(DoubleColumn), ColumnKind.Err, 0).Append(colSe);
			destinationTable.EnsureExistence(DefaultStandardDeviationColumnName, typeof(DoubleColumn), ColumnKind.V, 0).Append(colSd);
			destinationTable.EnsureExistence(DefaultSumColumnName, typeof(DoubleColumn), ColumnKind.V, 0).Append(colSum);
			destinationTable.EnsureExistence(DefaultSumSqrColumnName, typeof(DoubleColumn), ColumnKind.V, 0).Append(colSumSqr);
			destinationTable.EnsureExistence(DefaultNumberOfItemsColumnName, typeof(DoubleColumn), ColumnKind.V, 0).Append(colN);
			destinationTable.EnsureExistence(DefaultFractionInOneSigmaColumnName, typeof(DoubleColumn), ColumnKind.V, 0).Append(fracOneSigma);
			destinationTable.EnsureExistence(DefaultFractionInTwoSigmaColumnName, typeof(DoubleColumn), ColumnKind.V, 0).Append(fracTwoSigma);
			destinationTable.EnsureExistence(DefaultFractionInThreeSigmaColumnName, typeof(DoubleColumn), ColumnKind.V, 0).Append(fracThreeSigma);
			destinationTable.EnsureExistence(DefaultMinimumColumnName, typeof(DoubleColumn), ColumnKind.V, 0).Append(minimum);
			destinationTable.EnsureExistence(DefaultMaximumColumnName, typeof(DoubleColumn), ColumnKind.V, 0).Append(maximum);
		}
コード例 #11
0
ファイル: StatisticCommands.cs プロジェクト: Altaxo/Altaxo
		/// <summary>
		/// Calculates statistics of selected columns. Creates a new table where the statistical data will be written to.
		/// </summary>
		/// <param name="srctable">Source table.</param>
		/// <param name="selectedColumns">Selected data columns in the source table.</param>
		/// <param name="selectedRows">Selected rows in the source table.</param>
		/// <param name="destinationTable">The table where the statistical results are written to.</param>
		public static void DoStatisticsOnRows(
			this DataColumnCollection srctable,
			IAscendingIntegerCollection selectedColumns,
			IAscendingIntegerCollection selectedRows,
			DataColumnCollection destinationTable
			)
		{
			bool bUseSelectedColumns = (null != selectedColumns && 0 != selectedColumns.Count);
			int numcols = bUseSelectedColumns ? selectedColumns.Count : srctable.ColumnCount;
			if (numcols == 0)
				return; // nothing selected

			bool bUseSelectedRows = (null != selectedRows && 0 != selectedRows.Count);
			int numrows = bUseSelectedRows ? selectedRows.Count : srctable.RowCount;
			if (numrows == 0)
				return;

			Data.DoubleColumn cRows = new DoubleColumn();

			// 1st column is the mean, and holds the sum during the calculation
			Data.DoubleColumn colMean = new Data.DoubleColumn();

			// 2rd column is the standard deviation, and holds the square sum during calculation
			Data.DoubleColumn colSD = new Data.DoubleColumn();

			// 3th column is the standard e (N)
			Data.DoubleColumn colSE = new Data.DoubleColumn();

			// 4th column is the sum
			Data.DoubleColumn colSum = new Data.DoubleColumn();

			// 5th column is the number of items for statistics
			Data.DoubleColumn colNN = new Data.DoubleColumn();

			var colSumSqr = new Data.DoubleColumn();
			var colFracOneSigma = new Data.DoubleColumn();
			var colFracTwoSigma = new Data.DoubleColumn();
			var colFracThreeSigma = new Data.DoubleColumn();
			var colMinimum = new DoubleColumn();
			var colMaximum = new DoubleColumn();

			// first fill the cols c1, c2, c5 with zeros because we want to sum up
			for (int i = 0; i < numrows; i++)
			{
				colSum[i] = 0;
				colSumSqr[i] = 0;
				colNN[i] = 0;
				colMinimum[i] = double.PositiveInfinity;
				colMaximum[i] = double.NegativeInfinity;
			}

			for (int si = 0; si < numcols; si++)
			{
				Altaxo.Data.DataColumn col = bUseSelectedColumns ? srctable[selectedColumns[si]] : srctable[si];
				if (!(col is Altaxo.Data.INumericColumn))
					continue;

				// now do the statistics
				Data.INumericColumn ncol = (Data.INumericColumn)col;
				for (int i = 0; i < numrows; i++)
				{
					int row = bUseSelectedRows ? selectedRows[i] : i;
					cRows[i] = row;

					double val = ncol[row];
					if (Double.IsNaN(val))
						continue;

					colSum[i] += val;
					colSumSqr[i] += val * val;
					colNN[i] += 1;
					colMinimum[i] = Math.Min(colMinimum[i], val);
					colMaximum[i] = Math.Max(colMaximum[i], val);
				}
			} // for all selected columns

			// now calculate the statistics
			for (int i = 0; i < numrows; i++)
			{
				// now fill a new row in the worksheet
				double NN = colNN[i];
				double sum = colSum[i];
				double sumsqr = colSumSqr[i];
				if (NN > 0)
				{
					double mean = sum / NN;
					double ymy0sqr = sumsqr - sum * sum / NN;
					if (ymy0sqr < 0) ymy0sqr = 0; // if this is lesser zero, it is a rounding error, so set it to zero
					double sd = NN > 1 ? Math.Sqrt(ymy0sqr / (NN - 1)) : 0;
					double se = sd / Math.Sqrt(NN);

					colMean[i] = mean; // mean
					colSD[i] = sd;
					colSE[i] = se;
				}
				else
				{
					colMinimum[i] = double.NaN;
					colMaximum[i] = double.NaN;
				}
			} // for all rows

			// calculate fractions

			for (int i = 0; i < numrows; i++)
			{
				int row = bUseSelectedRows ? selectedRows[i] : i;

				double mean = colMean[i];
				double sd = colSD[i];

				// calculate fractions
				double oneSigmaLo = mean - 1 * sd, oneSigmaHi = mean + 1 * sd;
				double twoSigmaLo = mean - 2 * sd, twoSigmaHi = mean + 2 * sd;
				double threeSigmaLo = mean - 3 * sd, threeSigmaHi = mean + 3 * sd;
				int cntOneSigma = 0, cntTwoSigma = 0, cntThreeSigma = 0;

				for (int si = 0; si < numcols; si++)
				{
					Altaxo.Data.DataColumn col = bUseSelectedColumns ? srctable[selectedColumns[si]] : srctable[si];
					if (!(col is Altaxo.Data.INumericColumn))
						continue;

					// now do the statistics
					Data.INumericColumn ncol = (Data.INumericColumn)col;
					double val = ncol[row];
					if (Double.IsNaN(val))
						continue;

					if (Altaxo.Calc.RMath.IsInIntervalCC(val, oneSigmaLo, oneSigmaHi)) ++cntOneSigma;
					if (Altaxo.Calc.RMath.IsInIntervalCC(val, twoSigmaLo, twoSigmaHi)) ++cntTwoSigma;
					if (Altaxo.Calc.RMath.IsInIntervalCC(val, threeSigmaLo, threeSigmaHi)) ++cntThreeSigma;
				}

				colFracOneSigma[i] = cntOneSigma / (double)colNN[i];
				colFracTwoSigma[i] = cntTwoSigma / (double)colNN[i];
				colFracThreeSigma[i] = cntThreeSigma / (double)colNN[i];
			}

			destinationTable.EnsureExistence(DefaultRowNumberColumnName, typeof(DoubleColumn), ColumnKind.X, 0).Append(cRows);
			AppendStatisticalData(destinationTable, colMean, colSD, colSE, colSum, colSumSqr, colNN, colFracOneSigma, colFracTwoSigma, colFracThreeSigma, colMinimum, colMaximum);
		}
コード例 #12
0
ファイル: DataTable.cs プロジェクト: Altaxo/Altaxo
		protected override IEnumerable<Main.DocumentNodeAndName> GetDocumentNodeChildrenWithName()
		{
			if (null != _dataColumns)
				yield return new Main.DocumentNodeAndName(_dataColumns, () => _dataColumns = null, "DataCols");

			if (null != _propertyColumns)
				yield return new Main.DocumentNodeAndName(_propertyColumns, () => _propertyColumns = null, "PropCols");

			if (null != DataSource)
				yield return new Main.DocumentNodeAndName(_tableDataSource, () => _tableDataSource = null, "DataSource");

			if (null != PropertyBag)
				yield return new Main.DocumentNodeAndName(_tableProperties, () => _tableProperties = null, "PropertyBag");

			if (null != _tableScript)
				yield return new Main.DocumentNodeAndName(_tableScript, () => _tableScript = null, "TableScript");

			if (null != _notes)
				yield return new Main.DocumentNodeAndName(_notes, () => _notes = null, "Notes");

			if (null != _dataColumns && null != _dataColumns.ColumnScripts)
				yield return new Main.DocumentNodeAndName(_dataColumns.ColumnScripts, "DataColumnScripts");

			if (null != _propertyColumns && null != _propertyColumns.ColumnScripts)
				yield return new Main.DocumentNodeAndName(_propertyColumns.ColumnScripts, "PropertyColumnScripts");
		}
コード例 #13
0
 /// <summary>
 /// Wrapps a set of <see cref="DataColumn" />s into a writeable matrix so that the matrix rows corresponds to the <see cref="DataColumn" />s.
 /// </summary>
 /// <param name="collection">DataColumnCollection from which to select the data columns that are part of the matrix by their indices.</param>
 /// <param name="selectedColumns">The indices of the data columns in the collection that are part of the matrix. You can subsequently change this parameter without affecting this wrapper.</param>
 /// <param name="selectedRows">Selected rows of the data table that participate in the matrix. Remember that this are the columns of the wrapped matrix. This collection will be cloned here, i.e. you can subsequently change it without affecting this wrapper.</param>
 public static IMatrix ToRowMatrix(Altaxo.Data.DataColumnCollection collection, Altaxo.Collections.IAscendingIntegerCollection selectedColumns, Altaxo.Collections.IAscendingIntegerCollection selectedRows)
 {
     return(new DataColumnToRowMatrixWrapper(collection, selectedColumns, (IAscendingIntegerCollection)selectedRows.Clone()));
 }
コード例 #14
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="collection">DataColumnCollection from which to select the data columns that are part of the matrix by their indices.</param>
 /// <param name="selectedColumns">The indices of the data columns in the collection that are part of the matrix</param>
 /// <param name="selectedRows">Selected rows of the data table that participate in the matrix. Remember that this are the columns of the wrapped matrix. This collection is not cloned here, therefore it must not be subsequently changed!</param>
 public DataColumnToRowMatrixWrapper(Altaxo.Data.DataColumnCollection collection, Altaxo.Collections.IAscendingIntegerCollection selectedColumns, Altaxo.Collections.IAscendingIntegerCollection selectedRows)
     : base(collection, selectedColumns, selectedRows)
 {
 }
コード例 #15
0
    /// <summary>
    /// Copy constructor.
    /// </summary>
    /// <param name="from">The column collection to copy this data column collection from.</param>
    public DataColumnCollection(DataColumnCollection from)
    {
      this.m_LastColumnNameAdded = from.m_LastColumnNameAdded;
      this.m_LastColumnNameGenerated = from.m_LastColumnNameGenerated;

      // Copy all Columns
      for(int i=0;i<from.ColumnCount;i++)
      {
        DataColumn newCol = (DataColumn)from[i].Clone();
        DataColumnInfo newInfo = (DataColumnInfo)from.GetColumnInfo(from[i]).Clone();
        this.Add( newCol, newInfo);
      }
      // Copy all Column scripts
      foreach(System.Collections.DictionaryEntry d in from.ColumnScripts)
      {
        DataColumn srccol = (DataColumn)d.Key; // the original column this script belongs to
        DataColumn destcol = this[srccol.Name]; // the new (cloned) column the script now belongs to
        object destscript = ((ICloneable)d.Value).Clone(); // the cloned script

        // add the cloned script to the own collection
        this.ColumnScripts.Add(destcol,destscript);
      }
    }
コード例 #16
0
ファイル: DataTableWrapper.cs プロジェクト: Altaxo/Altaxo
		/// <summary>
		/// Gets the collection of valid rows from selected columns of a <see cref="DataColumnCollection" />.
		/// </summary>
		/// <param name="table">The collection of data columns.</param>
		/// <param name="selectedCols">The selected columns. An exception is thrown if one of these columns is non numeric.</param>
		/// <returns>An collection of ascending integer values. These values are the indizes of valid numeric rows, i.e. the number of elements in the array which have the value of true.</returns>
		public static AscendingIntegerCollection GetCollectionOfValidNumericRows(DataColumnCollection table, IAscendingIntegerCollection selectedCols)
		{
			int rowCount;
			VerifyAllColumnsNumeric(table, selectedCols, out rowCount);

			return GetCollectionOfValidNumericRows(GetValidNumericRows(table, selectedCols, rowCount));
		}
コード例 #17
0
ファイル: DataTableWrapper.cs プロジェクト: Altaxo/Altaxo
		/// <summary>
		/// Determines which of the rows of a set of columns is truly numeric, i.e. all columns in this row contains a value, which is not double.NaN.
		/// </summary>
		/// <param name="table">The data column collection.</param>
		/// <param name="selectedCols">The indizes of the columns in question into the collection.</param>
		/// <param name="rowCount">The minimum row count of all the selected columns.</param>
		/// <returns>A boolean array. If an element of the array is true at a given index, that row contains valid numeric values in all columns.</returns>
		public static bool[] GetValidNumericRows(DataColumnCollection table, IAscendingIntegerCollection selectedCols, int rowCount)
		{
			// determine the number of valid rows
			bool[] rowValid = new bool[rowCount];
			for (int i = 0; i < rowCount; i++)
				rowValid[i] = true;

			for (int i = 0; i < selectedCols.Count; i++)
			{
				INumericColumn col = (INumericColumn)table[selectedCols[i]];
				for (int j = 0; j < rowCount; j++)
				{
					if (double.IsNaN(col[j]))
						rowValid[j] = false;
				}
			}
			return rowValid;
		}
コード例 #18
0
ファイル: DataTableWrapper.cs プロジェクト: Altaxo/Altaxo
		/// <summary>
		/// Determines if all selected columns are numeric.
		/// </summary>
		/// <param name="table">The data column collection with the columns.</param>
		/// <param name="selectedCols">The index collection of the columns in quest.</param>
		/// <param name="rowCount">Returns the minimum of the row count of all the selected columns. The value is 0 if there is at least one non-numeric column.</param>
		/// <returns>True if all columns are numeric, false otherwise.</returns>
		public static bool AreAllColumnsNumeric(DataColumnCollection table, IAscendingIntegerCollection selectedCols, out int rowCount)
		{
			if (selectedCols.Count == 0)
			{
				rowCount = 0;
				return true;
			}

			rowCount = int.MaxValue;
			for (int i = 0; i < selectedCols.Count; i++)
			{
				if (!(table[selectedCols[i]] is Altaxo.Data.INumericColumn))
				{
					rowCount = 0;
					return false;
				}

				rowCount = Math.Min(rowCount, table[selectedCols[i]].Count);
			}
			return true;
		}
コード例 #19
0
ファイル: DataTableWrapper.cs プロジェクト: Altaxo/Altaxo
		/// <summary>
		/// Verifies that all selected columns are numeric and throws an exception if this is not the case.
		/// </summary>
		/// <param name="table">The data column collection with the columns.</param>
		/// <param name="selectedCols">The index collection of the columns in quest.</param>
		/// <param name="rowCount">Returns the minimum of the row count of all the selected columns. The value is 0 if there is at least one non-numeric column.</param>
		public static void VerifyAllColumnsNumeric(DataColumnCollection table, IAscendingIntegerCollection selectedCols, out int rowCount)
		{
			if (selectedCols.Count == 0)
			{
				rowCount = 0;
				return;
			}

			rowCount = int.MaxValue;
			for (int i = 0; i < selectedCols.Count; i++)
			{
				if (!(table[selectedCols[i]] is Altaxo.Data.INumericColumn))
					throw new ArgumentException(string.Format("The column \"{0}\" is not numeric!", table[selectedCols[i]].Name));

				rowCount = Math.Min(rowCount, table[selectedCols[i]].Count);
			}
		}
コード例 #20
0
ファイル: DataTableWrapper.cs プロジェクト: olesar/Altaxo
 /// <summary>
 /// Wrapps a set of <see cref="DataColumn" />s into a writeable matrix so that the matrix rows corresponds to the <see cref="DataColumn" />s.
 /// </summary>
 /// <param name="collection">DataColumnCollection from which to select the data columns that are part of the matrix by their indices.</param>
 /// <param name="selectedColumns">The indices of the data columns in the collection that are part of the matrix. You can subsequently change this parameter without affecting this wrapper.</param>
 /// <param name="nRows">Number of rows of the data table that participate in the matrix (starting from index 0). Remember that this are the columns of the wrapped matrix.</param>
 public static IMatrix <double> ToRowMatrix(Altaxo.Data.DataColumnCollection collection, Altaxo.Collections.IAscendingIntegerCollection selectedColumns, int nRows)
 {
     return(new DataColumnToRowMatrixWrapper(collection, selectedColumns, Altaxo.Collections.ContiguousIntegerRange.FromStartAndCount(0, nRows)));
 }
コード例 #21
0
ファイル: DataTable.cs プロジェクト: Altaxo/Altaxo
		/// <summary>
		/// Constructor for internal use only. Takes the two DataColumnCollections as Data and Properties. These collections are used directly (not by cloning them).
		/// </summary>
		/// <param name="datacoll">The data columns.</param>
		/// <param name="propcoll">The property columns.</param>
		protected DataTable(DataColumnCollection datacoll, DataColumnCollection propcoll)
		{
			_dataColumns = datacoll;
			_dataColumns.ParentObject = this;
			_dataColumns.ColumnScripts.ParentObject = this;

			_propertyColumns = propcoll;
			_propertyColumns.ParentObject = this; // set the parent of the cloned PropertyColumns
			_propertyColumns.ColumnScripts.ParentObject = this;

			_creationTime = _lastChangeTime = DateTime.UtcNow;
			_notes = new Main.TextBackedConsole() { ParentObject = this };
		}
コード例 #22
0
 public MultivariateLinearFitParameters(DataColumnCollection table, IAscendingIntegerCollection selectedDataColumns)
 {
   _table = table;
   _selectedDataColumns = selectedDataColumns;
 }
コード例 #23
0
      } // end serialization

      public ClipboardMemento(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
      {
        _collection = new DataColumnCollection();

        int numberOfColumns = info.GetInt32("ColumnCount");
        for(int nCol=0;nCol<numberOfColumns;nCol++)
        {
          string name = info.GetString("ColumnName_"+nCol.ToString());
          int    group = info.GetInt32("ColumnGroup_"+nCol.ToString());
          ColumnKind kind = (ColumnKind)info.GetValue("ColumnKind_"+nCol.ToString(),typeof(ColumnKind));

          DataColumn column = (DataColumn)info.GetValue("Column_"+nCol.ToString(),typeof(DataColumn));
        
        
          _collection.Add(column,name,kind,group);
        }
      }
コード例 #24
0
    public static LinearFitBySvd ShowDialogAndRegress(DataColumnCollection table, IAscendingIntegerCollection selectedColumns)
    {
      if(selectedColumns.Count<2)
        return null;

      object paramobject = new MultivariateLinearFitParameters(table,selectedColumns);

      if(!Current.Gui.ShowDialog(ref paramobject,"Multivariate linear fit"))
        return null;

      MultivariateLinearFitParameters parameters = (MultivariateLinearFitParameters)paramobject;

      LinearFitBySvd result =  Regress(parameters, true);

      return result;
    }
コード例 #25
0
		/// <summary>
		/// Checks the content of a matrix area of a table for NaN and infinite values. If such values are found, an <see cref="InvalidOperationException"/> is thrown with a diagnostic message.
		/// </summary>
		/// <param name="table">The table to check.</param>
		/// <param name="participatingRows">The rows participating in the matrix area.</param>
		/// <param name="participatingColumns">The columns participating in the matrix area.</param>
		/// <param name="checkForNaN">If set to <c>true</c>, this function will check for NaN values.</param>
		/// <param name="checkForInfinity">If set to <c>true</c>, this function will check for Infinite values.</param>
		/// <exception cref="System.InvalidOperationException">Is thrown if NaN or Infinite values are found in the matrix area.</exception>
		public static void CheckContentForNaNandInfiniteValues(DataColumnCollection table, IAscendingIntegerCollection participatingRows, IAscendingIntegerCollection participatingColumns, bool checkForNaN, bool checkForInfinity)
		{
			if (!checkForInfinity || checkForNaN)
				return; // nothing to do then

			for (int i = 0; i < participatingColumns.Count; ++i)
			{
				var c = table[participatingColumns[i]];

				for (int j = 0; j < participatingRows.Count; ++j)
				{
					double x = c[participatingRows[j]];

					if (checkForNaN && double.IsNaN(x))
						throw new InvalidOperationException(string.Format("Array value is NaN (Not a Number) at column={0}, row={1}", participatingColumns[i], participatingRows[j]));
					if (checkForInfinity && !(x >= double.MinValue && x <= double.MaxValue))
						throw new InvalidOperationException(string.Format("Array value is not a finite number at column={0}, row={1}", participatingColumns[i], participatingRows[j]));
				}
			}
		}
コード例 #26
0
        /// <summary>
        /// Retrieves the data columns from an Origin table.
        /// </summary>
        /// <param name="wks">The Origin worksheet to retrieve the data from.</param>
        /// <returns>The data columns with the data from the Origin worksheet.</returns>
        public static Altaxo.Data.DataColumnCollection GetDataColumns(this Origin.Worksheet wks)
        {
            var culture = Current.PropertyService.GetValue(Altaxo.Settings.CultureSettings.PropertyKeyDocumentCulture, Altaxo.Main.Services.RuntimePropertyKind.UserAndApplicationAndBuiltin).Culture;

            int nCols = wks.Cols;

            var result = new Altaxo.Data.DataColumnCollection();

            for (int c = 0; c < nCols; c++)
            {
                var srcCol = wks.Columns[c];

                Altaxo.Data.DataColumn destCol = GetAltaxoColumnFromOriginDataFormat(srcCol.DataFormat);

                int groupNumber = -1;

                var altaxoColumnKind = OriginToAltaxoColumnKind(srcCol.Type);

                if (altaxoColumnKind == Altaxo.Data.ColumnKind.X)
                {
                    groupNumber++;
                }

                if (destCol is DoubleColumn)
                {
                    var data = srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_NUMERIC, 0, -1, 0);
                    (destCol as DoubleColumn).Array = (double[])data;
                }
                else if (destCol is DateTimeColumn)
                {
                    var          data            = (double[])srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_NUMERIC, 0, -1, 0);
                    const double refDateAsDouble = 2451910; // this is the number of days in julian calendar belonging to the date below...
                    var          refDate         = DateTime.Parse("2001-01-01", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal);
                    for (int i = data.Length - 1; i >= 0; --i)
                    {
                        destCol[i] = refDate.AddDays(data[i] - refDateAsDouble);
                    }
                }
                else if (destCol is TextColumn && srcCol.DataFormat == COLDATAFORMAT.DF_TEXT_NUMERIC)
                {
                    var data = srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_VARIANT, 0, -1, 0);

                    var destColNum = new Altaxo.Data.DoubleColumn();

                    object[] oarr;
                    if (null != (oarr = data as object[]))
                    {
                        int numberOfNums    = 0;
                        int numberOfObjects = 0;
                        for (int i = 0; i < oarr.Length; ++i)
                        {
                            if (oarr[i] is double)
                            {
                                destColNum[i] = (double)oarr[i];
                                ++numberOfNums;
                            }
                            if (oarr[i] != null)
                            {
                                destCol[i] = string.Format(culture, "{0}", oarr[i]);
                                ++numberOfObjects;
                            }
                        }
                        // if the column consist mostly of numerics, then exchange it with destcol
                        if (numberOfNums >= 0.99 * numberOfObjects || numberOfNums >= numberOfObjects - 2)
                        {
                            destCol = destColNum;
                        }
                    }
                }
                else if (destCol is TextColumn)
                {
                    var      data = srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_TEXT, 0, -1, 0);
                    string[] sarr;
                    object[] oarr;

                    if (null != (sarr = data as string[]))
                    {
                        (destCol as TextColumn).Array = sarr;
                    }
                    else if (null != (oarr = data as object[]))
                    {
                        for (int i = 0; i < oarr.Length; ++i)
                        {
                            if (null != oarr[i])
                            {
                                destCol[i] = string.Format(culture, "{0}", oarr[i]);
                            }
                            else
                            {
                                destCol[i] = null;
                            }
                        }
                    }
                }

                result.Add(destCol, (!string.IsNullOrEmpty(srcCol.LongName) ? srcCol.LongName : srcCol.Name), altaxoColumnKind, Math.Max(0, groupNumber));
            }

            return(result);
        }
コード例 #27
0
ファイル: DataTable.cs プロジェクト: xuchuansheng/GenXSource
 /// <summary>
 /// Get the parent data table of a DataColumnCollection.
 /// </summary>
 /// <param name="colcol">The DataColumnCollection for which the parent table has to be found.</param>
 /// <returns>The parent data table of the DataColumnCollection, or null if it was not found.</returns>
 public static Altaxo.Data.DataTable GetParentDataTableOf(DataColumnCollection colcol)
 {
   if(colcol.ParentObject is DataTable)
     return (DataTable)colcol.ParentObject;
   else
     return (DataTable)Main.DocumentPath.GetRootNodeImplementing(colcol,typeof(DataTable));
 }
コード例 #28
0
 /// <summary>
 /// Wraps a set of <see cref="DataColumn" />s into a readonly matrix so that the matrix columns corresponds to the <see cref="DataColumn" />s But the first column consists of elements with a numerical value of 1. The number of columns
 /// of the resulting matrix is therefore 1 greater than the number of data columns in the argument.
 /// </summary>
 /// <param name="collection">Collection of <see cref="DataColumn" />s.</param>
 /// <param name="selectedColumns">Set set of indices into the collection that are part of the matrix. You can subsequently change this parameter without affecting this wrapper.</param>
 /// <param name="selectedRows">The set of rows that are part of the matrix. This collection will be cloned here, i.e. you can subsequently change it without affecting this wrapper.</param>
 /// <returns>The wrapping read only matrix.</returns>
 /// <remarks>This type of wrapper is usefull for instance for fitting purposes, where an intercept is needed.</remarks>
 public static IROMatrix ToROColumnMatrixWithIntercept(Altaxo.Data.DataColumnCollection collection, Altaxo.Collections.IAscendingIntegerCollection selectedColumns, Altaxo.Collections.IAscendingIntegerCollection selectedRows)
 {
     return(new InterceptPlusDataColumnToColumnROMatrixWrapper(collection, selectedColumns, (IAscendingIntegerCollection)selectedRows.Clone()));
 }
コード例 #29
0
ファイル: DataTable.cs プロジェクト: xuchuansheng/GenXSource
    /// <summary>
    /// Constructor for internal use only. Takes the two DataColumnCollections as Data and Properties. These collections are used directly (not by cloning them).
    /// </summary>
    /// <param name="datacoll">The data columns.</param>
    /// <param name="propcoll">The property columns.</param>
    protected DataTable(DataColumnCollection datacoll, DataColumnCollection propcoll)
    {
      this._dataColumns = datacoll;
      _dataColumns.ParentObject = this;
      _dataColumns.ParentChanged += new Main.ParentChangedEventHandler(this.EhChildParentChanged);

      this._propertyColumns = propcoll;
      this._propertyColumns.ParentObject = this; // set the parent of the cloned PropertyColumns
      _propertyColumns.ParentChanged += new Main.ParentChangedEventHandler(this.EhChildParentChanged);
      _creationTime = _lastChangeTime = DateTime.UtcNow;
    }
コード例 #30
0
 /// <summary>
 /// Wrapps a set of <see cref="DataColumn" />s into a writeable matrix so that the matrix rows corresponds to the <see cref="DataColumn" />s.
 /// </summary>
 /// <param name="collection">DataColumnCollection from which to select the data columns that are part of the matrix by their indices.</param>
 /// <param name="selectedColumns">The indices of the data columns in the collection that are part of the matrix. You can subsequently change this parameter without affecting this wrapper.</param>
 /// <param name="nRows">Number of rows of the data table that participate in the matrix (starting from index 0). Remember that this are the columns of the wrapped matrix.</param>
 public static IMatrix ToRowMatrix(Altaxo.Data.DataColumnCollection collection, Altaxo.Collections.IAscendingIntegerCollection selectedColumns, int nRows)
 {
     return(new DataColumnToRowMatrixWrapper(collection, selectedColumns, new Altaxo.Collections.IntegerRangeAsCollection(0, nRows)));
 }
コード例 #31
0
ファイル: DataTable.cs プロジェクト: xuchuansheng/GenXSource
    /// <summary>
    /// Transpose transpose the table, i.e. exchange columns and rows
    /// this can only work if all columns in the table are of the same type
    /// </summary>
    /// <param name="numberOfDataColumnsChangeToPropertyColumns">Number of data columns that are changed to property columns before transposing the table.</param>
    /// <param name="numberOfPropertyColumnsChangeToDataColumns">Number of property columns that are changed to data columns before transposing the table.</param>
    /// <returns>null if succeeded, error string otherwise</returns>
    public virtual string Transpose(int numberOfDataColumnsChangeToPropertyColumns, int numberOfPropertyColumnsChangeToDataColumns)
    {
    
      numberOfDataColumnsChangeToPropertyColumns = Math.Max(numberOfDataColumnsChangeToPropertyColumns,0);
      numberOfDataColumnsChangeToPropertyColumns = Math.Min(numberOfDataColumnsChangeToPropertyColumns,this.DataColumnCount);

      numberOfPropertyColumnsChangeToDataColumns = Math.Max( numberOfPropertyColumnsChangeToDataColumns, 0);
      numberOfPropertyColumnsChangeToDataColumns = Math.Min(  numberOfPropertyColumnsChangeToDataColumns, this.PropertyColumnCount);

      // first, save the first data columns that are changed to property columns
      Altaxo.Data.DataColumnCollection savedDataColumns = new DataColumnCollection();
      Altaxo.Data.DataColumnCollection savedPropColumns = new DataColumnCollection();

      Altaxo.Collections.IAscendingIntegerCollection savedDataColIndices = new Altaxo.Collections.IntegerRangeAsCollection(0,numberOfDataColumnsChangeToPropertyColumns);
      Altaxo.Collections.IAscendingIntegerCollection savedPropColIndices = new Altaxo.Collections.IntegerRangeAsCollection(0,numberOfPropertyColumnsChangeToDataColumns);
      // store the columns temporarily in another collection and remove them from the original collections
      DataColumns.MoveColumnsTo(savedDataColumns, 0, savedDataColIndices);
      this.PropertyColumns.MoveColumnsTo(savedPropColumns, 0, savedPropColIndices);

      // now transpose the data columns
      _dataColumns.Transpose();

      savedDataColumns.InsertRows(0,numberOfPropertyColumnsChangeToDataColumns); // take offset caused by newly inserted prop columns->data columns into account
      savedDataColumns.MoveColumnsTo(this.PropertyColumns,0, savedDataColIndices);

      savedPropColumns.RemoveRows(0,numberOfDataColumnsChangeToPropertyColumns); // take offset caused by data columns changed to property columns into account
      savedPropColumns.MoveColumnsTo(this.DataColumns,0,savedPropColIndices);

      // now insert both the temporary stored DataColumnCollections at the beginning

      return null; // no error message
    }
コード例 #32
0
 /// <summary>
 /// This fills a row of destination columns (different columns at same index) with values from another column collection. Both collections must have
 /// the same number of columns and a 1:1 match of the column types.
 /// </summary>
 /// <param name="destColumns">The collection of destination columns.</param>
 /// <param name="destRowIndex">The row index of destination columns to fill.</param>
 /// <param name="sourceColumns">The source table's property column collection.</param>
 /// <param name="sourceRowIndex">The row index of the source columns to use.</param>
 static private void FillRow(Altaxo.Data.DataColumn[] destColumns, int destRowIndex, Altaxo.Data.DataColumnCollection sourceColumns, int sourceRowIndex)
 {
     for (int nCol = 0; nCol < sourceColumns.ColumnCount; nCol++)
     {
         destColumns[nCol][destRowIndex] = sourceColumns[nCol][sourceRowIndex];
     }
 }
コード例 #33
0
ファイル: WorksheetActions.cs プロジェクト: Altaxo/Altaxo
		/// <summary>
		/// Retrieves the data columns from an Origin table.
		/// </summary>
		/// <param name="wks">The Origin worksheet to retrieve the data from.</param>
		/// <returns>The data columns with the data from the Origin worksheet.</returns>
		public static Altaxo.Data.DataColumnCollection GetDataColumns(this Origin.Worksheet wks)
		{
			var culture = Current.PropertyService.GetValue(Altaxo.Settings.CultureSettings.PropertyKeyDocumentCulture, Altaxo.Main.Services.RuntimePropertyKind.UserAndApplicationAndBuiltin).Culture;

			int nCols = wks.Cols;

			Altaxo.Data.DataColumnCollection result = new Altaxo.Data.DataColumnCollection();

			for (int c = 0; c < nCols; c++)
			{
				var srcCol = wks.Columns[c];

				Altaxo.Data.DataColumn destCol = GetAltaxoColumnFromOriginDataFormat(srcCol.DataFormat);

				int groupNumber = -1;

				var altaxoColumnKind = OriginToAltaxoColumnKind(srcCol.Type);

				if (altaxoColumnKind == Altaxo.Data.ColumnKind.X)
					groupNumber++;

				if (destCol is DoubleColumn)
				{
					var data = srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_NUMERIC, 0, -1, 0);
					(destCol as DoubleColumn).Array = (double[])data;
				}
				else if (destCol is DateTimeColumn)
				{
					var data = (double[])srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_NUMERIC, 0, -1, 0);
					const double refDateAsDouble = 2451910; // this is the number of days in julian calendar belonging to the date below...
					DateTime refDate = DateTime.Parse("2001-01-01", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeUniversal);
					for (int i = data.Length - 1; i >= 0; --i)
					{
						destCol[i] = refDate.AddDays(data[i] - refDateAsDouble);
					}
				}
				else if (destCol is TextColumn && srcCol.DataFormat == COLDATAFORMAT.DF_TEXT_NUMERIC)
				{
					var data = srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_VARIANT, 0, -1, 0);

					var destColNum = new Altaxo.Data.DoubleColumn();

					object[] oarr;
					if (null != (oarr = data as object[]))
					{
						int numberOfNums = 0;
						int numberOfObjects = 0;
						for (int i = 0; i < oarr.Length; ++i)
						{
							if (oarr[i] is double)
							{
								destColNum[i] = (double)oarr[i];
								++numberOfNums;
							}
							if (oarr[i] != null)
							{
								destCol[i] = string.Format(culture, "{0}", oarr[i]);
								++numberOfObjects;
							}
						}
						// if the column consist mostly of numerics, then exchange it with destcol
						if (numberOfNums >= 0.99 * numberOfObjects || numberOfNums >= numberOfObjects - 2)
						{
							destCol = destColNum;
						}
					}
				}
				else if (destCol is TextColumn)
				{
					var data = srcCol.GetData(Origin.ARRAYDATAFORMAT.ARRAY1D_TEXT, 0, -1, 0);
					string[] sarr;
					object[] oarr;

					if (null != (sarr = data as string[]))
					{
						(destCol as TextColumn).Array = sarr;
					}
					else if (null != (oarr = data as object[]))
					{
						for (int i = 0; i < oarr.Length; ++i)
						{
							if (null != oarr[i])
							{
								destCol[i] = string.Format(culture, "{0}", oarr[i]);
							}
							else
							{
								destCol[i] = null;
							}
						}
					}
				}

				result.Add(destCol, (!string.IsNullOrEmpty(srcCol.LongName) ? srcCol.LongName : srcCol.Name), altaxoColumnKind, Math.Max(0, groupNumber));
			}

			return result;
		}
コード例 #34
0
			public TableNode(DataColumnCollection coll, int firstColumn, int columnCount)
				: base(true)
			{
				_firstColumn = firstColumn;
				_columnCount = columnCount;
				_collection = coll;
				Text = string.Format("Cols {0}-{1}", firstColumn, firstColumn + columnCount - 1);
			}
コード例 #35
0
ファイル: WorksheetActions.cs プロジェクト: Altaxo/Altaxo
		public static DataColumnCollection GetPropertyColumns(this Origin.Worksheet wks)
		{
			if (null == wks)
				throw new ArgumentNullException("wks");

			DataColumnCollection result = new DataColumnCollection();

			// I found no way to ask, if a label column is used or not
			// therefore, we have to try all cells inside the longname, the units and the comments label column

			Dictionary<string, Altaxo.Data.TextColumn> labelCols = new Dictionary<string, Altaxo.Data.TextColumn>();

			DataColumn destLongNameCol = null, destUnitCol = null, destCommentCol = null;
			DataColumn[] paraCol = new DataColumn[20];

			var srcDataCols = wks.Cols;

			for (int i = 0; i < srcDataCols; ++i)
			{
				var srcCol = wks.Columns[i];

				if (!string.IsNullOrEmpty(srcCol.LongName))
				{
					if (null == destLongNameCol)
						destLongNameCol = result.EnsureExistence("LongName", typeof(TextColumn), ColumnKind.V, 0);
					destLongNameCol[i] = srcCol.LongName;
				}

				if (!string.IsNullOrEmpty(srcCol.Units))
				{
					if (null == destUnitCol)
						destUnitCol = result.EnsureExistence("Unit", typeof(TextColumn), ColumnKind.V, 0);
					destUnitCol[i] = srcCol.Units;
				}

				if (!string.IsNullOrEmpty(srcCol.Comments))
				{
					if (null == destCommentCol)
						destCommentCol = result.EnsureExistence("Comments", typeof(TextColumn), ColumnKind.V, 0);
					destCommentCol[i] = srcCol.Comments;
				}

				for (int nPara = 0; nPara <= 11; ++nPara)
				{
					if (!string.IsNullOrEmpty(srcCol.Parameter[nPara]))
					{
						if (null == paraCol[nPara])
							paraCol[nPara] = result.EnsureExistence("Parameter" + nPara.ToString(), typeof(TextColumn), ColumnKind.V, 0);
						paraCol[nPara][i] = srcCol.Parameter[nPara];
					}
				}
			}

			return result;
		}
コード例 #36
0
ファイル: StatisticCommands.cs プロジェクト: Altaxo/Altaxo
		/// <summary>
		/// Create a statistical table for statistics on columns. Property columns are not included in the statistical table.
		/// </summary>
		/// <param name="srcTable"></param>
		/// <param name="selectedColumns"></param>
		/// <returns></returns>
		private static DataTable CreateStatisticalTable(DataColumnCollection srcTable, IAscendingIntegerCollection selectedColumns)
		{
			DataTable result = new DataTable();

			result.DataColumns.Add(new TextColumn(), DefaultColumnNameColumnName, ColumnKind.X, 0);
			AddStatisticColumns(result);
			return result;
		}
コード例 #37
0
ファイル: AsciiImporter.cs プロジェクト: Altaxo/Altaxo
		/// <summary>
		/// Imports an Ascii stream into a table. The import options have to be known already.
		/// </summary>
		/// <param name="dataTable">The table into which to import.</param>
		/// <param name="stream">The stream to read from.</param>
		/// <param name="streamOriginHint">Stream origin hint. If the stream was opened from a file, you should prepend <see cref=" FileUrlStart"/> to the file name.</param>
		/// <param name="importOptions">The Ascii import options. This parameter can be null, or the options can be not fully specified. In this case the method tries to determine the import options by analyzing the stream.</param>
		/// <exception cref="System.ArgumentNullException">
		/// Argument importOptions is null
		/// or
		/// Argument table is null
		/// </exception>
		/// <exception cref="System.ArgumentException">Argument importOptions: importOptions must be fully specified, i.e. all elements of importOptions must be valid. Please run a document analysis in-before to get appropriate values.</exception>
		/// <exception cref="System.ArgumentOutOfRangeException">
		/// Unconsidered AsciiColumnType:  + impopt.RecognizedStructure[i].ToString()
		/// or
		/// Unknown switch case:  + impopt.HeaderLinesDestination.ToString()
		/// </exception>
		private static void InternalImportFromAsciiStream(this DataTable dataTable, Stream stream, string streamOriginHint, ref AsciiImportOptions importOptions)
		{
			if (null == importOptions || !importOptions.IsFullySpecified)
			{
				var analysisOptions = GetDefaultAsciiDocumentAnalysisOptions(dataTable);
				importOptions = AsciiDocumentAnalysis.Analyze(importOptions ?? new AsciiImportOptions(), stream, analysisOptions);
			}

			if (null == importOptions)
				throw new InvalidDataException("Import options could not be determined from the data stream. Possibly, the data stream is empty or it is not an Ascii data stream");
			if (!importOptions.IsFullySpecified)
				throw new InvalidDataException("Import options could not be fully determined from the data stream. Possibly, the data stream is empty or it is not an Ascii data stream");

			string sLine;
			stream.Position = 0; // rewind the stream to the beginning
			StreamReader sr = new StreamReader(stream, System.Text.Encoding.Default, true);
			DataColumnCollection newcols = new DataColumnCollection();

			DataColumnCollection newpropcols = new DataColumnCollection();

			// in case a structure is provided, allocate already the columsn

			if (null != importOptions.RecognizedStructure)
			{
				for (int i = 0; i < importOptions.RecognizedStructure.Count; i++)
				{
					switch (importOptions.RecognizedStructure[i].ColumnType)
					{
						case AsciiColumnType.Double:
							newcols.Add(new DoubleColumn());
							break;

						case AsciiColumnType.Int64:
							newcols.Add(new DoubleColumn());
							break;

						case AsciiColumnType.DateTime:
							newcols.Add(new DateTimeColumn());
							break;

						case AsciiColumnType.Text:
							newcols.Add(new TextColumn());
							break;

						case AsciiColumnType.DBNull:
							newcols.Add(new DBNullColumn());
							break;

						default:
							throw new ArgumentOutOfRangeException("Unconsidered AsciiColumnType: " + importOptions.RecognizedStructure[i].ToString());
					}
				}
			}

			// add also additional property columns if not enough there
			if (importOptions.NumberOfMainHeaderLines.HasValue && importOptions.NumberOfMainHeaderLines.Value > 0) // if there are more than one header line, allocate also property columns
			{
				int toAdd = importOptions.NumberOfMainHeaderLines.Value;
				for (int i = 0; i < toAdd; i++)
					newpropcols.Add(new Data.TextColumn());
			}

			// if decimal separator statistics is provided by impopt, create a number format info object
			System.Globalization.NumberFormatInfo numberFormatInfo = importOptions.NumberFormatCulture.NumberFormat;
			System.Globalization.DateTimeFormatInfo dateTimeFormat = importOptions.DateTimeFormatCulture.DateTimeFormat;

			var notesHeader = new System.Text.StringBuilder();
			notesHeader.Append("Imported");
			if (!string.IsNullOrEmpty(streamOriginHint))
				notesHeader.AppendFormat(" from {0}", streamOriginHint);
			notesHeader.AppendFormat(" at {0}", DateTime.Now);
			notesHeader.AppendLine();

			// first of all, read the header if existent
			for (int i = 0; i < importOptions.NumberOfMainHeaderLines; i++)
			{
				sLine = sr.ReadLine();
				if (null == sLine) break;

				var tokens = new List<string>(importOptions.SeparationStrategy.GetTokens(sLine));
				if (i == importOptions.IndexOfCaptionLine) // is it the column name line
				{
					for (int k = 0; k < tokens.Count; ++k)
					{
						var ttoken = tokens[k].Trim();
						if (!string.IsNullOrEmpty(ttoken))
						{
							string newcolname = newcols.FindUniqueColumnName(ttoken);
							newcols.SetColumnName(k, newcolname);
						}
					}
					continue;
				}

				switch (importOptions.HeaderLinesDestination)
				{
					case AsciiHeaderLinesDestination.Ignore:
						break;

					case AsciiHeaderLinesDestination.ImportToNotes:
						AppendLineToTableNotes(notesHeader, sLine);
						break;

					case AsciiHeaderLinesDestination.ImportToProperties:
						FillPropertyColumnWithTokens(newpropcols[i], tokens);
						break;

					case AsciiHeaderLinesDestination.ImportToPropertiesOrNotes:
						if (tokens.Count == importOptions.RecognizedStructure.Count)
							FillPropertyColumnWithTokens(newpropcols[i], tokens);
						else
							AppendLineToTableNotes(notesHeader, sLine);
						break;

					case AsciiHeaderLinesDestination.ImportToPropertiesAndNotes:
						FillPropertyColumnWithTokens(newpropcols[i], tokens);
						AppendLineToTableNotes(notesHeader, sLine);
						break;

					default:
						throw new ArgumentOutOfRangeException("Unknown switch case: " + importOptions.HeaderLinesDestination.ToString());
				}
			}

			// now the data lines
			for (int i = 0; true; i++)
			{
				sLine = sr.ReadLine();
				if (null == sLine)
					break;

				int maxcolumns = newcols.ColumnCount;

				int k = -1;
				foreach (string token in importOptions.SeparationStrategy.GetTokens(sLine))
				{
					k++;
					if (k >= maxcolumns)
						break;

					if (string.IsNullOrEmpty(token))
						continue;

					if (newcols[k] is DoubleColumn)
					{
						double val;
						if (double.TryParse(token, System.Globalization.NumberStyles.Any, numberFormatInfo, out val))
							((DoubleColumn)newcols[k])[i] = val;
					}
					else if (newcols[k] is DateTimeColumn)
					{
						DateTime val;
						if (DateTime.TryParse(token, dateTimeFormat, System.Globalization.DateTimeStyles.NoCurrentDateDefault, out val))
							((DateTimeColumn)newcols[k])[i] = val;
					}
					else if (newcols[k] is TextColumn)
					{
						((TextColumn)newcols[k])[i] = token.Trim();
					}
					else if (null == newcols[k] || newcols[k] is DBNullColumn)
					{
						bool bConverted = false;
						double val = Double.NaN;
						DateTime valDateTime = DateTime.MinValue;

						try
						{
							val = System.Convert.ToDouble(token);
							bConverted = true;
						}
						catch
						{
						}
						if (bConverted)
						{
							DoubleColumn newc = new DoubleColumn();
							newc[i] = val;
							newcols.Replace(k, newc);
						}
						else
						{
							try
							{
								valDateTime = System.Convert.ToDateTime(token);
								bConverted = true;
							}
							catch
							{
							}
							if (bConverted)
							{
								DateTimeColumn newc = new DateTimeColumn();
								newc[i] = valDateTime;

								newcols.Replace(k, newc);
							}
							else
							{
								TextColumn newc = new TextColumn();
								newc[i] = token;
								newcols.Replace(k, newc);
							}
						} // end outer if null==newcol
					}
				} // end of for all cols
			} // end of for all lines

			// insert the new columns or replace the old ones
			using (var suspendToken = dataTable.SuspendGetToken())
			{
				bool tableWasEmptyBefore = dataTable.DataColumns.ColumnCount == 0;
				for (int i = 0; i < newcols.ColumnCount; i++)
				{
					if (newcols[i] is DBNullColumn) // if the type is undefined, use a new DoubleColumn
						dataTable.DataColumns.CopyOrReplaceOrAdd(i, new DoubleColumn(), newcols.GetColumnName(i));
					else
						dataTable.DataColumns.CopyOrReplaceOrAdd(i, newcols[i], newcols.GetColumnName(i));

					// set the first column as x-column if the table was empty before, and there are more than one column
					if (i == 0 && tableWasEmptyBefore && newcols.ColumnCount > 1)
						dataTable.DataColumns.SetColumnKind(0, ColumnKind.X);
				} // end for loop

				// add the property columns
				for (int i = 0, j = 0; i < newpropcols.ColumnCount; i++)
				{
					if (newpropcols[i].Count == 0)
						continue;
					dataTable.PropCols.CopyOrReplaceOrAdd(j, newpropcols[i], newpropcols.GetColumnName(i));
					++j;
				}

				dataTable.Notes.Write(notesHeader.ToString());

				suspendToken.Dispose();
			}
		} // end of function ImportAscii
コード例 #38
0
ファイル: StatisticCommands.cs プロジェクト: Altaxo/Altaxo
		/// <summary>
		/// Calculates statistics of selected columns. Creates a new table where the statistical data will be written to.
		/// </summary>
		/// <param name="srctable">Source table.</param>
		/// <param name="selectedColumns">Selected data columns in the source table. If the argument is null, all columns will be used.</param>
		/// <param name="selectedRows">Selected rows in the source table. If the argument is null, all rows will be used.</param>
		/// <param name="destinationTable">The table where the statistical results are written to.</param>
		public static void DoStatisticsOnColumns(
			this DataColumnCollection srctable,
			IAscendingIntegerCollection selectedColumns,
			IAscendingIntegerCollection selectedRows,
			DataColumnCollection destinationTable
			)
		{
			bool bUseSelectedColumns = (null != selectedColumns && 0 != selectedColumns.Count);
			int numcols = bUseSelectedColumns ? selectedColumns.Count : srctable.ColumnCount;

			bool bUseSelectedRows = (null != selectedRows && 0 != selectedRows.Count);

			if (numcols == 0)
				return; // nothing selected

			// add a text column and some double columns
			// note: statistics is only possible for numeric columns since
			// otherwise in one column doubles and i.e. dates are mixed, which is not possible

			// 1st column is the name of the column of which the statistics is made
			Data.TextColumn colCol = new Data.TextColumn();

			// 2nd column is the mean
			Data.DoubleColumn colMean = new Data.DoubleColumn();

			// 3rd column is the standard deviation
			Data.DoubleColumn colSd = new Data.DoubleColumn();

			// 4th column is the standard e (N)
			Data.DoubleColumn colSe = new Data.DoubleColumn();

			// 5th column is the sum
			Data.DoubleColumn colSum = new Data.DoubleColumn();

			var colSumSqr = new Data.DoubleColumn();

			// 6th column is the number of items for statistics
			Data.DoubleColumn colN = new Data.DoubleColumn();

			var colFracOneSigma = new Data.DoubleColumn();
			var colFracTwoSigma = new Data.DoubleColumn();
			var colFracThreeSigma = new Data.DoubleColumn();

			var colMinimum = new DoubleColumn(); // Minimum of the values
			var colMaximum = new DoubleColumn(); // Maximum of the values

			int currRow = 0;
			for (int si = 0; si < numcols; si++)
			{
				Altaxo.Data.DataColumn col = bUseSelectedColumns ? srctable[selectedColumns[si]] : srctable[si];
				if (!(col is Altaxo.Data.INumericColumn))
					continue;

				int rows = bUseSelectedRows ? selectedRows.Count : srctable.RowCount;
				if (rows == 0)
					continue;

				// now do the statistics
				Data.INumericColumn ncol = (Data.INumericColumn)col;
				double sum = 0;
				double sumsqr = 0;
				int NN = 0;
				double minimum = double.PositiveInfinity;
				double maximum = double.NegativeInfinity;

				for (int i = 0; i < rows; i++)
				{
					double val = bUseSelectedRows ? ncol[selectedRows[i]] : ncol[i];
					if (Double.IsNaN(val))
						continue;

					NN++;
					sum += val;
					sumsqr += (val * val);
					minimum = Math.Min(minimum, val);
					maximum = Math.Max(maximum, val);
				}
				// now fill a new row in the worksheet

				double mean = sum / NN;
				double ymy0sqr = sumsqr - sum * sum / NN;
				if (ymy0sqr < 0) ymy0sqr = 0; // if this is lesser zero, it is a rounding error, so set it to zero
				double sd = NN > 1 ? Math.Sqrt(ymy0sqr / (NN - 1)) : 0;
				double se = sd / Math.Sqrt(NN);

				// calculate fractions
				double oneSigmaLo = mean - 1 * sd, oneSigmaHi = mean + 1 * sd;
				double twoSigmaLo = mean - 2 * sd, twoSigmaHi = mean + 2 * sd;
				double threeSigmaLo = mean - 3 * sd, threeSigmaHi = mean + 3 * sd;
				int cntOneSigma = 0, cntTwoSigma = 0, cntThreeSigma = 0;

				for (int i = 0; i < rows; i++)
				{
					double val = bUseSelectedRows ? ncol[selectedRows[i]] : ncol[i];
					if (Double.IsNaN(val))
						continue;

					if (Altaxo.Calc.RMath.IsInIntervalCC(val, oneSigmaLo, oneSigmaHi)) ++cntOneSigma;
					if (Altaxo.Calc.RMath.IsInIntervalCC(val, twoSigmaLo, twoSigmaHi)) ++cntTwoSigma;
					if (Altaxo.Calc.RMath.IsInIntervalCC(val, threeSigmaLo, threeSigmaHi)) ++cntThreeSigma;
				}

				if (0 == NN)
				{
					minimum = maximum = double.NaN;
				}

				colCol[currRow] = col.Name;
				colMean[currRow] = mean; // mean
				colSd[currRow] = sd;
				colSe[currRow] = se;
				colSum[currRow] = sum;
				colSumSqr[currRow] = sumsqr;
				colN[currRow] = NN;
				colFracOneSigma[currRow] = cntOneSigma / (double)NN;
				colFracTwoSigma[currRow] = cntTwoSigma / (double)NN;
				colFracThreeSigma[currRow] = cntThreeSigma / (double)NN;
				colMinimum[currRow] = minimum;
				colMaximum[currRow] = maximum;
				currRow++; // for the next column
			} // for all selected columns

			if (currRow != 0)
			{
				destinationTable.EnsureExistence(DefaultColumnNameColumnName, typeof(TextColumn), ColumnKind.X, 0).Append(colCol);
				AppendStatisticalData(destinationTable, colMean, colSd, colSe, colSum, colSumSqr, colN, colFracOneSigma, colFracTwoSigma, colFracThreeSigma, colMinimum, colMaximum);
			}
		}
コード例 #39
0
    /// <summary>
    /// Moves some columns of this collection to another collection-
    /// </summary>
    /// <param name="destination">The destination collection where the columns are moved to.</param>
    /// <param name="destindex">The index in the destination collection where the columns are moved to.</param>
    /// <param name="selectedColumns">The indices of the column of the source collection that are moved.</param>
    public void MoveColumnsTo(DataColumnCollection destination, int destindex, IAscendingIntegerCollection selectedColumns)
    {
      int nOriginalColumnCount = ColumnCount;
      
      int numberMoved = selectedColumns.Count;

      DataColumn[] tmpColumn = new DataColumn[numberMoved];
      DataColumnInfo[] tmpInfo = new DataColumnInfo[numberMoved];
      object[] tmpScript = new object[numberMoved];

      for(int i=0;i<numberMoved;i++)
      {
        tmpColumn[i] = this[selectedColumns[i]];
        tmpInfo[i] = (DataColumnInfo)this.m_ColumnInfo[m_ColumnsByNumber[i]];
        tmpScript[i] = this.m_ColumnScripts[tmpColumn[i]];
      }

      this.RemoveColumns(selectedColumns,false);

      destination.Insert(tmpColumn,tmpInfo,0,true);

      // Move the column scripts also
      for(int i=0; i<numberMoved; i++)
      {
        if(tmpScript[i]!=null)
          destination.m_ColumnScripts.Add(tmpColumn[i],tmpScript[i]);
      }
    }