예제 #1
0
        /// <summary>
        /// Copy ExportParms members to ResultsFormat
        /// </summary>
        /// <param name="ep"></param>

        public void CopyFromExportParms(ExportParms ep)
        {
            QueryId           = ep.QueryId;
            OutputDestination = ep.OutputDestination;
            RunInBackground   = ep.RunInBackground;

            ExportFileFormat        = ep.ExportFileFormat;
            OutputFileName          = ep.OutputFileName;
            OutputFileName2         = ep.OutputFileName2;
            DuplicateKeyTableValues = ep.DuplicateKeyValues;

            if (ep.QualifiedNumberSplit != QnfEnum.Undefined)
            {
                QualifiedNumberSplit = ep.QualifiedNumberSplit;
            }

            ExportStructureFormat = ep.ExportStructureFormat;
            StructureFlags        = ep.StructureFlags;
            FixedHeightStructures = ep.FixedHeightStructures;
            ColumnNameFormat      = ep.ColumnNameFormat;
            IncludeDataTypes      = ep.IncludeDataTypes;
            OpenMode       = ep.OpenMode;
            ViewStructures = ep.ViewStructures;

            return;
        }
예제 #2
0
        /// <summary>
        /// Build the Qm, DataTable, etc derived from the root query
        /// </summary>

        internal QueryManager BuildAssayResultsHeatMapSubqueryResults()
        {
            Query        rootQuery = BaseQuery.Root;                         // get root query
            QueryManager rootQm    = rootQuery.QueryManager as QueryManager; // and assoc manager

            AssayHeatmapProperties p = AssayHeatmapProperties;

            Query subQuery = null;             // the assay results heat map query

            if (BaseQuery.Parent != null)      // is Query a subQuery
            {
                subQuery = BaseQuery;
                QueryManager.RemoveSubQuery(subQuery, false, false);                 // remove any existing subquery but not assoc views
            }

            OutputDest   outputDest = OutputDest.Grid; // fix later
            QueryManager sqm        =                  // summarize root data
                                      rootQm.DataTableManager.Summarize(p.SumLevel, p.SumMethod, p.ColsToSum, outputDest, null);

            subQuery = sqm.Query;               // this is the new query and associated data

            rootQuery.Subqueries.Add(subQuery); // add subquery to root
            subQuery.Parent = rootQuery;        // link subquery to parent query
            BaseQuery       = subQuery;         // link view to subquery
            return(sqm);
        }
예제 #3
0
        /// <summary>
        /// Construct with supplied QueryManager & dest
        /// </summary>

        public ResultsFormat(QueryManager qm, OutputDest outputDest)
        {
            QueryManager      = qm;
            OutputDestination = outputDest;
            qm.ResultsFormat  = this;
            return;
        }
예제 #4
0
        /// <summary>
        /// Setup subquery with and QueryManger and execute the search step with the proper set of results keys from the parent query
        /// </summary>
        /// <param name="sq"></param>
        /// <param name="view"></param>
        /// <returns></returns>

        QueryManager SetupAndExecuteSecondaryQuery(
            Query sq,
            ResultsViewProps view)
        {
            //sq.ResultKeys = Qm.DataTableManager.ResultsKeys;
            //sq.UseResultKeys = true;

            QueryEngine   qe = new QueryEngine();
            Query         nq;
            List <string> resultKeys = qe.TransformAndExecuteQuery(sq, out nq);

            if (nq != null)
            {
                sq = nq;                         // if modified then replace original query and QE with the new ones
            }
            QueryManager sqm        = new QueryManager();
            OutputDest   outputDest = OutputDest.WinForms;

            QueryExec.InitializeQueryManager(sqm, sq, outputDest, qe, resultKeys);
            DataTableManager dtm = sqm.DataTableManager;

            sqm.QueryResultsControl = Qrc;             // same query results control as us
            //sq.Parent = Qm.Query; // set parent of subQuery;

            return(sqm);
        }
