public void ConstructorTest()
    {

      TimeSpanSeries ts = new TimeSpanSeries();
      ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 1, 12, 0, 0), new DateTime(2014, 1, 1, 12, 12, 0), 10));
      ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 1, 13, 1, 0), new DateTime(2014, 1, 1, 13, 12, 0), 10));
      ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 2, 12, 0, 0), new DateTime(2014, 1, 2, 12, 12, 0), 10));
      ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 3, 12, 0, 0), new DateTime(2014, 1, 3, 12, 12, 0), 10));
      ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 4, 12, 0, 0), new DateTime(2014, 1, 4, 12, 12, 0), 10));
      ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 4, 12, 12, 0), new DateTime(2014, 1, 4, 12, 24, 0), 10));
      ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 12, 12, 12, 0), new DateTime(2014, 1, 12, 12, 24, 0), 10));

      FixedTimeStepSeries fx = new FixedTimeStepSeries(ts, true);

      var daily = TSTools.ChangeZoomLevel(fx, TimeStepUnit.Day, true);

      Assert.AreEqual(5, daily.TimeSpanValues.Count());

      var monthly = TSTools.ChangeZoomLevel(fx, TimeStepUnit.Month, true);
      var yearly = TSTools.ChangeZoomLevel(fx, TimeStepUnit.Year, true);

      Assert.AreEqual(ts.Sum, monthly.Sum);

      ts = new TimeSpanSeries() { TimeStepSize = TimeStepUnit.Minute };
      ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 1, 12, 15, 0), new DateTime(2014, 1, 1, 12, 30, 0), 10));
      ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 1, 12, 30, 0), new DateTime(2014, 1, 1, 12, 45, 0), 10));
      ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 1, 14, 45, 0), new DateTime(2014, 1, 1, 15, 00, 0), 10));
      ts.GapFill(InterpolationMethods.DeleteValue, TimeSpan.FromMinutes(15));
      
      fx = new FixedTimeStepSeries(ts, false);

      Assert.AreEqual(10,fx.Items[0].Value);


    }
示例#2
0
        public void ChangeZoomLevelTimespan()
        {
            TimeSpanSeries ts = new TimeSpanSeries();

            ts.Items.Add(new TimeSpanValue(new DateTime(2010, 1, 1, 12, 0, 0), new DateTime(2010, 1, 1, 12, 15, 0), 10));
            ts.Items.Add(new TimeSpanValue(new DateTime(2010, 1, 1, 12, 15, 0), new DateTime(2010, 1, 1, 12, 30, 0), 10));
            ts.Items.Add(new TimeSpanValue(new DateTime(2010, 10, 1, 12, 0, 0), new DateTime(2010, 10, 1, 12, 15, 0), 10));
            ts.TimeStepSize = TimeStepUnit.Minute;

            TimeSpanSeries ts2 = new TimeSpanSeries(TSTools.ChangeZoomLevel(ts, TimeStepUnit.Month, true));

            Assert.AreEqual(20, ts2.Max);
            Assert.AreEqual(2, ts2.Count);
        }
示例#3
0
    public static double GetAccessability(TimeSpanSeries activeperiods)
    {
      if (activeperiods.Count == 0)
        return -1;
      if (activeperiods.Count == 1)
        return 1;
      double MeanTimeBetweenErrors = activeperiods.Items.Average(t => t.Duration.TotalSeconds);

      double MeanTimeInError = 0;
      for (int i = 0; i < activeperiods.Count - 1; i++)
      {
        MeanTimeInError += activeperiods.Items[i+1].StartTime.Subtract(activeperiods.Items[i].EndTime).TotalSeconds;
      }

      MeanTimeInError /= activeperiods.Count - 1;

      return MeanTimeBetweenErrors / (MeanTimeBetweenErrors + MeanTimeInError);

    }
