/// <summary> /// Fills (or refills) the data. The data source is represented by this instance, the destination table is provided in the argument <paramref name="destinationTable" />. /// </summary> /// <param name="destinationTable">The destination table.</param> public void FillData(Data.DataTable destinationTable) { if (null == destinationTable) { throw new ArgumentNullException("destinationTable"); } int reentrancyCount = Interlocked.Increment(ref _updateReentrancyCount); if (1 == reentrancyCount) { try { using (var token = destinationTable.SuspendGetToken()) { var tableConnector = new AltaxoTableConnector(destinationTable); _dataQuery.ReadDataFromOleDbConnection(tableConnector.ReadAction); } } finally { Interlocked.Decrement(ref _updateReentrancyCount); } } }
private IGPlotItem CreatePlotItem(string tablename, string columnname) { // create a new plotassociation from the column // first, get the y column from table and name Data.DataTable tab = Current.Project.DataTableCollection[tablename]; if (null != tab) { Data.DataColumn ycol = tab[columnname]; if (null != ycol) { Data.DataColumn xcol = tab.DataColumns.FindXColumnOf(ycol); XYColumnPlotItem result; if (null == xcol) { result = new XYColumnPlotItem(new XYColumnPlotData(new Altaxo.Data.IndexerColumn(), ycol), new G2DPlotStyleCollection(LineScatterPlotStyleKind.Scatter)); } else { result = new XYColumnPlotItem(new XYColumnPlotData(xcol, ycol), new G2DPlotStyleCollection(LineScatterPlotStyleKind.LineAndScatter)); } return(result); } } return(null); }
public void SetElements(bool bInit) { if (bInit) { m_xCol = m_PlotAssociation.XColumn; m_yCol = m_PlotAssociation.YColumn; m_labelCol = m_PlotAssociation.LabelColumn; m_PlotRange_From = m_PlotAssociation.PlotRangeStart; m_PlotRange_To = m_PlotAssociation.PlotRangeLength == int.MaxValue ? int.MaxValue : m_PlotAssociation.PlotRangeStart + m_PlotAssociation.PlotRangeLength - 1; CalcMaxPossiblePlotRangeTo(); } if (null != View) { string[] tables = Current.Project.DataTableCollection.GetSortedTableNames(); Data.DataTable t1 = Data.DataTable.GetParentDataTableOf(m_xCol as Main.IDocumentNode); Data.DataTable t2 = Data.DataTable.GetParentDataTableOf(m_yCol as Main.IDocumentNode); Data.DataTable tg = null; if (t1 != null && t2 != null && t1 == t2) { tg = t1; } else if (t1 == null) { tg = t2; } else if (t2 == null) { tg = t1; } int seltable = -1; if (tg != null) { seltable = Array.IndexOf(tables, tg.Name); } View.Tables_Initialize(tables, seltable); if (seltable >= 0) { string[] columns = Current.Project.DataTableCollection[tables[seltable]].DataColumns.GetColumnNames(); View.Columns_Initialize(columns, -1); } else { View.Columns_Initialize(new string[] {}, -1); } View.XColumn_Initialize(m_xCol == null ? String.Empty : m_xCol.FullName); View.YColumn_Initialize(m_yCol == null ? String.Empty : m_yCol.FullName); View.PlotRangeFrom_Initialize(m_PlotRange_From); CalcMaxPossiblePlotRangeTo(); } }
private string GetName(object obj) { string result = string.Empty; // first of all, retrieve the actual name var mylayer = obj as HostLayer; if (null == mylayer) return result; var layer = mylayer as XYPlotLayer; if (_layerNumber >= 0 && mylayer.SiblingLayers != null && _layerNumber < mylayer.SiblingLayers.Count) layer = mylayer.SiblingLayers[_layerNumber] as XYPlotLayer; if (null == layer) return result; IGPlotItem pa = null; if (_plotNumber < layer.PlotItems.Flattened.Length) { pa = layer.PlotItems.Flattened[_plotNumber]; } if (pa != null) { result = pa.GetName(0); if (_plotLabelStyle != null && !_plotLabelStyleIsPropColName && pa is XYColumnPlotItem) { XYColumnPlotItemLabelTextStyle style = XYColumnPlotItemLabelTextStyle.YS; try { style = (XYColumnPlotItemLabelTextStyle)Enum.Parse(typeof(XYColumnPlotItemLabelTextStyle), _plotLabelStyle, true); } catch (Exception) { } result = ((XYColumnPlotItem)pa).GetName(style); } if (_plotLabelStyleIsPropColName && _plotLabelStyle != null && pa is XYColumnPlotItem) { XYColumnPlotData pb = ((XYColumnPlotItem)pa).Data; Data.DataTable tbl = null; if (pb.YColumn is Data.DataColumn) tbl = Data.DataTable.GetParentDataTableOf((Data.DataColumn)pb.YColumn); if (tbl != null) { int colNumber = tbl.DataColumns.GetColumnNumber((Data.DataColumn)pb.YColumn); if (tbl.PropertyColumns.ContainsColumn(_plotLabelStyle)) result = tbl.PropertyColumns[_plotLabelStyle][colNumber].ToString(); } } } return result; }
public void EhView_DataAvailableBeforeExpand(NGTreeNode node) { Data.DataTable dt = Current.Project.DataTableCollection[node.Text]; if (null != dt) { node.Nodes.Clear(); NGTreeNode[] toadd = new NGTreeNode[dt.DataColumns.ColumnCount]; for (int i = 0; i < toadd.Length; i++) { toadd[i] = new NGTreeNode(dt[i].Name); } node.Nodes.AddRange(toadd); } }
/// <summary> /// JSON转DataSet /// </summary> /// <param name="Json">JSON串</param> /// <returns>DataSet</returns> public static Data.DataSet JsonToDataSet(string Json) { try { Data.DataSet ds = new Data.DataSet(); JavaScriptSerializer JSS = new JavaScriptSerializer(); object obj = JSS.DeserializeObject(Json); Dictionary <string, object> datajson = (Dictionary <string, object>)obj; foreach (var item in datajson) { Data.DataTable dt = new Data.DataTable(item.Key); object[] rows = (object[])item.Value; foreach (var row in rows) { Dictionary <string, object> val = (Dictionary <string, object>)row; Data.DataRow dr = dt.NewRow(); foreach (KeyValuePair <string, object> sss in val) { if (!dt.Columns.Contains(sss.Key)) { dt.Columns.Add(sss.Key.ToString()); dr[sss.Key] = sss.Value; } else { dr[sss.Key] = sss.Value; } } dt.Rows.Add(dr); } ds.Tables.Add(dt); } return(ds); } catch { return(null); } }
/// <summary> /// Reorders the columns so that they can be copyied into an Origin table. /// </summary> /// <param name="table">The table to reorder.</param> public static void ReorderColumnsInTableForCompatibilityWithOrigin(Data.DataTable table) { var groupBegin = new Dictionary <int, Data.DataColumn>(); var groupEnd = new Dictionary <int, Data.DataColumn>(); for (int i = 0; i < table.DataColumnCount; i++) { var currentCol = table[i]; int currentGroup = table.DataColumns.GetColumnGroup(i); if (!groupBegin.ContainsKey(currentGroup)) { groupBegin.Add(currentGroup, currentCol); groupEnd.Add(currentGroup, currentCol); } var currentKind = table.DataColumns.GetColumnKind(i); // if the column is a x-column, then move it to the begin of the group if (currentKind == Altaxo.Data.ColumnKind.X && !object.ReferenceEquals(currentCol, groupBegin[currentGroup])) { int destIndex = table.DataColumns.GetColumnNumber(groupBegin[currentGroup]); table.ChangeColumnPosition(Collections.ContiguousIntegerRange.FromStartAndCount(i, 1), destIndex); groupBegin[currentGroup] = currentCol; continue; } // if the column is away from the rest of the group, move it to the end of the group int lastIndex = table.DataColumns.GetColumnNumber(groupEnd[currentGroup]); if (i > 1 + lastIndex) { int destIndex = 1 + lastIndex; table.ChangeColumnPosition(Collections.ContiguousIntegerRange.FromStartAndCount(i, 1), destIndex); groupEnd[currentGroup] = currentCol; continue; } groupEnd[currentGroup] = currentCol; } }
public void EhView_BeforeExpand(TreeNode node) { TreeNode rootNode = GetRootNode(node); if (rootNode.Tag is DataTableCollection) { if (node.Tag is DataTableCollection) { node.Nodes.Clear(); TreeNode[] toadd = new TreeNode[Current.Project.DataTableCollection.Count]; int i = 0; foreach (DataTable table in Current.Project.DataTableCollection) { toadd[i] = new TreeNode(table.Name, new TreeNode[1] { new TreeNode() }); toadd[i].Tag = table; i++; } node.Nodes.AddRange(toadd); return; } else if (node.Tag is DataTable) { Data.DataTable dt = (DataTable)node.Tag; node.Nodes.Clear(); TreeNode[] toadd = new TreeNode[dt.DataColumns.ColumnCount]; for (int i = 0; i < toadd.Length; i++) { toadd[i] = new TreeNode(dt[i].Name); toadd[i].Tag = dt[i]; } node.Nodes.AddRange(toadd); return; } } }
public static Data.DataTable ToDataTable([NotNull] this IEnumerable <BlockAttribute> blockAtts, string name) { var dTable = new Data.DataTable(name); dTable.Columns.Add("Name", typeof(string)); dTable.Columns.Add("Quantity", typeof(int)); blockAtts .GroupBy(blk => blk, (blk, blks) => new { Block = blk, Count = blks.Count() }, new BlockAttributeEqualityComparer()) .Iterate(row => { var dRow = dTable.Rows.Add(row.Block.Name, row.Count); row.Block.Attributes.Iterate(att => { if (!dTable.Columns.Contains(att.Key)) { dTable.Columns.Add(att.Key); } dRow[att.Key] = att.Value; }); }); return(dTable); }
/// <summary> /// Tests if column reordering is neccessary in order to put a table to origin. Column reordering is neccessary if the table contains more than /// one column group, and the x column of every column group is not the first column. Origin only supports table with multiple groups if the first column /// of every group is the x-column. /// </summary> /// <param name="table">The table to test.</param> /// <returns>True if column reodering is neccessary, false otherwise.</returns> public static bool IsColumnReorderingNeccessaryForPuttingTableToOrigin(Data.DataTable table) { // Testen, wieviele Gruppen var groupColumns = new Dictionary <int, int>(); // counts the number of columns per group for (int i = 0; i < table.DataColumnCount; i++) { int currentGroup = table.DataColumns.GetColumnGroup(i); if (groupColumns.ContainsKey(currentGroup)) { groupColumns[currentGroup] += 1; } else { groupColumns.Add(currentGroup, 1); } var currentKind = table.DataColumns.GetColumnKind(i); if (groupColumns.Count > 1 && groupColumns[currentGroup] > 1) { if (currentKind == Altaxo.Data.ColumnKind.X) { return(true); } if (currentGroup != table.DataColumns.GetColumnGroup(i - 1)) { return(true); } } } return(false); }
public Settings() { _settings = new Data.DataTable(TableName, DirectoryPath, FileName, FieldNames); }
public static void StatisticsOnColumns( Altaxo.AltaxoDocument mainDocument, Altaxo.Data.DataTable srctable, IAscendingIntegerCollection selectedColumns, IAscendingIntegerCollection selectedRows ) { bool bUseSelectedColumns = (null != selectedColumns && 0 != selectedColumns.Count); int numcols = bUseSelectedColumns ? selectedColumns.Count : srctable.DataColumns.ColumnCount; bool bUseSelectedRows = (null != selectedRows && 0 != selectedRows.Count); if (numcols == 0) { return; // nothing selected } Data.DataTable table = null; // the created table // 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(); // 6th column is the number of items for statistics Data.DoubleColumn colN = new Data.DoubleColumn(); 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.DataColumns.RowCount; if (rows == 0) { continue; } // now do the statistics Data.INumericColumn ncol = (Data.INumericColumn)col; double sum = 0; double sumsqr = 0; int NN = 0; 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); } // now fill a new row in the worksheet 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); colCol[currRow] = col.Name; colMean[currRow] = mean; // mean colSd[currRow] = sd; colSe[currRow] = se; colSum[currRow] = sum; colN[currRow] = NN; currRow++; // for the next column } } // for all selected columns if (currRow != 0) { table = new Altaxo.Data.DataTable("Statistics of " + srctable.Name); table.DataColumns.Add(colCol, "Col", Altaxo.Data.ColumnKind.X); // new : add a copy of all property columns; can be usefull for (int i = 0; i < srctable.PropertyColumnCount; i++) { DataColumn originalColumn = srctable.PropertyColumns[i]; DataColumn clonedColumn = (DataColumn)originalColumn.Clone(); clonedColumn.Clear(); for (int si = 0; si < numcols; si++) { int idx = bUseSelectedColumns ? selectedColumns[si] : si; clonedColumn[si] = originalColumn[idx]; } table.DataColumns.Add(clonedColumn, srctable.PropertyColumns.GetColumnName(i), srctable.PropertyColumns.GetColumnKind(i), srctable.PropertyColumns.GetColumnGroup(i)); } table.DataColumns.Add(colMean, "Mean"); table.DataColumns.Add(colSd, "Sd"); table.DataColumns.Add(colSe, "Se"); table.DataColumns.Add(colSum, "Sum"); table.DataColumns.Add(colN, "N"); mainDocument.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); } }