Exemplo n.º 1
0
        /// <summary>
        /// 记录数据
        /// </summary>
        /// <param name="ts"></param>
        /// <param name="name"></param>
        public void Put(ITimeSeries ts, String name)
        {
            TimeUnit tu = ts.TimeUnit;

            if (!this.timeSerials.ContainsKey(tu))
            {
                this.timeSerials.Add(tu, new ConcurrentDictionary <string, object>());
            }
            ConcurrentDictionary <string, object> d = this.timeSerials[tu];

            d[name] = ts;

            IndicatorMeta meta = metas[name];

            if (meta == null)
            {
                throw new Exception("缺少" + name + "的元数据");
            }
            String filename = this.GetFullFileName(meta, tu);

            ts.Save(filename);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 创建时序数据
        /// </summary>
        /// <param name="name"></param>
        /// <param name="timeunit"></param>
        /// <param name="forced">true表示如果数据已经有,会删除重建</param>
        /// <returns></returns>
        public ITimeSeries Create(String name, TimeUnit timeunit, bool forced = true)
        {
            //内存中是否已经存在
            if (!timeSerials.ContainsKey(timeunit))
            {
                timeSerials.Add(timeunit, new ConcurrentDictionary <string, object>());
            }
            ConcurrentDictionary <string, object> d = timeSerials[timeunit];

            if (d.ContainsKey(name) && ((IList)d[name]).Count > 0 && !forced)
            {
                return((ITimeSeries)d[name]);
            }
            //查找元信息
            if (name == null || name == "")
            {
                return(null);
            }
            IndicatorMeta meta = metas[name];

            if (meta == null)
            {
                throw new Exception("缺少" + name + "的元数据");
            }

            //文件中是否存在,存在则读取
            ITimeSeries result       = null;
            String      fullFilename = GetFullFileName(meta, timeunit);

            if (File.Exists(fullFilename) && !forced)
            {
                result = (ITimeSeries)meta.IndicatorType.GetConstructor(new Type[] { typeof(String), typeof(TimeUnit) }).Invoke(new Object[] { code, timeunit });
                result.Load(fullFilename);
                d[name] = result;
                return(result);
            }


            //文件中不存在,尝试用小周期创建大周期
            TimeUnit baseTU = timeunit >= TimeUnit.day ? TimeUnit.day : TimeUnit.minute;

            if (baseTU != timeunit)
            {
                ITimeSeries baseTS = Create(name, baseTU, false);//取得小周期
                if (baseTS != null)
                {
                    result = baseTS.Zoomout(timeunit);
                    if (result != null)
                    {
                        d[name] = result;
                        result.Save(this.GetFullFileName(meta, timeunit));
                        return(result);
                    }
                }
            }

            //尝试使用产生器产生
            if (meta.Geneartor == null)
            {
                return(null);
            }

            Properties props = new Properties();

            props.Put("TimeSerialsDataSet", this);
            props.Put("timeunit", timeunit);
            props.Put("name", name);
            props.Put("code", code);
            result = (ITimeSeries)meta.Geneartor(props);
            if (result != null)
            {
                this.Put(result, name);
            }
            return(result);
        }