示例#4
0
    /// <summary>
    /// Checks if there are any holes in the data series. Returns the active periods.
    /// </summary>
    /// <param name="data"></param>
    /// <param name="Interval"></param>
    /// <returns></returns>
    public static TimeSpanSeries GetActivePeriods(TimeStampSeries data, TimeSpan Interval)
    {
      TimeSpanSeries toreturn = new TimeSpanSeries();

      if (data.Count > 0)
      {
        TimeSpanValue currentvalue = new TimeSpanValue(data.StartTime, data.StartTime, 1);
        for (int i = 0; i < data.Count; i++)
        {
          if (data.Items[i].Time <= currentvalue.EndTime.Add(Interval))
            currentvalue.EndTime = data.Items[i].Time;
          else
          {
            toreturn.Items.Add(currentvalue);
            currentvalue = new TimeSpanValue(data.Items[i].Time, data.Items[i].Time, 1);
          }
        }
        toreturn.Items.Add(currentvalue);
      }
      return toreturn;
    }
        public void ConstructorTest()
        {
            TimeSpanSeries ts = new TimeSpanSeries();

            ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 1, 12, 0, 0), new DateTime(2014, 1, 1, 12, 12, 0), 10));
            ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 1, 13, 1, 0), new DateTime(2014, 1, 1, 13, 12, 0), 10));
            ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 2, 12, 0, 0), new DateTime(2014, 1, 2, 12, 12, 0), 10));
            ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 3, 12, 0, 0), new DateTime(2014, 1, 3, 12, 12, 0), 10));
            ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 4, 12, 0, 0), new DateTime(2014, 1, 4, 12, 12, 0), 10));
            ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 4, 12, 12, 0), new DateTime(2014, 1, 4, 12, 24, 0), 10));
            ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 12, 12, 12, 0), new DateTime(2014, 1, 12, 12, 24, 0), 10));

            FixedTimeStepSeries fx = new FixedTimeStepSeries(ts, true);

            var daily = TSTools.ChangeZoomLevel(fx, TimeStepUnit.Day, true);

            Assert.AreEqual(5, daily.TimeSpanValues.Count());

            var monthly = TSTools.ChangeZoomLevel(fx, TimeStepUnit.Month, true);
            var yearly  = TSTools.ChangeZoomLevel(fx, TimeStepUnit.Year, true);

            Assert.AreEqual(ts.Sum, monthly.Sum);

            ts = new TimeSpanSeries()
            {
                TimeStepSize = TimeStepUnit.Minute
            };
            ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 1, 12, 15, 0), new DateTime(2014, 1, 1, 12, 30, 0), 10));
            ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 1, 12, 30, 0), new DateTime(2014, 1, 1, 12, 45, 0), 10));
            ts.Items.Add(new TimeSpanValue(new DateTime(2014, 1, 1, 14, 45, 0), new DateTime(2014, 1, 1, 15, 00, 0), 10));
            ts.GapFill(InterpolationMethods.DeleteValue, TimeSpan.FromMinutes(15));

            fx = new FixedTimeStepSeries(ts, false);

            Assert.AreEqual(10, fx.Items[0].Value);
        }
    public void ChangeZoomLevelTimespan()
    {
      TimeSpanSeries ts = new TimeSpanSeries();
      ts.Items.Add(new TimeSpanValue(new DateTime(2010, 1, 1, 12, 0, 0), new DateTime(2010, 1, 1, 12, 15, 0), 10));
      ts.Items.Add(new TimeSpanValue(new DateTime(2010, 1, 1, 12, 15, 0), new DateTime(2010, 1, 1, 12, 30, 0), 10));
      ts.Items.Add(new TimeSpanValue(new DateTime(2010, 10, 1, 12, 0, 0), new DateTime(2010, 10, 1, 12, 15, 0), 10));
      ts.TimeStepSize = TimeStepUnit.Minute;

      TimeSpanSeries ts2 = new TimeSpanSeries(TSTools.ChangeZoomLevel(ts, TimeStepUnit.Month, true));
      Assert.AreEqual(20, ts2.Max);
      Assert.AreEqual(2, ts2.Count);


    }
示例#7
0
    /// <summary>
    /// Changes the zoomlevel of a timespanseries
    /// </summary>
    /// <param name="Data"></param>
    /// <param name="NewZoomLevel"></param>
    /// <param name="Accumulate"></param>
    /// <returns></returns>
    public static IEnumerable<TimeSpanValue> ChangeZoomLevel(TimeSpanSeries Data, TimeStepUnit NewZoomLevel, bool Accumulate)
    {
      if (Data.TimeStepSize <= NewZoomLevel)
        return null;

      List<TimeSpanValue> ToReturn = new List<TimeSpanValue>();

      DateTime start = Data.StartTime;
      DateTime end = Data.EndTime;

      TimeSpanValue CurrentValue = new TimeSpanValue(GetTimeOfFirstTimeStep(start, NewZoomLevel), GetTimeOfFirstTimeStep(start, NewZoomLevel).AddTimeStepUnit(NewZoomLevel), 0);
      double currentcount = 0;
      foreach (var v in Data.Items.Where(dv => dv.Value != Data.DeleteValue))
      {
        if (CurrentValue.StartTime <= v.StartTime & v.StartTime<= CurrentValue.EndTime)
        {
          if (CurrentValue.EndTime >= v.EndTime) //We are still within the timespan
          {
            CurrentValue.Value += v.Value;
            currentcount++;
          }
          else //We exceed the timespan
          {
            double outsidefraction =(v.EndTime.Subtract(CurrentValue.EndTime).TotalDays / v.EndTime.Subtract(v.StartTime).TotalDays);
              CurrentValue.Value += v.Value*(1 - outsidefraction);
              currentcount += 1 - outsidefraction;

            if (!Accumulate & currentcount != 0)
              CurrentValue.Value /= currentcount;
            ToReturn.Add(CurrentValue);
            CurrentValue = new TimeSpanValue(CurrentValue.EndTime, CurrentValue.EndTime.AddTimeStepUnit(NewZoomLevel), v.Value*outsidefraction);
            currentcount = outsidefraction;
          }
        }
        else
        {
          if (!Accumulate & currentcount != 0)
            CurrentValue.Value /= currentcount;
          ToReturn.Add(CurrentValue);
          CurrentValue = new TimeSpanValue(GetTimeOfFirstTimeStep(v.StartTime, NewZoomLevel), GetTimeOfFirstTimeStep(v.StartTime, NewZoomLevel).AddTimeStepUnit(NewZoomLevel), v.Value);
          currentcount = 1;
        }
      }
      if (!Accumulate & currentcount != 0)
        CurrentValue.Value /= currentcount;
      ToReturn.Add(CurrentValue);

      return ToReturn;
    }