예제 #5
0
        /// <summary>
        /// Run Query & return any error message
        /// </summary>
        /// <param name="query"></param>
        /// <param name="queryDest"></param>
        /// <param name="outputFormContext"></param>
        /// <param name="browseExistingResults">If true browse existing results</param>
        /// <param name="suppressNoDataMessage"></param>
        /// <returns>Command command or an error message</command></returns>

        public static string RunQuery(
            Query query,
            OutputDest outputDest,
            OutputFormContext outputFormContext,
            ExitingQueryResultsDelegate exitingQueryResultsCallBack = null,
            bool browseExistingResults = false,
            bool suppressNoDataMessage = false
            )
        {
            ResultsFormat rf = new ResultsFormat();

            rf.OutputDestination = outputDest;
            rf.OutputFormContext = outputFormContext;
            rf.CustomExitingQueryResultsCallback = exitingQueryResultsCallBack;
            rf.SuppressNoDataMessage             = suppressNoDataMessage;

            string response = RunQuery2(query, rf, browseExistingResults);

            query.UseResultKeys = false;             // turn off use of keys

            if (response != "" && !response.ToLower().StartsWith("command") && !suppressNoDataMessage)
            {
                MessageBoxMx.Show(
                    response, UmlautMobius.String,
                    MessageBoxButtons.OK, MessageBoxIcon.Information);

                response = "Command EditQuery";
            }

            return(response);
        }
예제 #6
0
        /// <summary>
        /// Run query using supplied OutputDest displaying any error message
        /// </summary>
        /// <param name="query"></param>
        /// <param name="outputDest"></param>
        /// <returns></returns>

        public static string RunQuery(
            Query query,
            OutputDest outputDest)
        {
            try
            {
                bool browseExistingResults = QbUtil.BrowseExistingDataTable(query);
                return(RunQuery(query, outputDest, OutputFormContext.Session, null, browseExistingResults));
            }

            catch (UserQueryException ex)
            {             // just show message
                Progress.Hide();
                MessageBoxMx.ShowError(ex.Message);
                return("");
            }

            catch (Exception ex)
            {             // non-standard query exception, provide more detail
                Progress.Hide();
                string msg = DebugLog.FormatExceptionMessage(ex);

                if (!Lex.Contains(msg, "QueryLogged:"))                 // exception & query
                {
                    QueryEngine.LogExceptionAndSerializedQuery(msg, query);
                }
                else
                {
                    ServicesLog.Message(msg);                  // just log exception
                }
                MessageBoxMx.ShowError("Unexpected Exception\n\n" + msg);
                return("");
            }
        }
예제 #7
0
        /// <summary>
        /// Build the data table of unpivoted results
        /// </summary>
        /// <param name="includeActivityClass"></param>
        /// <returns></returns>

        internal bool BuildUnpivotedResults(
            bool includeActivityClass)
        {
            int fi;

            DialogResult dr = Qm.DataTableManager.CompleteRetrieval();

            if (dr == DialogResult.Cancel)
            {
                return(false);
            }

            DataIncludesDates = false;

            int tables = 0, tablesWithDates = 0;             // see what percentage of tables have dates

            foreach (ResultsTable rt in Rf.Tables)
            {
                for (fi = 0; fi < rt.Fields.Count; fi++)
                {
                    if (fi == 1)
                    {
                        tables++;                              // count if more that just key field
                    }
                    ResultsField rfld = rt.Fields[fi];
                    if (rfld.MetaColumn.DataType == MetaColumnType.Date)
                    {
                        tablesWithDates++;
                        break;
                    }
                }

                if (fi < rt.Fields.Count)
                {
                    break;
                }
            }

            if (tables > 0 && (float)tablesWithDates / tables >= .5)
            {
                DataIncludesDates = true;
            }

            SetupActivityClassCondFormat();

            if (Math.Sqrt(4) == 4)             // todo: determine when to do this
            {
                AssayHeatmapProperties p          = AssayHeatmapProperties;
                OutputDest             outputDest = OutputDest.WinForms;
                QueryManager           sqm        = Qm.DataTableManager.Summarize(p.SumLevel, p.SumMethod, p.ColsToSum, outputDest, null);
            }

            //string name = rootQuery.UserObject.Name; // (don't change name of base query)
            //if (!Lex.StartsWith(name, "Pivot View of "))
            //  name = "Pivot View of " + name;
            //Qm.Query.UserObject.Name = name;

            return(true);
        }
