Beispiel #1
0
        public override async Task <EvaluateNumDataReply> EvaluateNumData(EvaluateNumDataRequest request, ServerCallContext context)
        {
            await _semaphoreSlim.WaitAsync();

            var reply = new EvaluateNumDataReply();

            try
            {
                var numDataColumns = ROpsApi.EvaluateNumData(request.Code);

                reply.Payload = new EvaluateNumDataPayload();

                foreach (var numDataColumn in numDataColumns)
                {
                    var doubleColumn = new DoubleColumn
                    {
                        Name = numDataColumn.Name
                    };
                    doubleColumn.Doubles.Add(numDataColumn.Data);
                    reply.Payload.DoubleColumns.Add(doubleColumn);
                }
            }
            catch (Exception ex)
            {
                reply.Error = PopulateError(ex);
                _logger.LogError(ex, nameof(EvaluateNumData));
            }
            finally
            {
                _semaphoreSlim.Release();
            }

            return(await Task.FromResult(reply));
        }
Beispiel #2
0
        public void TestDouble()
        {
            IColumn column = new DoubleColumn("my_double_field", 7, 4);

            column.NotNull();
            Assert.Equal("`my_double_field` DOUBLE(7, 4) NOT NULL", generator.ToSQL(column));
        }
Beispiel #3
0
        /// <summary>
        /// Fills destination column with values from an original column by help of a fractional index.
        /// </summary>
        /// <param name="destinationColumn">Column to fill. The old data in this column will be cleared before.</param>
        /// <param name="fractionalIndex">Array of fractional indices. Each item points into the originalColumn to that value that should be included in the master column at the item's index.</param>
        /// <param name="originalColumn">Column with the source data.</param>
        public static void SetColumnFromFractionalIndex(
            this DataColumn destinationColumn,
            DoubleColumn fractionalIndex,
            DataColumn originalColumn)
        {
            destinationColumn.Clear();

            for (int i = 0; i < fractionalIndex.Count; i++)
            {
                double fracIdx = fractionalIndex[i];
                int    idxBase = (int)Math.Floor(fracIdx);
                double rel     = fracIdx - idxBase;

                if (0 == rel)
                {
                    destinationColumn[i] = originalColumn[idxBase];
                }
                else
                {
                    try
                    {
                        var firstValue  = originalColumn[idxBase];
                        var secondValue = originalColumn[idxBase + 1];
                        destinationColumn[i] = firstValue + rel * (secondValue - firstValue);
                    }
                    catch (Exception)
                    {
                        destinationColumn[i] = originalColumn[idxBase];
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Imports a Origin OPJ file (tables only) into corresponding new tables in Altaxo.
        /// </summary>
        /// <param name="filename">The file name of the origin OPJ file.</param>
        /// <returns>Null if the import was successfull, or a error message.</returns>
        public static string Import(string filename)
        {
            var opj = new OpjFile(filename);

            opj.Parse();

            // now create corresponding tables in Altaxo

            for (int nspread = 0; nspread < opj.numSpreads(); nspread++)
            {
                // Create a new table
                string tablename = Current.Project.DataTableCollection.FindNewItemName(opj.spreadName(nspread));
                var    table     = new DataTable(tablename);

                int numberOfColumns = opj.numCols(nspread);
                for (int ncol = 0; ncol < numberOfColumns; ncol++)
                {
                    string     colname      = opj.colName(nspread, ncol);
                    string     coltype      = opj.colType(nspread, ncol);
                    int        numberOfRows = opj.numRows(nspread, ncol);
                    ColumnKind kind         = coltype == "X" ? ColumnKind.X : ColumnKind.V;

                    var column = new DoubleColumn(numberOfRows);
                    column.CopyDataFrom(opj.Data(nspread, ncol), numberOfRows);

                    colname = table.DataColumns.FindUniqueColumnName(colname);
                    table.DataColumns.Add(column, colname, kind, 0);
                }

                table.Name = tablename;
                Current.Project.DataTableCollection.Add(table);
                Current.ProjectService.CreateNewWorksheet(table);
            }
            return(null);
        }
Beispiel #5
0
        public static void Interpolation(IWorksheetController ctrl, InterpolationParameters parameters)
        {
            var _columnToGroupNumber = new Dictionary <DataColumn, int>();

            for (int nSel = 0; nSel < ctrl.SelectedDataColumns.Count; nSel++)
            {
                Altaxo.Data.DataColumn yCol = ctrl.DataTable.DataColumns[ctrl.SelectedDataColumns[nSel]];
                Altaxo.Data.DataColumn xCol = ctrl.DataTable.DataColumns.FindXColumnOf(yCol);

                if (!(yCol is INumericColumn))
                {
                    Current.Gui.ErrorMessageBox("The selected column is not numeric!");
                    return;
                }
                if (!(xCol is INumericColumn))
                {
                    Current.Gui.ErrorMessageBox("The x-column of the selected column is not numeric!");
                    return;
                }

                var xRes = new DoubleColumn();
                var yRes = new DoubleColumn();
                if (!_columnToGroupNumber.TryGetValue(xCol, out var newgroup))
                {
                    newgroup = ctrl.DataTable.DataColumns.GetUnusedColumnGroupNumber();
                    ctrl.DataTable.DataColumns.Add(xRes, xCol.Name + ".I", ColumnKind.X, newgroup);
                    _columnToGroupNumber.Add(xCol, newgroup);
                }
                ctrl.DataTable.DataColumns.Add(yRes, yCol.Name + ".I", ColumnKind.V, newgroup);

                Interpolation(xCol, yCol, parameters, xRes, yRes);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Merges two tables by corresponding x-columns.
        /// </summary>
        /// <param name="masterTable">Master table. Values from the slave table will be recalculated to fit the x-values of the master table.</param>
        /// <param name="masterXColumn">The master x-column of the master table.</param>
        /// <param name="slaveTable">The table providing the data for merging into the master table.</param>
        /// <param name="slaveXColumn">The x column of the slave table.</param>
        /// <param name="columnsToMerge">Indices of that columns of the slave table that should be merged into the master table.</param>
        /// <param name="createNewTable">If true, a new table is created as a clone of the master table. The data from the slave table are then merged into that clone. If false,
        /// the data are directly merged into the master table.</param>
        /// <returns>If <c>createNewTable</c> is true, then the newly created table. If false, then the provided master table where the data are merge to.</returns>
        public static DataTable MergeTable(
            this DataTable masterTable, DataColumn masterXColumn,
            DataTable slaveTable, DataColumn slaveXColumn,
            Altaxo.Collections.IAscendingIntegerCollection columnsToMerge,
            bool createNewTable)
        {
            DataTable destinationTable;

            if (createNewTable)
            {
                destinationTable = (DataTable)masterTable.Clone();
            }
            else
            {
                destinationTable = masterTable;
            }

            // create a fractional index column with the same length than the master table
            // that points into the slave table

            DoubleColumn fractIndex = GetFractionalIndex(masterXColumn, slaveXColumn);

            MergeTable(masterTable, fractIndex, slaveTable, columnsToMerge);

            return(destinationTable);
        }
Beispiel #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="columnRe">The real part of the resulting complex vector.</param>
 /// <param name="columnIm">The imaginary part of the resulting complex vector.</param>
 /// <param name="start">Start of the range both in <paramref name="columnRe"/> and <paramref name="columnRe"/> that is wrapped.</param>
 /// <param name="nRows">The number of rows that are part of the wrapping vector.</param>
 public DoubleColumnToComplexDoubleVectorWrapper(DoubleColumn columnRe, DoubleColumn columnIm, int start, int nRows)
 {
     _columnRe = columnRe;
     _columnIm = columnIm;
     _start    = start;
     _rows     = nRows;
 }
Beispiel #8
0
 public DoublePropertyMapping(DoubleColumn column, IMemberAccessor member, int physicalIndex, int logicalIndex)
 {
     this.column   = column;
     Member        = member;
     PhysicalIndex = physicalIndex;
     LogicalIndex  = logicalIndex;
 }
Beispiel #9
0
 public DoublePropertyMapping(DoubleColumn column, IMemberAccessor member, int fileIndex, int workIndex)
 {
     this.column    = column;
     this.member    = member;
     this.FileIndex = fileIndex;
     this.WorkIndex = workIndex;
 }
Beispiel #10
0
 public SumDouble(DoubleColumn column)
 {
     if (object.Equals(null, column))
     {
         throw new NullReferenceException("column cannot be null");
     }
     this.mColumn = column;
 }
Beispiel #11
0
        /// <summary>
        /// This returns a read and writeable complex vector that wraps two <see cref="DoubleColumn" />s.
        /// </summary>
        /// <param name="columnRe">The column that represents the real part of the vector.</param>
        /// <param name="columnIm">The column that represents the imaginary part of the vector.</param>
        /// <returns>An <see cref="IComplexDoubleVector"/>  wrapping the <see cref="DoubleColumn" />s.</returns>
        public static IComplexDoubleVector ToComplexDoubleVector(this DoubleColumn columnRe, DoubleColumn columnIm)
        {
            if (columnIm.Count != columnRe.Count)
            {
                throw new ArgumentException("The provided columns have different length. Thus the resulting vector length is undetermined.");
            }

            return(new DoubleColumnToComplexDoubleVectorWrapper(columnRe, columnIm, 0, columnRe.Count));
        }
        public void TestFromHours_ToDouble()
        {
            var hoursColumn    = new DoubleColumn("Duration");
            var durationColumn = TimeSpanColumn.FromHours(hoursColumn);

            var actual = durationColumn.Format(null, TimeSpan.FromDays(1));

            Assert.AreEqual("24", actual);
        }
        public void TestFromMilliseconds_FromDouble()
        {
            var msColumn       = new DoubleColumn("Duration");
            var durationColumn = TimeSpanColumn.FromMillseconds(msColumn);

            var actual = (TimeSpan)durationColumn.Parse(null, "86400000");

            Assert.AreEqual(TimeSpan.FromDays(1), actual);
        }
        public void TestFromMinutes_ToDouble()
        {
            var minutesColumn  = new DoubleColumn("Duration");
            var durationColumn = TimeSpanColumn.FromMinutes(minutesColumn);

            var actual = durationColumn.Format(null, TimeSpan.FromDays(1));

            Assert.AreEqual("1440", actual);
        }
        public void ZeroElements()
        {
            DoubleColumn d = new DoubleColumn();

            Assert.AreEqual(0, d.Count);
            Assert.AreEqual(false, d.IsDirty);
            Assert.AreEqual(true, d.IsElementEmpty(0));
            Assert.AreEqual(true, d.IsElementEmpty(1));
        }
        public void TestFromDays_ToNull()
        {
            var daysColumn     = new DoubleColumn("Duration");
            var durationColumn = TimeSpanColumn.FromDays(daysColumn);

            var actual = durationColumn.Format(null, null);

            Assert.AreEqual(String.Empty, actual);
        }
        public void TestFromDays_FromNull()
        {
            var daysColumn     = new DoubleColumn("Duration");
            var durationColumn = TimeSpanColumn.FromDays(daysColumn);

            var actual = (TimeSpan?)durationColumn.Parse(null, String.Empty);

            Assert.IsNull(actual);
        }
        public void TestFromSeconds_ToDouble()
        {
            var secondsColumn  = new DoubleColumn("Duration");
            var durationColumn = TimeSpanColumn.FromSeconds(secondsColumn);

            var actual = durationColumn.Format(null, TimeSpan.FromDays(1));

            Assert.AreEqual("86400", actual);
        }
        public void TestFromDays_FromDouble()
        {
            var daysColumn     = new DoubleColumn("Duration");
            var durationColumn = TimeSpanColumn.FromDays(daysColumn);

            var actual = (TimeSpan)durationColumn.Parse(null, "1");

            Assert.AreEqual(TimeSpan.FromDays(1), actual);
        }
Beispiel #20
0
        public static void Interpolation(WorksheetController ctrl)
        {
            if (ctrl.SelectedDataColumns.Count == 0)
            {
                return;
            }

            object paramobject = new InterpolationParameters();

            if (!Current.Gui.ShowDialog(ref paramobject, "Interpolation"))
            {
                return;
            }

            InterpolationParameters parameters = (InterpolationParameters)paramobject;


            Altaxo.Data.DataColumn yCol = ctrl.Doc.DataColumns[ctrl.SelectedDataColumns[0]];
            Altaxo.Data.DataColumn xCol = ctrl.Doc.DataColumns.FindXColumnOf(yCol);

            if (!(yCol is INumericColumn))
            {
                Current.Gui.ErrorMessageBox("The selected column is not numeric!");
                return;
            }
            if (!(xCol is INumericColumn))
            {
                Current.Gui.ErrorMessageBox("The x-column of the selected column is not numeric!");
                return;
            }

            int       rows = Math.Min(xCol.Count, yCol.Count);
            IROVector yVec = DataColumnWrapper.ToROVector((INumericColumn)yCol, rows);
            IROVector xVec = DataColumnWrapper.ToROVector((INumericColumn)xCol, rows);

            parameters.InterpolationInstance.Interpolate(xVec, yVec);

            DoubleColumn xRes = new DoubleColumn();
            DoubleColumn yRes = new DoubleColumn();

            for (int i = 0; i < parameters.NumberOfPoints; i++)
            {
                double r = i / (double)(parameters.NumberOfPoints - 1);
                double x = parameters.XOrg * (1 - r) + parameters.XEnd * (r);
                double y = ((IInterpolationFunction)parameters.InterpolationInstance).GetYOfX(x);
                xRes[i] = x;
                yRes[i] = y;
            }

            int newgroup = ctrl.DataTable.DataColumns.GetUnusedColumnGroupNumber();

            ctrl.DataTable.DataColumns.Add(xRes, xCol.Name + ".I", ColumnKind.X, newgroup);
            ctrl.DataTable.DataColumns.Add(yRes, yCol.Name + ".I", ColumnKind.V, newgroup);
        }
        public void TenEmptyElements()
        {
            DoubleColumn d = new DoubleColumn(10);

            Assert.AreEqual(0, d.Count);
            Assert.AreEqual(false, d.IsDirty);
            for (int i = 0; i < 11; i++)
            {
                Assert.AreEqual(true, d.IsElementEmpty(i));
            }
        }
Beispiel #22
0
        /// <summary>
        /// Determines if column c has monotonically increasing values.
        /// </summary>
        /// <param name="c">Column to test.</param>
        /// <param name="allowNaN">If true, NaN values will ignored. If false, the function will return false if there are NaN values present.</param>
        /// <returns>True if the values are monotonically increasing.</returns>
        public static bool IsMonotonicallyIncreasing(this DoubleColumn c, bool allowNaN)
        {
            if (c.Count == 0)
            {
                return(true);
            }

            int i = 0;

            if (allowNaN)
            {
                for (i = 0; i < c.Count; i++)
                {
                    if (!double.IsNaN(c[i]))
                    {
                        break;
                    }
                }
            }
            if (i >= c.Count)
            {
                return(false);
            }

            double start = c[i];

            if (double.IsNaN(start))
            {
                return(false);
            }

            for (i++; i < c.Count; i++)
            {
                double next = c[i];
                if (double.IsNaN(next))
                {
                    if (allowNaN)
                    {
                        continue;
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (!(start <= next))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #23
0
        /// <summary>
        /// Save the General.FileFormats.Excel settings to the settings file
        /// </summary>
        /// <param name="excelNode">XML-node for the General.FileFormats.Excel settings</param>
        public void Save(XmlNode excelNode)
        {
            string xpath;

            xpath = "./informationLevel";
            SettingsHelper.SetSettingValue(xpath, excelNode, InformationLevel.ToString());

            xpath = "./doubleColumn";
            SettingsHelper.SetSettingValue(xpath, excelNode, DoubleColumn.ToString());

            xpath = "./showDataNotes";
            SettingsHelper.SetSettingValue(xpath, excelNode, ShowDataNotes.ToString());
        }
Beispiel #24
0
    static CreditText ParseDouble(XmlReader reader, GUISkin skin)
    {
        DoubleColumn text = new DoubleColumn();

        reader.ReadToFollowing("dheading");
        text.style = skin.GetStyle(reader.GetAttribute("style"));
        text.text1 = reader.ReadInnerXml();
        reader.ReadToFollowing("dtext");
        text.style2 = skin.GetStyle(reader.GetAttribute("style"));
        text.text2  = reader.ReadInnerXml();
        //Debug.Log ("Parsed Double, Text1 = " + text.text1 + ", Style1 " + text.style.ToString() + ", Text2 = " + text.text2 + ", Style2 = " + text.style2);
        return(text);
    }
Beispiel #25
0
        /// <summary>
        /// Compare the values in a double array with values in a double column and see if they match.
        /// </summary>
        /// <param name="values">An array of double values.</param>
        /// <param name="col">A double column to compare with the double array.</param>
        /// <returns>True if the length of the array is equal to the length of the <see cref="DoubleColumn" /> and the values in
        /// both array match to each other, otherwise false.</returns>
        public static bool ValuesMatch(double[] values, DoubleColumn col)
        {
            if (values.Length != col.Count)
            {
                return(false);
            }

            for (int i = 0; i < values.Length; i++)
            {
                if (col[i] != values[i])
                {
                    return(false);
                }
            }

            return(true);
        }
        public void RowInsertionOneBeforeEnd()
        {
            DoubleColumn d = new DoubleColumn(10);

            Assert.AreEqual(0, d.Count);
            Assert.AreEqual(false, d.IsDirty);

            // set rows 0 to 9 to i
            for (int i = 0; i < 10; i++)
            {
                d[i] = i;
            }
            Assert.AreEqual(10, d.Count);

            // testing parent change notification setting the parent
            MyColumnParent parent = new MyColumnParent();

            parent.ChildChanged = new EventHandler(parent.TestParentAddNotification);
            d.ParentObject      = parent;
            Assert.AreEqual(1, parent.CallCount, "There was no parent add notification");
            parent.Reset();

            parent.Reset();
            parent.ChildChanged = new EventHandler(parent.ExpectingDataChange9To12_NoDecrease);
            // now insert
            d.InsertRows(9, 3);
            Assert.AreEqual(1, parent.CallCount, "There was no data change notification");

            // test the data
            Assert.AreEqual(13, d.Count);

            for (int i = 0; i < 9; i++)
            {
                Assert.AreEqual(i, d[i]);
            }

            Assert.AreEqual(double.NaN, d[9]);
            Assert.AreEqual(double.NaN, d[10]);
            Assert.AreEqual(double.NaN, d[11]);

            for (int i = 12; i < 13; i++)
            {
                Assert.AreEqual(i - 3, d[i]);
            }
        }
Beispiel #27
0
        public void RowInsertionInTheMiddle()
        {
            var d = new DoubleColumn(10);

            Assert.AreEqual(0, d.Count);
            Assert.AreEqual(false, d.IsDirty);

            // set rows 0 to 9 to i
            for (int i = 0; i < 10; i++)
            {
                d[i] = i;
            }
            Assert.AreEqual(10, d.Count);

            // testing parent change notification setting the parent
            var parent = new MyColumnParent();

            parent.ChildChanged = new EventHandler(parent.TestParentAddNotification);
            d.ParentObject      = parent;
            Assert.AreEqual(1, parent.CallCount, "There was no parent add notification");
            parent.Reset();

            parent.Reset();
            parent.ChildChanged = new EventHandler(parent.ExpectingDataChange5To12_NoDecrease);
            // now insert
            d.InsertRows(5, 3);
            Assert.AreEqual(1, parent.CallCount, "There was no data change notification");

            // test the data
            Assert.AreEqual(13, d.Count);

            for (int i = 0; i < 5; i++)
            {
                Assert.AreEqual(i, d[i]);
            }

            Assert.AreEqual(double.NaN, d[5]);
            Assert.AreEqual(double.NaN, d[6]);
            Assert.AreEqual(double.NaN, d[7]);

            for (int i = 8; i < (8 + 5); i++)
            {
                Assert.AreEqual(i - 3, d[i]);
            }
        }
Beispiel #28
0
        public static void GenerateValues(MultivariateLinearFitParameters parameters, LinearFitBySvd fit)
        {
            DataColumn dependentColumn = parameters.Table[parameters.SelectedDataColumns[parameters.DependentColumnIndexIntoSelection]];

            if (parameters.GenerateRegressionValues)
            {
                var col = new DoubleColumn();
                VectorMath.Copy(VectorMath.ToROVector(fit.PredictedValues), DataColumnWrapper.ToVector(col, parameters.SelectedDataRows));
                parameters.Table.Add(col, dependentColumn.Name + "(predicted)", ColumnKind.V, parameters.Table.GetColumnGroup(dependentColumn));
            }

            if (parameters.GenerateResidualValues)
            {
                var col = new DoubleColumn();
                VectorMath.Copy(VectorMath.ToROVector(fit.ResidualValues), DataColumnWrapper.ToVector(col, parameters.SelectedDataRows));
                parameters.Table.Add(col, dependentColumn.Name + "(residual)", ColumnKind.V, parameters.Table.GetColumnGroup(dependentColumn));
            }
        }
Beispiel #29
0
        /// <summary>
        /// Merges two tables by fractional index.
        /// </summary>
        /// <param name="destinationTable">Table to merge into.</param>
        /// <param name="fractionalIndex">Array of fractional indices. Each item points into the slaveTable to the value that should be included in the master column at the item's index.</param>
        /// <param name="slaveTable">The table providing the data for merging into the master table.</param>
        /// <param name="slaveColumnsToMerge">Indices of that columns of the slave table that should be merged into the master table.</param>
        public static void MergeTable(
            this DataTable destinationTable,
            DoubleColumn fractionalIndex,
            DataTable slaveTable,
            IAscendingIntegerCollection slaveColumnsToMerge)
        {
            int destinationTableStartIdx = destinationTable.DataColumnCount;

            destinationTable.AddDataColumnsWithPropertiesFrom(slaveTable, slaveColumnsToMerge);

            for (int i = 0; i < slaveColumnsToMerge.Count; i++)
            {
                int        slaveColIdx = slaveColumnsToMerge[i];
                DataColumn newCol      = destinationTable[destinationTableStartIdx + i];

                SetColumnFromFractionalIndex(newCol, fractionalIndex, slaveTable[slaveColIdx]);
            }
        }
Beispiel #30
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]));
            }
        }
Beispiel #31
0
 public ColumnAdder<DoubleResult> Column(DoubleColumn column)
 {
     return new ColumnAdder<DoubleResult>(this, column);
 }
Beispiel #32
0
 public InitializedTestTable()
     : base("MyTable")
 {
     DateColumn = new DateColumn(this, "MyDateColumn");
     DateTimeColumn = new DateTimeColumn(this, "MyDateTimeColumn");
     DecimalColumn = new DecimalColumn(this, "MyDecimalColumn");
     DoubleColumn = new DoubleColumn(this, "MyDoubleColumn");
     IntColumn = new IntColumn(this, "MyIntColumn");
     StringColumn = new StringColumn(this, "MyStringColumn");
 }
 public DoublePropertyMapping(DoubleColumn column, PropertyInfo property)
 {
     this.column = column;
     this.property = property;
 }