/// <summary>
        /// Calculates Minimum SaltSplit
        /// </summary>
        /// <param name="id">Customer identifier</param>
        /// <param name="selectedTrainId">selected Train Id</param>
        /// <returns>Returns list</returns>
        public List<double> CalculateMinSaltSplit(long id, double degredation, string selectedTrainId = "0")
        {
            try
            {
                int waterDemand = this.predictiveRepository.GetWaterDemand(id);
                List<train> trainData = new List<train>();
                List<vessel> vesselData = new List<vessel>();
                List<BedNum_Interval> intervalList = new List<BedNum_Interval>();
                List<double> lbsChemicalList = new List<double>();
                TimeSpan intervalSum = new TimeSpan();
                List<double> replacementPlan = new List<double>();
                List<double> output = new List<double>();
                trainData = this.predictiveRepository.GetCustomerTrains(id);
                vesselData = this.predictiveRepository.GetCustomerVessels(id);
                double numberOfTrains;
                if (selectedTrainId == "0")
                    numberOfTrains = trainData.Count;
                else
                    numberOfTrains = 1;

                double numberCubicFeet = 0, numberRegens = 0;
                List<double> numberRegenPerTrain = new List<double>();
                string usingManifold = string.Empty;
                foreach (var item in trainData)
                {
                    usingManifold = item.using_manifold;
                    if (item.trainID == Convert.ToInt32(selectedTrainId))
                    {
                        numberRegenPerTrain.Add(Convert.ToDouble(item.regens_per_month));
                    }
                    else if (selectedTrainId == "0")
                    {
                        numberRegenPerTrain.Add(Convert.ToDouble(item.regens_per_month));
                    }
                }
                if (usingManifold == "NO")
                {
                    numberRegens = numberRegenPerTrain.Sum(); // Get the total number of regens for the system
                }
                else
                {
                    foreach (var item in vesselData)
                    {
                        if (selectedTrainId != "0")
                        {
                            numberRegenPerTrain.Add(Convert.ToDouble(item.num_regens));
                        }
                        else
                        {
                            if (item.train_trainID == Convert.ToInt32(selectedTrainId))
                            {
                                numberRegenPerTrain.Add(Convert.ToDouble(item.num_regens));
                            }
                        }

                    }
                    numberRegens = numberRegenPerTrain.Sum(); // Get the total number of regens for the system
                }
                List<double> numCuFt = new List<double>();
                int vesselNumber = 0;
                foreach (var item in vesselData)
                {
                    vesselNumber++;
                    if (selectedTrainId == "0")
                    {

                        //numberCubicFeet = numberCubicFeet + Convert.ToDouble(item.size);
                        DateTime purchasedate = Convert.ToDateTime(item.date_replaced, new CultureInfo("en-US", true));
                        TimeSpan interval = DateTime.Today - purchasedate;
                        BedNum_Interval bed_interval = new BedNum_Interval();
                        bed_interval.bed_number = item.bed_number;
                        bed_interval.span = interval;
                        intervalList.Add(bed_interval);
                        replacementPlan.Add(Convert.ToInt32(item.replacement_plan));
                        double lbsChemical = Convert.ToDouble(item.lbs_chemical);

                        if (vesselNumber % 2 != 0)
                        {  // Only the anion vessels
                            numCuFt.Add(Convert.ToDouble(item.size));
                            lbsChemicalList.Add(lbsChemical);
                        }
                    }
                    else
                    {
                        if (item.train_trainID == Convert.ToInt32(selectedTrainId))
                        {

                            //numberCubicFeet = numberCubicFeet + Convert.ToDouble(item.size);
                            DateTime purchasedate = Convert.ToDateTime(item.date_replaced, new CultureInfo("en-US", true));
                            TimeSpan interval = DateTime.Today - purchasedate;
                            BedNum_Interval bed_interval = new BedNum_Interval();
                            bed_interval.bed_number = item.bed_number;
                            bed_interval.span = interval;
                            intervalList.Add(bed_interval);
                            replacementPlan.Add(Convert.ToInt32(item.replacement_plan));
                            double lbsChemical = Convert.ToDouble(item.lbs_chemical);

                            if (vesselNumber % 2 != 0)
                            {  // Only the anion vessels
                                numCuFt.Add(Convert.ToDouble(item.size));
                                lbsChemicalList.Add(lbsChemical);
                            }
                        }
                    }
                    numberCubicFeet = numCuFt.Sum(); // Use only the number of CubicFt for the Anion Vessel
                }

                int num_anions = 0;
                foreach (var span in intervalList)
                {
                    // Ensure we are summing only the ANION vesel purchase dates!
                    if (span.bed_number == "2")
                    {
                        intervalSum += span.span;
                        num_anions++;
                    }
                }

                double average = 0;
                if (intervalList.Count > 0)
                {
                    average = intervalSum.TotalMilliseconds / num_anions;
                }
                else
                {
                    average = intervalSum.TotalMilliseconds;
                }
                TimeSpan averageResinAge = TimeSpan.FromMilliseconds(average);
                double age = averageResinAge.TotalDays / 7;
                double grainAverage = this.predictiveRepository.GetGrainsWeightTotal(id.ToString());

                double minimumSaltSplit = 9.8;
                output.Add(minimumSaltSplit);
                output.Add(age);
                return output;
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Loads the Model
        /// </summary>
        /// <param name="customerId">customer Identifier</param>
        /// <param name="currentSaltSplit">current Salt Split</param>
        /// <param name="trainRepository">train Repository</param>
        /// <param name="predictiveRepository">predictive Repository</param>
        /// <param name="conductivityS1">conductivity S1</param>
        /// <param name="conductivityS2">conductivity S2</param>
        /// <param name="sourceOnePercent">source One Percent</param>
        /// <param name="startingSaltSplit">starting Salt Split</param>
        /// <param name="resinLifeExpectancy">resin Life Expectancy</param>
        /// <param name="simulationConfidence">simulation Confidence</param>
        /// <param name="numberSimulationIterations">number of Simulation Iterations</param>
        /// <param name="simulationMethod">simulation Method</param>
        /// <param name="standardDevThreshold">standardDev Threshold</param>
        /// <param name="resinAge">resin Age parameter</param>
        /// <param name="replacementLevel">replacement Level</param>
        /// <param name="rtiCleaningLevel">rti Cleaning Level</param>
        /// <param name="selectedTrain">selected Train</param>
        /// <param name="donotReplaceResin">donot Replace Resin</param>
        /// <returns>Returns the price data</returns>
        public PriceData LoadModel(string customerId, double currentSaltSplit, IRepository<train> trainRepository, IPredictiveModelRepository predictiveRepository, List<string>[] conductivityS1, List<string>[] conductivityS2, double sourceOnePercent, double startingSaltSplit, double resinLifeExpectancy, int simulationConfidence, int numberSimulationIterations, string simulationMethod, int standardDevThreshold, double resinAge, double replacementLevel, double rtiCleaningLevel, string selectedTrain, bool donotReplaceResin)
        {
            try
            {
                ProcessData process = new ProcessData();
                process.Compute(conductivityS1, conductivityS2, sourceOnePercent);
                currentSaltSplitValue = currentSaltSplit;
                List<vessel> lstCustomerVessels = new List<vessel>();
                lstCustomerVessels = predictiveRepository.GetCustomerVessels(Convert.ToInt64(customerId));
                List<BedNum_Interval> intervalList = new List<BedNum_Interval>();
                List<double> vesselSizeList = new List<double>();
                List<double> lbsChemicalList = new List<double>();
                TimeSpan intervalSum = new TimeSpan();
                List<double> replacementPlan = new List<double>();
                int selectedTrainId;
                if (selectedTrain == "0")
                {
                    selectedTrainId = 0;
                }
                else
                {
                    selectedTrainId = Convert.ToInt16(selectedTrain);
                    lstCustomerVessels = lstCustomerVessels.Where(item => selectedTrain == Convert.ToString(item.train_trainID)).ToList();
                }
                if (lstCustomerVessels != null)
                {
                    foreach (var vesselList in lstCustomerVessels)
                    {
                        int trainID = Convert.ToInt32(vesselList.train_trainID);
                        if (trainID == selectedTrainId)
                        {
                            DateTime purchase_date = Convert.ToDateTime(vesselList.date_replaced, new CultureInfo("en-US", true));
                            TimeSpan interval = DateTime.Today - purchase_date;
                            BedNum_Interval bednum_interval = new BedNum_Interval();
                            bednum_interval.bed_number = vesselList.bed_number;
                            bednum_interval.span = interval;
                            intervalList.Add(bednum_interval);
                            replacementPlan.Add(Convert.ToInt32(vesselList.replacement_plan));
                            double lbsChemical = Convert.ToDouble(vesselList.lbs_chemical);
                            double vesselSize = Convert.ToDouble(vesselList.size);
                            vesselSizeList.Add(vesselSize);
                            lbsChemicalList.Add(lbsChemical);
                        }
                        if (selectedTrainId == 0)
                        {
                            DateTime purchase_date = Convert.ToDateTime(vesselList.date_replaced, new CultureInfo("en-US", true));
                            TimeSpan interval = DateTime.Today - purchase_date;
                            BedNum_Interval bednum_interval = new BedNum_Interval();
                            bednum_interval.bed_number = vesselList.bed_number;
                            bednum_interval.span = interval;
                            intervalList.Add(bednum_interval);
                            replacementPlan.Add(Convert.ToInt32(vesselList.replacement_plan));
                            double lbsChemical = Convert.ToDouble(vesselList.lbs_chemical);
                            double vesselSize = Convert.ToDouble(vesselList.size);
                            vesselSizeList.Add(vesselSize);
                            lbsChemicalList.Add(lbsChemical);
                        }
                    }
                }

                    int anionCount = 0;
                    foreach (var span in intervalList)
                    {
                        // Ensure we are only summing the ANION resin age only
                        if (span.bed_number == "2")
                        {
                            intervalSum += span.span;
                            anionCount++;
                        }
                    }

                double average = intervalSum.TotalMilliseconds / anionCount;
                TimeSpan averageResinAge = new TimeSpan();
                if (!double.IsNaN(average))
                {
                    averageResinAge = TimeSpan.FromMilliseconds(average);
                }
                double size = 0.0;
                if (vesselSizeList != null && vesselSizeList.Count > 0)
                {
                    size = vesselSizeList.Sum();
                }

                trainResinAmount = size;
                bool cation = true;
                foreach (var vesselSize in vesselSizeList)
                {
                    if (cation)
                    {
                        dataToSend.AmountCation += vesselSize;
                    }
                    else
                    {
                        dataToSend.AmountAnion += vesselSize;
                    }
                    cation = !cation;
                }

                trainAnionResinAmount = dataToSend.AmountAnion; // Set the amount of resin for just the ANION

                cation = true;

                foreach (var chemAmt in lbsChemicalList)
                {
                    if (cation)
                    {
                        dataToSend.AcidUsage = chemAmt;
                    }
                    else
                    {
                        dataToSend.CausticUsage = chemAmt;
                    }
                    cation = !cation;
                }

                lbsAnionChemical = dataToSend.CausticUsage; // Set the amount of Caustic

                int customerCustomerId = Convert.ToInt16(customerId);
                List<train> trains = trainRepository.GetAll().Where(p => p.customer_customerID == customerCustomerId).ToList();
                trainGPMValues = new string[trains.Count];
                trainGPM = new double[trains.Count];
                for (int i = 0; i < trains.Count; i++)
                {
                    trainGPMValues[i] = trains[i].gpm;
                    trainGPM[i] = Convert.ToDouble(trains[i].gpm);
                }

                if (selectedTrainId == 0 && trainGPM != null && trainGPM.Length > 0)
                {
                    selectedTrainGPM = trainGPM.Average();
                }
                else if (trainGPM != null && trainGPM.Length > 0)
                {
                    selectedTrainGPM = trainGPM[0];
                }

                this.LoadTrainData(2, trainGPMValues);

                List<double> regenTimes = new List<double>();
                foreach (var train in trains)
                {
                    regenTimes.Add(Convert.ToInt32(train.regen_duration));
                }

                PriceData priceData = this.RunModel(startingSaltSplit, currentSaltSplit, resinLifeExpectancy, simulationConfidence, numberSimulationIterations, simulationMethod, standardDevThreshold, resinAge, replacementLevel, rtiCleaningLevel, donotReplaceResin, regenTimes, selectedTrainId, trains, lstCustomerVessels);
                return priceData;
            }
            catch
            {
                throw;
            }
        }