예제 #8
0
/// <summary>
/// Setup the QueryManager members for the specified query
/// </summary>
/// <param name="q"></param>
/// <param name="outputDest"></param>
/// <param name="qe"></param>
/// <param name="resultsKeys"></param>

        public void Initialize(
            Query q,
            OutputDest outputDest,
            QueryEngine qe,
            List <string> resultsKeys)
        {
            ResultsFormat rf = new ResultsFormat(null, outputDest);

            Initialize(q, rf, qe, resultsKeys);
            return;
        }
예제 #9
0
/// <summary>
/// Summarize the current data set producing one row per key value (e.g. CompoundId)
/// </summary>
/// <param name="sumMethod"></param>
/// <param name="outputFormat"></param>
/// <param name="targetMap"></param>
/// <returns></returns>

        public QueryManager Summarize(
            TargetAssaySummarizationLevel sumLevel,
            SummarizationType sumMethod,
            ColumnsToTransform colsToSumm,
            OutputDest outputDest,
            TargetMap targetMap)
        {
            //if (UnpivotedResults) return SummarizeUnpivoted(sumLevel, sumMethod, outputDest, targetMap);
            //else return SummarizePivoted(sumLevel, sumMethod, colsToSumm, outputDest, targetMap);
            throw new NotImplementedException();
        }
예제 #10
0
        /// <summary>
        /// Setup the QueryManager members for the specified query
        /// </summary>
        /// <param name="qm"></param>
        /// <param name="q"></param>
        /// <param name="qe"></param>
        /// <param name="resultsKeys"></param>

        public static void InitializeQueryManager(
            QueryManager qm,
            Query q,
            OutputDest outputDest,
            QueryEngine qe,
            List <string> resultsKeys)
        {
            ResultsFormat rf = new ResultsFormat(qm, outputDest);

            InitializeQueryManager(qm, q, rf, qe, resultsKeys);
            return;
        }
예제 #11
0
/// <summary>
/// Complete initialization for specified OutputDest
/// </summary>

        public void CompleteInitialization(OutputDest outputDest)
        {
            ResultsFormat rf = ResultsFormat;

            if (rf != null)
            {
                rf.OutputDestination = outputDest;
            }

            else
            {
                rf = new ResultsFormat(this, outputDest);
            }

            CompleteInitialization(rf);
            return;
        }
예제 #12
0
        /// <summary>
        /// Construct with supplied OutputDest
        /// </summary>

        public ResultsFormat(OutputDest outputDest)
        {
            OutputDestination = outputDest;
            return;
        }
