Example #1
0
        private void SaveTechContext(string context, IndexDefinitionInfo define)
        {
            string objCode = (int)this.ObjectType + "";
            string code    = objCode + "_" + this.ObjectCode + "_" + define.code + "_" + this.Cycle;

            using (var entity = new StockManDBEntities())
            {
                var item = entity.tech_context.FirstOrDefault(p => p.code == code);
                if (item == null)
                {
                    entity.tech_context.Add(new tech_context()
                    {
                        code          = code,
                        category_code = objCode,
                        object_code   = this.ObjectCode,
                        index_code    = define.code,
                        context       = context,
                        createtime    = DateTime.Now
                    });
                }
                else
                {
                    item.context    = context;
                    item.createtime = DateTime.Now;
                }
                try
                {
                    entity.SaveChanges();
                }
                catch (Exception ex)
                {
                    this.Log().Error(ex.Message);
                }
            }
        }
        protected IList <IndexData> GetLastIndexData(stock stock, IndexDefinitionInfo define)
        {
            using (StockManDBEntities entity = new StockManDBEntities())
            {
                string sql = @"select * from " + define.table_name + " where f_code='" + stock.code + "' order by code desc limit 50";

                entity.Database.Connection.Open();
                using (entity.Database.Connection)
                {
                    System.Data.IDbCommand commond = entity.Database.Connection.CreateCommand();
                    commond.CommandText = sql;
                    IDataReader reader = commond.ExecuteReader();

                    IList <IndexData> list = new List <IndexData>();
                    while (reader.Read())
                    {
                        IndexData id = new IndexData();
                        id.date = DateTime.Parse(reader["date"] + "");
                        foreach (var filed in define.fields)
                        {
                            id.Add(double.Parse(reader[filed.name] + ""));
                        }

                        list.Add(id);
                    }
                    entity.Database.Connection.Close();
                    return(list);
                }
            }
        }
Example #3
0
        private void SaveTechState(IndexDefinitionInfo define, IndexState result)
        {
            using (StockManDBEntities entity = new StockManDBEntities())
            {
                var cate        = (int)this.ObjectType + "";
                var code        = cate + "_" + this.ObjectCode + "_" + define.code;
                var objectState = entity.objectstate.FirstOrDefault(p => p.code == code);
                if (objectState == null)
                {
                    var temp = new objectstate()
                    {
                        code          = code,
                        category_code = cate,
                        object_code   = this.ObjectCode,
                        index_code    = define.code,
                        date          = DateTime.Now
                    };

                    switch (this.Cycle)
                    {
                    case TechCycle.day:
                        temp.day = (int)result;
                        break;

                    case TechCycle.week:
                        temp.week = (int)result;
                        break;

                    default:
                        temp.month = (int)result;
                        break;
                    }
                    entity.objectstate.Add(temp);
                }
                else
                {
                    switch (this.Cycle)
                    {
                    case TechCycle.day:
                        objectState.last_day = objectState.day;
                        objectState.day      = (int)result;
                        break;

                    case TechCycle.week:
                        objectState.last_week = objectState.week;
                        objectState.week      = (int)result;
                        break;

                    default:
                        objectState.last_month = objectState.month;
                        objectState.month      = (int)result;
                        break;
                    }
                    objectState.date = DateTime.Now;
                }

                entity.SaveChanges();
            }
        }
Example #4
0
        private void SaveTechData(IndexDefinitionInfo define, IList <IndexData> result)
        {
            IList <string> fields = define.fields.Select(p => p.name).ToList();

            switch (this.Cycle)
            {
            case TechCycle.day:
                indexService.AddTechByDay(define.table_name, fields, this.ObjectCode, result);
                break;

            case TechCycle.week:
                indexService.AddTechByWeek(define.table_name, fields, this.ObjectCode, result);
                break;

            case TechCycle.month:
                indexService.AddTechByMonth(define.table_name, fields, this.ObjectCode, result);
                break;
            }


            //string str = "";
            //string table = define.table_name;
            //foreach (Field f in define.fields)
            //{
            //    if (str.Length == 0)
            //    {
            //        str = f.name;
            //    }
            //    else
            //    {
            //        str += "," + f.name;
            //    }
            //}
            //string sqlTemplate = string.Format(@"insert into {0} (code,f_code,date,{1})values", table, str) + "({0})";

            //foreach (IndexData ds in result)
            //{
            //    //入库
            //    //字段映射,0->k,1->d,2->j
            //    string v = string.Format("'{0}','{1}','{2}'", ObjectCode + ds.date.ToString("yyyyMMdd"), ObjectCode,
            //        ds.date.ToString("yyyy-MM-dd"));

            //    foreach (double d in ds)
            //    {
            //        v += ",'" + d + "'";
            //    }
            //    string sql = string.Format(sqlTemplate, v);

            //    using (StockManDBEntities entity = new StockManDBEntities())
            //    {
            //        entity.Database.ExecuteSqlCommand(sql);
            //    }
            //}
        }
Example #5
0
        private IList <IndexData> CalculateData(IndexDefinitionInfo define)
        {
            //获取算法

            var contextOld = GetTechContext(define);

            var contextNew           = "";
            IList <IndexData> result = IndexCalculate.GetIndexData(define.algorithm_script, define.parameter, contextOld, out contextNew, PriceList);

            SaveTechContext(contextNew, define);

            return(result);
        }
