Ejemplo n.º 1
0
 public void TestColumnsFromResultsTables()
 {
     SrmDocument srmDocument = ResultsUtil.DeserializeDocument("silac_1_to_4.sky", GetType());
     using (Database database = new Database())
     {
         database.AddSrmDocument(srmDocument);
         SimpleReport report = new SimpleReport
         {
             Columns = new[]
                                                 {
                                                     new ReportColumn(typeof (DbTransitionResult),
                                                         "PrecursorResult", "PeptideResult", "ProteinResult", "ReplicateName"),
                                                     new ReportColumn(typeof (DbTransition),"Precursor","Peptide","Protein","Name"),
                                                     new ReportColumn(typeof (DbTransition),"Precursor","Peptide","Sequence"),
                                                     new ReportColumn(typeof (DbTransitionResult), "Area"),
                                                 },
         };
         ColumnSet columnSet = ColumnSet.GetTransitionsColumnSet(database.GetSchema());
         TreeView treeView = new TreeView();
         treeView.Nodes.AddRange(columnSet.GetTreeNodes().ToArray());
         List<NodeData> columnInfos;
         columnSet.GetColumnInfos(report, treeView, out columnInfos);
         Assert.AreEqual(report.Columns.Count, columnInfos.Count);
         SimpleReport reportCompare = (SimpleReport)columnSet.GetReport(columnInfos, null);
         Assert.IsTrue(ArrayUtil.EqualsDeep(report.Columns, reportCompare.Columns));
     }
 }
Ejemplo n.º 2
0
        private SimpleReport Pivot(SimpleReport simpleReport, PivotType pivotType)
        {
            var crossTabHeaders = pivotType == null
                ? new ReportColumn[0]
                : pivotType.GetCrosstabHeaders(simpleReport.Columns);
            var groupByColumns = pivotType == null
                ? new ReportColumn[0]
                : pivotType.GetGroupByColumns(simpleReport.Columns);

            foreach (ReportColumn id in crossTabHeaders)
            {
                groupByColumns.Remove(id);
            }
            var normalColumns   = new List <ReportColumn>();
            var crossTabColumns = new List <ReportColumn>();

            foreach (ReportColumn id in simpleReport.Columns)
            {
                Type   table;
                String column;
                Schema.Resolve(id.Table, id.Column, out table, out column);
                if (pivotType != null && pivotType.IsCrosstabValue(table, column))
                {
                    crossTabColumns.Add(id);
                }
                else
                {
                    normalColumns.Add(id);
                }
            }
            if (crossTabColumns.Count == 0)
            {
                return(simpleReport);
            }
            return(new PivotReport
            {
                Columns = normalColumns,
                GroupByColumns = new List <ReportColumn>(groupByColumns),
                CrossTabHeaders = crossTabHeaders,
                CrossTabValues = crossTabColumns
            });
        }