예제 #13
0
        /// <summary>
        /// Format qualified number
        /// </summary>
        /// <param name="qn"></param>
        /// <param name="qc"></param>
        /// <param name="mergedField"></param>
        /// <param name="displayFormat"></param>
        /// <param name="decimals"></param>
        /// <param name="qnFormat"></param>
        /// <param name="outputDest"></param>
        /// <returns></returns>

        public string Format(
            QueryColumn qc,
            bool mergedField,
            ColumnFormatEnum displayFormat,
            int decimals,
            QnfEnum qnFormat,
            OutputDest outputDest)
        {
            string result, uri, href, txt, tok;

            result = "";

            QualifiedNumber qn = this;

            MetaColumn mc = qc.MetaColumn;

            if (qn.Qualifier == null)
            {
                qn.Qualifier = "";
            }
            if (qn.TextValue == null)
            {
                qn.TextValue = "";
            }
            if (qn.Hyperlink == null)
            {
                qn.Hyperlink = "";
            }

            if (QnSubcolumns.IsCombinedFormat(qnFormat))             // normal combined number
            {
                if (qn.NumberValue == NullValue.NullNumber && qn.NValue == NullValue.NullNumber &&
                    qn.NValueTested == NullValue.NullNumber && qn.TextValue == "")
                {                 // null value
                    result = NullValueString;
                    if (outputDest == OutputDest.Html && (NullValueString == "" || NullValueString == " "))
                    {
                        result = "<br>";                         // html blank
                    }
                    return(result);
                }

                result = qn.Format(displayFormat, decimals);

                if (qn.NValue > 1 || qn.NValueTested > 1 ||                 // format with sd, n
                    (qn.NValue >= 0 && qn.NValueTested > qn.NValue) ||      // number tested > n
                    (qn.NumberValue == NullValue.NullNumber &&              // also null numbers if some nonzero nvalue
                     (qn.NValue > 0 || qn.NValueTested > 0)))
                {
                    txt = "";

                    if (qn.NValue > 1 && (qnFormat & QnfEnum.StdDev) != 0 &&                     // include sd
                        (qn.StandardDeviation != NullValue.NullNumber ||
                         qn.StandardError != NullValue.NullNumber))
                    {                     // format standard deviation
                        if ((qnFormat & QnfEnum.DisplayStdDevLabel) != 0)
                        {
                            txt += "sd=";
                        }

                        if (qn.StandardDeviation == NullValue.NullNumber)                         // calc sd from se if don't have
                        {
                            qn.StandardDeviation = qn.StandardError * Math.Sqrt(qn.NValue);
                        }
                        txt += FormatNumber(qn.StandardDeviation, displayFormat, decimals);
                    }

                    if (qn.NValue > 1 && (qnFormat & QnfEnum.StdErr) != 0 &&                     // include se
                        (qn.StandardError != NullValue.NullNumber ||
                         qn.StandardDeviation != NullValue.NullNumber))
                    {                     // format standard error
                        if (txt != "")
                        {
                            txt += ", ";
                        }
                        if ((qnFormat & QnfEnum.DisplayStdErrLabel) != 0)
                        {
                            txt += "se=";
                        }

                        txt += FormatNumber(qn.StandardError, displayFormat, decimals);
                    }

                    if (qn.NValue != NullValue.NullNumber &&
                        (qnFormat & QnfEnum.NValue) != 0)
                    {                     // format n value
                        if (txt != "")
                        {
                            txt += ", ";
                        }
                        if ((qnFormat & QnfEnum.DisplayNLabel) != 0)
                        {
                            txt += "n=";
                        }

                        txt += qn.NValue.ToString();
                        if (qn.NValueTested != NullValue.NullNumber && qn.NValueTested != qn.NValue)
                        {
                            txt += "/" + qn.NValueTested.ToString();                             // add number tested if different
                        }
                    }
                    if (txt != "")
                    {
                        result += " (" + txt + ")";                                // build complete string
                    }
                }

                if (qn.DbLink != null && qn.DbLink != "" && qn.DbLink != "." && !mergedField &&                 // do we have an associated resultId
                    (outputDest == OutputDest.WinForms || outputDest == OutputDest.Html))
                {
                    uri = qn.FormatHyperlink(qc);

                    //if (outputDest == OutputDest.Grid) // store link info in separate field
                    //  qn.Hyperlink = uri;

                    //else if (outputDest == OutputDest.Html) // build full html tag
                    //{
                    if (uri != "")
                    {
                        result = result = "<a href=" + Lex.Dq(uri) + ">" + result + "</a>";
                    }
                    //}
                }
            }

// Format one piece of a split qualified number

            else if ((qnFormat & QnfEnum.Qualifier) != 0)             // qualifier
            {
                result = qn.Qualifier;
            }

            else if ((qnFormat & QnfEnum.NumericValue) != 0)             // basic number
            {
                if (qn.NumberValue != NullValue.NullNumber)
                {
                    result = FormatNumber(qn.NumberValue, displayFormat, decimals);
                }

                else
                {
                    result = null;
                }

                //else (obsolete, don't output any text values into numeric column, add option for separate column later)
                //{
                //  if (qn.NValue != NullValue.NullNumber)
                //    result = "ND"; // some NValue, return not determined

                //  else result = qn.TextValue; // return any text value
                //}
            }

            else if ((qnFormat & QnfEnum.StdDev) != 0)             // standard deviation
            {
                if (qn.StandardDeviation != NullValue.NullNumber)
                {
                    result = FormatNumber(qn.StandardDeviation, displayFormat, decimals);
                }
            }

            else if ((qnFormat & QnfEnum.StdErr) != 0)             // standard error
            {
                if (qn.StandardError != NullValue.NullNumber)
                {
                    result = FormatNumber(qn.StandardError, displayFormat, decimals);
                }
            }

            else if ((qnFormat & QnfEnum.NValue) != 0)             // N
            {
                if (qn.NValue != NullValue.NullNumber)
                {
                    result = qn.NValue.ToString();
                }
            }

            else if ((qnFormat & QnfEnum.NValueTested) != 0)             // number tested
            {
                if (qn.NValueTested != NullValue.NullNumber)
                {
                    result = qn.NValueTested.ToString();
                }
            }

            else if ((qnFormat & QnfEnum.TextValue) != 0)             // text value
            {
                if (!Lex.IsNullOrEmpty(qn.TextValue))
                {
                    result = qn.TextValue;
                }
            }

            return(result);
        }
