protected virtual void RunPrimary() { using (Trail.AddCheckpoint(ProcessCheckpoints.OldWayFlow)) { this.oldWayAgent.Init().RunPrimaryOnly(); this.oldWayAgent.Trail.UniqueID = this.args.TrailUniqueID; this.oldWayAgent.Trail.SetTag(this.args.Tag).Save(DB, null, TrailPrimaryStatus.OldPrimary); } // old flow step using (Trail.AddCheckpoint(ProcessCheckpoints.GatherData)) { var inputData = new LGRejectionInputData(); inputData.Init( this.oldWayAgent.Trail.MyInputData.DataAsOf, this.oldWayAgent.Trail.MyInputData, this.oldWayAgent.Trail.MyInputData ); GatherData(inputData); Trail.MyInputData.Init(inputData.DataAsOf, inputData, inputData); } // gather data step using (Trail.AddCheckpoint(ProcessCheckpoints.MakeDecision)) { if (Trail.MyInputData.AutoDecisionInternalLogic) { Trail.Dunno <InternalFlow>().Init(); } else { Trail.Dunno <LogicalGlueFlow>().Init(); } if (LogicalGlueFlowFollowed) { LogicalGlueFlow(); } else { InternalFlow(); } } // make decision step } // RunPrimary
} // MakeDecision private void GatherData() { var inputData = new LGRejectionInputData(); inputData.Init( this.oldWayAgent.Trail.MyInputData.DataAsOf, this.oldWayAgent.Trail.MyInputData, this.oldWayAgent.Trail.MyInputData ); var sr = DB.GetFirst( "AV_LogicalGlueDataForAutoReject", CommandSpecies.StoredProcedure, new QueryParameter("CustomerID", this.args.CustomerID), new QueryParameter("CompanyID", this.args.CompanyID), new QueryParameter("ProcessingDate", this.args.Now) ); inputData.CompanyID = this.args.CompanyID; TypeOfBusiness typeOfBusiness; inputData.TypeOfBusiness = Enum.TryParse(sr["TypeOfBusiness"], out typeOfBusiness) ? typeOfBusiness : EZBob.DatabaseLib.Model.Database.TypeOfBusiness.Entrepreneur; inputData.CompanyIsRegulated = sr["IsRegulated"]; inputData.AutoDecisionInternalLogic = sr["AutoDecisionInternalLogic"]; inputData.LoanCount = sr["LoanCount"]; CustomerOriginEnum coe; inputData.CustomerOrigin = Enum.TryParse(sr["CustomerOrigin"], out coe) ? coe : (CustomerOriginEnum?)null; LoanSourceName ls; inputData.LoanSource = Enum.TryParse(sr["LoanSource"], out ls) ? ls : (LoanSourceName?)null; inputData.RequestID = sr["RequestID"]; inputData.ResponseID = sr["ResponseID"]; inputData.ResponseErrors = new List <string>(); if (inputData.ResponseID <= 0) { inputData.ResponseErrors.Add("No response received."); } inputData.ResponseHttpStatus = sr["HttpStatus"]; AddError(inputData.ResponseErrors, sr["ErrorMessage"]); AddError(inputData.ResponseErrors, sr["ParsingExceptionType"]); AddError(inputData.ResponseErrors, sr["ParsingExceptionMessage"]); long?timeoutSourceID = sr["TimeoutSourceID"]; if (timeoutSourceID != null) { AddError( inputData.ResponseErrors, "Timeout: " + Enum.GetNames(typeof(LGTimeoutSources))[timeoutSourceID.Value - 1] ); } // if AddError(inputData.ResponseErrors, sr["ErrorCode"]); AddError(inputData.ResponseErrors, sr["Exception"]); int errCount = sr["EncodingFailureCount"]; if (errCount > 0) { inputData.ResponseErrors.Add(Grammar.Number(errCount, "encoding failure") + " detected."); } errCount = sr["MissingColumnCount"]; if (errCount > 0) { inputData.ResponseErrors.Add(Grammar.Number(errCount, "missing column") + " detected."); } errCount = sr["WarningCount"]; if (errCount > 0) { inputData.ResponseErrors.Add(Grammar.Number(errCount, "warning") + " detected."); } inputData.HardReject = sr["EtlCodeID"] == (int)LGEtlCode.HardReject; Bucket bucket; inputData.Bucket = Enum.TryParse(sr["Grade"], out bucket) ? bucket : (Bucket?)null; inputData.Score = sr["Score"]; inputData.MatchingGradeRanges = new MatchingGradeRanges(); if (inputData.Score != null) { DB.ForEachRowSafe( r => inputData.MatchingGradeRanges.Add(new MatchingGradeRanges.SubproductGradeRange { ProductSubTypeID = sr["ProductSubTypeID"], GradeRangeID = r["GradeRangeID"], }), "AV_LoadMatchingGradeRanges", CommandSpecies.StoredProcedure, new QueryParameter("CustomerID", this.args.CustomerID), new QueryParameter("Score", inputData.Score.Value), new QueryParameter("Regulated", inputData.CompanyIsRegulated), new QueryParameter("ProcessingDate", this.args.Now) ); } // if Trail.MyInputData.Init(inputData.DataAsOf, inputData, inputData); Log.Debug( "Customer {0} has company {1} of type {3} data at {2:d}", this.args.CustomerID, this.args.CompanyID, this.args.Now, inputData.TypeOfBusiness ); } // GatherData
} // RunSecondary private void GatherData(LGRejectionInputData inputData) { var sp = new LoadLGAutoRejectData(DB, Log) { CustomerID = this.args.CustomerID, CompanyID = this.args.CompanyID, Now = this.args.Now, }; sp.ExecuteNonQuery(); inputData.CompanyID = this.args.CompanyID; inputData.TypeOfBusiness = sp.TypeOfBusiness; inputData.CompanyIsRegulated = sp.IsRegulated; inputData.AutoDecisionInternalLogic = sp.AutoDecisionInternalLogic; inputData.CustomerOrigin = customerOrigins.Contains(sp.OriginID) ? (CustomerOriginEnum)sp.OriginID : (CustomerOriginEnum?)null; inputData.LoanSource = loanSources.Contains(sp.LoanSourceID) ? (LoanSourceName)sp.LoanSourceID : (LoanSourceName?)null; Inference inference = InjectorStub.GetEngine().GetInferenceIfExists( this.args.CustomerID, this.args.Now, false, 0 ); if (inference == null) { inputData.RequestID = null; inputData.ResponseID = null; inputData.ResponseErrors = null; inputData.HardReject = false; inputData.Bucket = null; inputData.Score = null; inputData.MatchingGradeRanges = null; } else { inputData.RequestID = inference.UniqueID; inputData.ResponseID = inference.ResponseID; if (inference.ResponseID <= 0) { inputData.ResponseErrors.Add("No response received."); } inputData.ResponseHttpStatus = (inference.Status == null) ? (int?)null : (int)inference.Status.HttpStatus; bool receivedError = (inference.Etl != null) && (inference.Etl.Code != null) && inference.Etl.Code.IsError; if (inference.Error.HasError()) { inputData.ResponseErrors.AddRange( new [] { inference.Error.Message, inference.Error.ParsingExceptionType, inference.Error.ParsingExceptionMessage, }.Where(s => !string.IsNullOrWhiteSpace(s)) ); if (inference.Error.TimeoutSource != null) { inputData.ResponseErrors.Add("Timeout: " + inference.Error.TimeoutSource.Name); } ModelOutput model = inference.ModelOutputs.ContainsKey(ModelNames.NeuralNetwork) ? inference.ModelOutputs[ModelNames.NeuralNetwork] : null; if ((model != null) && !model.Error.IsEmpty) { if (!string.IsNullOrWhiteSpace(model.Error.ErrorCode)) { inputData.ResponseErrors.Add(model.Error.ErrorCode); } if (!string.IsNullOrWhiteSpace(model.Error.Exception)) { inputData.ResponseErrors.Add(model.Error.Exception); } inputData.ResponseErrors.AddRange( model.Error.EncodingFailures.Where(ef => !ef.IsEmpty).Select(ef => ef.ToString()) ); inputData.ResponseErrors.AddRange(model.Error.MissingColumns); inputData.ResponseErrors.AddRange( model.Error.Warnings.Where(w => !w.IsEmpty).Select(w => w.ToString()) ); } // if } // if inference has error inputData.HardReject = (inference.Etl != null) && (inference.Etl.Code != null) && inference.Etl.Code.IsHardReject; inputData.Bucket = inference.Bucket == null ? (LocalBucket?)null : (LocalBucket)(int)inference.Bucket; inputData.Score = inference.Score; inputData.MatchingGradeRanges = new MatchingGradeRanges(); if (inputData.Score.HasValue && inputData.CustomerOrigin.HasValue && inputData.LoanSource.HasValue) { var loader = new LoadOfferRanges( this.args.CustomerID, this.args.CompanyID, this.args.Now, DB, Log ).Execute(); loader.ExportMatchingGradeRanges(inputData.MatchingGradeRanges); } // if } // if inference is null } // GatherData