Ejemplo n.º 3
0
 public static Report Load(ReportSpec reportSpec)
 {
     SimpleReport simpleReport;
     if (reportSpec.CrossTabHeaders != null)
     {
         PivotReport pivotReport = new PivotReport
                                       {
                                           GroupByColumns = reportSpec.GroupBy,
                                           CrossTabHeaders = reportSpec.CrossTabHeaders,
                                           CrossTabValues = reportSpec.CrossTabValues
                                       };
         simpleReport = pivotReport;
     }
     else
     {
         simpleReport = new SimpleReport();
     }
     simpleReport.Columns = reportSpec.Select;
     return simpleReport;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a Report for the given set of columns.
        /// The columns are inspected to see which table has to be queried.
        /// Also, a PivotReport will be returned if any columns from a Results table were
        /// selected, and pivotResults is true.
        /// </summary>
        public Report GetReport(List <NodeData> columnInfos, PivotType pivotType)
        {
            // Get the common prefix, and the ancestor table it represents
            Identifier commonPrefix = GetCommonPrefix(columnInfos);
            Table      table        = MostManyTable;
            int        prefixLength = 0;

            if (commonPrefix != null)
            {
                prefixLength = commonPrefix.Parts.Count;
                for (int i = 0; i < prefixLength; i++)
                {
                    table = table.Parent.ParentTable;
                }
            }
            // Calculate the list of ReportColumns from the NodeData
            var displayColumns = new List <ReportColumn>();

            foreach (NodeData columnInfo in columnInfos)
            {
                Identifier identifier = columnInfo.ReportColumn.Column.RemovePrefix(prefixLength);
                if (columnInfo.Results)
                {
                    displayColumns.Add(new ReportColumn(table.ResultsClass, ToResultsIdentifier(identifier)));
                }
                else if (columnInfo.ResultsSummary)
                {
                    displayColumns.Add(new ReportColumn(table.ResultsSummaryClass, ToResultsSummaryIdentifier(identifier)));
                }
                else
                {
                    displayColumns.Add(new ReportColumn(table.PersistentClass, identifier));
                }
            }
            SimpleReport simpleReport = new SimpleReport
            {
                Columns = displayColumns
            };

            return(Pivot(simpleReport, pivotType));
        }
Ejemplo n.º 5
0
        public static Report Load(ReportSpec reportSpec)
        {
            SimpleReport simpleReport;

            if (reportSpec.CrossTabHeaders != null)
            {
                PivotReport pivotReport = new PivotReport
                {
                    GroupByColumns  = reportSpec.GroupBy,
                    CrossTabHeaders = reportSpec.CrossTabHeaders,
                    CrossTabValues  = reportSpec.CrossTabValues
                };
                simpleReport = pivotReport;
            }
            else
            {
                simpleReport = new SimpleReport();
            }
            simpleReport.Columns = reportSpec.Select;
            return(simpleReport);
        }
Ejemplo n.º 6
0
        private SimpleReport Pivot(SimpleReport simpleReport, PivotType pivotType)
        {
            var crossTabHeaders = pivotType == null
                ? new ReportColumn[0]
                : pivotType.GetCrosstabHeaders(simpleReport.Columns);
            var groupByColumns = pivotType == null
                ? new ReportColumn[0]
                : pivotType.GetGroupByColumns(simpleReport.Columns);

            foreach (ReportColumn id in crossTabHeaders)
            {
                groupByColumns.Remove(id);
            }
            var normalColumns = new List<ReportColumn>();
            var crossTabColumns = new List<ReportColumn>();
            foreach (ReportColumn id in simpleReport.Columns)
            {
                Type table;
                String column;
                Schema.Resolve(id.Table, id.Column, out table, out column);
                if (pivotType != null && pivotType.IsCrosstabValue(table, column))
                {
                    crossTabColumns.Add(id);
                }
                else
                {
                    normalColumns.Add(id);
                }
            }
            if (crossTabColumns.Count == 0)
            {
                return simpleReport;
            }
            return new PivotReport
                       {
                           Columns = normalColumns,
                           GroupByColumns = new List<ReportColumn>(groupByColumns),
                           CrossTabHeaders = crossTabHeaders,
                           CrossTabValues = crossTabColumns
                       };
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Returns a Report for the given set of columns.
 /// The columns are inspected to see which table has to be queried.
 /// Also, a PivotReport will be returned if any columns from a Results table were
 /// selected, and pivotResults is true.
 /// </summary>
 public Report GetReport(List<NodeData> columnInfos, PivotType pivotType)
 {
     // Get the common prefix, and the ancestor table it represents
     Identifier commonPrefix = GetCommonPrefix(columnInfos);
     Table table = MostManyTable;
     int prefixLength = 0;
     if (commonPrefix != null)
     {
         prefixLength = commonPrefix.Parts.Count;
         for (int i = 0; i < prefixLength; i++ )
         {
             table = table.Parent.ParentTable;
         }
     }
     // Calculate the list of ReportColumns from the NodeData
     var displayColumns = new List<ReportColumn>();
     foreach(NodeData columnInfo in columnInfos)
     {
         Identifier identifier = columnInfo.ReportColumn.Column.RemovePrefix(prefixLength);
         if (columnInfo.Results)
         {
             displayColumns.Add(new ReportColumn(table.ResultsClass, ToResultsIdentifier(identifier)));
         }
         else if (columnInfo.ResultsSummary)
         {
             displayColumns.Add(new ReportColumn(table.ResultsSummaryClass, ToResultsSummaryIdentifier(identifier)));
         }
         else
         {
             displayColumns.Add(new ReportColumn(table.PersistentClass, identifier));
         }
     }
     SimpleReport simpleReport = new SimpleReport
                    {
                        Columns = displayColumns
                    };
     return Pivot(simpleReport, pivotType);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Used when loading a saved Report, this method figures out what to display in the UI.
        /// The saved Report just has the information necessary to execute the query, which
        /// is the set of columns to query, and paired with the tables to query.
        /// This then needs to be transformed back into which columns in the big tree view were
        /// selected, and whether the "Pivot Results" checkbox was checked.
        /// </summary>
        public void GetColumnInfos(Report report, TreeView treeView, out List <NodeData> columnInfos)
        {
            // CONSIDER: Why have the base class?
            if (!(report is SimpleReport))
            {
                throw new InvalidOperationException(Resources.ColumnSet_GetColumnInfos_Unexpected_report_type);
            }
            SimpleReport simpleReport = (SimpleReport)report;

            columnInfos = new List <NodeData>();
            var allColumns  = new List <ReportColumn>(simpleReport.Columns);
            var pivotReport = simpleReport as PivotReport;

            if (pivotReport != null)
            {
                allColumns.AddRange(pivotReport.CrossTabValues);
            }
            if (allColumns.Count == 0)
            {
                return;
            }
            var allTables = new HashSet <Type>(from reportColumn in allColumns
                                               select reportColumn.Table);

            Table      table  = MostManyTable;
            Identifier prefix = null;

            while (table != null)
            {
                if (allTables.Contains(table.PersistentClass) ||
                    allTables.Contains(table.ResultsClass) ||
                    allTables.Contains(table.ResultsSummaryClass))
                {
                    break;
                }
                if (table.Parent == null)
                {
                    string tableNames = string.Join(", ", (from reportTable in allTables // Not L10N
                                                           select reportTable.ToString()).ToArray());
                    throw new InvalidDataException(string.Format(Resources.ColumnSet_GetColumnInfos_Unable_to_find_table_for__0_, tableNames));
                }
                table  = table.Parent.ParentTable;
                prefix = new Identifier(prefix, table.Name);
            }

            foreach (var unqualifiedId in allColumns)
            {
                Identifier identifier;
                TableType  type = ReportColumn.GetTableType(unqualifiedId.Table);
                switch (type)
                {
                case TableType.result:
                    identifier = JoinIds(prefix, unqualifiedId.Column, ToResultsIdentifier);
                    break;

                case TableType.summary:
                    identifier = JoinIds(prefix, unqualifiedId.Column, ToResultsSummaryIdentifier);
                    break;

                default:
                    identifier = JoinIds(prefix, unqualifiedId.Column);
                    break;
                }

                columnInfos.Add(FindNodeData(treeView, type, identifier));
            }
        }