예제 #1
0
        // 按因子对象初始因子数据缓存集
        public bool InitDataCaches(IData_Factors infoFactors, IData_Factor infoFactor, bool useEvent = false)
        {
            if (_isInited == false)
            {
                return(false);
            }
            IDataCaches_Manage dataManage = this.GetDataCaches_Manage(infoFactors);

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

            if (dataManage.GetDataCaches(infoFactor, false) == null)
            {
                DataCaches dataCaches = (DataCaches)dataManage.GetDataCaches(infoFactor, true);

                //注册检查集初始事件
                if (useEvent)
                {
                    dataCaches.DataChecks_Initial += new DataCachesChecksInitial_EventHandler(EventHandler_DataCachesChecksInitial);
                    dataCaches.Event_DataChecks_Initial();
                }
                return(this._IndexFactors(infoFactors, infoFactor));
            }
            return(true);
        }
예제 #2
0
        // 按因子对象初始因子数据缓存集
        public bool InitDataCaches(IData_Factors infoFactors, IData_Factor infoFactor)
        {
            //提取管理类
            IDataCaches_Manage dataManage = this.GetDataCaches_Manage(infoFactors, true);

            return(this._IndexFactors(infoFactors, infoFactor) && dataManage.InitDataCaches(infoFactor));
        }
예제 #3
0
 public DataChecks(string tagName, IDataCaches_Manage dataCaches_Manage, IDataChecks parent = null, IDataCheck_Msger msger = null)
 {
     _tag               = tagName;
     _Msger             = msger;
     _Parent            = parent;
     _DataCaches_Manage = dataCaches_Manage;
     _DataChecks        = new Dictionary <string, IDataCheck>();
 }
예제 #4
0
        /// <summary>按因子对象初始因子数据缓存对象
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="infoFactors">因子对象集</param>
        /// <param name="infoFactor">因子对象</param>
        /// <param name="tagName">标识</param>
        /// <param name="typeTimeFrequency">数据频率</param>
        /// <param name="cacheNums">缓存数据数量</param>
        /// <returns></returns>
        public bool InitDataCache <T>(IData_Factors infoFactors, IData_Factor infoFactor, string tagName, typeTimeFrequency typeTimeFrequency, int cacheNums)
        {
            //提取管理类
            IDataCaches_Manage dataManage = this.GetDataCaches_Manage(infoFactors, true);

            return(this._IndexFactors(infoFactors, infoFactor) &&
                   dataManage.InitDataCache <T>(infoFactor, tagName, typeTimeFrequency, cacheNums));
        }
예제 #5
0
        public virtual bool CheckDatas <T>(DateTime dtTime, T data, IDataCaches_Manage dataCaches_Manage)
        {
            bool bResult = true;

            foreach (KeyValuePair <string, IDataCheck> check in _DataChecks)
            {
                IDataCheck <T> dataCheck = (IDataCheck <T>)check.Value;
                bResult = dataCheck.CheckData(dtTime, data, dataCaches_Manage) && bResult;
            }
            return(bResult);
        }
예제 #6
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);
            }

            return(dataManage.GetDataCaches(infoFactor, autoInit));
        }
예제 #7
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));
            }
        }
예제 #8
0
        /// <summary>提取指定因子对象集的数据缓存集管理对象
        /// </summary>
        /// <param name="infoFactors">因子对象集</param>
        /// <param name="autoInit">是否自动初始</param>
        /// <returns></returns>
        public IDataCaches_Manage GetDataCaches_Manage(IData_Factors infoFactors, bool autoInit = false)
        {
            IDataCaches_Manage dataManage = null;

            if (_DataCaches_Manages.TryGetValue(infoFactors.ID, out dataManage))
            {
                //What ever you gonna do next...
            }
            if (autoInit && dataManage == null)
            {
                if (this.InitDataCaches_Manage(infoFactors, autoInit))
                {
                    return(GetDataCaches_Manage(infoFactors));
                }
            }
            return(dataManage);
        }
예제 #9
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);
        }
예제 #10
0
 public virtual bool InitDataCaches_Manage(IDataCaches_Manage dataCaches_Manage)
 {
     _DataCaches_Manage = dataCaches_Manage;
     return(true);
 }
예제 #11
0
 public virtual bool CheckData(DateTime dtTime, T data, IDataCaches_Manage dataCaches_Manage = null)
 {
     return(true);
 }
예제 #12
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);
            //}
        }
예제 #13
0
 public DataChecks_Quote(string tagName, IDataCaches_Manage dataCaches_Manage, IDataChecks parent = null, IDataCheck_Msger msger = null) : base(tagName, dataCaches_Manage, parent, msger)
 {
 }