예제 #14
0
/// <summary>
/// Summarize unpivoted unsummarized assay data by target
/// </summary>
/// <param name="parms"></param>
/// <param name="qm2"></param>
/// <returns></returns>

        public QueryManager SummarizeByTargetUnpivoted(
            TargetSummaryOptions summaryOptions,
            QueryManager qm2)
        {
            // This method takes an unpivoted input query, summarizes it according to the summarization parameters
            // and then formats the summarized data according to the specified output format.
            // If a targetMap is specified then then coordinates are included in the output, the summarization
            // level must be target, and the output format must be unpivoted.

            QueryTable        qt, qt2;
            DataRowMx         dr, dr2;
            DataRowAttributes dra;
            string            cid = "", currentCid;
            int rti, rfi;

            AssayDict tad = TargetAssayDict;                                                // be sure target assay dict has been loaded

            TargetAssaySummarizationLevel sumLevel  = TargetAssaySummarizationLevel.Target; // target level
            SummarizationType             sumMethod = summaryOptions.UseMeans ? SummarizationType.BioResponseMean : SummarizationType.MostPotent;
            OutputDest outputDest = OutputDest.WinForms;
            TargetMap  targetMap  = TargetMapDao.GetMapWithCoords(summaryOptions.TargetMapName);

            qt = Query.GetQueryTableByName(MultiDbAssayDataNames.CombinedNonSumTableName);
            if (qt == null)
            {
                throw new Exception("Query table not found: " + MultiDbAssayDataNames.CombinedNonSumTableName);
            }

            UnpivotedAssayResultFieldPositionMap voMap = UnpivotedAssayResultFieldPositionMap.NewOriginalMap();             // used for fast indexing of value by col name

            voMap.InitializeFromQueryTableVoPositions(qt, 0);

            if (qm2 == null)             // need to create query manager?
            {
                qm2 = new QueryManager();
                qm2 = InitializeSubqueryQm(MultiDbAssayDataNames.CombinedNonSumTableName);
            }

            Query q2 = qm2.Query;

            qt2 = q2.GetQueryTableByNameWithException(MultiDbAssayDataNames.BaseTableName);

            UnpivotedAssayResultFieldPositionMap voMap2 = UnpivotedAssayResultFieldPositionMap.NewOriginalMap();             // used for fast indexing of value by col name

            voMap2.InitializeFromQueryTableVoPositions(qt2, 0);

// Summarize rows & store in DataSet

            qm2.DataTable.Clear();

            Dictionary <string, object> includedTargets = null;

            if (summaryOptions.TargetsWithActivesOnly)
            {             // scan data & make a list of targets to be included
                includedTargets = new Dictionary <string, object>();
                // ...
            }

            List <UnpivotedAssayResult> tars = new List <UnpivotedAssayResult>();           // build list of TA rows here

            currentCid = "";

            for (int dri = 0; dri <= DataTableMx.Rows.Count; dri++)
            {
                if (dri < DataTableMx.Rows.Count)
                {
                    dr  = DataTableMx.Rows[dri];
                    cid = dr[KeyValueVoPos] as string;
                    dra = GetRowAttributes(dr);
                    if (dra != null && dra.Filtered)
                    {
                        continue;
                    }
                    if (currentCid == "")
                    {
                        currentCid = cid;
                    }
                }
                else
                {
                    dr = null;
                }

                if (dr == null || cid != currentCid)
                {                       // summarize rows for current cid & add to new datatable
                    if (tars.Count > 0) //
                    {
                        List <UnpivotedAssayResult> sumTars = TargetAssayUtil.SummarizeData(
                            tars,
                            sumLevel,
                            sumMethod,
                            true,
                            NullValue.NullNumber,
                            NullValue.NullNumber,
                            targetMap);

                        int voLength2 = qm2.DataTable.Columns.Count;
                        foreach (UnpivotedAssayResult sumTar in sumTars)
                        {
                            object[] vo2 = sumTar.ToValueObject(voLength2, voMap2);
                            dr2 = qm2.DataTable.NewRow();
                            dr2.ItemArrayRef = vo2;                             // copy ref for efficiency since vo won't be changed
                            qm2.DataTable.Rows.Add(dr2);
                        }
                    }
                    if (dr == null)
                    {
                        break;
                    }
                    tars.Clear();
                    currentCid = cid;
                }

                UnpivotedAssayResult tar = UnpivotedAssayResult.FromValueObjectNew(dr.ItemArray, voMap);
                tars.Add(tar);                 // store in form for summarization
            }

            qm2.DataTableManager.InitializeRowAttributes();

            return(qm2);
        }
