/// <summary> /// Thoughput chart /// </summary> /// <param name="customerId">CustomerId parameter</param> /// <param name="Cur_SS">Curent Salt Split</param> /// <param name="startingSaltSplit">starting Salt Split</param> /// <param name="resinLifeExpectancy">resin Life Expectancy</param> /// <param name="simulationconfidence">simulation confidence</param> /// <param name="numberSimulationIterations">num of simulation iterations</param> /// <param name="simMethod">simulation Method</param> /// <param name="standardDeviationThreshold">stdDev threshold</param> /// <param name="resinAge">resin Age parameter</param> /// <param name="RTIcleaning_effectivness">RTI cleaning effectivness</param> /// <param name="replacementLevel">Replacement Level</param> /// <param name="rticleaningLevel">RTIcleaning Level</param> /// <param name="ReGen_effectivness">ReGeneration effectivness</param> /// <param name="selectedTrain">Selected Train</param> /// <param name="donotReplaceResin">Dont Replace Resin</param> /// <returns>Returns the price data</returns> public PriceData Thoughputchart(string customerId, double currentSaltSplit, double startingSaltSplit, double resinLifeExpectancy, int simulationconfidence, int numberSimulationIterations, string simMethod, int standardDeviationThreshold, double resinAge, double replacementLevel, double rticleaningLevel, string selectedTrain, bool donotReplaceResin) { try { double[] sourceId = this.predictiveRepository.FetchSourceIdTP(customerId); List<water_data> conductivitSource1 = new List<water_data>(); PriceData priceData = new PriceData(); if (sourceId != null && sourceId.Length > 0) { double sourceIdOne = sourceId[0]; conductivitSource1 = (from waterData in this.modifiedwaterdataRepository.GetAll() where waterData.sourceID == sourceIdOne select waterData).ToList(); } if (conductivitSource1.Count > 0) { List<water_data> conductivitSource2 = new List<water_data>(); if (sourceId != null && sourceId.Length > 1 && sourceId[1] == 0) { conductivitSource2 = conductivitSource1; } else if (sourceId != null && sourceId.Length > 1) { double sourceIdTwo = sourceId[1]; conductivitSource2 = (from waterData in this.modifiedwaterdataRepository.GetAll() where waterData.sourceID == sourceIdTwo select waterData).ToList(); } List<string>[] conductivitySourceArray1 = new List<string>[5]; List<string>[] conductivitySourceArray2 = new List<string>[5]; conductivitySourceArray1[0] = (from cond in conductivitSource1 select Convert.ToString(cond.dataID)).ToList(); conductivitySourceArray1[1] = (from cond in conductivitSource1 select Convert.ToString(cond.cond)).ToList(); conductivitySourceArray1[2] = (from cond in conductivitSource1 select Convert.ToString(cond.temp)).ToList(); conductivitySourceArray1[3] = (from cond in conductivitSource1 select Convert.ToString(cond.measurment_date)).ToList(); conductivitySourceArray1[4] = (from cond in conductivitSource1 select Convert.ToString(cond.sourceID)).ToList(); conductivitySourceArray2[0] = (from cond in conductivitSource2 select Convert.ToString(cond.dataID)).ToList(); conductivitySourceArray2[1] = (from cond in conductivitSource2 select Convert.ToString(cond.cond)).ToList(); conductivitySourceArray2[2] = (from cond in conductivitSource2 select Convert.ToString(cond.temp)).ToList(); conductivitySourceArray2[3] = (from cond in conductivitSource2 select Convert.ToString(cond.measurment_date)).ToList(); conductivitySourceArray2[4] = (from cond in conductivitSource2 select Convert.ToString(cond.sourceID)).ToList(); double sourceOnePercent = predictiveRepository.GetFirstSourcePercentage(customerId); ThroughputChart tpchart = new ThroughputChart(); priceData = tpchart.LoadModel(customerId, currentSaltSplit, this.modifiedTrainRepository, this.predictiveRepository, conductivitySourceArray1, conductivitySourceArray2, sourceOnePercent, startingSaltSplit, resinLifeExpectancy, simulationconfidence, numberSimulationIterations, simMethod, standardDeviationThreshold, resinAge, replacementLevel, rticleaningLevel, selectedTrain, donotReplaceResin); return priceData; } return priceData; } catch { throw; } }
/// <summary> /// Depicts the Cost analyzer chart /// </summary> /// <param name="dataToSend">data To Send</param> /// <param name="currentTrain">current Train</param> /// <param name="customerId">customer Identifier</param> /// <returns>Returns the cost</returns> public List<Tuple<int, double, double>> OpenCostWindow(PriceData dataToSend, int currentTrain, string customerId) { try { var numTrains = dataToSend.NumberTrains; var numRegensNormOps = dataToSend.RegensPerWeekNormalOps; var numRegensClean = dataToSend.RegensPerWeekClean; var cleanTP = dataToSend.CleanThroughput; var normOpsTP = dataToSend.NormalOpsThroughput; var trainList = dataToSend.TrainList; var grains = dataToSend.GrainForcast; var saltSplit = dataToSend.SaltSplit; var amtCation = dataToSend.AmountCation; var amtAnion = dataToSend.AmountAnion; var lbsCaustic = dataToSend.CausticUsage; var lbsAcid = dataToSend.AcidUsage; List<Tuple<int, double, double>> data = CalculatorInitializer(numTrains, numRegensNormOps, numRegensClean, cleanTP, normOpsTP, trainList, currentTrain, true, saltSplit, grains, amtCation, amtAnion, lbsCaustic, lbsAcid, customerId); return data; } catch { throw; } }
/// <summary> /// Run Model which calculates the required computations /// </summary> /// <param name="startingSaltSplit">starting Salt Split</param> /// <param name="currentSaltSplit">current Salt Split</param> /// <param name="resinLifeExpectancy">resin Life Expectancy</param> /// <param name="simulationConfidence">simulation Confidence</param> /// <param name="numberSimulationIterations">number Simulation Iterations</param> /// <param name="simulationMethod">simulation Method</param> /// <param name="standardDeviationThreshold">standard Deviation Threshold</param> /// <param name="resinAge">resin Age parameter</param> /// <param name="replacementLevel">replacement Level</param> /// <param name="rtiCleaningLevel">rti Cleaning Level</param> /// <param name="donotReplaceResin">dont Replace Resin</param> /// <returns>Returns the Price data</returns> public PriceData RunModel(double startingSaltSplit, double currentSaltSplit, double resinLifeExpectancy, int simulationConfidence, int numberSimulationIterations, string simulationMethod, int standardDeviationThreshold, double resinAge, double replacementLevel, double rtiCleaningLevel, bool donotReplaceResin) { try { var trainList = dataToSend.TrainList; var numberOfTrains = dataToSend.NumberTrains; if (calculationRun) { dataToSend = new PriceData(); } dataToSend.TrainList = trainList; dataToSend.NumberTrains = numberOfTrains; double numberOfWeeks = Convert.ToDouble(resinLifeExpectancy); var standardDevData = ProcessData.WeeklyWeightedAverageCondstdDev; RandomNumberSimulation conductivity = new RandomNumberSimulation(); double roundedAgeValues = Convert.ToDouble(string.Format("{0:0.00}", resinAge)); Dictionary<int, double> grainForeCast = conductivity.BeginCalculation(standardDevData, simulationConfidence, numberSimulationIterations, simulationMethod, standardDeviationThreshold, roundedAgeValues); int grainCount = grainForeCast.Count; int numberOfLoops = Convert.ToInt16(resinLifeExpectancy); if (numberOfLoops >= grainCount) { int weeksToAdd = Convert.ToInt32(numberOfLoops - grainCount); int lastGrainWeek = 0; if (grainForeCast != null && grainForeCast.Count > 0) { lastGrainWeek = grainForeCast.Last().Key + 1; } int grainIndx = 0; for (int loop = 0; loop <= weeksToAdd; loop++) { double grainToAdd = 0; if (grainForeCast != null && grainForeCast.Count > 0) { grainToAdd = grainForeCast.ElementAt(grainIndx).Value; grainForeCast.Add(lastGrainWeek, grainToAdd); lastGrainWeek++; grainIndx++; } } } dataToSend.GrainForcast = grainForeCast; double rtiCleaningeffectivness = 28.0; ThroughputBuilder tp = new ThroughputBuilder(); Dictionary<DateTime, Tuple<int, double, string>> throughputCleanPrediction = tp.ThroughputBuild(replacementLevel, rtiCleaningLevel, currentSaltSplit, grainForeCast, trainResinAmount, rtiCleaningeffectivness, selectedTrainGPM, resinAge, startingSaltSplit, numberOfWeeks, true, donotReplaceResin); var afterConditions = tp.AfterSystemConditions; Dictionary<DateTime, Tuple<int, double, string>> throughputNoCleanPrediction = tp.ThroughputBuild(replacementLevel, rtiCleaningLevel, currentSaltSplit, grainForeCast, trainResinAmount, rtiCleaningeffectivness, selectedTrainGPM, resinAge, startingSaltSplit, numberOfWeeks, false, donotReplaceResin); var beforeConditions = tp.BeforeSystemConditions; List<double> reginWeek = new List<double>(); List<double> hoursWeek = new List<double>(); List<double> reginTime = new List<double>(); List<double> tpWeek = new List<double>(); List<double> ssWeek = new List<double>(); List<double> beforeSaltSplit = new List<double>(); List<double> afterSaltSplit = new List<double>(); List<int> weeks = new List<int>(); List<Tuple<int, double>> regweekToSendNormal = new List<Tuple<int, double>>(); List<Tuple<int, double>> regweekToSendClean = new List<Tuple<int, double>>(); int weekNumber = 0; foreach (var week in beforeConditions) { weekNumber++; weeks.Add(weekNumber); reginWeek.Add(week.Item2); hoursWeek.Add(week.Item3); reginTime.Add(week.Item4); tpWeek.Add(week.Item5); ssWeek.Add(week.Item6); beforeSaltSplit.Add(week.Item6); Tuple<int, double> reginsPerWeeK = new Tuple<int, double>(weekNumber, week.Item2); regweekToSendNormal.Add(reginsPerWeeK); } dataToSend.RegensPerWeekNormalOps = regweekToSendNormal; dataToSend.CleanThroughput = throughputCleanPrediction; dataToSend.NormalOpsThroughput = throughputNoCleanPrediction; double averageTPBefore = 0; if (tpWeek != null && tpWeek.Count > 0) { averageTPBefore = Math.Round(tpWeek.Average(), 0); } if (reginWeek != null && reginWeek.Count > 0) { dataToSend.RegensPerWeekAverageBefore = Math.Round(reginWeek.Average(), 2); } if (hoursWeek != null && hoursWeek.Count > 0) { dataToSend.HoursPerRunAverageBefore = Math.Round(hoursWeek.Average(), 2); } if (reginTime != null && reginTime.Count > 0) { dataToSend.RegenTimeAverageBefore = Math.Round(reginTime.Average(), 2); } dataToSend.ThroughputAverageBefore = averageTPBefore; if (ssWeek != null && ssWeek.Count > 0) { dataToSend.NumberRegens = Math.Round(ssWeek.Average()); } if (withCleaning || withAndWithoutCleaning) { reginWeek.Clear(); hoursWeek.Clear(); reginTime.Clear(); tpWeek.Clear(); ssWeek.Clear(); foreach (var week in afterConditions) { reginWeek.Add(week.Item2); hoursWeek.Add(week.Item3); reginTime.Add(week.Item4); tpWeek.Add(week.Item5); ssWeek.Add(week.Item6); } if (reginWeek != null && reginWeek.Count > 0) { dataToSend.RegensPerWeekAverageAfter = Math.Round(reginWeek.Average(), 2); } if (hoursWeek != null && hoursWeek.Count > 0) { dataToSend.HoursPerRunAverageAfter = Math.Round(hoursWeek.Average(), 2); } if (reginTime != null && reginTime.Count > 0) { dataToSend.RegenTimeAverageAfter = Math.Round(reginTime.Average(), 2); } if (tpWeek != null && tpWeek.Count > 0) { dataToSend.ThroughputAverageAfter = Math.Round(tpWeek.Average(), 0); } } weekNumber = 0; foreach (var week in afterConditions) { weekNumber++; Tuple<int, double> reginsPerWeeK = new Tuple<int, double>(weekNumber, week.Item2); afterSaltSplit.Add(week.Item6); regweekToSendClean.Add(reginsPerWeeK); } Dictionary<int, Tuple<double?, double?>> saltSplitData = new Dictionary<int, Tuple<double?, double?>>(); int length; if (beforeSaltSplit.Count < afterSaltSplit.Count) { length = afterSaltSplit.Count; } else { length = beforeSaltSplit.Count; } for (int i = 0; i < length; i++) { int aftercount = afterSaltSplit.Count; int beforecount = beforeSaltSplit.Count; double? before = 0; double? after = 0; int week = 0; bool shouldAdd = true; if (beforecount > aftercount) { if (i < aftercount) { before = beforeSaltSplit.ElementAt(i); after = afterSaltSplit.ElementAt(i); week = i + 1; } else { shouldAdd = false; } } else if (beforecount < aftercount) { if (i < beforecount) { before = beforeSaltSplit.ElementAt(i); after = afterSaltSplit.ElementAt(i); week = i + 1; } else { shouldAdd = false; } } else if (beforecount == aftercount) { before = beforeSaltSplit.ElementAt(i); after = afterSaltSplit.ElementAt(i); week = i + 1; } Tuple<double?, double?> temp = new Tuple<double?, double?>(before, after); if (shouldAdd) { saltSplitData.Add(week, temp); } } dataToSend.RegensPerWeekClean = regweekToSendClean; dataToSend.CleanThroughput = throughputCleanPrediction; dataToSend.NormalOpsThroughput = throughputNoCleanPrediction; dataToSend.SaltSplit = saltSplitData; dataToSend.NumberWeeks = numberOfWeeks; return dataToSend; } catch { throw; } }
/// <summary> /// Depicts the Cost analyzer chart /// </summary> /// <param name="dataToSend">data To Send</param> /// <param name="currentTrain">current Train</param> /// <param name="customerId">customer Identifier</param> /// <returns>Returns the cost</returns> public List<Tuple<int, double, double>> OpenCostWindow(PriceData dataToSend, int currentTrain, string customerId, bool isFirstLoad) { try { var numTrains = dataToSend.NumberTrains; var numRegensNormOps = dataToSend.RegensPerWeekNormalOps; var numRegensClean = dataToSend.RegensPerWeekClean; var cleanTP = dataToSend.CleanThroughput; var normOpsTP = dataToSend.NormalOpsThroughput; var trainList = dataToSend.TrainList; var grains = dataToSend.GrainForcast; var saltSplit = dataToSend.SaltSplit; var amtCation = dataToSend.AmountCation; var amtAnion = dataToSend.AmountAnion; var lbsCaustic = dataToSend.CausticUsage; var lbsAcid = dataToSend.AcidUsage; var causticPrice = dataToSend.CausticPrice; var acidPrice = dataToSend.AcidPrice; // Set variables in variable class for acess by any method calculationParameters.WithCleaningTP = cleanTP; calculationParameters.WithOutCleaningTP = normOpsTP; calculationParameters.TrainList = trainList; calculationParameters.NumberRegenerationsNormalOps = numRegensNormOps; calculationParameters.NumberRegenerationsClean = numRegensClean; calculationParameters.NumberOfTrains = numTrains; calculationParameters.SaltSplit = saltSplit; calculationParameters.GrainForcast = grains; calculationParameters.AcidConcentration = dataToSend.acidConcentratoin; calculationParameters.CausticConcentration = dataToSend.causticConcentration; calculationParameters.AcidPrice = dataToSend.AcidPrice; calculationParameters.CausticPrice = dataToSend.CausticPrice; calculationParameters.AcidPriceConversion = 1; calculationParameters.CausticPriceConversion = 1; calculationParameters.CationCleaningPrice = dataToSend.cleaningPriceCation; calculationParameters.AnionCleaningPrice = dataToSend.cleaningPriceAnion; calculationParameters.ReplacementPriceAnion = dataToSend.replacePirceAnion; calculationParameters.ReplacemtntPriceCation = dataToSend.replacePriceCation; calculationParameters.AnionAmount = dataToSend.AmountAnion; calculationParameters.CationAmount = dataToSend.AmountCation; calculationParameters.AmountOfAcid = dataToSend.AcidUsage; calculationParameters.AmountOfCaustic = dataToSend.CausticUsage; List<Tuple<int, double, double>> data = CalculatorInitializer(numTrains, numRegensNormOps, numRegensClean, cleanTP, normOpsTP, trainList, currentTrain, isFirstLoad, saltSplit, grains, amtCation, amtAnion, lbsCaustic, lbsAcid, customerId, causticPrice, acidPrice); return data; } catch { throw; } }
/// <summary> /// Run Model which calculates the required computations /// </summary> /// <param name="startingSaltSplit">starting Salt Split</param> /// <param name="currentSaltSplit">current Salt Split</param> /// <param name="resinLifeExpectancy">resin Life Expectancy</param> /// <param name="simulationConfidence">simulation Confidence</param> /// <param name="numberSimulationIterations">number Simulation Iterations</param> /// <param name="simulationMethod">simulation Method</param> /// <param name="standardDeviationThreshold">standard Deviation Threshold</param> /// <param name="resinAge">resin Age parameter</param> /// <param name="replacementLevel">replacement Level</param> /// <param name="rtiCleaningLevel">rti Cleaning Level</param> /// <param name="donotReplaceResin">dont Replace Resin</param> /// <returns>Returns the Price data</returns> public PriceData RunModel(double startingSaltSplit, double currentSaltSplit, double resinLifeExpectancy, int simulationConfidence, int numberSimulationIterations, string simulationMethod, int standardDeviationThreshold, double resinAge, double replacementLevel, double rtiCleaningLevel, bool donotReplaceResin, List<double> regenTimes, int selectedTrainId, List<train> trains, List<vessel> vessels) { try { var trainList = dataToSend.TrainList; var numberOfTrains = dataToSend.NumberTrains; if (calculationRun) { dataToSend = new PriceData(); } dataToSend.TrainList = trainList; dataToSend.NumberTrains = numberOfTrains; double numberOfWeeks = Convert.ToDouble(resinLifeExpectancy); var standardDevData = ProcessData.WeeklyWeightedAverageCondstdDev; RandomNumberSimulation conductivity = new RandomNumberSimulation(); double roundedAgeValues = Convert.ToDouble(string.Format("{0:0.00}", resinAge)); Dictionary<int, double> grainForeCast = conductivity.BeginCalculation(standardDevData, simulationConfidence, numberSimulationIterations, simulationMethod, standardDeviationThreshold, roundedAgeValues); int grainCount = grainForeCast.Count; int numberOfLoops = Convert.ToInt16(resinLifeExpectancy); if (numberOfLoops >= grainCount) { int weeksToAdd = Convert.ToInt32(numberOfLoops - grainCount); int lastGrainWeek = 0; if (grainForeCast != null && grainForeCast.Count > 0) { lastGrainWeek = grainForeCast.Last().Key + 1; } int grainIndx = 0; for (int loop = 0; loop <= weeksToAdd; loop++) { double grainToAdd = 0; if (grainForeCast != null && grainForeCast.Count > 0) { grainToAdd = grainForeCast.ElementAt(grainIndx).Value; grainForeCast.Add(lastGrainWeek, grainToAdd); lastGrainWeek++; grainIndx++; } } } dataToSend.GrainForcast = grainForeCast; double rtiCleaningeffectivness = 28.0; ThroughputBuilder tp = new ThroughputBuilder(); Dictionary<DateTime, Tuple<int, double, string>> throughputCleanPrediction = new Dictionary<DateTime,Tuple<int,double,string>>(); Dictionary<DateTime, Tuple<int, double, string>> throughputNoCleanPrediction = new Dictionary<DateTime, Tuple<int, double, string>>(); List<Tuple<double, double, double, double, double, double>> beforeConditions = new List<Tuple<double, double, double, double, double, double>>(); List<Tuple<double, double, double, double, double, double>> afterConditions = new List<Tuple<double, double, double, double, double, double>>(); List<Dictionary<DateTime, Tuple<int, double, string>>> throughputCleanPredictionAllTrains = new List<Dictionary<DateTime, Tuple<int, double, string>>>(); List<Dictionary<DateTime, Tuple<int, double, string>>> throughputNoCleanPredictionAllTrains = new List<Dictionary<DateTime,Tuple<int,double,string>>>(); List<List<Tuple<double, double, double, double, double, double>>> beforeConditionsAllTrains = new List<List<Tuple<double,double,double,double,double,double>>>(); List<List<Tuple<double, double, double, double, double, double>>> afterConditionsAllTrains = new List<List<Tuple<double, double, double, double, double, double>>>(); List<double> reginWeek_before = new List<double>(); List<double> hoursWeek_before = new List<double>(); List<double> reginTime_before = new List<double>(); List<double> tpWeek_before = new List<double>(); List<double> ssWeek_before = new List<double>(); List<double> reginWeek_after = new List<double>(); List<double> hoursWeek_after = new List<double>(); List<double> reginTime_after = new List<double>(); List<double> tpWeek_after = new List<double>(); List<double> ssWeek_after = new List<double>(); List<double> beforeSaltSplit = new List<double>(); List<double> afterSaltSplit = new List<double>(); List<int> weeks = new List<int>(); List<Tuple<int, double>> regweekToSendNormal = new List<Tuple<int, double>>(); List<Tuple<int, double>> regweekToSendClean = new List<Tuple<int, double>>(); List<double> grainsWeek_before_AllTrains = new List<double>(); List<double> reginWeek_before_AllTrains = new List<double>(); List<double> hoursWeek_before_AllTrains = new List<double>(); List<double> reginTime_before_AllTrains = new List<double>(); List<double> tpWeek_before_AllTrains = new List<double>(); List<double> ssWeek_before_AllTrains = new List<double>(); List<double> grainsWeek_after_AllTrains = new List<double>(); List<double> reginWeek_after_AllTrains = new List<double>(); List<double> hoursWeek_after_AllTrains = new List<double>(); List<double> reginTime_after_AllTrains = new List<double>(); List<double> tpWeek_after_AllTrains = new List<double>(); List<double> ssWeek_after_AllTrains = new List<double>(); List<double> beforeSaltSplit_AllTrains = new List<double>(); List<double> afterSaltSplit_AllTrains = new List<double>(); List<int> weeks_AllTrains = new List<int>(); List<Tuple<int, double>> regweekToSendNormal_AllTrains = new List<Tuple<int, double>>(); List<Tuple<int, double>> regweekToSendClean_AllTrains = new List<Tuple<int, double>>(); List<DateTime> dateWeekTpPair_AllTrains = new List<DateTime>(); List<Tuple<double, double, string>> beforeWeekTP_Pair_AllTrains = new List<Tuple<double,double,string>>(); List<Tuple<double, double, string>> afterWeekTP_Pair_AllTrains = new List<Tuple<double,double,string>>(); int weekNumber = 0; double numRegensBefore = 0; double numRegensAfter = 0; if (selectedTrainId != 0) { throughputCleanPrediction = tp.ThroughputBuild(replacementLevel, rtiCleaningLevel, currentSaltSplit, grainForeCast, trainAnionResinAmount, rtiCleaningeffectivness, selectedTrainGPM, resinAge, startingSaltSplit, numberOfWeeks, true, donotReplaceResin, regenTimes.Average(), selectedTrainId, trains.Count); afterConditions = tp.AfterSystemConditions; throughputNoCleanPrediction = tp.ThroughputBuild(replacementLevel, rtiCleaningLevel, currentSaltSplit, grainForeCast, trainAnionResinAmount, rtiCleaningeffectivness, selectedTrainGPM, resinAge, startingSaltSplit, numberOfWeeks, false, donotReplaceResin, regenTimes.Average(), selectedTrainId, trains.Count); beforeConditions = tp.BeforeSystemConditions; foreach (var week in beforeConditions) { weekNumber++; weeks.Add(weekNumber); reginWeek_before.Add(week.Item2); hoursWeek_before.Add(week.Item3); reginTime_before.Add(week.Item4); tpWeek_before.Add(week.Item5); ssWeek_before.Add(week.Item6); beforeSaltSplit.Add(week.Item6); Tuple<int, double> reginsPerWeeK = new Tuple<int, double>(weekNumber, week.Item2); regweekToSendNormal.Add(reginsPerWeeK); } weekNumber = 0; foreach (var week in afterConditions) { weekNumber++; Tuple<int, double> reginsPerWeeK = new Tuple<int, double>(weekNumber, week.Item2); afterSaltSplit.Add(week.Item6); regweekToSendClean.Add(reginsPerWeeK); } } else // If selected train == 0 (all trains) { // Perform the simulation for each train in the system for (int train = 1; train <= trains.Count; train++) // for each train in the system { int trainID = Convert.ToInt32(trains.ElementAt(train-1).trainID); selectedTrainGPM = Convert.ToDouble(trains.ElementAt(train - 1).gpm); double regenTime = Convert.ToInt32(trains.ElementAt(train - 1).regen_duration); double amtAnionResin = 0; List<double> resinAges = new List<double>(); var train_vessels = vessels.Where(ves => ves.train_trainID == trainID); int count = 0; foreach (var vessel in train_vessels) // for each vessel in the current train { if (count % 2 != 0) // If it is an anion vessel { amtAnionResin += Convert.ToInt32(vessel.size); DateTime purchaseDate = DateTime.Parse(vessel.date_replaced); TimeSpan span = DateTime.Today - purchaseDate; resinAges.Add(span.TotalDays); } count++; } double resAge = resinAges.Count() != 0 ? resinAges.Average() / 7 : 0; throughputCleanPrediction = tp.ThroughputBuild(replacementLevel, rtiCleaningLevel, currentSaltSplit, grainForeCast, amtAnionResin, rtiCleaningeffectivness, selectedTrainGPM, resAge, startingSaltSplit, numberOfWeeks, true, donotReplaceResin, regenTime, trainID, trains.Count); throughputCleanPredictionAllTrains.Add(throughputCleanPrediction); afterConditions = tp.AfterSystemConditions; afterConditionsAllTrains.Add(afterConditions); throughputNoCleanPrediction = tp.ThroughputBuild(replacementLevel, rtiCleaningLevel, currentSaltSplit, grainForeCast, amtAnionResin, rtiCleaningeffectivness, selectedTrainGPM, resAge, startingSaltSplit, numberOfWeeks, false, donotReplaceResin, regenTime, trainID, trains.Count); throughputNoCleanPredictionAllTrains.Add(throughputNoCleanPrediction); beforeConditions = tp.BeforeSystemConditions; beforeConditionsAllTrains.Add(beforeConditions); numRegensBefore += beforeConditions.Average(regens => regens.Item2); numRegensAfter += afterConditions.Average(regens => regens.Item2); beforeConditions = new List<Tuple<double, double, double, double, double, double>>(); // Reset the before conditions afterConditions = new List<Tuple<double, double, double, double, double, double>>(); // Reset the after conditions throughputCleanPrediction = new Dictionary<DateTime, Tuple<int, double, string>>(); // Reset the before conditions throughputNoCleanPrediction = new Dictionary<DateTime, Tuple<int, double, string>>(); // Reset the after conditions tp = new ThroughputBuilder(); // Reset the TP builder class } int beforeMaxLength = beforeConditionsAllTrains.Select(len => len.Count()).ToList().Max(); int afterMaxLength = afterConditionsAllTrains.Select(len => len.Count()).ToList().Max(); List<Tuple<int, double, double, double, double, double>>[] before_conditions = new List<Tuple<int, double, double, double, double, double>>[beforeMaxLength]; List<Tuple<int, double, double, double, double, double>>[] after_conditions = new List<Tuple<int, double, double, double, double, double>>[afterMaxLength]; foreach (var trains_beforeConditions in beforeConditionsAllTrains) // Cycle through all of the before system conditions for each train { foreach (var week in trains_beforeConditions) // Go through each week's before conditions for each train in the system and add to an array of lists { Tuple<int, double, double, double, double, double> thisWeeksBeforeConditions = new Tuple<int,double,double,double,double,double>(weekNumber+1, week.Item2, week.Item3, week.Item4, week.Item5, week.Item6); if (before_conditions[weekNumber] == null) // Initialize the array object if it is empty before_conditions[weekNumber] = new List<Tuple<int, double, double, double, double, double>>(); before_conditions[weekNumber].Add(thisWeeksBeforeConditions); weekNumber++; } weekNumber = 0; } weekNumber = 0; foreach (var trains_afterConditions in afterConditionsAllTrains) // Cycle through all of the before system conditions for each train { foreach (var week in trains_afterConditions) // Go through each week's after conditions for each train in the system and add to an array of lists { Tuple<int, double, double, double, double, double> thisWeeksAfterConditions = new Tuple<int, double, double, double, double, double>(weekNumber+1, week.Item2, week.Item3, week.Item4, week.Item5, week.Item6); if (after_conditions[weekNumber] == null) // Initialize the array object if it is empty after_conditions[weekNumber] = new List<Tuple<int, double, double, double, double, double>>(); after_conditions[weekNumber].Add(thisWeeksAfterConditions); weekNumber++; } weekNumber = 0; } foreach (var weekly_conditions in before_conditions) // Average together the data for each of the trains before conditions { weekNumber++; weeks_AllTrains.Add(weekNumber + 1); double _grainWeek = weekly_conditions.Select(grains => grains.Item1).ToList().Average(); double _reginWeek = weekly_conditions.Select(regenPerWeek => regenPerWeek.Item2).ToList().Average(); double _hoursWeek = weekly_conditions.Select(hrPerRun => hrPerRun.Item3).ToList().Average(); double _reginTime = weekly_conditions.Select(regenTime => regenTime.Item4).ToList().Average(); double _tpWeek = weekly_conditions.Select(throughput => throughput.Item5).ToList().Average(); double _ssWeek = weekly_conditions.Select(SaltSplit => SaltSplit.Item6).ToList().Average(); double _beforeSS = weekly_conditions.Select(SaltSplit => SaltSplit.Item6).ToList().Average(); grainsWeek_before_AllTrains.Add(_grainWeek); reginWeek_before_AllTrains.Add(_reginWeek); hoursWeek_before_AllTrains.Add(_hoursWeek); reginTime_before_AllTrains.Add(_reginTime); tpWeek_before_AllTrains.Add(_tpWeek); ssWeek_before_AllTrains.Add(_ssWeek); beforeSaltSplit_AllTrains.Add(_beforeSS); Tuple<int, double> reginsPerWeeK = new Tuple<int, double>(weekNumber, weekly_conditions.Select(regenPerWeek => regenPerWeek.Item2).ToList().Average()); Tuple<double, double, double, double, double, double> beforeCondition = new Tuple<double,double,double,double,double,double>(_grainWeek, _reginWeek, _hoursWeek, _reginTime, _tpWeek, _ssWeek); regweekToSendNormal_AllTrains.Add(reginsPerWeeK); beforeConditions.Add(beforeCondition); } // Use the new average value from each of the train simulations BEFORE weeks = weeks_AllTrains; reginWeek_before = reginWeek_before_AllTrains; hoursWeek_before = hoursWeek_before_AllTrains; reginTime_before = reginTime_before_AllTrains; tpWeek_before = tpWeek_before_AllTrains; ssWeek_before = ssWeek_before_AllTrains; weekNumber = 0; foreach (var weekly_conditions in after_conditions) // Average together the data for each of the trains after conditions { weekNumber++; double _grainWeek = weekly_conditions.Select(grains => grains.Item1).ToList().Average(); double _reginWeek = weekly_conditions.Select(regenPerWeek => regenPerWeek.Item2).ToList().Average(); double _hoursWeek = weekly_conditions.Select(hrPerRun => hrPerRun.Item3).ToList().Average(); double _reginTime = weekly_conditions.Select(regenTime => regenTime.Item4).ToList().Average(); double _tpWeek = weekly_conditions.Select(throughput => throughput.Item5).ToList().Average(); double _ssWeek = weekly_conditions.Select(SaltSplit => SaltSplit.Item6).ToList().Average(); double _afterSS = weekly_conditions.Select(SaltSplit => SaltSplit.Item6).ToList().Average(); grainsWeek_after_AllTrains.Add(_grainWeek); reginWeek_after_AllTrains.Add(_reginWeek); hoursWeek_after_AllTrains.Add(_hoursWeek); reginTime_after_AllTrains.Add(_reginTime); tpWeek_after_AllTrains.Add(_tpWeek); ssWeek_after_AllTrains.Add(_ssWeek); afterSaltSplit_AllTrains.Add(_afterSS); Tuple<int, double> reginsPerWeeK = new Tuple<int, double>(weekNumber, weekly_conditions.Select(regenPerWeek => regenPerWeek.Item2).ToList().Average()); Tuple<double, double, double, double, double, double> afterCondition = new Tuple<double, double, double, double, double, double>(_grainWeek, _reginWeek, _hoursWeek, _reginTime, _tpWeek, _ssWeek); regweekToSendClean_AllTrains.Add(reginsPerWeeK); afterConditions.Add(afterCondition); } // Use the new average value from each of the train simulations AFTER reginWeek_after = reginWeek_after_AllTrains; hoursWeek_after = hoursWeek_after_AllTrains; reginTime_after = reginTime_after_AllTrains; tpWeek_after = tpWeek_after_AllTrains; ssWeek_after = ssWeek_after_AllTrains; regweekToSendNormal = regweekToSendNormal_AllTrains; regweekToSendClean = regweekToSendClean_AllTrains; beforeMaxLength = throughputNoCleanPredictionAllTrains.Select(len => len.Count()).ToList().Max(); afterMaxLength = throughputCleanPredictionAllTrains.Select(len => len.Count()).ToList().Max(); List<Dictionary<DateTime, Tuple<int, double, string>>>[] before = new List<Dictionary<DateTime, Tuple<int, double, string>>>[beforeMaxLength]; List<Dictionary<DateTime, Tuple<int, double, string>>>[] after = new List<Dictionary<DateTime, Tuple<int, double, string>>>[afterMaxLength]; weekNumber = 0; foreach (var trains_beforeConditions in throughputNoCleanPredictionAllTrains) // Cycle through all of the before system conditions for each train { foreach (var week in trains_beforeConditions) // Go through each week's before conditions for each train in the system and add to an array of lists { Dictionary<DateTime, Tuple<int, double, string>> dictionary = new Dictionary<DateTime, Tuple<int, double, string>>(); Tuple<int, double, string> thisWeeksBeforeConditions = new Tuple<int, double, string>(week.Value.Item1, week.Value.Item2, week.Value.Item3); dictionary.Add(week.Key, thisWeeksBeforeConditions); if (before[weekNumber] == null) // Initialize the array object if it is empty before[weekNumber] = new List<Dictionary<DateTime, Tuple<int, double, string>>>(); before[weekNumber].Add(dictionary); weekNumber++; } weekNumber = 0; } weekNumber = 0; foreach (var trains_afterConditions in throughputCleanPredictionAllTrains) // Cycle through all of the before system conditions for each train { foreach (var week in trains_afterConditions) // Go through each week's before conditions for each train in the system and add to an array of lists { Dictionary<DateTime, Tuple<int, double, string>> dictionary = new Dictionary<DateTime, Tuple<int, double, string>>(); Tuple<int, double, string> thisWeeksAfterConditions = new Tuple<int, double, string>(week.Value.Item1, week.Value.Item2, week.Value.Item3); dictionary.Add(week.Key, thisWeeksAfterConditions); if (after[weekNumber] == null) // Initialize the array object if it is empty after[weekNumber] = new List<Dictionary<DateTime, Tuple<int, double, string>>>(); after[weekNumber].Add(dictionary); weekNumber++; } weekNumber = 0; } weekNumber = 0; foreach (var weekly_conditions in before) // Average together the data for each of the trains before conditions { List<int> grains = new List<int>(); List<double> throughputVal = new List<double>(); List<string> cleaOrReplace = new List<string>(); int len = weekly_conditions.Count()-1; for (int trn = 0; trn <= len; trn++) { grains.Add(weekly_conditions.ElementAt(trn).Values.ElementAt(0).Item1); throughputVal.Add(weekly_conditions.ElementAt(trn).Values.ElementAt(0).Item2); cleaOrReplace.Add(weekly_conditions.ElementAt(trn).Values.ElementAt(0).Item3); } //dateWeekTpPair_AllTrains = weekly_conditions //weekNumber++; //weeks_AllTrains.Add(weekNumber + 1); //grainsWeek_AllTrains.Add(weekly_conditions.Select(grains => grains.Item1).ToList().Average()); //reginWeek_AllTrains.Add(weekly_conditions.Select(regenPerWeek => regenPerWeek.Item2).ToList().Average()); //hoursWeek_AllTrains.Add(weekly_conditions.Select(hrPerRun => hrPerRun.Item3).ToList().Average()); //reginTime_AllTrains.Add(weekly_conditions.Select(regenTime => regenTime.Item4).ToList().Average()); //tpWeek_AllTrains.Add(weekly_conditions.Select(throughput => throughput.Item5).ToList().Average()); //Tuple<int, double> reginsPerWeeK = new Tuple<int, double>(weekNumber, weekly_conditions.Select(regenPerWeek => regenPerWeek.Item2).ToList().Average()); //regweekToSendNormal_AllTrains.Add(reginsPerWeeK); //if (grains.First() == 120 || weekNumber == 80) //{ // // stop here //} Tuple<int, double, string> thisWeeksBeforeConditions = new Tuple<int, double, string>(grains.First(), throughputVal.Average(), cleaOrReplace.First()); //dictionary.Add(weekly_conditions.ElementAt(0).Keys.ElementAt(0), thisWeeksAfterConditions); throughputNoCleanPrediction.Add(weekly_conditions.ElementAt(0).Keys.ElementAt(0), thisWeeksBeforeConditions); //.Select(x => tranform(x)) // .Where(y => y != null) //Check for nulls // .ToList(); weekNumber++; } weekNumber = 0; foreach (var weekly_conditions in after) // Average together the data for each of the trains before conditions { List<int> grains = new List<int>(); List<double> throughputVal = new List<double>(); List<string> cleaOrReplace = new List<string>(); int len = weekly_conditions.Count() - 1; for (int trn = 0; trn <= len; trn++) { grains.Add(weekly_conditions.ElementAt(trn).Values.ElementAt(0).Item1); throughputVal.Add(weekly_conditions.ElementAt(trn).Values.ElementAt(0).Item2); cleaOrReplace.Add(weekly_conditions.ElementAt(trn).Values.ElementAt(0).Item3); } Tuple<int, double, string> thisWeeksAfterConditions = new Tuple<int, double, string>(grains.First(), throughputVal.Average(), cleaOrReplace.First()); throughputCleanPrediction.Add(weekly_conditions.ElementAt(0).Keys.ElementAt(0), thisWeeksAfterConditions); weekNumber++; } } dataToSend.RegensPerWeekNormalOps = regweekToSendNormal; dataToSend.CleanThroughput = throughputCleanPrediction; dataToSend.NormalOpsThroughput = throughputNoCleanPrediction; double averageTPBefore = 0; if (tpWeek_before != null && tpWeek_before.Count > 0) { averageTPBefore = Math.Round(tpWeek_before.Average(), 0); } if (reginWeek_before != null && reginWeek_before.Count > 0 && selectedTrainId != 0) { dataToSend.RegensPerWeekAverageBefore = Math.Round(reginWeek_before.Average(), 2); } else { dataToSend.RegensPerWeekAverageBefore = Math.Round(numRegensBefore, 2); } if (hoursWeek_before != null && hoursWeek_before.Count > 0) { dataToSend.HoursPerRunAverageBefore = Math.Round(hoursWeek_before.Average(), 2); } if (reginTime_before != null && reginTime_before.Count > 0) { dataToSend.RegenTimeAverageBefore = Math.Round(reginTime_before.Average(), 2); } dataToSend.ThroughputAverageBefore = averageTPBefore; if (ssWeek_before != null && ssWeek_before.Count > 0) { dataToSend.NumberRegens = Math.Round(ssWeek_before.Average()); } if (withCleaning || withAndWithoutCleaning) { //reginWeek_after.Clear(); //hoursWeek_after.Clear(); //reginTime_after.Clear(); //tpWeek_after.Clear(); //ssWeek_after.Clear(); foreach (var week in afterConditions) { reginWeek_after.Add(week.Item2); hoursWeek_after.Add(week.Item3); reginTime_after.Add(week.Item4); tpWeek_after.Add(week.Item5); ssWeek_after.Add(week.Item6); } if (reginWeek_after != null && reginWeek_after.Count > 0 && selectedTrainId != 0) { dataToSend.RegensPerWeekAverageAfter = Math.Round(reginWeek_after.Average(), 2); } else { dataToSend.RegensPerWeekAverageAfter = Math.Round(numRegensAfter, 2); } if (hoursWeek_after != null && hoursWeek_after.Count > 0) { dataToSend.HoursPerRunAverageAfter = Math.Round(hoursWeek_after.Average(), 2); } if (reginTime_after != null && reginTime_after.Count > 0) { dataToSend.RegenTimeAverageAfter = Math.Round(reginTime_after.Average(), 2); } if (tpWeek_after != null && tpWeek_after.Count > 0) { dataToSend.ThroughputAverageAfter = Math.Round(tpWeek_after.Average(), 0); } } //// Clear previous data used in ALL TRAINS calculation //if (selectedTrainId != 0) //{ // tp = new ThroughputBuilder(); // throughputCleanPrediction = new Dictionary<DateTime, Tuple<int, double, string>>(); // throughputNoCleanPrediction = new Dictionary<DateTime, Tuple<int, double, string>>(); // beforeConditions = new List<Tuple<double, double, double, double, double, double>>(); // afterConditions = new List<Tuple<double, double, double, double, double, double>>(); // regweekToSendClean = new List<Tuple<int, double>>(); // regweekToSendNormal = new List<Tuple<int, double>>(); // throughputCleanPrediction = tp.ThroughputBuild(replacementLevel, rtiCleaningLevel, currentSaltSplit, grainForeCast, trainAnionResinAmount, rtiCleaningeffectivness, selectedTrainGPM, resinAge, startingSaltSplit, numberOfWeeks, true, donotReplaceResin, regenTimes.Average(), selectedTrainId, trains.Count); // afterConditions = tp.AfterSystemConditions; // throughputNoCleanPrediction = tp.ThroughputBuild(replacementLevel, rtiCleaningLevel, currentSaltSplit, grainForeCast, trainAnionResinAmount, rtiCleaningeffectivness, selectedTrainGPM, resinAge, startingSaltSplit, numberOfWeeks, false, donotReplaceResin, regenTimes.Average(), selectedTrainId, trains.Count); // beforeConditions = tp.BeforeSystemConditions; // weeks.Clear(); // reginWeek.Clear(); // hoursWeek.Clear(); // reginTime.Clear(); // tpWeek.Clear(); // ssWeek.Clear(); // beforeSaltSplit.Clear(); // afterSaltSplit.Clear(); // foreach (var week in beforeConditions) // { // weekNumber++; // weeks.Add(weekNumber); // reginWeek.Add(week.Item2); // hoursWeek.Add(week.Item3); // reginTime.Add(week.Item4); // tpWeek.Add(week.Item5); // ssWeek.Add(week.Item6); // beforeSaltSplit.Add(week.Item6); // Tuple<int, double> reginsPerWeeK = new Tuple<int, double>(weekNumber, week.Item2); // regweekToSendNormal.Add(reginsPerWeeK); // } // weekNumber = 0; // foreach (var week in afterConditions) // { // weekNumber++; // Tuple<int, double> reginsPerWeeK = new Tuple<int, double>(weekNumber, week.Item2); // afterSaltSplit.Add(week.Item6); // regweekToSendClean.Add(reginsPerWeeK); // } //} Dictionary<int, Tuple<double?, double?>> saltSplitData = new Dictionary<int, Tuple<double?, double?>>(); int length; if (beforeSaltSplit.Count < afterSaltSplit.Count) { length = afterSaltSplit.Count; } else { length = beforeSaltSplit.Count; } for (int i = 0; i < length; i++) { int aftercount = afterSaltSplit.Count; int beforecount = beforeSaltSplit.Count; double? before = 0; double? after = 0; int week = 0; bool shouldAdd = true; if (beforecount > aftercount) { if (i < aftercount) { before = beforeSaltSplit.ElementAt(i); after = afterSaltSplit.ElementAt(i); week = i + 1; } else { shouldAdd = false; } } else if (beforecount < aftercount) { if (i < beforecount) { before = beforeSaltSplit.ElementAt(i); after = afterSaltSplit.ElementAt(i); week = i + 1; } else { shouldAdd = false; } } else if (beforecount == aftercount) { before = beforeSaltSplit.ElementAt(i); after = afterSaltSplit.ElementAt(i); week = i + 1; } Tuple<double?, double?> temp = new Tuple<double?, double?>(before, after); if (shouldAdd) { saltSplitData.Add(week + ((throughputCleanPrediction.Values.ElementAt(0).Item1) - 1), temp); } } dataToSend.RegensPerWeekNormalOps = regweekToSendNormal; dataToSend.RegensPerWeekClean = regweekToSendClean; dataToSend.CleanThroughput = throughputCleanPrediction; dataToSend.NormalOpsThroughput = throughputNoCleanPrediction; dataToSend.SaltSplit = saltSplitData; dataToSend.NumberWeeks = numberOfWeeks; return dataToSend; } catch { throw; } }
public void OpenCostWindow() { List<Tuple<int, double>> RegensPerWeekNormalOps = new List<Tuple<int, double>>(); RegensPerWeekNormalOps.Add(new Tuple<int, double>(1, 2)); List<Tuple<int, double>> RegensPerWeekClean = new List<Tuple<int, double>>(); RegensPerWeekClean.Add(new Tuple<int, double>(1, 2)); Dictionary<DateTime, Tuple<int, double, string>> NormalOpsThroughput = new Dictionary<DateTime, Tuple<int, double, string>>(); NormalOpsThroughput.Add(DateTime.Now, new Tuple<int, double, string>(1, 2, "Replace")); Dictionary<DateTime, Tuple<int, double, string>> CleanThroughput = new Dictionary<DateTime, Tuple<int, double, string>>(); CleanThroughput.Add(DateTime.Now, new Tuple<int, double, string>(1, 2, "Replace")); PriceData dataToSend = new PriceData() { RegensPerWeekNormalOps = RegensPerWeekNormalOps, RegensPerWeekClean = RegensPerWeekClean, NormalOpsThroughput = NormalOpsThroughput, CleanThroughput = CleanThroughput }; int currentTrain = 1; string customerId = "1"; mockedCustRepository.Setup(m => m.FindById(customerId)).Returns(new customer() { acid_price = 1, caustic_price = 1 }); mockedVesselRepository.Setup(m => m.GetById(currentTrain)).Returns(new vessel()); ICostAnalyzerService service = new CostAnalyzerService(mockedCustRepository.Object, mockedTrainRepository.Object, mockedVesselRepository.Object ); var returnObj = service.OpenCostWindow(dataToSend, currentTrain, customerId, true); Assert.IsNotNull(returnObj); Assert.IsInstanceOfType(returnObj, typeof(List<Tuple<int, double, double>>)); var result = (List<Tuple<int, double, double>>)returnObj; Assert.IsNotNull(result); mockedCustRepository.Verify(m => m.FindById(customerId), Times.Once()); }