public async Task <IActionResult> PutAddRuleModel(PSRClientContractorModel psrClientContractorModel)
        {
            int id = psrClientContractorModel.PSRClientContractorId;

            if (id != psrClientContractorModel.PSRClientContractorId)
            {
                return(BadRequest());
            }

            _context.Entry(psrClientContractorModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PSRClientContractorModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> PutDesignationAccessModel(DesignationAccessModel designationAccessModel)
        {
            int id = designationAccessModel.DAId;

            if (id != designationAccessModel.DAId)
            {
                return(BadRequest());
            }

            _context.Entry(designationAccessModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DesignationAccessModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> PutAddRuleModel(ScrewCompressorConfigurationModel addRuleModel)
        {
            int id = addRuleModel.AddRuleId;

            if (id != addRuleModel.AddRuleId)
            {
                return(BadRequest());
            }

            _context.Entry(addRuleModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AddRuleModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutUserSkillLibraryModel(UserSkillLibraryModel Model)
        {
            int id = Model.SKillLibraryId;

            if (id != Model.SKillLibraryId)
            {
                return(BadRequest());
            }

            _context.Entry(Model).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserSkillLibraryModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutAddRuleModel(UserProductionModel UserProductionModel)
        {
            int id = UserProductionModel.UserProductionId;

            if (id != UserProductionModel.UserProductionId)
            {
                return(BadRequest());
            }

            _context.Entry(UserProductionModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserProductionModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #6
0
        public async Task <ActionResult <PrescriptiveLookupMasterModel> > PostLookupMassterModel(PrescriptiveLookupMasterModel lookupMasterModel)
        {
            DateTime dt = DateTime.Now;

            lookupMasterModel.Date = dt.Date;
            _context.PrescriptiveLookupMassterModelData.Add(lookupMasterModel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLookupMassterModel", new { id = lookupMasterModel.PrescriptiveLookupMasterId }, lookupMasterModel));
        }
        public async Task <Object> PostUploadImage()
        {
            try
            {
                var    file       = Request.Form.Files[0];
                var    folderName = Path.Combine("wwwroot\\DPM_Profile_Images\\");
                var    rootPath   = Path.Combine(Directory.GetCurrentDirectory(), folderName);
                var    UserId     = User.Claims.First(c => c.Type == "UserID").Value;
                string pathToSave = string.Format("{0}{1}", rootPath, UserId);
                // Check folder exists
                if (!Directory.Exists(pathToSave))
                {
                    Directory.CreateDirectory(pathToSave);
                }

                // Check file exists
                var profileImage = Directory.GetFiles(pathToSave).FirstOrDefault();
                if (profileImage != null)
                {
                    System.IO.DirectoryInfo directory = new DirectoryInfo(pathToSave);
                    foreach (FileInfo image in directory.GetFiles())
                    {
                        image.Delete();
                    }
                }

                if (file.Length > 0)
                {
                    var    fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
                    var    fullPath = Path.Combine(pathToSave, fileName);
                    string dbPath   = string.Format("DPM_Profile_Images/{0}/{1}", UserId, fileName);
                    var    user     = await this.context.RegisterUsers.FirstOrDefaultAsync(a => a.UserId == UserId);

                    user.ImageUrl             = dbPath;
                    context.Entry(user).State = EntityState.Modified;
                    await context.SaveChangesAsync();

                    using (var stream = new FileStream(fullPath, FileMode.Create))
                    {
                        file.CopyTo(stream);
                        stream.Position = 0;
                    }

                    return(Ok(user));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, $"Internal server error: {ex}"));
            }
        }
        public async Task <IActionResult> PostConfiguration([FromBody] List <ScrewCompressorTrainModel> compressuredetails)
        {
            string userId = User.Claims.First(c => c.Type == "UserID").Value;

            try
            {
                foreach (var item in compressuredetails)
                {
                    DateTime datetime = Convert.ToDateTime(item.Date).Date;
                    item.InsertedDate = datetime;
                    if (datetime == DateTime.MinValue)
                    {
                        item.InsertedDate = DateTime.Now.Date;
                    }
                    item.UserId          = userId;
                    item.FailureModeType = "RD";
                    item.TenantId        = 1;
                    _context.ScrewCompressureTrainData.Add(item);
                    await _context.SaveChangesAsync();
                }
                return(Ok(compressuredetails));
            }
            catch (Exception exe)
            {
                return(BadRequest(exe.Message));
            }
        }
Пример #9
0
 public async Task <ActionResult> Post(List <MSSStrategyModel> mSSStrategyModels)
 {
     try
     {
         foreach (var item in mSSStrategyModels)
         {
             _context.MSSStrategyModels.Add(item);
             await _context.SaveChangesAsync();
         }
         return(Ok());
     }
     catch (System.Exception exe)
     {
         return(BadRequest(exe.Message));
     }
 }
        public async Task <IActionResult> PostSaveNewRCA(RCAModel rcaModel)
        {
            try
            {
                DateTime Date = DateTime.Now;
                var      Code = Convert.ToString(Date.TimeOfDay);
                rcaModel.RCACode = Code;
                rcaModel.UserId  = User.Claims.First(c => c.Type == "UserID").Value;
                await _context.rCAModels.AddAsync(rcaModel);

                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception exe)
            {
                return(BadRequest(exe.Message));
            }
        }
 public async Task <ActionResult <CentrifugalPumpModel> > PostCenterifugalPump([FromBody] List <CentrifugalPumpModel> centrifugalPumpModel)
 {
     try
     {
         string   userId     = User.Claims.First(c => c.Type == "UserID").Value;
         DateTime d1         = DateTime.Now;
         var      collection = centrifugalPumpModel.ToList();
         foreach (var item in collection)
         {
             item.InsertedDate = d1.Date;
             item.UserId       = userId;
             _context.CentrifugalPumpModelData
             .Add(item);
             await _context.SaveChangesAsync();
         }
         return(Ok(collection));
     }
     catch (Exception exe)
     {
         return(BadRequest(exe.Message));
     }
 }
Пример #12
0
 public async Task <IActionResult> Post([FromBody] List <CentrifugalPumpPredictionModel> CentrifugalPumpPredictionModel)
 {
     try
     {
         string userId = User.Claims.First(c => c.Type == "UserID").Value;
         foreach (var item in CentrifugalPumpPredictionModel)
         {
             DateTime datetime = item.InsertedDate;
             if (datetime == DateTime.MinValue)
             {
                 item.InsertedDate = DateTime.Now.Date;
             }
             item.UserId     = userId;
             item.Prediction = "pending";
             _context.CentrifugalPumpPredictions.Add(item);
             await _context.SaveChangesAsync();
         }
         return(Ok(CentrifugalPumpPredictionModel));
     }
     catch (Exception exe)
     {
         return(BadRequest(exe.Message));
     }
 }
        public async Task <IActionResult> FuturePrediction()
        {
            try
            {
                string userId = User.Claims.First(c => c.Type == "UserID").Value;
                List <CentrifugalPumpPredictionModel> CPM = await _context.CentrifugalPumpPredictions.Where(a => a.UserId == userId && string.IsNullOrEmpty(a.FuturePrediction))
                                                            .OrderByDescending(a => a.CentifugalPumpPID)
                                                            .ToListAsync();

                List <DateTime> Date = new List <DateTime>();
                CPM.Sort((x, y) => DateTime.Compare(x.InsertedDate, y.InsertedDate));
                CPM.Reverse();
                var x = (from obj in CPM group obj by obj.InsertedDate into g select new { Date = g.Key, Duplicatecount = g.Count() }).ToList();
                if (x.Count > 5)
                {
                    var             TagNumber = CPM[0].TagNumber;
                    var             BatchId   = CPM[0].BatchId;
                    List <double>   SP1       = new List <double>();
                    List <double>   SP2       = new List <double>();
                    List <double>   SQ        = new List <double>();
                    List <double>   SI        = new List <double>();
                    List <DateTime> SDate     = new List <DateTime>();
                    Date = CPM.Select(x => x.InsertedDate).Distinct().ToList();
                    for (int i = 0; i < Date.Count; i++)
                    {
                        List <double> LP1   = new List <double>();
                        List <double> LP2   = new List <double>();
                        List <double> LQ    = new List <double>();
                        List <double> LI    = new List <double>();
                        int           count = 0;
                        if (x[i].Date == Date[i] && x[i].Duplicatecount > 5)
                        {
                            for (int ii = 0; ii < CPM.Count; ii++)
                            {
                                if (count < 5)
                                {
                                    if (CPM[ii].InsertedDate == Date[i])
                                    {
                                        LP1.Add(Convert.ToDouble(CPM[ii].P1));
                                        LP2.Add(Convert.ToDouble(CPM[ii].P2));
                                        LQ.Add(Convert.ToDouble(CPM[ii].Q));
                                        LI.Add(Convert.ToDouble(CPM[ii].I));
                                        count = count + 1;
                                    }
                                }
                                else if (count == 5)
                                {
                                    SP1.Add(LP1.Sum() / 5);
                                    SP2.Add(LP2.Sum() / 5);
                                    SQ.Add(LQ.Sum() / 5);
                                    SI.Add(LI.Sum() / 5);
                                    SDate.Add(Date[i]);
                                    break;
                                }
                            }
                        }
                        else if (x[i].Date == Date[i] && x[i].Duplicatecount < 5)
                        {
                            List <CentrifugalPumpPredictionModel> PredictionRecord = CPM.FindAll(a => a.InsertedDate == Date[i]);
                            LP1.Add(Convert.ToDouble(PredictionRecord[0].P1));
                            LP2.Add(Convert.ToDouble(PredictionRecord[0].P2));
                            LQ.Add(Convert.ToDouble(PredictionRecord[0].Q));
                            LI.Add(Convert.ToDouble(PredictionRecord[0].I));
                            SP1.Add(LP1.Sum());
                            SP2.Add(LP2.Sum());
                            SQ.Add(LQ.Sum());
                            SI.Add(LI.Sum());
                            SDate.Add(Date[i]);
                        }
                    }
                    SP1.Reverse();
                    SP2.Reverse();
                    SQ.Reverse();
                    SI.Reverse();
                    SDate.Reverse();
                    CentrifugalPumpFuturePredictionModel CPFM = new CentrifugalPumpFuturePredictionModel();
                    if (SP1.Count > 5)
                    {
                        for (int i = 0; i < (SP1.Count - 5); i++)
                        {
                            var      P1 = (SP1.ElementAt(i) + SP1.ElementAt(i + 1) + SP1.ElementAt(i + 2) + SP1.ElementAt(i + 3) + SP1.ElementAt(i + 4));
                            var      P2 = (SP2.ElementAt(i) + SP2.ElementAt(i + 1) + SP2.ElementAt(i + 2) + SP2.ElementAt(i + 3) + SP2.ElementAt(i + 4));
                            var      Q  = (SQ.ElementAt(i) + SQ.ElementAt(i + 1) + SQ.ElementAt(i + 2) + SQ.ElementAt(i + 3) + SQ.ElementAt(i + 4));
                            var      I  = (SI.ElementAt(i) + SI.ElementAt(i + 1) + SI.ElementAt(i + 2) + SI.ElementAt(i + 3) + SI.ElementAt(i + 4));
                            DateTime FuturePredictionDate = SDate.Last().AddDays(i + 1);
                            CPFM.CentifugalPumpFID = 0;
                            CPFM.TagNumber         = TagNumber;
                            CPFM.BatchId           = BatchId;
                            CPFM.UserId            = userId;
                            CPFM.P1     = Convert.ToDecimal(string.Format("{0:F2}", (P1 / 5)));
                            CPFM.P2     = Convert.ToDecimal(string.Format("{0:F2}", (P2 / 5)));
                            CPFM.Q      = Convert.ToDecimal(string.Format("{0:F2}", (Q / 5)));
                            CPFM.I      = Convert.ToDecimal(string.Format("{0:F2}", (I / 5)));
                            CPFM.FPDate = FuturePredictionDate;
                            _context.CentrifugalPumpFuturePredictionModels.Add(CPFM);
                            await _context.SaveChangesAsync();
                        }
                        foreach (var item in CPM)
                        {
                            item.FuturePrediction = "Done";
                            _context.CentrifugalPumpPredictions.Attach(item);
                            _context.Entry(item).State = EntityState.Modified;
                            await _context.SaveChangesAsync();
                        }
                    }
                }
                return(Ok(x));
            }
            catch (Exception exe)
            {
                return(BadRequest(exe.Message));
            }
        }
Пример #14
0
        public async Task <IActionResult> GetMovngAverage()
        {
            try
            {
                //string userId = User.Claims.First(c => c.Type == "UserID").Value;
                //List<ScrewCompressorPredictionModel> screwCompressors = await _context.ScrewCompressurePredictionData
                //                                                                .Where(a => a.UserId == userId && string.IsNullOrEmpty(a.FuturePrediction))
                //                                                                .OrderBy(a => a.InsertedDate.Year)
                //                                                                .ThenBy(d => d.InsertedDate.Month)
                //                                                                .ThenBy(d => d.InsertedDate.Day)
                //                                                                .ToListAsync();

                //var prediction = screwCompressors.ToList(); ;

                //if (prediction.Count > 0)
                //{

                //    var length = prediction.Count;

                //    List<int> TenantIdList = new List<int>();
                //    List<int> BatchIdList = new List<int>();
                //    List<decimal> PS1List = new List<decimal>();
                //    List<decimal> PD1List = new List<decimal>();
                //    List<decimal> PS2List = new List<decimal>();
                //    List<decimal> PD2List = new List<decimal>();
                //    List<decimal> TS1List = new List<decimal>();
                //    List<decimal> TD1List = new List<decimal>();
                //    List<decimal> TS2List = new List<decimal>();
                //    List<decimal> TD2List = new List<decimal>();
                //    List<DateTime> DateList = new List<DateTime>();
                //    foreach (var item in prediction)
                //    {

                //        TenantIdList.Add(item.TenantId);
                //        BatchIdList.Add(item.BatchId);
                //        PS1List.Add(item.PS1);
                //        PD1List.Add(item.PD1);
                //        PS2List.Add(item.PS2);
                //        PD2List.Add(item.PD2);
                //        TS1List.Add(item.TS1);
                //        TD1List.Add(item.TD1);
                //        TS2List.Add(item.TS2);
                //        TD2List.Add(item.TD2);
                //        DateList.Add(item.InsertedDate);
                //        item.FuturePrediction = "Done";
                //        _context.ScrewCompressurePredictionData.Attach(item);
                //        _context.Entry(item).State = EntityState.Modified;
                //        await _context.SaveChangesAsync();


                //    }

                //    ScrewCompressorFuturePredictionModel screwcompressorFuturePrediction = new ScrewCompressorFuturePredictionModel();
                //    int BatchId = BatchIdList.IndexOf(0);

                //    for (int i = 0; i < length - 5; i++)
                //    {
                //        DateTime dateTime = DateList.Last();
                //        dateTime = dateTime.Date.AddDays(+1);
                //        DateList.Add(dateTime);


                //        var PS1 = (PS1List.ElementAt(i) + PS1List.ElementAt(i + 1) + PS1List.ElementAt(i + 2) + PS1List.ElementAt(i + 3) + PS1List.ElementAt(i + 4));
                //        var PD1 = (PD1List.ElementAt(i) + PD1List.ElementAt(i + 1) + PD1List.ElementAt(i + 2) + PD1List.ElementAt(i + 3) + PD1List.ElementAt(i + 4));
                //        var PS2 = (PS2List.ElementAt(i) + PS2List.ElementAt(i + 1) + PS2List.ElementAt(i + 2) + PS2List.ElementAt(i + 3) + PS2List.ElementAt(i + 4));
                //        var PD2 = (PD2List.ElementAt(i) + PD2List.ElementAt(i + 1) + PD2List.ElementAt(i + 2) + PD2List.ElementAt(i + 3) + PD2List.ElementAt(i + 4));
                //        var TS1 = (TS1List.ElementAt(i) + TS1List.ElementAt(i + 1) + TS1List.ElementAt(i + 2) + TS1List.ElementAt(i + 3) + TS1List.ElementAt(i + 4));
                //        var TD1 = (TD1List.ElementAt(i) + TD1List.ElementAt(i + 1) + TD1List.ElementAt(i + 2) + TD1List.ElementAt(i + 3) + TD1List.ElementAt(i + 4));
                //        var TS2 = (TS2List.ElementAt(i) + TS2List.ElementAt(i + 1) + TS2List.ElementAt(i + 2) + TS2List.ElementAt(i + 3) + TS2List.ElementAt(i + 4));
                //        var TD2 = (TD2List.ElementAt(i) + TD2List.ElementAt(i + 1) + TD2List.ElementAt(i + 2) + TD2List.ElementAt(i + 3) + TD2List.ElementAt(i + 4));

                //        screwcompressorFuturePrediction.SCFPId = 0;
                //        screwcompressorFuturePrediction.UserId = userId;
                //        screwcompressorFuturePrediction.TenantId = TenantIdList.First();
                //        screwcompressorFuturePrediction.BatchId = BatchId;
                //        screwcompressorFuturePrediction.Prediction = "pending";
                //        screwcompressorFuturePrediction.PS1 = Convert.ToDecimal(string.Format("{0:F2}", (PS1 / 5)));
                //        screwcompressorFuturePrediction.PD1 = Convert.ToDecimal(string.Format("{0:F2}", (PD1 / 5)));
                //        screwcompressorFuturePrediction.PS2 = Convert.ToDecimal(string.Format("{0:F2}", (PS2 / 5)));
                //        screwcompressorFuturePrediction.PD2 = Convert.ToDecimal(string.Format("{0:F2}", (PD2 / 5)));
                //        screwcompressorFuturePrediction.TS1 = Convert.ToDecimal(string.Format("{0:F2}", (TS1 / 5)));
                //        screwcompressorFuturePrediction.TD1 = Convert.ToDecimal(string.Format("{0:F2}", (TD1 / 5)));
                //        screwcompressorFuturePrediction.TS2 = Convert.ToDecimal(string.Format("{0:F2}", (TS2 / 5)));
                //        screwcompressorFuturePrediction.TD2 = Convert.ToDecimal(string.Format("{0:F2}", (TD2 / 5)));
                //        screwcompressorFuturePrediction.PredictedDate = DateList.Last();
                //        _context.ScrewCompressureFuturePrediction.Add(screwcompressorFuturePrediction);
                //        await _context.SaveChangesAsync();

                //    }


                string userId = User.Claims.First(c => c.Type == "UserID").Value;
                List <ScrewCompressorPredictionModel> screwCompressors = await _context.ScrewCompressurePredictionData
                                                                         .Where(a => a.UserId == userId && string.IsNullOrEmpty(a.FuturePrediction))
                                                                         .OrderByDescending(a => a.PredictionId)
                                                                         .ToListAsync();

                List <DateTime> Date = new List <DateTime>();
                screwCompressors.Sort((x, y) => DateTime.Compare(x.InsertedDate, y.InsertedDate));
                screwCompressors.Reverse();
                var x = (from obj in screwCompressors group obj by obj.InsertedDate into g select new { Date = g.Key, Duplicatecount = g.Count() }).ToList();
                if (x.Count > 5)
                {
                    var             BatchId  = screwCompressors[0].BatchId;
                    var             TenantId = screwCompressors[0].TenantId;
                    List <double>   SPS1List = new List <double>();
                    List <double>   SPD1List = new List <double>();
                    List <double>   SPS2List = new List <double>();
                    List <double>   SPD2List = new List <double>();
                    List <double>   STS1List = new List <double>();
                    List <double>   STD1List = new List <double>();
                    List <double>   STS2List = new List <double>();
                    List <double>   STD2List = new List <double>();
                    List <DateTime> SDate    = new List <DateTime>();
                    Date = screwCompressors.Select(x => x.InsertedDate).Distinct().ToList();

                    for (int i = 0; i < Date.Count; i++)
                    {
                        List <double> LPS1List = new List <double>();
                        List <double> LPD1List = new List <double>();
                        List <double> LPS2List = new List <double>();
                        List <double> LPD2List = new List <double>();
                        List <double> LTS1List = new List <double>();
                        List <double> LTD1List = new List <double>();
                        List <double> LTS2List = new List <double>();
                        List <double> LTD2List = new List <double>();
                        int           count    = 0;
                        if (x[i].Date == Date[i] && x[i].Duplicatecount > 5)
                        {
                            for (int ii = 0; ii < screwCompressors.Count; ii++)
                            {
                                if (count < 5)
                                {
                                    if (screwCompressors[ii].InsertedDate == Date[i])
                                    {
                                        LPS1List.Add(Convert.ToDouble(screwCompressors[ii].PS1));
                                        LPD1List.Add(Convert.ToDouble(screwCompressors[ii].PD1));
                                        LPS2List.Add(Convert.ToDouble(screwCompressors[ii].PS2));
                                        LPD2List.Add(Convert.ToDouble(screwCompressors[ii].PD2));
                                        LTS1List.Add(Convert.ToDouble(screwCompressors[ii].TS1));
                                        LTD1List.Add(Convert.ToDouble(screwCompressors[ii].TD1));
                                        LTS2List.Add(Convert.ToDouble(screwCompressors[ii].TS2));
                                        LTD2List.Add(Convert.ToDouble(screwCompressors[ii].TD2));

                                        count = count + 1;
                                    }
                                }
                                else if (count == 5)
                                {
                                    SPS1List.Add(LPS1List.Sum() / 5);
                                    SPD1List.Add(LPD1List.Sum() / 5);
                                    SPS2List.Add(LPS2List.Sum() / 5);
                                    SPD2List.Add(LPD2List.Sum() / 5);
                                    STS1List.Add(LTS1List.Sum() / 5);
                                    STD1List.Add(LTD1List.Sum() / 5);
                                    STS2List.Add(LTS2List.Sum() / 5);
                                    STD2List.Add(LTD2List.Sum() / 5);
                                    SDate.Add(Date[i]);
                                    break;
                                }
                            }
                        }
                        else if (x[i].Date == Date[i] && x[i].Duplicatecount < 5)
                        {
                            List <ScrewCompressorPredictionModel> PredictionRecord = screwCompressors.FindAll(a => a.InsertedDate == Date[i]);
                            SPS1List.Add(Convert.ToDouble(PredictionRecord[0].PS1));
                            SPD1List.Add(Convert.ToDouble(PredictionRecord[0].PD1));
                            SPS2List.Add(Convert.ToDouble(PredictionRecord[0].PS2));
                            SPD2List.Add(Convert.ToDouble(PredictionRecord[0].PD2));
                            STS1List.Add(Convert.ToDouble(PredictionRecord[0].TS1));
                            STD1List.Add(Convert.ToDouble(PredictionRecord[0].TD1));
                            STS2List.Add(Convert.ToDouble(PredictionRecord[0].TS2));
                            STD2List.Add(Convert.ToDouble(PredictionRecord[0].TD2));
                            SDate.Add(Date[i]);
                        }
                    }

                    SPS1List.Reverse();
                    SPD1List.Reverse();
                    SPS2List.Reverse();
                    SPD2List.Reverse();
                    STS1List.Reverse();
                    STD1List.Reverse();
                    STS2List.Reverse();
                    STD2List.Reverse();
                    SDate.Reverse();
                    ScrewCompressorFuturePredictionModel screwcompressorFuturePrediction = new ScrewCompressorFuturePredictionModel();
                    if (SPS1List.Count > 5)
                    {
                        for (int i = 0; i < (SPS1List.Count - 5); i++)
                        {
                            var      PS1 = (SPS1List.ElementAt(i) + SPS1List.ElementAt(i + 1) + SPS1List.ElementAt(i + 2) + SPS1List.ElementAt(i + 3) + SPS1List.ElementAt(i + 4));
                            var      PD1 = (SPD1List.ElementAt(i) + SPD1List.ElementAt(i + 1) + SPD1List.ElementAt(i + 2) + SPD1List.ElementAt(i + 3) + SPD1List.ElementAt(i + 4));
                            var      PS2 = (SPS2List.ElementAt(i) + SPS2List.ElementAt(i + 1) + SPS2List.ElementAt(i + 2) + SPS2List.ElementAt(i + 3) + SPS2List.ElementAt(i + 4));
                            var      PD2 = (SPD2List.ElementAt(i) + SPD2List.ElementAt(i + 1) + SPD2List.ElementAt(i + 2) + SPD2List.ElementAt(i + 3) + SPD2List.ElementAt(i + 4));
                            var      TS1 = (STS1List.ElementAt(i) + STS1List.ElementAt(i + 1) + STS1List.ElementAt(i + 2) + STS1List.ElementAt(i + 3) + STS1List.ElementAt(i + 4));
                            var      TD1 = (STD1List.ElementAt(i) + STD1List.ElementAt(i + 1) + STD1List.ElementAt(i + 2) + STD1List.ElementAt(i + 3) + STD1List.ElementAt(i + 4));
                            var      TS2 = (STS2List.ElementAt(i) + STS2List.ElementAt(i + 1) + STS2List.ElementAt(i + 2) + STS2List.ElementAt(i + 3) + STS2List.ElementAt(i + 4));
                            var      TD2 = (STD2List.ElementAt(i) + STD2List.ElementAt(i + 1) + STD2List.ElementAt(i + 2) + STD2List.ElementAt(i + 3) + STD2List.ElementAt(i + 4));
                            DateTime FuturePredictionDate = SDate.Last().AddDays(i + 1);


                            screwcompressorFuturePrediction.SCFPId        = 0;
                            screwcompressorFuturePrediction.UserId        = userId;
                            screwcompressorFuturePrediction.TenantId      = TenantId;
                            screwcompressorFuturePrediction.BatchId       = BatchId;
                            screwcompressorFuturePrediction.Prediction    = "pending";
                            screwcompressorFuturePrediction.PS1           = Convert.ToDecimal(string.Format("{0:F2}", (PS1 / 5)));
                            screwcompressorFuturePrediction.PD1           = Convert.ToDecimal(string.Format("{0:F2}", (PD1 / 5)));
                            screwcompressorFuturePrediction.PS2           = Convert.ToDecimal(string.Format("{0:F2}", (PS2 / 5)));
                            screwcompressorFuturePrediction.PD2           = Convert.ToDecimal(string.Format("{0:F2}", (PD2 / 5)));
                            screwcompressorFuturePrediction.TS1           = Convert.ToDecimal(string.Format("{0:F2}", (TS1 / 5)));
                            screwcompressorFuturePrediction.TD1           = Convert.ToDecimal(string.Format("{0:F2}", (TD1 / 5)));
                            screwcompressorFuturePrediction.TS2           = Convert.ToDecimal(string.Format("{0:F2}", (TS2 / 5)));
                            screwcompressorFuturePrediction.TD2           = Convert.ToDecimal(string.Format("{0:F2}", (TD2 / 5)));
                            screwcompressorFuturePrediction.PredictedDate = FuturePredictionDate;

                            _context.ScrewCompressureFuturePrediction.Add(screwcompressorFuturePrediction);
                            await _context.SaveChangesAsync();
                        }

                        foreach (var item in screwCompressors)
                        {
                            _context.ScrewCompressurePredictionData.Attach(item);
                            item.FuturePrediction = "Done";
                            await _context.SaveChangesAsync();
                        }
                    }
                }
                return(Ok(x));
            }
            catch (Exception exe)
            {
                return(Ok(exe.Message));
            }
        }
Пример #15
0
        public async Task <IActionResult> PostConfiguration([FromBody] List <CentrifugalPumpTrainModel> pumpdetails)
        {
            string userId = User.Claims.First(c => c.Type == "UserID").Value;

            try
            {
                var ScrewCompressorConfigurationModel = await _context.AddRuleModels.Where(a => a.MachineType == "Pump" && a.EquipmentType == "Centrifugal Pump" && a.FailureModeType == "FM1").OrderBy(a => a.AddRuleId).ToListAsync();

                double Dcustomer = Convert.ToDouble(ScrewCompressorConfigurationModel[0].Alarm);
                double HAlaram   = Convert.ToDouble(ScrewCompressorConfigurationModel[1].Alarm);
                double HTrigger  = Convert.ToDouble(ScrewCompressorConfigurationModel[1].Trigger);
                var    Formula   = ScrewCompressorConfigurationModel[2].Columns;
                double GConstant = Convert.ToDouble(ScrewCompressorConfigurationModel[3].Alarm);
                double CosPhi    = Convert.ToDouble(ScrewCompressorConfigurationModel[4].Alarm);
                double Voltage   = Convert.ToDouble(ScrewCompressorConfigurationModel[5].Alarm);

                List <CentrifugalPumpHQLibraryModel> centrifugalPumpHQLibraryModel = await _context.CentrifugalPumpHQLibraryModels.OrderBy(a => a.CentrifugalPumpHQLibraryID).ToListAsync();

                var           HQLibraryList = centrifugalPumpHQLibraryModel.ToList();
                List <double> QLlist        = new List <double>();
                string        result        = "";
                foreach (var i in HQLibraryList)
                {
                    QLlist.Add(Convert.ToDouble(i.Q));
                }
                foreach (var item in pumpdetails)
                {
                    DateTime datetime = item.InsertedDate;
                    if (datetime == DateTime.MinValue)
                    {
                        item.InsertedDate = DateTime.Now;
                    }
                    DateTime dt       = item.InsertedDate;
                    DateTime dateOnly = dt.Date;
                    item.InsertedDate = dateOnly;
                    item.UserId       = userId;

                    double P1 = Convert.ToDouble(item.P1);
                    double P2 = Convert.ToDouble(item.P2);
                    double KW = (1.732 * Voltage * CosPhi * Convert.ToDouble(item.I)) / 1000;

                    //double HCustomernumber = 10 * (P2 - P1) / Dcustomer;
                    string p1 = string.Format("{0:G}", P1);
                    string p2 = string.Format("{0:G}", P2);
                    string d  = string.Format("{0:G}", Dcustomer);

                    var       f1                = Formula.Replace("P1", p1);
                    var       f2                = f1.Replace("P2", p2);
                    var       f3                = f2.Replace("D", d);
                    DataTable dtw               = new DataTable();
                    var       HCustomernumber   = dtw.Compute(f3, "");
                    double    Qnumber           = Convert.ToSingle(item.Q);
                    double    Firstclosest      = QLlist.Aggregate((x, y) => Math.Abs(x - Qnumber) < Math.Abs(y - Qnumber) ? x : y);
                    int       Firstclosestindex = QLlist.IndexOf(Firstclosest);

                    if (Firstclosestindex != -1)
                    {
                        double difference;
                        if (Qnumber < Firstclosest)
                        {
                            Firstclosestindex = Firstclosestindex - 1;
                            difference        = Firstclosest - Qnumber;
                        }
                        else
                        {
                            difference = Qnumber - Firstclosest;
                        }
                        var    FirstClosestValue  = HQLibraryList[Firstclosestindex];
                        double FirstHClose        = Convert.ToDouble(FirstClosestValue.H);
                        double FirstQClose        = Convert.ToDouble(FirstClosestValue.Q);
                        double FirstKWClose       = Convert.ToDouble(FirstClosestValue.KW);
                        double FirstCalEffClose   = Convert.ToDouble(FirstClosestValue.CalculatedEff);
                        double FirstGraphEffClose = Convert.ToDouble(FirstClosestValue.GraphEff);

                        var    SecondClosestValue  = HQLibraryList[Firstclosestindex + 1];
                        double SecondHClose        = Convert.ToDouble(SecondClosestValue.H);
                        double SecondQClose        = Convert.ToDouble(SecondClosestValue.Q);
                        double SecondKWClose       = Convert.ToDouble(SecondClosestValue.KW);
                        double SecondCalEffClose   = Convert.ToDouble(SecondClosestValue.CalculatedEff);
                        double SecondGraphEffClose = Convert.ToDouble(SecondClosestValue.GraphEff);

                        double ValueQDifference = SecondQClose - FirstQClose;
                        double DeviationH       = (FirstHClose - SecondHClose) / ValueQDifference;
                        double HValueLibrary    = FirstHClose - (DeviationH * difference);
                        double Trigger          = (HValueLibrary * HTrigger);  // Trigger
                        double Alarm            = ((HValueLibrary * HAlaram)); // Alarm

                        double ValueKWDifference = SecondKWClose - FirstKWClose;
                        double DeviationKW       = (SecondKWClose - FirstKWClose) / ValueQDifference;
                        double KWValueLibrary    = FirstKWClose + (DeviationKW * difference);

                        double ValueCalEffDifference = 0.00;
                        if (FirstCalEffClose > SecondCalEffClose)
                        {
                            ValueCalEffDifference = FirstCalEffClose - SecondCalEffClose;
                        }
                        else
                        {
                            ValueCalEffDifference = SecondCalEffClose - FirstCalEffClose;
                        }
                        double DeviationCalEff           = ValueCalEffDifference / ValueQDifference;
                        double CalEffFromLibValueLibrary = 0.00;
                        if (FirstCalEffClose > SecondCalEffClose)
                        {
                            CalEffFromLibValueLibrary = FirstCalEffClose - (DeviationCalEff * difference);
                        }
                        else
                        {
                            CalEffFromLibValueLibrary = FirstCalEffClose + (DeviationCalEff * difference);
                        }


                        double ValueGraphEffDifference = 0.00;
                        if (FirstGraphEffClose > SecondGraphEffClose)
                        {
                            ValueGraphEffDifference = FirstGraphEffClose - SecondGraphEffClose;
                        }
                        else
                        {
                            ValueGraphEffDifference = SecondGraphEffClose - FirstGraphEffClose;
                        }
                        double DeviationGraphEff           = ValueGraphEffDifference / ValueQDifference;
                        double GraphEffFromLibValueLibrary = 0.00;
                        if (FirstCalEffClose > SecondCalEffClose)
                        {
                            GraphEffFromLibValueLibrary = FirstGraphEffClose - (DeviationGraphEff * difference);
                        }
                        else
                        {
                            GraphEffFromLibValueLibrary = FirstGraphEffClose + (DeviationGraphEff * difference);
                        }

                        double ErrorGraphEff = GraphEffFromLibValueLibrary - CalEffFromLibValueLibrary;

                        double CustomerEffWithDeviation = ((Convert.ToDouble(item.Q) * Dcustomer * GConstant * Convert.ToDouble(HCustomernumber)) / KW) / 1000;
                        double CustomerEff = CustomerEffWithDeviation + ErrorGraphEff;

                        double DeviationEffPercentage = ((GraphEffFromLibValueLibrary - CustomerEff) / GraphEffFromLibValueLibrary) * 100;

                        if (DeviationEffPercentage >= 20)
                        {
                            result = "Degrade";
                        }
                        else if (DeviationEffPercentage >= 10)
                        {
                            result = "Incipient";
                        }
                        else
                        {
                            result = "Normal";
                        }

                        //if (Trigger >= HCustomernumber)
                        //{
                        //    result = "Degrade";
                        //}
                        //else if (Alarm >= HCustomernumber)
                        //{
                        //    result = "Incipient";
                        //}
                        //else
                        //{
                        //    result = "Normal";
                        //}
                    }
                    item.Classification = result;
                    _context.CentrifugalPumpTrainData.Add(item);
                    await _context.SaveChangesAsync();
                }
                return(Ok(pumpdetails));
            }
            catch (Exception exe)
            {
                return(BadRequest(exe.Message));
            }
        }