Ejemplo n.º 1
0
        private static bool ParseDHMSTokens(string[] dhmsTokens, string decimalSeparator, string negativeSign, [MaybeNullWhen(false)] out TimeSpanValue value)
        {
            value = null;
            bool result = false;

            // We must have at least two non-empty, non-whitespace (NENWS) tokens (e.g., M:S).
            //  Note: D.H:M input will cause the S token to still be null when we get here, so we
            //  can't assume that everything after the first NENWS token will also be a NENWS token.
            // Only the first NENWS token can contain a negative sign.
            // Only the Seconds token can contain a decimal separator.
            var nenwsTokens = dhmsTokens.SkipWhile(x => string.IsNullOrWhiteSpace(x));

            if (nenwsTokens.Count() >= 2 &&
                ValidateTokens(nenwsTokens.Skip(1), x => x == null || !x.Contains(negativeSign)) &&
                ValidateTokens(dhmsTokens.Take(3), x => x == null || !x.Contains(decimalSeparator)))
            {
                if (GetTicks(dhmsTokens[0], TimeSpan.TicksPerDay, false, out long daysTicks) &&
                    GetTicks(dhmsTokens[1], TimeSpan.TicksPerHour, false, out long hoursTicks) &&
                    GetTicks(dhmsTokens[2], TimeSpan.TicksPerMinute, false, out long minutesTicks) &&
                    GetTicks(dhmsTokens[3], TimeSpan.TicksPerSecond, true, out long secondsTicks))
                {
                    // Negative on the first token means the whole TimeSpan should be negative.
                    // We have to check if the token text starts with a negative sign because the
                    // numeric value might be zero (e.g., "-00:19:01").
                    long     sign     = nenwsTokens.First().StartsWith(negativeSign, StringComparison.CurrentCulture) ? -1 : 1;
                    TimeSpan timeSpan = TimeSpan.FromTicks(sign * (daysTicks + hoursTicks + minutesTicks + secondsTicks));
                    value  = new TimeSpanValue(timeSpan);
                    result = true;
                }
            }

            return(result);
        }
        private double?GetValue(IRun run, string columnName)
        {
            if (run == null || string.IsNullOrEmpty(columnName))
            {
                return(null);
            }

            if (Enum.IsDefined(typeof(AxisDimension), columnName))
            {
                AxisDimension axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), columnName);
                return(GetValue(run, axisDimension));
            }
            else if (Enum.IsDefined(typeof(SizeDimension), columnName))
            {
                SizeDimension sizeDimension = (SizeDimension)Enum.Parse(typeof(SizeDimension), columnName);
                return(GetValue(run, sizeDimension));
            }
            else
            {
                IItem value = Content.GetValue(run, columnName);
                if (value == null)
                {
                    return(null);
                }

                DoubleValue   doubleValue   = value as DoubleValue;
                IntValue      intValue      = value as IntValue;
                TimeSpanValue timeSpanValue = value as TimeSpanValue;
                DateTimeValue dateTimeValue = value as DateTimeValue;
                double?       ret           = null;
                if (doubleValue != null)
                {
                    if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value))
                    {
                        ret = doubleValue.Value;
                    }
                }
                else if (intValue != null)
                {
                    ret = intValue.Value;
                }
                else if (timeSpanValue != null)
                {
                    ret = timeSpanValue.Value.TotalSeconds;
                }
                else if (dateTimeValue != null)
                {
                    ret = dateTimeValue.Value.ToOADate();
                }
                else
                {
                    int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName);
                    ret = GetCategoricalValue(columnIndex, value.ToString());
                }

                return(ret);
            }
        }
Ejemplo n.º 3
0
 private void Runs_CollectionReset(object sender, CollectionItemsChangedEventArgs <IRun> e)
 {
     if (Optimizer != null)
     {
         Optimizer.Runs.RemoveRange(e.OldItems);
     }
     foreach (IRun run in e.Items)
     {
         IItem item;
         run.Results.TryGetValue("Execution Time", out item);
         TimeSpanValue executionTime = item as TimeSpanValue;
         if (executionTime != null)
         {
             ExecutionTime += executionTime.Value;
         }
     }
 }
