예제 #1
0
        public static string Consistency(QcRuleSetup qcSetup, DataTable dt, List <DataAccessDef> accessDefs, IIndexDBAccess indexData)
        {
            string    returnStatus = "Passed";
            RuleModel rule         = JsonConvert.DeserializeObject <RuleModel>(qcSetup.RuleObject);
            JObject   dataObject   = JObject.Parse(qcSetup.DataObject);
            JToken    value        = dataObject.GetValue(rule.DataAttribute);
            string    strValue     = value.ToString();

            if (Common.CompletenessCheck(strValue) == "Passed")
            {
                string     dataType = rule.DataType;
                IndexModel index    = Task.Run(() => indexData.GetIndex(qcSetup.IndexId, qcSetup.DataConnector)).GetAwaiter().GetResult();
                if (index != null)
                {
                    string         query           = " where " + index.DataKey;
                    DataAccessDef  dataAccessDef   = accessDefs.First(x => x.DataType == dataType);
                    string         sql             = dataAccessDef.Select + query;
                    IADODataAccess consistencyConn = new ADODataAccess();
                    DataTable      ct = consistencyConn.GetDataTable(sql, qcSetup.ConsistencyConnectorString);
                    Dictionary <string, string> columnTypes = ct.GetColumnTypes();
                    if (ct.Rows.Count > 0)
                    {
                        string strRefValue = ct.Rows[0][rule.DataAttribute].ToString();
                        string valueType   = columnTypes[rule.DataAttribute];
                        if (Common.CompletenessCheck(strRefValue) == "Passed")
                        {
                            returnStatus = RuleMethodUtilities.ConsistencyCheck(strValue, strRefValue, valueType);
                        }
                    }
                }
            }
            return(returnStatus);
        }
예제 #2
0
        public static PredictionResult PredictDepthUsingIDW(QcRuleSetup qcSetup, DbUtilities dbConn)
        {
            double?          depth  = null;
            PredictionResult result = new PredictionResult
            {
                Status = "Failed"
            };
            DataTable nb = RuleMethodUtilities.GetNeighbors(dbConn, qcSetup);

            if (nb != null)
            {
                depth = RuleMethodUtilities.CalculateDepthUsingIdw(nb, qcSetup);
            }

            if (depth != null)
            {
                RuleModel rule       = JsonConvert.DeserializeObject <RuleModel>(qcSetup.RuleObject);
                JObject   dataObject = JObject.Parse(qcSetup.DataObject);
                dataObject[rule.DataAttribute] = depth;
                string remark = dataObject["REMARK"] + $";{rule.DataAttribute} has been predicted by QCEngine;";
                dataObject["REMARK"] = remark;
                result.DataObject    = dataObject.ToString();
                result.DataType      = rule.DataType;
                result.SaveType      = "Update";
                result.IndexId       = qcSetup.IndexId;
                result.Status        = "Passed";
            }

            return(result);
        }
예제 #3
0
        public static PredictionResult PredictLogDepthAttributes(QcRuleSetup qcSetup, DbUtilities dbConn)
        {
            PredictionResult result = new PredictionResult
            {
                Status = "Failed"
            };
            JObject   dataObject = JObject.Parse(qcSetup.DataObject);
            RuleModel rule       = JsonConvert.DeserializeObject <RuleModel>(qcSetup.RuleObject);
            string    jsonLog    = RuleMethodUtilities.GetLogCurveDepths(dbConn, qcSetup.DataObject);

            if (!string.IsNullOrEmpty(jsonLog))
            {
                JObject logObject = JObject.Parse(jsonLog);
                string  attribute = rule.DataAttribute;
                dataObject[attribute] = logObject[attribute];
                string remark = dataObject["REMARK"] + $";{attribute} was calculated from curve array;";
                dataObject["REMARK"] = remark;
                result.DataObject    = dataObject.ToString();
                result.DataType      = rule.DataType;
                result.SaveType      = "Update";
                result.IndexId       = qcSetup.IndexId;
                result.Status        = "Passed";
            }
            return(result);
        }
예제 #4
0
        public static string CurveSpikes(QcRuleSetup qcSetup, DataTable dt, List <DataAccessDef> accessDefs, IIndexDBAccess indexData)
        {
            string               returnStatus = "Passed";
            string               error        = "";
            RuleModel            rule         = JsonConvert.DeserializeObject <RuleModel>(qcSetup.RuleObject);
            JObject              dataObject   = JObject.Parse(qcSetup.DataObject);
            double               nullValue    = Common.GetLogNullValue(dataObject.ToString());
            CurveSpikeParameters spikeParams  = new CurveSpikeParameters()
            {
                WindowSize   = 5,
                SeveritySize = 4
            };

            if (!string.IsNullOrEmpty(rule.RuleParameters))
            {
                try
                {
                    spikeParams = JsonConvert.DeserializeObject <CurveSpikeParameters>(rule.RuleParameters);
                    if (spikeParams.WindowSize == 0)
                    {
                        spikeParams.WindowSize = 5;
                    }
                    if (spikeParams.SeveritySize == 0)
                    {
                        spikeParams.SeveritySize = 4;
                    }
                }
                catch (Exception ex)
                {
                    error = $"Bad Json, {ex}";
                }
            }
            spikeParams.NullValue = nullValue;
            List <double> measuredValues = new List <double>();

            try
            {
                JToken value    = dataObject.GetValue("MEASURED_VALUE");
                string strValue = value.ToString();
                if (!string.IsNullOrEmpty(strValue))
                {
                    measuredValues = strValue.Split(',').Select(double.Parse).ToList();
                }
            }
            catch (Exception ex)
            {
                error = $"Problems with the log arrays, {ex}";
            }

            bool spike = RuleMethodUtilities.CurveHasSpikes(measuredValues, spikeParams);

            if (spike)
            {
                returnStatus = "Failed";
            }

            return(returnStatus);
        }