Example #6
0
        private string GetTechContext(IndexDefinitionInfo define)
        {
            string code = (int)this.ObjectType + "_" + this.ObjectCode + "_" + define.code + "_" + this.Cycle;

            using (StockManDBEntities entity = new StockManDBEntities())
            {
                var context = entity.tech_context.FirstOrDefault(p => p.code == code);
                if (context == null)
                {
                    return(string.Empty);
                }
                return(context.context);
            }
        }
Example #7
0
        protected void BuidTable(IndexDefinitionInfo define)
        {
            string sql = @"create table if not exists `{0}` ({1}, PRIMARY KEY (`code`),KEY `f_code` (`f_code`));";

            //string sql = @"if not exists (select * from sysobjects where id = object_id(N'{0}') and OBJECTPROPERTY(id, N'IsUserTable') = 1)"
            //           + @"create table {0} ({1})";
            string sql1 = @"code varchar(50) NOT NULL,f_code varchar(50) NULL, date datetime NULL";

            foreach (var field in define.fields)
            {
                sql1 += "," + field.name + " float NULL";
            }

            string result = string.Format(sql, define.table_name, sql1);

            using (var entity = new StockManDBEntities())
            {
                //this.Log().Info("构建表:" + define.table_name);
                entity.Database.ExecuteSqlCommand(result);
            }
        }
Example #8
0
        private void SaveTag(IndexDefinitionInfo define, string result)
        {
            if (string.IsNullOrEmpty(result))
            {
                return;
            }
            using (StockManDBEntities entity = new StockManDBEntities())
            {
                //cate_object_code+tag_code+date
                var tag = entity.tag.FirstOrDefault(p => p.name == result);
                if (tag == null)
                {
                    tag = entity.tag.Add(new EntityModel.tag {
                        name = result
                    });
                }

                var cate      = (int)this.ObjectType + "";
                var code      = cate + "_" + this.ObjectCode + "_" + tag.code;
                var objectTag = entity.object_tag_map.FirstOrDefault(p => p.code == code);
                if (objectTag == null)
                {
                    entity.object_tag_map.Add(new object_tag_map
                    {
                        code          = code,
                        category_code = (int)this.ObjectType + "",
                        createdate    = DateTime.Now,
                        object_code   = this.ObjectCode,
                        tag_code      = tag.code + "",
                        tag_name      = tag.name,
                        index_code    = define.code,
                        cycle         = this.Cycle.ToString().ToLower()
                    });
                }

                entity.SaveChanges();
            }
        }
Example #9
0
        private void Calculate(IndexDefinitionInfo define, TechCycle cycle)
        {
            IIndex indexGener = new Dma();// CodeHelper.GetIEvaluator(define.server_algorithm_code);

            IList <stockcategory> cateList = cateService.GetCategoryList("tencent");

            int tatol = 0;

            foreach (var category in cateList)
            {
                IList <stock> stockList = stockService.GetStockByCategory(category.code);

                foreach (stock stock in stockList)
                {
                    IList <PriceInfo> list          = stockService.GetStockPriceDayInfo(stock);
                    IList <IndexData> listIndexData = GetLastIndexData(stock, define);

                    var result = indexGener.GetState(listIndexData);
                    this.Log().Info(stock.name + "_" + result);
                    using (StockManDBEntities entity = new StockManDBEntities())
                    {
                        var cate        = "1";
                        var code        = cate + "_" + stock.code + "_" + define.code;
                        var objectState = entity.objectstate.FirstOrDefault(p => p.code == code);
                        if (objectState == null)
                        {
                            var temp = new objectstate()
                            {
                                code          = code,
                                category_code = cate,
                                object_code   = stock.code,
                                index_code    = define.code,
                                date          = DateTime.Now
                            };

                            switch (cycle)
                            {
                            case TechCycle.day:
                                temp.day = (int)result;
                                break;

                            case TechCycle.week:
                                temp.week = (int)result;
                                break;

                            default:
                                temp.month = (int)result;
                                break;
                            }
                            entity.objectstate.Add(temp);
                        }
                        else
                        {
                            switch (cycle)
                            {
                            case TechCycle.day:
                                objectState.last_day = objectState.day;
                                objectState.day      = (int)result;
                                break;

                            case TechCycle.week:
                                objectState.last_week = objectState.week;
                                objectState.week      = (int)result;
                                break;

                            default:
                                objectState.last_month = objectState.month;
                                objectState.month      = (int)result;
                                break;
                            }
                        }

                        entity.SaveChanges();
                    }

                    if (++tatol > 3)
                    {
                        break;
                    }
                }
                if (tatol > 3)
                {
                    break;
                }
            }
        }
Example #10
0
        private string CalculateTag(IndexDefinitionInfo define)
        {
            var result = IndexCalculate.GetTag(define.algorithm_script, GetLastIndexData(define));

            return(result);
        }
Example #11
0
        private IndexState CalculateState(IndexDefinitionInfo define)
        {
            var result = IndexCalculate.GetState(define.algorithm_script, GetLastIndexData(define));

            return(result);
        }
Example #12
0
 private void ClearTechData(IndexDefinitionInfo define)
 {
     throw new NotImplementedException();
 }