private static void ApplyOccupationFactor(Customer customer, ref RateTracker rateTracker) { if (customer.Occupation == "Roofer" || customer.Occupation == "Logger" || customer.Occupation == "Police") { OutputString.responseMessage += "\nDangerous Job"; rateTracker.RiskFactor += 0.3; rateTracker.HighRiskTracker.Add("Dangerous Job"); } }
public override void Define() { RateTracker rateTracker = null; When() .Match(() => rateTracker); //IT SEEMS LIKE I CAN NOT INCLUDE LOGIC AROUND RATETRACKER HERE Then() //Calling function to apply the logic within this rule .Do(ctx => ApplyHighRiskFactor(ref rateTracker)); }
private static void ApplyHighRiskFactor(ref RateTracker rateTracker) { if (rateTracker.HighRiskTracker.Count > 2) { OutputString.responseMessage += "\nHigh Risk"; rateTracker.HighRisk = true; } else { OutputString.responseMessage += "\nLow Risk"; rateTracker.HighRisk = false; } }
private static void HospitalFactor(Customer customer, ref RateTracker rateTracker) { if (customer.Gender == "Male") { rateTracker.RiskFactor += 0.1; OutputString.responseMessage += "\nGender: Male"; } else if (customer.Gender == "Female") { rateTracker.RiskFactor -= 0.1; OutputString.responseMessage += "\nGender Female"; } }
private static void HospitalFactor(Customer customer, ref RateTracker rateTracker) { if (customer.MSinceHospital == 0) { rateTracker.RiskFactor += 0.4; OutputString.responseMessage += "\n1 Hospital Visit This Month"; } else if (customer.PreExisingConditions.Length == 2) { rateTracker.RiskFactor += 0.4 * 1 / customer.MSinceHospital; OutputString.responseMessage += $"\nHospital Visit {customer.MSinceHospital} Months Ago"; } }
private static void ApplyPricingFunction(Customer customer, ref RateTracker rateTracker, Order order) { if (rateTracker.HighRisk == true && order.InsuranceType == "Participating") { OutputString.responseMessage += $"\nUnable to apply Insurance Type: Participating, Due to High Risk (Only Term Currently Available for This User)"; } else if (rateTracker.HighRisk == true && order.InsuranceType == "Universal") { OutputString.responseMessage += $"\nUnable to apply Insurance Type: Universal, Due to High Risk (Only Term Currently Available for This User)"; } else if (rateTracker.HighRisk == true && order.PolicyMaximum > 1000000) { OutputString.responseMessage += $"\nCustomer is High Risk and Cannot Request a Policy Over $1000000"; } else { if (customer.InsuranceType != order.InsuranceType) { rateTracker.OneTimeFee += 200; OutputString.responseMessage += $"\nChanging Exisiting Insurance Type Therefore $200 Conversion One Time Fee"; } if (order.InsuranceType == "Term") { rateTracker.Cost = 300; OutputString.responseMessage += $"\nTerm Insurance Availible Initial Cost Before RiskFactor: $300"; } else if (order.InsuranceType == "Participating") { rateTracker.Cost = 250; OutputString.responseMessage += $"\nParticipating Insurance Availible Initial Cost Before RiskFactor: $250"; } else if (order.InsuranceType == "Universal") { rateTracker.Cost = 200; OutputString.responseMessage += $"\nUniversal Insurance Availible Initial Cost Before RiskFactor: $200"; } if (order.PolicyMaximum < 100000) { rateTracker.Cost += 30; } else if (order.PolicyMaximum >= 100000 && order.PolicyMaximum <= 1000000) { rateTracker.Cost += 60; } else if (order.PolicyMaximum > 1000000) { rateTracker.Cost += 80; } OutputString.responseMessage += $"\n\nFinal Cost With Risk Factor of {Math.Round(rateTracker.RiskFactor, 1)} and Policy Maximum of {order.PolicyMaximum} is ${Math.Round(rateTracker.Cost*rateTracker.RiskFactor, 2)}"; } }
public override void Define() { Customer customer = null; RateTracker rateTracker = null; When() .Match(() => rateTracker) .And(xx => xx .Match <Customer>(() => customer, c => c.PreExisingConditions.Length != 0)); Then() //Calling function to apply the logic within this rule .Do(ctx => PreExisitngConditionFactor(customer, ref rateTracker)); }
public override void Define() { Customer customer = null; RateTracker rateTracker = null; When() //Using rate tracker object to track variables and a trigger for other functions if EligibleForNewRate and LookingForNewRate is true .Match(() => rateTracker) .And(xx => xx .Match <Customer>(() => customer, c => c.IsSmoker)); Then() //Calling function to apply the logic within this rule .Do(ctx => ApplySmokerFactor(customer, ref rateTracker)); }
public override void Define() { Customer customer = null; RateTracker rateTracker = null; Order order = null; When() //Using rate tracker object to track variables and a trigger for other functions if EligibleForNewRate and LookingForNewRate is true .Match(() => rateTracker) .And(xx => xx .Match <Customer>(() => customer, c => !String.IsNullOrEmpty(c.InsuranceType))) .And(xxx => xxx .Match <Order>(() => order, o => !String.IsNullOrEmpty(o.InsuranceType))); Then() //Calling function to apply the logic within this rule .Do(ctx => ApplyPricingFunction(customer, ref rateTracker, order)); }
private static void PreExisitngConditionFactor(Customer customer, ref RateTracker rateTracker) { if (customer.PreExisingConditions.Length == 1) { OutputString.responseMessage += $"\n1 Pre-Exisitng Conditions \nRiskFactor: {Math.Round(rateTracker.RiskFactor, 1)} \nHigh Risk Cases: {rateTracker.HighRiskTracker.Count}"; } else if (customer.PreExisingConditions.Length == 2) { rateTracker.RiskFactor += 0.2; OutputString.responseMessage += $"\n2 Pre-Exisitng Conditions \nRiskFactor: {Math.Round(rateTracker.RiskFactor, 1)} \nHigh Risk Cases: {rateTracker.HighRiskTracker.Count}"; } else if (customer.PreExisingConditions.Length > 2) { rateTracker.RiskFactor += 0.4; OutputString.responseMessage += $"\nHigh Risk Pre-Exisitng Conditions \nRiskFactor: {Math.Round(rateTracker.RiskFactor, 1)} \nHigh Risk Cases: {rateTracker.HighRiskTracker.Count}"; rateTracker.HighRiskTracker.Add("PreExisitngCond"); } }
private static void ApplyAgeFactor(Customer customer, ref RateTracker rateTracker) { if (0 < customer.Age && customer.Age <= 21) { OutputString.responseMessage = "age < 21"; } else if (21 < customer.Age && customer.Age <= 39) { rateTracker.RiskFactor += 0.1; OutputString.responseMessage = "21 < age < 39"; } else if (39 < customer.Age && customer.Age <= 59) { OutputString.responseMessage = "39 < age < 59 "; rateTracker.RiskFactor += 0.2; } else if (59 < customer.Age) { OutputString.responseMessage = "60 < age "; rateTracker.RiskFactor += 0.3; rateTracker.HighRiskTracker.Add("Age"); } }
/// <summary> /// </summary> public List <int> Validate(string RootPath, RateTracker Tracker, AsyncIOQueue IOQueue, BuildManfiestValidateProgressCallbackHandler Callback = null) { LazyCacheBlockInfo(); List <int> FailedBlocks = new List <int>(); try { LockBlockInfo(); int TaskCount = Environment.ProcessorCount; Task[] FileTasks = new Task[TaskCount]; int BlockCounter = 0; long BytesValidated = 0; bool Aborted = false; // Check the size of each file. for (int i = 0; i < Files.Count; i++) { BuildManifestFileInfo FileInfo = Files[i]; string FilePath = Path.Combine(RootPath, FileInfo.Path); string DirPath = Path.GetDirectoryName(FilePath); if (!Directory.Exists(DirPath)) { Directory.CreateDirectory(DirPath); Logger.Log(LogLevel.Warning, LogCategory.Manifest, "Expected directory {0} does not exist, creating.", DirPath); } FileInfo Info = new FileInfo(FilePath); if (!Info.Exists || Info.Length != FileInfo.Size) { using (FileStream Stream = new FileStream(FilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { Logger.Log(LogLevel.Warning, LogCategory.Manifest, "File {0} is not of expected length {1} (is {2}) settting length.", FilePath, FileInfo.Size, Info.Length); Stream.SetLength(FileInfo.Size); } } } // Check each individual block of data for validity. for (int i = 0; i < TaskCount; i++) { FileTasks[i] = Task.Run( () => { byte[] Buffer = new byte[BlockSize]; while (!Aborted) { int BlockIndex = Interlocked.Increment(ref BlockCounter) - 1; if (BlockIndex >= BlockCount) { break; } BuildManifestBlockInfo BInfo = BlockInfo[BlockIndex]; long BufferLength = 0; bool Success = GetBlockData(BlockIndex, RootPath, IOQueue, Buffer, out BufferLength); uint Checksum = 0; if (Version >= 2) { Checksum = Crc32Fast.Compute(Buffer, 0, (int)BufferLength); } else { Checksum = Crc32Slow.Compute(Buffer, (int)BufferLength); } if (!Success || BlockChecksums[BlockIndex] != Checksum) { Logger.Log(LogLevel.Warning, LogCategory.Manifest, "Block {0} failed checksum, block contains following sub-blocks:", BlockIndex); for (int SubBlock = 0; SubBlock < BInfo.SubBlocks.Length; SubBlock++) { BuildManifestSubBlockInfo SubBInfo = BInfo.SubBlocks[SubBlock]; Logger.Log(LogLevel.Warning, LogCategory.Manifest, "\tfile={0} offset={1} size={2}", SubBInfo.File.Path, SubBInfo.FileOffset, SubBInfo.FileSize); } lock (FailedBlocks) { FailedBlocks.Add(BlockIndex); } } Interlocked.Add(ref BytesValidated, BInfo.TotalSize); if (Callback != null) { if (!Callback.Invoke(BytesValidated, TotalSize, Guid, BlockIndex)) { Aborted = true; } } } } ); } Task.WaitAll(FileTasks); } finally { UnlockBlockInfo(); } return(FailedBlocks); }
private static void ApplySmokerFactor(Customer customer, ref RateTracker rateTracker) { OutputString.responseMessage += "\nIs Smoker"; rateTracker.RiskFactor += 0.7; rateTracker.HighRiskTracker.Add("Smoker"); }