예제 #5
0
        public static PredictionResult PredictMissingDataObjects(QcRuleSetup qcSetup, DbUtilities dbConn)
        {
            PredictionResult result = new PredictionResult
            {
                Status = "Failed"
            };
            RuleModel rule          = JsonConvert.DeserializeObject <RuleModel>(qcSetup.RuleObject);
            string    rulePar       = rule.RuleParameters;
            JObject   ruleParObject = JObject.Parse(rulePar);
            string    dataType      = ruleParObject["DataType"].ToString();

            if (string.IsNullOrEmpty(rulePar))
            {
                throw new NullReferenceException("Rule parameter is null.");
            }
            string emptyJson = RuleMethodUtilities.GetJsonForMissingDataObject(rulePar, dbConn);

            if (emptyJson == "Error")
            {
                throw new NullReferenceException("Could not create an empty json data object, maybe you are missing Datatype in parameters");
            }
            string json = RuleMethodUtilities.PopulateJsonForMissingDataObject(rulePar, emptyJson, qcSetup.DataObject);

            if (json == "Error")
            {
                throw new NullReferenceException("Could not create an json data object, problems with keys in parameters");
            }
            json = RuleMethodUtilities.AddDefaultsForMissingDataObjects(rulePar, json);
            if (json == "Error")
            {
                throw new NullReferenceException("Could not create an json data object, problems with defaults in parameters");
            }
            result.DataObject = json;
            result.DataType   = dataType;
            result.SaveType   = "Insert";
            result.IndexId    = qcSetup.IndexId;
            result.Status     = "Passed";
            return(result);
        }
예제 #6
0
        public static PredictionResult PredictDominantLithology(QcRuleSetup qcSetup, DbUtilities dbConn)
        {
            PredictionResult result = new PredictionResult
            {
                Status = "Failed"
            };

            JObject dataObject = JObject.Parse(qcSetup.DataObject);
            string  uwi        = dataObject["UWI"].ToString();
            string  curveName  = "GR";
            JToken  value      = dataObject.GetValue("PICK_DEPTH");
            double? pickDepth  = value.GetNumberFromJToken();

            if (pickDepth == null || pickDepth == -99999.0)
            {
                result.Status = "Failed";
            }
            else
            {
                string    select = "SELECT JSONDATAOBJECT from pdo_qc_index";
                string    query  = " where IndexNode = '/'";
                DataTable idx    = dbConn.GetDataTable(select, query);
                if (idx.Rows.Count == 1)
                {
                    string               jsondata   = idx.Rows[0]["JSONDATAOBJECT"].ToString();
                    ConnectParameters    source     = JsonConvert.DeserializeObject <ConnectParameters>(jsondata);
                    List <DataAccessDef> accessDefs = JsonConvert.DeserializeObject <List <DataAccessDef> >(source.DataAccessDefinition);

                    DataAccessDef logType = accessDefs.First(x => x.DataType == "Log");
                    select = logType.Select;
                    query  = $" where CURVE_ID = '{curveName}' and UWI = '{uwi}'";
                    DataTable lc = dbConn.GetDataTable(select, query);
                    if (lc.Rows.Count == 1)
                    {
                        double logNullValue = Common.GetDataRowNumber(lc.Rows[0], "NULL_REPRESENTATION");

                        DataAccessDef logCurvedType = accessDefs.First(x => x.DataType == "LogCurve");
                        select = logCurvedType.Select;
                        query  = $" where CURVE_ID = '{curveName}' and UWI = '{uwi}'";
                        DataTable lg          = dbConn.GetDataTable(select, query);
                        DataTable sortedCurve = RuleMethodUtilities.GetSortedLogCurve(lg, uwi);

                        if (sortedCurve.Rows.Count > 0)
                        {
                            int rowNumber = RuleMethodUtilities.GetRowNumberForPickDepth(sortedCurve, (double)pickDepth);

                            double?smoothLogValue = RuleMethodUtilities.GetSmoothLogValue(sortedCurve, logNullValue, rowNumber);

                            string rock;
                            if (smoothLogValue >= 0 & smoothLogValue < 10)
                            {
                                rock = "Salt";
                            }
                            if (smoothLogValue >= 10 & smoothLogValue < 20)
                            {
                                rock = "Limestone";
                            }
                            else if (smoothLogValue >= 20 & smoothLogValue < 55)
                            {
                                rock = "Sandstone";
                            }
                            else if (smoothLogValue >= 55 & smoothLogValue < 150)
                            {
                                rock = "Shale";
                            }
                            else
                            {
                                rock = "Unknown";
                            }

                            dataObject["DOMINANT_LITHOLOGY"] = rock;
                            string remark = dataObject["REMARK"] + $";Pick depth has been predicted by QCEngine";
                            dataObject["REMARK"] = remark;

                            RuleModel rule = JsonConvert.DeserializeObject <RuleModel>(qcSetup.RuleObject);
                            result.DataObject = dataObject.ToString();
                            result.DataType   = rule.DataType;
                            result.SaveType   = "Update";
                            result.IndexId    = qcSetup.IndexId;
                            result.Status     = "Passed";
                        }
                    }
                }
            }

            return(result);
        }