예제 #1
0
        public Specs GetSpecsByIndex(int idx)
        {
            if (this._model == null || this._model.LibBase == null)
            {
                return(null);
            }
            if (idx < 0 || idx > this._model.LibBase.Count)
            {
                return(null);
            }
            if (!this._model.LibBase.Components.Contains("ID"))
            {
                return(null);
            }
            var s    = this._model.LibBase[idx];
            int dbID = (int)s.Components["ID"].ActualValue;

            if (dbID < 1)
            {
                return(null);
            }
            ;
            using (var db = new NIRCeneterEntities())
            {
                var dbs = db.Specs.Where(d => d.ID == dbID).FirstOrDefault();
                return(dbs);
            }
        }
예제 #2
0
        public bool Predict(ref Specs s)
        {
            if (s == null || s.Spec == null)
            {
                return(false);
            }
            if (this._maxNum < 1)
            {
                return(false);
            }
            try
            {
                if (this._model == null || this._model.SpecLib == null || this._model.SpecLib.Count < 1)
                {
                    return(false);
                }
                var r = this._model.Predict(s.Spec);
                if (!r.IsId)
                {
                    return(false);
                }
                if (r.Items.Length < 1 || !r.Items.First().Spec.Components.Contains("ID"))
                {
                    return(false);
                }
                int dbID = (int)r.Items.First().Spec.Components["ID"].ActualValue;
                if (dbID < 1)
                {
                    return(false);
                }
                using (var db = new NIRCeneterEntities())
                {
                    var dsepc = db.Specs.Where(d => d.ID == dbID).FirstOrDefault();
                    if (dsepc == null)
                    {
                        return(false);
                    }
                    s.Result          = dsepc.Result;
                    s.ResultObj       = dsepc.ResultObj;
                    s.ResultType      = dsepc.ResultType;
                    s.Spec.Components = dsepc.Spec.Components;
                    s.PredictByA      = true;

                    //修改密度的值
                    var c = s.Spec.Components.Where(d => d.Name == "密度(20℃)").FirstOrDefault();
                    if (c != null)
                    {
                        Random rd = new Random();
                        c.PredictedValue = c.PredictedValue * (1 + 0.0008 * (0.5 - rd.NextDouble()));
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
            }
            return(false);
        }
예제 #3
0
파일: Oil.cs 프로젝트: Volador17/OilCute
        private static List <PropertyTable> init()
        {
            using (var db = new NIRCeneterEntities())
            {
                var gt = db.Properties.GroupBy(d => d.TableID);
                var tb = new List <PropertyTable>();
                foreach (var g in gt)
                {
                    var    tbl = (PropertyType)g.Key;
                    double bs, be;
                    switch (tbl)
                    {
                    case PropertyType.ChaiYou:
                        bs = 180;
                        be = 350;
                        break;

                    case PropertyType.LaYou:
                        bs = 350;
                        be = 540;
                        break;

                    case PropertyType.PenQi:
                        bs = 140;
                        be = 240;
                        break;

                    case PropertyType.ShiNao:
                        bs = 15;
                        be = 180;
                        break;

                    case PropertyType.ZhaYou:
                        bs = 540;
                        be = 1600;
                        break;

                    default:
                        bs = 15;
                        be = 180;
                        break;
                    }

                    tb.Add(new PropertyTable()
                    {
                        BoilingEnd   = be,
                        BoilingStart = bs,
                        Datas        = g.Select(d => new PropertyEntity()
                        {
                            Code = d.Code, ColumnIdx = d.ColumnIdx, Index = d.Idx, Name = d.Name, Name2 = d.Name1, Unit = d.Units, Eps = d.Eps, ShowEngineer = true, ShowRIPP = true
                        }).ToList(),
                        Table = (PropertyType)g.Key
                    });
                }
                return(tb);
            }
        }
예제 #4
0
파일: OilAPI.cs 프로젝트: Volador17/OilCute
        public List <PropertyTable> GetData(Specs s, BindModel predictor)
        {
            using (var db = new NIRCeneterEntities())
            {
                var r = s.OilData;
                if (r != null)
                {
                    return(r);
                }

                if (s == null || s.ResultObj == null)
                {
                    return(null);
                }
                var pr = s.ResultObj;
                if (s.ResultObj.MethodType == PredictMethod.Integrate && predictor != null)
                {
                    var papi = predictor.PredictForAPI(s.Spec, true);
                    if (papi.MethodType == PredictMethod.Fitting || papi.MethodType == PredictMethod.Identify)
                    {
                        pr = papi;
                    }
                }
                r = Serialize.DeepClone <List <PropertyTable> >(this._initP);
                OilInfoBEntity oil = null;
                switch (pr.MethodType)
                {
                case NIR.Models.PredictMethod.Identify:
                    oil = getByName(s, pr, ref r);
                    break;

                case NIR.Models.PredictMethod.Fitting:
                    oil = getByRate(s, pr, ref r);
                    break;

                case NIR.Models.PredictMethod.PLSBind:
                    oil = getByProperties(s, pr, ref r);
                    break;

                default:
                    break;
                }
                GetNIRData(s, oil, ref r);
                if (oil != null)
                {
                    r = r.OrderBy(d => (int)d.Table).ToList();
                    db.OilData.AddObject(new OilData()
                    {
                        SID  = s.ID,
                        Data = Serialize.ObjectToByte(r)
                    });
                    db.SaveChanges();
                }
                else
                {
                    foreach (var t in r)
                    {
                        foreach (var dd in t.Datas)
                        {
                            if (dd.Value == 0)
                            {
                                dd.Value = double.NaN;
                            }
                        }
                    }
                }

                return(r);
            }
        }
예제 #5
0
파일: OilAPI.cs 프로젝트: Volador17/OilCute
        public bool APIGetData(BindModel predictor, ref Specs s)
        {
            log.Info("db before");
            using (var db = new NIRCeneterEntities())
            {
                var r = s.OilData;
                if (r != null)
                {
                    return(true);
                }
                log.Info("db after");
                if (s == null || s.ResultObj == null)
                {
                    return(false);
                }
                var pr = s.ResultObj;
                if (s.ResultObj.MethodType == PredictMethod.Integrate && predictor != null)
                {
                    var papi = predictor.PredictForAPI(s.Spec, true);
                    if (papi.MethodType == PredictMethod.Fitting || papi.MethodType == PredictMethod.Identify)
                    {
                        pr = papi;
                    }
                }
                r = Serialize.DeepClone <List <PropertyTable> >(this._initP);
                OilInfoBEntity oil = null;
                switch (pr.MethodType)
                {
                case NIR.Models.PredictMethod.Identify:
                    oil = getByName(s, pr, ref r);
                    break;

                case NIR.Models.PredictMethod.Fitting:
                    oil = getByRate(s, pr, ref r);
                    break;

                case PredictMethod.Integrate:
                case NIR.Models.PredictMethod.PLSBind:
                    oil = getByProperties(s, pr, ref r);
                    break;

                default:
                    break;
                }
                GetNIRData(s, oil, ref r);
                if (oil != null)
                {
                    r = r.OrderBy(d => (int)d.Table).ToList();
                    db.OilData.AddObject(new OilData()
                    {
                        SID  = s.ID,
                        Data = Serialize.ObjectToByte(r)
                    });
                    db.SaveChanges();
                    s.OilData = r;
                    return(true);
                }
                else
                {
                    s.OilData = null;
                }

                return(false);
            }
        }