示例#1
0
 public DataChecks(string tagName, IDataCaches dataCaches, IDataChecks parent = null, IDataCheck_Msger msger = null)
 {
     _tag        = tagName;
     _Msger      = msger;
     _Parent     = parent;
     _DataCaches = dataCaches;
     _DataChecks = new Dictionary <string, IDataCheck>();
 }
        //设置缓存数据对象-修正
        //public virtual Data_Quote SetData_ValueCheck(Data_Quote pData, typeTimeFrequency timeFrequency)
        //{
        //    pData.QuoteTimeType = timeFrequency;
        //    return pData;
        //}



        //初始规则信息集合-Caches-弃用
        private bool InitDataChecks_Caches(IData_Factors pFactors, IData_Factor pFactor)
        {
            IDataCaches dataCaches          = _managerCaches.GetDataCaches(pFactors, pFactor);
            IDataChecks poDataChecks_Caches = new DataChecks_Quote(dataCaches.ID, dataCaches);
            bool        bResult             = dataCaches.InitDataChecks(poDataChecks_Caches);

            return(bResult);
        }
        //初始规则信息集合-全部-弃用
        private bool InitDataChecks_CheckAll(IDataCaches dataCaches)
        {
            bool bResult = true;

            foreach (var item in _setsDataCache)
            {
                bResult = bResult && this.InitDataChecks_Check(dataCaches, item.Key);
            }
            return(bResult);
        }
示例#4
0
        public virtual bool CheckDatas <T>(DateTime dtTime, T data, IDataCaches dataCaches)
        {
            bool bResult = true;

            foreach (KeyValuePair <string, IDataCheck> check in _DataChecks)
            {
                IDataCheck <T> dataCheck = (IDataCheck <T>)check.Value;
                bResult = dataCheck.CheckData(dtTime, data, dataCaches) && bResult;
            }
            return(bResult);
        }
示例#5
0
        public IDataCache <T> GetDataCache <T>(IData_Factor infoFactor, string strTag = "", typeTimeFrequency typeTimeFrequency = typeTimeFrequency.None, bool autoInit = false, int cacheNums = 1)
        {
            IDataCaches dataCaches = GetDataCaches(infoFactor, autoInit);

            if (dataCaches == null)
            {
                return(null);
            }

            IDataCache <T> data = dataCaches.GetDataCache <T>(strTag, typeTimeFrequency, autoInit, cacheNums);

            return(data);
        }
示例#6
0
        public bool InitDataCheck <T>(string tagFactors, string tagFactor, string strTag, typeTimeFrequency typeTimeFrequency, string tagDataCheck, IDataCheck <T> dataCheck, bool isCanCover = false)
        {
            if (tagFactors + "" == "")
            {
                return(false);
            }

            //DataCaches_Manage
            IData_Factors infoFactors = this._GetFactors(tagFactors);

            if (infoFactors == null)
            {
                return(false);
            }
            IDataCaches_Manage dataCaches_Manage = this.GetDataCaches_Manage(infoFactors);

            if (dataCaches_Manage == null)
            {
                return(false);
            }
            if (tagFactor + "" == "")
            {
                return(dataCaches_Manage.InitDataCheck <T>(tagDataCheck, dataCheck, isCanCover));
            }

            //DataCaches
            IData_Factor infoFactor = infoFactors.GetData_Factor(tagFactor);

            if (infoFactor == null)
            {
                return(false);
            }
            IDataCaches dataCaches = this.GetDataCaches(infoFactors, infoFactor);

            if (dataCaches == null)
            {
                return(false);
            }

            IDataCache dataCache = dataCaches.GetDataCache <T>(strTag, typeTimeFrequency);

            if (dataCache == null)
            {
                return(dataCaches.InitDataCheck <T>(tagDataCheck, dataCheck, isCanCover));
            }
            else
            {
                return(dataCache.InitDataCheck(tagDataCheck, dataCheck, isCanCover));
            }
        }
        //初始规则信息集合-Cache-弃用
        private bool InitDataChecks_Cache(IData_Factors pFactors, IData_Factor pFactor, Data_Quote data)
        {
            //数据缓存集检查
            IDataCaches dataCaches = _managerCaches.GetDataCaches(pFactors, pFactor);

            if (dataCaches == null)
            {
                return(false);
            }

            //初始检查集
            bool bResult = this.InitDataChecks_CheckAll(dataCaches);

            return(bResult);
        }