예제 #15
0
/// <summary>
/// Summarize pivoted data
/// </summary>
/// <param name="sumLevel"></param>
/// <param name="sumMethod"></param>
/// <returns></returns>

        public QueryManager SummarizePivoted(
            TargetAssaySummarizationLevel sumLevel,
            SummarizationType sumMethod,
            ColumnsToTransform colsToSumm,
            OutputDest outputDest,
            TargetMap targetMap)
        {
            QueryManager      qm2;
            QueryTable        qt;
            DataRow           dr, dr2;
            DataRowAttributes dra;
            string            cid = "", currentCid;
            int rti, rfi;

            qm2 = InitializeSubqueryQm(MultiDbAssayDataNames.CombinedNonSumTableName);

#if false
// Get the data for a compound, summarize & add results to data for charting

            DataTableManager dtm = Qm0.DataTableManager;

            for (int dri = 0; dri < dtm.DataTable.Rows.Count; dri++)
            {
                DataRow           dr  = dtm.DataTable.Rows[dri];
                DataRowAttributes dra = GetRowAttributes(dr);

                string keyVal = dr[KeyValueVoPos] as string;

                if (keyVal != curKeyVal || Rf.Tables.Count <= 1)                 // going to new key
                {
                    curKeyVal  = keyVal;
                    curKeyRow  = dri;
                    rowsForKey = 0;
                }

                rowsForKey++;

                object o = dr[dci];
//				if (o is string && ((string)o) == "") o = o; // debug
                if (NullValue.IsNull(o))
                {
                    if (rowsForKey == 0 ||                                               // count as null if first row for key
                        dra.TableRowState[colInfo.TableIndex] != RowStateEnum.Undefined) // or real row data but col is null
                    {
                        stats.NullsExist = true;
                    }
                    continue;
                }

                else if (o is MobiusDataType)
                {                 // create a MobiusDataType that we can point to
                    o       = MobiusDataType.New(o);
                    dr[dci] = o;
                }
                MobiusDataType val = o as MobiusDataType;

                try
                {
                    if (val.FormattedText == null)                     // get formatted text if not done yet
                    {
                        val = QueryManager.ResultsFormatter.FormatField(rt, ti, rfld, fi, dr, dri, val, -1, false);
                    }
                    dictKey = val.FormattedText.ToUpper();

                    if (!stats.DistinctValueDict.ContainsKey(dictKey))
                    {
                        DistinctValueAndPosition dvp = new DistinctValueAndPosition();
                        dvp.Value = val;
                        stats.DistinctValueDict[dictKey] = dvp;
                    }
                }
                catch (Exception ex) { val = val; }
            }             // row loop

            dtm.n
#endif


            return(qm2);
        }
예제 #16
0
 internal RaspberryPiOutput(OutputDest dest)
 {
     _dest = dest;
     Name = (dest == OutputDest.HDMI) ? "HDMI" : "3.5mm Jack";
 }