Ejemplo n.º 4
0
 public override int GetHashCode()
 {
     unchecked
     {
         var result = GuidValue.GetHashCode();
         result = (result * 397) ^ (StringValue != null ? StringValue.GetHashCode() : 0);
         result = (result * 397) ^ IntValue;
         result = (result * 397) ^ LongValue.GetHashCode();
         result = (result * 397) ^ BoolValue.GetHashCode();
         result = (result * 397) ^ ByteValue.GetHashCode();
         result = (result * 397) ^ DecimalValue.GetHashCode();
         result = (result * 397) ^ DoubleValue.GetHashCode();
         result = (result * 397) ^ DateTimeValue.GetHashCode();
         result = (result * 397) ^ MaybeMoney.GetHashCode();
         result = (result * 397) ^ TimeSpanValue.GetHashCode();
         return(result);
     }
 }
Ejemplo n.º 5
0
 private void Runs_ItemsAdded(object sender, CollectionItemsChangedEventArgs <IRun> e)
 {
     foreach (IRun run in e.Items)
     {
         IItem item;
         run.Results.TryGetValue("Execution Time", out item);
         TimeSpanValue executionTime = item as TimeSpanValue;
         if (executionTime != null)
         {
             if (Optimizer.ExecutionState == ExecutionState.Started)
             {
                 runsExecutionTime += executionTime.Value;
             }
             else
             {
                 ExecutionTime += executionTime.Value;
             }
         }
     }
 }
Ejemplo n.º 6
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;
    }
Ejemplo n.º 7
0
        public override string ToString()
        {
            switch (Type)
            {
            case DataType.String:
                return(StringValue);

            case DataType.Numeric:
                return(NumericValue.ToString());

            case DataType.Boolean:
                return(BoolValue.ToString());

            case DataType.DateTime:
                return(DateTimeValue.ToString());

            case DataType.TimeSpan:
                return(TimeSpanValue.ToString());

            default:
                return("");
            }
        }
 /// <summary>
 /// Converts the value using the apropriate converter. Start time is included. Endtime is not
 /// </summary>
 /// <param name="values"></param>
 /// <returns></returns>
 public virtual TimeSpanValue Convert(TimeSpanValue val)
 {
   if (val.StartTime >= Start & val.EndTime < End)
     return new TimeSpanValue(val.StartTime, val.EndTime, ConvertFunction(val.Value));
   else
     return val;
 }
Ejemplo n.º 9
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;
    }
Ejemplo n.º 10
0
     /// <summary>
 /// Returns the appropriate time step for a given time period
 /// </summary>
 /// <param name="Start"></param>
 /// <param name="End"></param>
 /// <returns></returns>
 public static TimeStepUnit GetTimeStep(TimeSpanValue value)
 {
   return GetTimeStep(value.StartTime, value.EndTime);
 }
 public override TimeSpanValue Convert(TimeSpanValue val)
 {
   return new TimeSpanValue(val.StartTime, val.EndTime, val.Value * val.Duration.TotalSeconds * Par2.Value);
 }
Ejemplo n.º 12
0
        public static bool TryParse(string text, DateTimeFormatInfo timeFmt, NumberFormatInfo numFmt, [MaybeNullWhen(false)] out TimeSpanValue value)
        {
            value = null;
            bool result = false;

            // Only use our custom parser if time formats are using ':' separators.
            // If another culture is using some other time format, then the caller
            // should try to let the system parse it.
            const char c_separator = ':';

            if (!string.IsNullOrEmpty(text) && timeFmt.ShortTimePattern.Contains(c_separator))
            {
                string[] tokens    = text.Trim().Split(new char[] { c_separator }, StringSplitOptions.RemoveEmptyEntries);
                int      numTokens = tokens.Length;
                if (numTokens >= 2 && numTokens <= 4)
                {
                    string decimalSeparator = numFmt.NumberDecimalSeparator;
                    string[]? dhmsTokens = GetDHMSTokens(tokens, decimalSeparator);
                    if (dhmsTokens != null)
                    {
                        result = ParseDHMSTokens(dhmsTokens, decimalSeparator, numFmt.NegativeSign, out value);
                    }
                }
            }

            return(result);
        }