示例#8
0
        public IDataCaches GetDataCaches(IData_Factor infoFactor, bool autoInit = false)
        {
            IDataCaches dataCaches = null;

            if (_DataCaches.TryGetValue(infoFactor.ID, out dataCaches))
            {
                //What ever you gonna do next...
            }
            if (autoInit && dataCaches == null)
            {
                if (InitDataCaches(infoFactor))
                {
                    return(GetDataCaches(infoFactor));
                }
            }
            return(dataCaches);
        }
示例#9
0
        public bool InitDataCache <T>(IData_Factor infoFactor, string tagName, typeTimeFrequency typeTimeFrequency, int cacheNums)
        {
            IDataCaches dataCaches = this.GetDataCaches(infoFactor);

            if (dataCaches == null)
            {
                if (InitDataCaches(infoFactor))
                {
                    dataCaches = this.GetDataCaches(infoFactor);
                    if (dataCaches == null)
                    {
                        return(false);
                    }
                }
            }
            return(dataCaches.InitDataCache <T>(tagName, typeTimeFrequency, cacheNums));
        }
示例#10
0
 public bool CheckData <T>(DateTime dtTime, T data, IDataCaches dataCaches = null)
 {
     //以检查集的方式统一管理--观察者模式
     if (_DataChecks != null)
     {
         bool bResult = _DataChecks.CheckDatas(dtTime, data, dataCaches);
         if (bResult && this._DataChecks.Parent != null)
         {
             if (this._DataChecks.Parent.DataCaches_Manage != null)
             {
                 //向上递归终止,暂不需要实现最顶层的DataCheck
                 //bResult = this._DataChecks.Parent.DataCaches_Manager.CheckData<T>(dtTime, data, this);
             }
         }
         return(bResult);
     }
     return(true);
 }
示例#11
0
        //初始规则信息集合-指定时间级别-弃用
        private bool InitDataChecks_Check(IDataCaches dataCaches, typeTimeFrequency timeFrequency)
        {
            //数据缓存集检查
            if (dataCaches == null)
            {
                return(false);
            }

            //提取数据缓存对象、及检查对象集
            IDataCache <Data_Quote> poDataCache        = dataCaches.GetDataCache <Data_Quote>("", timeFrequency);
            IDataChecks             poDataChecks_Cache = new DataChecks_Quote(poDataCache.ID, poDataCache, null, _msger);

            //初始检查集
            bool bResult = poDataCache.InitDataChecks(poDataChecks_Cache);

            bResult = bResult && this.InitDataCheck(poDataChecks_Cache, timeFrequency);
            return(bResult);
        }
示例#12
0
        /// <summary>提取指定因子对象集、因子对象的数据缓存集
        /// </summary>
        /// <param name="infoFactors">因子对象集</param>
        /// <param name="infoFactor">因子对象</param>
        /// <param name="autoInit">是否自动初始</param>
        /// <returns></returns>
        public IDataCaches GetDataCaches(IData_Factors infoFactors, IData_Factor infoFactor, bool autoInit = false)
        {
            //提取管理类
            IDataCaches_Manage dataManage = this.GetDataCaches_Manage(infoFactors, autoInit);

            if (dataManage == null)
            {
                return(null);
            }

            IDataCaches dataCaches = dataManage.GetDataCaches(infoFactor, false);

            if (autoInit && dataCaches == null)
            {
                if (this.InitDataCaches(infoFactors, infoFactor, autoInit))
                {
                    return(GetDataCaches(infoFactors, infoFactor));
                }
            }
            return(dataCaches);
        }
示例#13
0
        /// <summary>按因子对象集、因子对象提取缓存数据对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="infoFactors">因子对象集</param>
        /// <param name="infoFactor">因子对象</param>
        /// <param name="strTag">自定义标识</param>
        /// <param name="typeTimeFrequency">时间频率</param>
        /// <param name="autoInit">不存在时是否自定初始</param>
        /// <param name="cacheNums">缓存数据数量,autoInit为false时无效</param>
        /// <returns></returns>
        public IDataCache <T> GetDataCache <T>(IData_Factors infoFactors, IData_Factor infoFactor, string strTag = "", typeTimeFrequency typeTimeFrequency = typeTimeFrequency.none, bool autoInit = false, int cacheNums = 1)
        {
            IDataCaches dataCaches = this.GetDataCaches(infoFactors, infoFactor, autoInit);

            if (dataCaches == null)
            {
                return(null);
            }

            IDataCache <T> dataCache = dataCaches.GetDataCache <T>(strTag, typeTimeFrequency);

            if (autoInit && dataCache == null)
            {
                if (this.InitDataCache <T>(infoFactors, infoFactor, strTag, typeTimeFrequency, cacheNums, autoInit))
                {
                    return(GetDataCache <T>(infoFactors, infoFactor, strTag, typeTimeFrequency));
                }
            }

            //事件触发
            return(dataCache);
        }
