public static void AnalysisFirst() { DateTime year5 = new DateTime(2013, 1, 1); DateTime year2 = new DateTime(2016, 1, 1); var all = StockBaseInfo.FindAll(StockBaseInfo._.Kind, 1); int index = 1; Parallel.For(0, all.Count, new ParallelOptions() { MaxDegreeOfParallelism = 8 }, i => { XTrace.WriteLine("进度:{0}/{1}", index++, all.Count); StockDayData.Meta.ConnName = "stock_" + all[i].Code; var list = StockDayData.FindAll(StockDayData._.Code == all[i].Code, StockDayData._.StatDate.Asc(), null, 0, 0); if (list != null && list.Count > 0) { StockElementInfo et = new StockElementInfo(); et.Code = all[i].Code; et.Name = all[i].Name; et.Price = list.Last().EndPrice; et.MaxPrice = list.Where(n => n.StatDate > year5).Max(n => n.EndPrice); //list.Max(n => n.EndPrice); et.MinPrice = list.Where(n => n.StatDate > year5).Min(n => n.EndPrice);// list.Min(n => n.EndPrice); et.MaxRate = et.MaxPrice / et.MinPrice; et.Max5year = list.Where(n => n.StatDate > year2).Max(n => n.EndPrice); et.Min5year = list.Where(n => n.StatDate > year2).Min(n => n.EndPrice); et.Max5Rate = et.Max5year / et.Min5year; et.Rate = et.Max5year / et.Price; et.UpdateDate = DateTime.Now; et.Save(); } //SELECT * from StockElementInfo WHERE Price > 8 and MaxRate >8 and Max5Rate > 4 }); }
/// <summary> /// 同步股票上市时间,最早取2000年,以第一次有数据开始计算 /// </summary> public static void ScanStockStartTime() { var all = StockBaseInfo.FindAll(StockBaseInfo._.Kind, 1); int index = 1; foreach (var item in all) { XTrace.WriteLine("进度:{0}/{1}",index ++,all.Count); //"stock_"+item.Code; //if (item.StartDate > new DateTime(2000, 1, 2)) continue; if (index < 2095) continue; var entity = StockDayData.FindAll(StockDayData._.Code == item.Code, StockDayData._.StatDate.Desc(),null,0,1); if(entity !=null && entity.Count>0) { if(entity[0].StatDate<new DateTime(2018,1,1)) { item.Kind = 0; item.Update(); } //item.StartDate = entity[0].StatDate; //item.Update();2758 } } }
public bool SaveStock(StockBaseInfo baseInfo) { try { return(true); } catch (Exception) { throw; } }
private StockBaseInfo GetBaseStock(SQLiteDataReader reader) { StockBaseInfo stock = new StockBaseInfo() { Code = reader["StockCode"].Value <string>(), Name = reader["StockName"].Value <string>(), SpellingInShort = reader["SpellingInShort"].Value <string>(), No = reader["StockNo"].Value <string>(), }; return(stock); }
public static void Test() { var all = StockBaseInfo.FindAll(); List<StockBaseInfo> list = new List<StockBaseInfo>(); foreach (var item in all) { if(item.Name.Contains("ST")) //(item.Code.CheckCode()) { item.Kind = 0; list.Add(item); } } list.Save(true); }
/// <summary> /// 拆分数据分库 /// </summary> public static void SpliteDB() { var all = StockBaseInfo.FindAll(StockBaseInfo._.Kind, 1); int index = 0; foreach (var item in all) { index++; if(item.Kind == 1) { StockDayData.Meta.ConnName = "stock_day"; var data = StockDayData.FindAll(StockDayData._.Code, item.Code); StockDayData.Meta.ConnName = "stock_"+item.Code; data.Save(true); XTrace.WriteLine("进度:{0}/{1},Code={2},记录数:{3}",index,all.Count,item.Code,data.Count); } } }
static void Main(string[] args) { // 创建注册组件的builder var builder = new ContainerBuilder(); //根据类型注册组件 ConsoleLogger 暴漏服务:ILogger //builder.RegisterType<ConsoleLogger>().As<ILogger>(); // 根据实例注册组件 output 暴漏服务:TextWriter DbSession output = new DbSession("server=.;database=Stock;uid=sa;pwd=1", DbDialect.SqlServer); builder.RegisterInstance(output).As <DbSession>(); //#region Repository //builder.RegisterGeneric(typeof(IBaseRepository<>)); //builder.RegisterGeneric(typeof(BaseRepository<>)); builder.RegisterGeneric(typeof(BaseRepository <>)).Named("basepository", typeof(IBaseRepository <>)).InstancePerLifetimeScope(); builder.RegisterType <StockBaseInfoRepository>().As <IStockBaseInfoRepository>(); builder.RegisterType <StockDayInfoRepository>().As <IStockDayInfoRepository>(); //#endreion //反射注册组件,手动指定构造函数,这里指定了调用 MyComponent(ILogger log,IConfigReader config)的构造函数进行注册 builder.RegisterType <StockService>() .UsingConstructor(typeof(IStockBaseInfoRepository), typeof(IStockDayInfoRepository)).As <IStockService>(); StockBaseInfo info = new StockBaseInfo() { Id = Guid.NewGuid().ToString(), Name = "Test" }; //构建一个容器完成注册 var rootcontainer = builder.Build(); //可以通过下面这种方式手动获取IConfigReader 的实现类 //这种手动解析的方式需要 从生命周期作用域内获取组件,以保证组件最终被释放 //不要直接从根容器rootcontainer中解析组件,很有可能会导致内存泄漏 using (var scope = rootcontainer.BeginLifetimeScope()) { var stockService = scope.Resolve <IStockService>(); stockService.SaveStock(info); } Console.WriteLine("Hello World!"); }