/// <summary>
 /// Initializes a new instance of the <see cref="PredictiveModelService" /> class
 /// </summary>
 /// <param name="trainRepository">trainRepository parameter</param>
 /// <param name="waterdataRepository">waterdataRepository parameter</param>
 /// <param name="predictiveRepository">predictiveRepository parameter</param>
 /// <param name="vesselRepository">vesselRepository parameter</param>
 public PredictiveModelService(IRepository<train> trainRepository, IRepository<water_data> waterdataRepository, IPredictiveModelRepository predictiveRepository, IVesselRepository vesselRepository)
 {
     this.modifiedwaterdataRepository = waterdataRepository;
     this.predictiveRepository = predictiveRepository;
     this.modifiedTrainRepository = trainRepository;
     this.modifiedVesselRepository = vesselRepository;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PredictiveSystemController" /> class
 /// </summary>
 /// <param name="modifiedPredictiveRepository">modified Predictive Repository</param>
 /// <param name="predictiveModelService">predictive Model Service</param>
 /// <param name="customerRepository">customer Repository</param>
 /// <param name="modifiedCustomerRepository">modified Customer Repository</param>
 /// <param name="vesselRepository">vessel Repository</param>
 /// <param name="trainRepository">train Repository</param>
 public PredictiveSystemController(IPredictiveModelRepository modifiedPredictiveRepository, IPredictiveModelService predictiveModelService, IRepository<customer> customerRepository, ICustomerRepository modifiedCustomerRepository, IRepository<vessel> vesselRepository, IRepository<train> trainRepository)
 {
     this.modifiedPredictiveRepository = modifiedPredictiveRepository;
     this.predictiveModelService = predictiveModelService;
     this.customerRepository = customerRepository;
     this.modifiedCustomerRepository = modifiedCustomerRepository;
     this.vesselRepository = vesselRepository;
     this.trainRepository = trainRepository;
 }
Beispiel #3
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
            {
                Dictionary<string, string> vessel = new Dictionary<string, string>();
                Dictionary<int, Dictionary<string, string>> allVesselData = new Dictionary<int, Dictionary<string, string>>();
                ProcessData process = new ProcessData();
                process.Compute(conductivityS1, conductivityS2, sourceOnePercent);
                currentSaltSplitValue = currentSaltSplit;
                List<vessel> lstCustomerVessels = new List<vessel>();
                lstCustomerVessels = predictiveRepository.GetCustomerVessels(Convert.ToInt64(customerId));
                List<TimeSpan> intervalList = new List<TimeSpan>();
                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;
                            intervalList.Add(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;
                            intervalList.Add(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);
                        }
                    }
                }
                foreach (var span in intervalList)
                {
                    intervalSum += span;
                }
                double average = intervalSum.TotalMilliseconds / intervalList.Count;
                TimeSpan averageResinAge = new TimeSpan();
                if (!double.IsNaN(average))
                {
                    averageResinAge = TimeSpan.FromMilliseconds(average);
                }
                double age = (averageResinAge.TotalDays) / 7;
                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;
                }
                cation = true;

                foreach (var chemAmt in lbsChemicalList)
                {
                    if (cation)
                    {
                        dataToSend.AcidUsage = chemAmt;
                    }
                    else
                    {
                        dataToSend.CausticUsage = chemAmt;
                    }
                    cation = !cation;
                }
                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);
                PriceData priceData = this.RunModel(startingSaltSplit, currentSaltSplit, resinLifeExpectancy, simulationConfidence, numberSimulationIterations, simulationMethod, standardDevThreshold, resinAge, replacementLevel, rtiCleaningLevel, donotReplaceResin);
                return priceData;
            }
            catch
            {
                throw;
            }
        }