示例#14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            //测试因子及设置
            Console.WriteLine("测试因子及设置:");
            DateTime       dtBase          = DateTime.Now;
            IData_Factor   poFactor        = new Data_Factor("Factor_001", "Sdssf", "测试因子", "测试标准");
            IDataCache_Set poDataCache_Set = new DataCache_Set("", dtBase, typeTimeFrequency.None, 0, poFactor);

            //测试 DataCache
            Console.WriteLine("测试 DataCache:");
            DataCache <int> dataCache0 = new DataCache <int>("int002", typeTimeFrequency.Hour, 12, poDataCache_Set);

            dataCache0.Init(dtBase);
            dataCache0.SetData(dtBase, 10);
            dataCache0.SetData(dtBase.AddHours(1), 10);

            DataCache <Data_Iot <string> > dataCache2 = new DataCache <Data_Iot <string> >("Data_Iot001", typeTimeFrequency.Minute_1, 60, poDataCache_Set);

            dataCache2.Init(dtBase);
            dataCache2.SetData(dtBase, new Data_Iot <string>(dtBase, "10"));
            dataCache2.SetData(dtBase.AddMinutes(1), new Data_Iot <string>(dtBase.AddMinutes(1), "11"));
            dataCache2.SetData(dtBase.AddMinutes(5), new Data_Iot <string>(dtBase.AddMinutes(5), "15"));

            //测试 IDataCaches
            Console.WriteLine("测试 DataCaches:");
            IDataCaches dataCaches = new DataCaches(poFactor, poDataCache_Set);

            dataCaches.InitDataCache <int>("int002", typeTimeFrequency.Day, 6);
            dataCaches.InitDataCache <Data_Iot <string> >("Data_Iot002", typeTimeFrequency.Hour, 24);
            IDataCache <Data_Iot <string> > poDataCache2 = dataCaches.GetDataCache <Data_Iot <string> >("Data_Iot001", typeTimeFrequency.Minute_1);

            //测试 IDataCaches_Manage
            Console.WriteLine("测试 IDataCaches_Manage:");
            IData_Factors      poFactors         = new Data_Factors("Factors_001", "Sdssf", "测试因子", "测试标准");
            IDataCaches_Manage dataCaches_Manage = new DataCaches_Manage(poFactors, poDataCache_Set);

            dataCaches_Manage.InitDataCache <int>(poFactor, "manage001", typeTimeFrequency.Day, 7);
            dataCaches_Manage.SetData <int>(poFactor, "manage001", dtBase, 11, typeTimeFrequency.Day);
            int data = dataCaches_Manage.GetData <int>(poFactor, "manage001", dtBase, typeTimeFrequency.Day);

            //测试 DataCaches_Manager
            Console.WriteLine("测试 DataCaches_Manager:");
            DataCaches_Manager dataCaches_Manager = new DataCaches_Manager();

            dataCaches_Manager.Init(dtBase);
            dataCaches_Manager.InitDataCache <int>(poFactors, poFactor, "manage001", typeTimeFrequency.Day, 3);

            IData_Factors poFactors2 = new Data_Factors("Factors_002", "Nosdfsf", "测试因子2", "测试标准2");
            IData_Factor  poFactor2  = new Data_Factor("Factor_002", "Sdssf02", "测试因子", "测试标准");
            IData_Factor  poFactor3  = new Data_Factor("Factor_003", "Sdssf03", "测试因子", "测试标准");

            dataCaches_Manager.InitDataCache <Data_Iot <int> >(poFactors2, poFactor2, "manage002", typeTimeFrequency.Hour, 12);
            dataCaches_Manager.InitDataCache <Data_Iot <int> >(poFactors2, poFactor2, "manage002", typeTimeFrequency.Minute_1, 5);


            //测试 DataCheck_Test --缓存数据对象
            IDataCheck_Msger poMsger = new DataCheck_Msger_Test(false, 0);

            IDataCaches poDataCaches = dataCaches_Manager.GetDataCaches(poFactors2, poFactor2);
            IDataCache <Data_Iot <int> > poDataCache = poDataCaches.GetDataCache <Data_Iot <int> >("manage002", typeTimeFrequency.Hour);
            IDataChecks poDataChecks = new DataChecks_Test(poDataCache.ID, poDataCache, null, poMsger);

            poDataCache.InitDataChecks(poDataChecks);
            IDataCheck <Data_Iot <int> > poDataCheck = new DataCheck_Test <Data_Iot <int> >(poDataCache.ID, poDataCache);

            poDataChecks.InitDataCheck <Data_Iot <int> >(poDataCheck.Tag, poDataCheck, true);
            dataCaches_Manager.SetData <Data_Iot <int> >(poFactors2, poFactor2, "manage002", dtBase.AddHours(1), new Data_Iot <int>(dtBase, 11), typeTimeFrequency.Hour);

            //测试 DataCheck_Test --缓存数据集对象
            IDataChecks poDataChecks2 = new DataChecks_Test(poDataCaches.ID + "_2", poDataCaches);
            IDataCheck <Data_Iot <int> > poDataCheck2 = new DataCheck_Tests <Data_Iot <int> >(poDataCache.ID + "_2", poDataCache);

            poDataCaches.InitDataChecks(poDataChecks2);
            poDataCaches.InitDataCheck <Data_Iot <int> >(poDataCheck2.Tag, poDataCheck2);

            poDataChecks.InitDataChecks(poDataChecks2);     //设置因子的上级联动IDataChecks
            dataCaches_Manager.SetData <Data_Iot <int> >(poFactors2, poFactor2, "manage002", dtBase.AddHours(1), new Data_Iot <int>(dtBase, 9), typeTimeFrequency.Hour);

            //测试 DataCheck_Test --缓存数据集管理对象
            IDataChecks poDataChecks3 = new DataChecks_Test(poDataCaches.ID + "_3", poDataCaches);
            IDataCheck <Data_Iot <int> > poDataCheck3        = new DataCheck_TestM <Data_Iot <int> >(poDataCache.ID + "_3", poDataCache);
            IDataCaches_Manage           poDataCaches_Manage = dataCaches_Manager.GetDataCaches_Manage(poFactors2);

            poDataCaches_Manage.InitDataChecks(poDataChecks3);
            poDataChecks3.InitDataCheck(poDataCheck3.Tag, poDataCheck3);
            poDataChecks2.InitDataChecks(poDataChecks3);     //设置因子集的上级联动IDataChecks
            dataCaches_Manager.SetData <Data_Iot <int> >(poFactors2, poFactor2, "manage002", dtBase.AddHours(1), new Data_Iot <int>(dtBase, 5), typeTimeFrequency.Hour);
            Data_Iot <int> pp = dataCaches_Manager.GetData <Data_Iot <int> >(poFactors2, poFactor2, "manage002", dtBase.AddHours(1), typeTimeFrequency.Hour);


            //压力测试         数据初始建议用 InitDatas 避免历史数据判断
            Console.WriteLine("测试  Stress testing!\n");
            Console.WriteLine("测试 初始:");
            DataCaches_Manager manager = new DataCaches_Manager();

            manager.Init(dtBase);
            DateTime dtStart0      = DateTime.Now;
            int      factorsNums   = 2000;
            int      factorNums    = 10;
            int      factorTagNums = 5;
            int      cachesNums    = 10;
            int      nsum0         = 0;

            for (int i = 0; i < factorsNums; i++)
            {
                IData_Factors pFactors = new Data_Factors("TestFactors_" + i.ToString(), "Factors_" + i.ToString(), i.ToString(), i.ToString());
                for (int j = 0; j < factorNums; j++)
                {
                    IData_Factor pFactor = new Data_Factor("TestFactor_" + j.ToString(), "Factor_" + j.ToString(), j.ToString(), j.ToString());

                    for (int k = 0; k < factorTagNums; k++)
                    {
                        manager.InitDataCache <Data_Iot <int> >(pFactors, pFactor, k.ToString(), typeTimeFrequency.Minute_1, cachesNums);
                        for (int kk = 0; kk < cachesNums; kk++)
                        {
                            Data_Iot <int> pData = new Data_Iot <int>(dtBase.AddMinutes(-kk), -kk);
                            manager.SetData <Data_Iot <int> >(pFactors, pFactor, k.ToString(), pData.Time, pData, typeTimeFrequency.Minute_1);
                            nsum0++;
                        }
                    }
                }
            }
            DateTime dtEnd0 = DateTime.Now;

            Console.WriteLine(string.Format("测试 初始耗时: {0} s.  {1}个, 频率 {2} 万/s", (dtEnd0 - dtStart0).TotalSeconds, nsum0, nsum0 / 10000 / (dtEnd0 - dtStart0).TotalSeconds));


            Console.WriteLine("测试 赋值:");
            DateTime dtStart1 = DateTime.Now;
            int      nsum = 0, nStep = 1, nStpes = 10;

            for (int step = 0; step < nStpes; step++)
            {
                for (int i = 0; i < factorsNums; i++)
                {
                    for (int j = 0; j < factorNums; j++)
                    {
                        for (int k = 0; k < factorTagNums; k++)
                        {
                            for (int kk = 0; kk < cachesNums; kk++)
                            {
                                Data_Iot <int> pData = new Data_Iot <int>(dtBase.AddMinutes(nStep), nStep);
                                manager.SetData <Data_Iot <int> >("TestFactors_" + i.ToString(), "TestFactor_" + j.ToString(), k.ToString(), pData.Time, pData, typeTimeFrequency.Minute_1);
                                nsum++;
                            }
                        }
                    }
                }
            }
            nStep++;
            DateTime dtEnd1 = DateTime.Now;

            Console.WriteLine(string.Format("测试 赋值耗时: {0} s. {1}个, 频率 {2} 万/s", (dtEnd1 - dtStart1).TotalSeconds, nsum, nsum / 10000 / (dtEnd1 - dtStart1).TotalSeconds));

            Console.WriteLine("测试  ended!");



            //DatasCache_Manage_Iot<float> manager = new DatasCache_Manage_Iot<float>(DateTime.Now, (float)-1001.0001);
            //for (int i = 0; i < 10000; i++)
            //{
            //    manager.Init(i.ToString(), (float)-1001.0001);
            //}

            //// 模拟值(载入旧的)
            //IDataCache_Manage<float> datas = manager.GetData("1");
            //IDatas_Iot<float> data = datas.GetDatas(typeTimeFrequency.Hour);
            //DateTime dt = data.DataSet_TypeTime.Time_Start;
            //for (int i = 0; i < data.DataSet_TypeTime.Sum_Step + 2; i++)
            //{
            //    data.SetData(dt.AddHours(i), i);
            //}
            //Dictionary<int, IotDatas_Manage> datas = new Dictionary<int, IotDatas_Manage>();
            //for (int i = 0; i < 1; i++)
            //{
            //    IotDatas_Manage manage = new IotDatas_Manage();
            //    manage.Init();
            //    datas.Add(i, manage);
            //}
        }
 public NotifyHub(IDataCaches <User> cache)
 {
     _cache = cache;
 }
示例#16
0
 public UserRoleRepository(IDataCaches <UserRole> cachce, IDataRepository data)
 {
     _cachce = cachce;
     _data   = data;
 }
示例#17
0
 public virtual bool InitDataCaches(IDataCaches dataCaches)
 {
     _DataCaches = dataCaches;
     return(true);
 }
 public RoleRepository(IDataCaches <Role> dataCaches, IDataRepository dataRepository)
 {
     _cachce = dataCaches;
     _data   = dataRepository;
 }
示例#19
0
 public UsersController(IUserRepository repository, IDataCaches <User> dataCaches, IConfiguration configuration)
 {
     Configuration = configuration;
     _repository   = repository;
     _dataCaches   = dataCaches;
 }
示例#20
0
 public virtual bool CheckData(DateTime dtTime, T data, IDataCaches dataCaches = null)
 {
     return(true);
 }
示例#21
0
 public UserRepository(IDataCaches <User> dataCaches, IDataRepository dataRepository)
 {
     _cachce = dataCaches;
     _data   = dataRepository;
 }
示例#22
0
 public DataChecks_Quote(string tagName, IDataCaches dataCaches, IDataChecks parent = null, IDataCheck_Msger msger = null) : base(tagName, dataCaches, parent, msger)
 {
 }