Exemplo n.º 1
0
        /// <summary>
        /// 添加该grDataPoint 到集合中,并根据站名和时间自动分配到相关的Wccs中
        /// </summary>
        /// <param name="grDataPoint"></param>
        public void AddGrDataPoint(GrDataPoint grDataPoint)
        {
            if (grDataPoint == null)
            {
                throw new ArgumentNullException("grDataPoint");
            }

            WastingCaloricCalculatorWithName wccwn = this._wccwns.FindWccwn(
                grDataPoint.StationName,
                true
                );

            //
            wccwn.AddGrDataPoint(grDataPoint);

            // grdataPoint 要求按照时间顺序依次加入
            //
            // 以站名称 和 时间区分
            //
            // 查找和grDataPoint同名的wcc, 如果没有则创建
            //
            //      如果该grDataPoint能加入该wcc则加入
            //
            //      否则新建wcc并加入该grDataPoint
            //
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="grDataPoint"></param>
        private void CreateAndAddNewWcc(GrDataPoint grDataPoint)
        {
            WastingCaloricCalculator newwcc = new WastingCaloricCalculator(grDataPoint.DateTime);

            newwcc.AddGrDataPoint(grDataPoint);
            _wccs.Add(newwcc);
        }
 /// <summary>
 /// 按照时间顺序自动加入相关的Wcc中,或自动创建Wcc并加入到wccs中
 /// </summary>
 /// <param name="grDataPoint"></param>
 public void AddGrDataPoint(GrDataPoint grDataPoint)
 {
     if (_wccs.Count > 0)
     {
         // 已包含数据
         WastingCaloricCalculator lastwcc = _wccs[_wccs.Count - 1];
         if (lastwcc.IsTodayGrDataPoint(grDataPoint))
         {
             lastwcc.AddGrDataPoint(grDataPoint);
         }
         else if (lastwcc.IsNextDayDataPoint(grDataPoint))
         {
             if (lastwcc.CanCalcZeroDataPoint(grDataPoint))
             {
                 GrDataPoint zerogdp = lastwcc.CalcZeroDataPoint(grDataPoint);
                 lastwcc.AddGrDataPoint(zerogdp);
                 CreateAndAddNewWcc(zerogdp);
             }
             else
             {
                 CreateAndAddNewWcc(grDataPoint);
             }
         }
         else
         {
             CreateAndAddNewWcc(grDataPoint);
         }
     }
     else
     {
         CreateAndAddNewWcc(grDataPoint);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="grDataPoint"></param>
 /// <returns></returns>
 public int Add(GrDataPoint grDataPoint)
 {
     if (grDataPoint == null)
     {
         throw new ArgumentNullException("add()");
     }
     return(_list.Add(grDataPoint));
 }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="grDataPoint"></param>
 public void AddGrDataPoint(GrDataPoint grDataPoint)
 {
     Debug.Assert(
         grDataPoint.DateTime.Date == this.Date ||
         (grDataPoint.DateTime.Date - this.Date == TS_ONEDAY &&
          grDataPoint.DateTime.TimeOfDay == TimeSpan.Zero)
         );
     this._grDataPoints.Add(grDataPoint);
 }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="grDataPoint"></param>
        /// <returns></returns>
        public bool CanCalcZeroDataPoint(GrDataPoint grDataPoint)
        {
            if (this.LastGrDataPoint == null)
            {
                return(false);
            }

            if (LastGrDataPoint.DateTime.TimeOfDay >= TS_SPLIT &&
                grDataPoint.DateTime.TimeOfDay < TS_SPLIT)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public int Calc()
        {
            if (this._grDataPoints.Count == 0)
            {
                return(0);
            }

            // ? 只有一个数据时,无法计算热量
            //
            if (this._grDataPoints.Count == 1)
            {
                return(1);
            }

            float onegtSum = 0;
            float onebtSum = 0;
            int   onesum   = 0;

            for (int i = 0; i < this._grDataPoints.Count; i++)
            {
                GrDataPoint gdp = _grDataPoints[i];
                onegtSum += gdp.OneGiveTemp;
                onebtSum += gdp.OneBackTemp;

                if (i != 0)
                {
                    GrDataPoint preGdp     = _grDataPoints[i - 1];
                    int         thesumdiff = gdp.OneSum - preGdp.OneSum;
                    if (thesumdiff > 0)
                    {
                        onesum += thesumdiff;
                    }
                }
            }

            GrDataPoint firstGdp = _grDataPoints[0];
            GrDataPoint lastGdp  = _grDataPoints[_grDataPoints.Count - 1];
            TimeSpan    ts       = lastGdp.DateTime - firstGdp.DateTime;

            float onegtAvg = onegtSum / _grDataPoints.Count;
            float onebtAvg = onebtSum / _grDataPoints.Count;

            return(Calc(onegtAvg, onebtAvg, onesum, ts));
            //throw new NotImplementedException( "calc()" );
        }
Exemplo n.º 8
0
        public void testCalcZeroDataPoint()
        {
            string      name = "name";
            GrDataPoint dp1  = new GrDataPoint(
                name,
                DateTime.Parse("2007-10-12 12:00:00"),
                100,
                50,
                1000
                );

            GrDataPoint dp2 = new GrDataPoint(
                name,
                DateTime.Parse("2007-10-13 11:59:59"),
                80,
                40,
                1200
                );

            WastingCaloricCalculator wcc = new WastingCaloricCalculator(DateTime.Parse("2007-10-12"));

            wcc.AddGrDataPoint(dp1);
            GrDataPoint ans = wcc.CalcZeroDataPoint(dp2);

            Assert.AreEqual(name, ans.StationName);
            Assert.AreEqual(DateTime.Parse("2007-10-13 0:0:0"), ans.DateTime);
            Assert.AreEqual(90F, ans.OneGiveTemp, 0.1F);
            Assert.AreEqual(45F, ans.OneBackTemp, 0.1F);
            Assert.AreEqual(1100F, ans.OneSum, 0.1F);


            Assert.AreEqual(true, wcc.CanCalcZeroDataPoint(dp2));
            Assert.AreEqual(false, wcc.IsTodayGrDataPoint(dp2));
            Assert.AreEqual(true, wcc.IsNextDayDataPoint(dp2));

            // 1 gr data point
            Assert.AreEqual(1, wcc.Calc());

            wcc.AddGrDataPoint(ans);
            Assert.AreEqual(1, wcc.Calc());
        }
Exemplo n.º 9
0
        /// <summary>
        /// 计算零点的GrDataPoint值
        /// </summary>
        /// <param name="grDataPoint">下一天上午的第一个值</param>
        /// <returns></returns>
        public GrDataPoint CalcZeroDataPoint(GrDataPoint grDataPoint)
        {
            // 两个数据点时间相差一天
            //
            Debug.Assert(grDataPoint.DateTime.Date - this.Date == TimeSpan.FromDays(1));

            // 是同一个站点的
            //
            if (this.LastGrDataPoint != null)
            {
                Debug.Assert(grDataPoint.StationName == this.LastGrDataPoint.StationName);
            }

            // timespan of zero to last data point
            //
            TimeSpan tsZero2Ldp = this.Date - this.LastGrDataPoint.DateTime + TS_ONEDAY;

            // timespan of right data point to last data point
            //
            TimeSpan tsRdp2Ldp = grDataPoint.DateTime - this.LastGrDataPoint.DateTime;

            float k = (float)tsZero2Ldp.Ticks / (float)tsRdp2Ldp.Ticks;

            float onegt  = CalcLinearVal(this.LastGrDataPoint.OneGiveTemp, grDataPoint.OneGiveTemp, k);
            float onebt  = CalcLinearVal(this.LastGrDataPoint.OneBackTemp, grDataPoint.OneBackTemp, k);
            int   onesum = (int)CalcLinearVal(this.LastGrDataPoint.OneSum, grDataPoint.OneSum, k);

            GrDataPoint newdp = new GrDataPoint(
                grDataPoint.StationName,
                grDataPoint.DateTime.Date,
                onegt,
                onebt,
                onesum
                );

            return(newdp);
        }
Exemplo n.º 10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="grDataPoint"></param>
 /// <returns></returns>
 public bool IsNextDayDataPoint(GrDataPoint grDataPoint)
 {
     Debug.Assert(grDataPoint != null);
     return(grDataPoint.DateTime.Date - this.Date
            == TimeSpan.FromDays(1));
 }
Exemplo n.º 11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="grDataPoint"></param>
 /// <returns></returns>
 public bool IsTodayGrDataPoint(GrDataPoint grDataPoint)
 {
     Debug.Assert(grDataPoint != null);
     return(grDataPoint.DateTime.Date == this.Date);
 }
Exemplo n.º 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="grDataPoint"></param>
 public void Remove(GrDataPoint grDataPoint)
 {
     _list.Remove(grDataPoint);
 }