public static TimeSpan ConvertDoubleToTimeSpan(double amountPassed, TimeUnits spanUnitsPassed)
        {
            TimeSpan spanResult = new TimeSpan();

            switch (spanUnitsPassed)
            {
                case TimeUnits.Day:
                    spanResult = GetDaysForTimeSpan(amountPassed);
                    break;
                case TimeUnits.Hour:
                    spanResult = GetHoursForTimeSpan(amountPassed);
                    break;
                case TimeUnits.Minute:
                    spanResult = GetMinutesForTimeSpan(amountPassed);
                    break;
                case TimeUnits.Second:
                    spanResult = GetSecondsForTimeSpan(amountPassed);
                    break;
                case TimeUnits.Millisecond:
                    spanResult = GetMillisecondsForTimeSpan(amountPassed);
                    break;
                case TimeUnits.None:
                    // This Does Nothing
                    break;
                default:
                    // Generate ErrorBase Here
                    break;
            }

            return spanResult;
        }
        public static double ConvertToPixels(DateTime CurrentTime, TimeUnits timeUnit)
        {
            double TickWidth = 2.38E-11;
            double MinuteWidth = ((TickWidth*8.64E11/24d)/60) * ScaleFactor;

            double HourWidth = MinuteWidth * 60;
            double DayWidth = HourWidth * 24;

            switch (timeUnit)
            {
                case TimeUnits.Years:
                    double DaysInYear = 365d;
                    if (DateTime.IsLeapYear(CurrentTime.Year))
                        DaysInYear = 366;
                    double YearWidth = DayWidth * DaysInYear;

                    return YearWidth * Zoom.Value;
                case TimeUnits.Months:
                    double MonthWidth = DayWidth * DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month);

                    return MonthWidth * Zoom.Value;
                case TimeUnits.Weeks:
                    double WeekWidth = DayWidth * 7;
                    return WeekWidth * Zoom.Value;
                case TimeUnits.Days:
                    return DayWidth * Zoom.Value;
                case TimeUnits.Hours:
                    return HourWidth * Zoom.Value;
                case TimeUnits.Minutes:
                    return MinuteWidth * Zoom.Value;
                default:
                    return TickWidth *  Zoom.Value;

            }
        }
            public static double InstantToRelative(DateTime instant, DateTime start, TimeUnits units = TimeUnits.SECONDS)
            {
                TimeSpan tspan;
                double instantAsRelative = 0.0;

                tspan = instant.Subtract(start);

                //Years and Months are not exactly

                switch (units)
                {
                   case TimeUnits.YEARS:
                  instantAsRelative = tspan.TotalDays / 365.0;
                  break;
                   case TimeUnits.MONTHS:
                  instantAsRelative = tspan.TotalDays / 30.0;
                  break;
                   case TimeUnits.DAYS:
                  instantAsRelative = tspan.TotalDays;
                  break;
                   case TimeUnits.HOURS:
                  instantAsRelative = tspan.TotalHours;
                  break;
                   case TimeUnits.MINUTES:
                  instantAsRelative = tspan.TotalMinutes;
                  break;
                   case TimeUnits.SECONDS:
                  instantAsRelative = tspan.TotalSeconds;
                  break;
                }

                return instantAsRelative;
            }
            public static DateTime InstantToDateTime(double instant, DateTime start, TimeUnits units = TimeUnits.SECONDS)
            {
                DateTime instantAsDate = start;

                switch (units)
                {
                   case TimeUnits.YEARS:
                  instantAsDate = start.AddYears((int)instant);
                  break;
                   case TimeUnits.MONTHS:
                  instantAsDate = start.AddMonths((int)instant);
                  break;
                   case TimeUnits.DAYS:
                  instantAsDate = start.AddDays(instant);
                  break;
                   case TimeUnits.HOURS:
                  instantAsDate = start.AddHours(instant);
                  break;
                   case TimeUnits.MINUTES:
                  instantAsDate = start.AddMinutes(instant);
                  break;
                   case TimeUnits.SECONDS:
                  instantAsDate = start.AddSeconds(instant);
                  break;
                }

                return instantAsDate;
            }
Example #5
0
        public static DateTime AddType(this DateTime instance, TimeUnits type, double increment)
        {
            DateTime result = instance;

            switch (type)
            {
                case TimeUnits.Days:
                    result = instance.AddDays(increment);
                    break;
                case TimeUnits.Months:
                    increment *= DateTime.DaysInMonth(instance.Year, instance.Month);
                    result = instance.AddDays((int)(Math.Floor(increment)));
                    break;
                case TimeUnits.Weeks:

                    result = instance.AddDays(increment * 7);
                    break;
                case TimeUnits.Years:
                    if (DateTime.IsLeapYear(instance.Year))
                        increment *= 366;
                    else
                        increment *= 365;

                    result = instance.AddDays((int)(Math.Floor(increment)));
                    break;
                case TimeUnits.Hours:
                    result = instance.AddHours(increment);
                    break;
            }

            return result;
        }
Example #6
0
        public override double ConvertToPixels(DateTime CurrentTime, TimeUnits timeUnit)
        {
            //double TickWidth = 2.38E-11;
            double HourWidth = 1.6;// 0.7;// TickWidth * 8.64E11 / 24d;
            double TickWidth = HourWidth * 24d / 8.64E11;
            double DayWidth = HourWidth * 24;
            switch (timeUnit)
            {
                case TimeUnits.Years:
                    double DaysInYear = 365d;
                    if (DateTime.IsLeapYear(CurrentTime.Year))
                        DaysInYear = 366;
                    double YearWidth = DayWidth * DaysInYear;

                    return YearWidth * Zoom.Value;
                case TimeUnits.Months:
                    double MonthWidth = DayWidth * DateTime.DaysInMonth(CurrentTime.Year, CurrentTime.Month);

                    return MonthWidth * Zoom.Value;
                case TimeUnits.Weeks:
                    double WeekWidth = DayWidth * 7;
                    return WeekWidth * Zoom.Value;
                case TimeUnits.Days:
                    return DayWidth * Zoom.Value;
                case TimeUnits.Hours:
                    return HourWidth * Zoom.Value;
                default:
                    return TickWidth * Zoom.Value;
            }
        }
Example #7
0
		public SoundLoop(uint start, TimeUnits startUnit, uint end, TimeUnits endUnit, int count)
		{
			this.start = start;
			this.startUnit = startUnit;
			this.end = end;
			this.endUnit = endUnit;
			this.count = count;
		}
Example #8
0
        public static double GetWidth(DateTime CurrentTime, DateTime time, TimeUnits timeUnit)
        {
            double result = TimeUnitScalar.ConvertToPixels(time, timeUnit);

            if (timeUnit == TimeUnits.Years)
            {
                if (CurrentTime.Year == time.Year)
                {
                    double DaysInYear = 365d;
                    if (DateTime.IsLeapYear(time.Year))
                        DaysInYear = 366;
                    result *= (double)(DaysInYear - time.DayOfYear + 1) / DaysInYear;
                }
            }
            else if (timeUnit == TimeUnits.Months)
            {
                if (CurrentTime.Month == time.Month)
                    result *= (double)(DateTime.DaysInMonth(time.Year, time.Month) - time.Day + 1) / (double)DateTime.DaysInMonth(time.Year, time.Month);

            }
            else if (timeUnit == TimeUnits.Weeks)
            {
                int daysInWeek = 7;

                int weekCurrent = GetWeekOfYear(CurrentTime);
                int weekTime = GetWeekOfYear(time);

                if (weekTime == 52)
                {
                    daysInWeek = 7;

                    if (DateTime.IsLeapYear(time.Year))
                        daysInWeek++;

                    result *= (double)daysInWeek / 7d;
                }

                if (weekTime == 53)
                {
                    result = 0;

                }
                else if (weekCurrent == weekTime)
                {
                    daysInWeek = 7 - (CurrentTime.DayOfYear - (7 * (weekCurrent-1))) +2 ;

                    result *= (double)daysInWeek  / 7d;
                }
            }

            return result;
        }
		internal static extern Result FMOD_System_GetStreamBufferSize(IntPtr systemHandle, ref uint fileBufferSize, ref TimeUnits fileBufferSizeType);
		internal static extern Result FMOD_Sound_GetLength(IntPtr soundHandle, ref uint length, TimeUnits lengthType);
Example #11
0
        /// <summary>
        /// Warning: bug found. dt.Offset may be incorrect as offsets could be different if range crosses daylight saving switch, i.e. October - December, or month of November in the EST USA.
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public static DateTimeOffset StartOf(this DateTimeOffset dt, TimeUnits unit)
        {
            switch(unit)
            {
                case TimeUnits.Century:
                {
                    int year = dt.Year/100*100;
                    return new DateTimeOffset(year, 1, 1, 0, 0, 0, dt.Offset);
                }
                case TimeUnits.Decade:
                {
                    int year = dt.Year/10*10;
                    return new DateTimeOffset(year, 1, 1, 0, 0, 0, dt.Offset);
                }
                case TimeUnits.Year:
                {
                    return new DateTimeOffset(dt.Year, 1, 1, 0, 0, 0, dt.Offset);
                }
                case TimeUnits.Quarter:
                {
                    int month = (dt.Quarter() - 1)*3 + 1;
                    return new DateTimeOffset(dt.Year, month, 1, 0, 0, 0, dt.Offset);
                }
                case TimeUnits.Week:
                {
                    DayOfWeek weekStart = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
                    int delta = weekStart - dt.DayOfWeek;
                    return dt.AddDays(delta).StartOf(TimeUnits.Day);
                }
                case TimeUnits.Month:
                {
                    return new DateTimeOffset(dt.Year, dt.Month, 1, 0, 0, 0, dt.Offset);
                }
                case TimeUnits.Day:
                {
                    return new DateTimeOffset(dt.Year, dt.Month, dt.Day, 0, 0, 0, dt.Offset);
                }
                case TimeUnits.Hour:
                {
                    return new DateTimeOffset(dt.Year, dt.Month, dt.Day, dt.Hour, 0, 0, dt.Offset);
                }
                case TimeUnits.Minute:
                {
                    return new DateTimeOffset(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0, dt.Offset);
                }
                case TimeUnits.Second:
                {
                    return new DateTimeOffset(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second, dt.Offset);
                }
            }

            throw new Exception("Calculation of start of unit \"{0}\" is not implemented.".SmartFormat(unit));
        }
Example #12
0
 /// <summary>
 /// Warning: bug found. dt.Offset may be incorrect as offsets could be different if range crosses daylight saving switch, i.e. October - December, or month of November in the EST USA.
 /// </summary>
 /// <param name="dt"></param>
 /// <param name="unit"></param>
 /// <returns></returns>
 public static TimeMomentRange RangeToDate(this DateTimeOffset? dt, TimeUnits unit)
 {
     return unit.ToDate(dt);
 }
Example #13
0
 /// <summary>
 /// Warning: bug found. dt.Offset may be incorrect as offsets could be different if range crosses daylight saving switch, i.e. October - December, or month of November in the EST USA.
 /// </summary>
 /// <param name="dt"></param>
 /// <param name="unitCount"></param>
 /// <param name="unit"></param>
 /// <returns></returns>
 public static TimeMomentRange RangePrevious(this DateTimeOffset? dt, ulong unitCount, TimeUnits unit)
 {
     return unit.Previous(unitCount, dt);
 }
Example #14
0
 /// <summary>
 /// A timer is basically a histogram of the duration of a type of event and a meter of the rate of its occurrence.
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all timers in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="samplingType">Type of the sampling to use (see SamplingType for details ).</param>
 /// <param name="rateUnit">Time unit for rates reporting. Defaults to Second ( occurrences / second ).</param>
 /// <param name="durationUnit">Time unit for reporting durations. Defaults to Milliseconds. </param>
 /// <param name="tag">Optional tag that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 public ITimer Timer(string name, Units unit, SamplingTypes samplingType = SamplingTypes.FavorRecent, TimeUnits rateUnit = TimeUnits.Seconds, TimeUnits durationUnit = TimeUnits.Milliseconds, string tag = null)
 {
     return new Timer(_context.Timer(name, unit.ToString(), (SamplingType)samplingType, (TimeUnit)rateUnit, (TimeUnit)durationUnit, tag));
 }
Example #15
0
 internal static extern Result FMOD_Channel_GetPosition(IntPtr channelHandle, ref uint position, TimeUnits positionType);
Example #16
0
 public ITimer Timer(string name, Units unit, SamplingTypes samplingType = SamplingTypes.FavorRecent, TimeUnits rateUnit = TimeUnits.Seconds, TimeUnits durationUnit = TimeUnits.Milliseconds, string tag = null)
 {
     return(_timer);
 }
Example #17
0
 public IMeter Meter(string name, string unitName, TimeUnits rateUnit, string tag = null)
 {
     return(_meter);
 }
Example #18
0
 public IMeter Meter(string name, Units unit, TimeUnits rateUnit = TimeUnits.Seconds, string tag = null)
 {
     return(_meter);
 }
Example #19
0
 public ITimer Timer(string name, Units unit, SamplingTypes samplingType, TimeUnits rateUnit, TimeUnits durationUnit, string tag = null)
 {
     return(_timer);
 }
Example #20
0
        public static async Task <bool> HasMonthly(List <int> targets, int energy, int paramter, TimeUnits unit, DateTime start, DateTime finish)
        {
            var node = new StatisticalNode(targets, energy, new List <int> {
                paramter
            }, unit, start, finish, StatisticalModes.Building, StatisticalWay.Total, null, null);

            var dicBLL    = new DictionaryBLL();
            var meterBLL  = new MeterBLL();
            var parameter = dicBLL.Get(node.ParameterTypeId).Select(d => d.Id).ToList();

            // 获取关联的一级统计设备
            IEnumerable <int> meters = (await meterBLL.GetStatisticalObj(node)).SelectMany(x => x.Meters).Select(x => x.Id);

            // 统计能耗结果
            return(meterBLL.Count(x => meters.Contains(x.Id) && x.MeterMonthlyResults.Any(m => m.StartTime >= start)) > 0);
        }
Example #21
0
        //public static IEnumerable<GisBuildingData> ToGisList(IQueryable<Building> nodes)
        //{
        //    var start_month = DateTime.Parse(DateTime.Today.ToString("yyyy-MM-01"));
        //    var start_year = DateTime.Parse(DateTime.Today.ToString("yyyy-01-01"));
        //    var ids = nodes.Select(x => x.Id).ToList();
        //    var cids = nodes.SelectMany(x => x.Children).Select(x => x.Id).ToList();
        //    var arr = ids.Concat(cids).Distinct().ToList();
        //    var list = nodes.ToList().Select(node => new GisBuildingData()
        //    {
        //        Id = node.Id,
        //        Name = node.Name,
        //        BuildingCategoryName = node.BuildingCategoryDict.ChineseName,
        //        //Year = node.BuildingInfo.Year,
        //        //UpFloor = node.BuildingInfo.UpFloor,
        //        ManagerCount = node.ManagerCount,
        //        CustomerCount = node.CustomerCount,
        //        TotalArea = node.TotalArea,
        //        LivingArea = node.LivingArea,
        //        WorkingArea = node.WorkingArea,
        //        ReceptionArea = node.ReceptionArea,
        //        Year = node.Year,
        //        UpFloor = node.UpFloor,
        //        //Electric = GetTotal(new List<int>() { node.Id }, 90001, 60019, TimeUnits.Monthly, start_month, DateTime.Today).SelectMany(x => x.Result).Sum(x => x.Value),
        //        //Water = GetTotal(new List<int>() { node.Id }, 90031, 60023, TimeUnits.Monthly, start_month, DateTime.Today).SelectMany(x => x.Result).Sum(x => x.Value),
        //        //ElectricYear = GetTotal(new List<int>() { node.Id }, 90001, 60019, TimeUnits.Yearly, start_year, DateTime.Today).SelectMany(x => x.Result).Sum(x => x.Value),
        //        //WaterYear = GetTotal(new List<int>() { node.Id }, 90031, 60023, TimeUnits.Yearly, start_year, DateTime.Today).SelectMany(x => x.Result).Sum(x => x.Value),
        //        Icon = "",
        //        Children = node.Children.Select(c => new GisBuildingData()
        //        {
        //            Id = c.Id,
        //            Name = c.Name,
        //            BuildingCategoryName = node.BuildingCategoryDict.ChineseName,
        //            ManagerCount = node.ManagerCount,
        //            CustomerCount = node.CustomerCount,
        //            TotalArea = node.TotalArea,
        //            LivingArea = node.LivingArea,
        //            WorkingArea = node.WorkingArea,
        //            ReceptionArea = node.ReceptionArea,
        //            Year = node.Year,
        //            UpFloor = node.UpFloor,
        //            //Electric = GetTotal(new List<int>() { node.Id }, 90001, 60019, TimeUnits.Monthly, start_month, DateTime.Today).SelectMany(x => x.Result).Sum(x => x.Value),
        //            //Water = GetTotal(new List<int>() { node.Id }, 90031, 60023, TimeUnits.Monthly, start_month, DateTime.Today).SelectMany(x => x.Result).Sum(x => x.Value),
        //            //ElectricYear = GetTotal(new List<int>() { node.Id }, 90001, 60019, TimeUnits.Yearly, start_year, DateTime.Today).SelectMany(x => x.Result).Sum(x => x.Value),
        //            //WaterYear = GetTotal(new List<int>() { node.Id }, 90031, 60023, TimeUnits.Yearly, start_year, DateTime.Today).SelectMany(x => x.Result).Sum(x => x.Value),
        //            Icon = ""
        //        }).ToList(),
        //        Meters = node.Meters.Select(m => m.ToGisData(1)).ToList()
        //    });
        //    var water_month = GetTotal(arr, 90031, 60023, TimeUnits.Monthly, start_month, DateTime.Now);
        //    var elec_month = GetTotal(arr, 90031, 60023, TimeUnits.Monthly, start_month, DateTime.Now);
        //    var water_year = GetTotal(arr, 90031, 60023, TimeUnits.Yearly, start_year, DateTime.Now);
        //    var elec_year = GetTotal(arr, 90031, 60023, TimeUnits.Yearly, start_year, DateTime.Now);
        //    foreach (var item in list)
        //    {
        //        var elec_m = elec_month.FirstOrDefault(x => x.StatisticalId == item.Id);
        //        if (elec_m != null) item.Electric = elec_m.Result.Sum(x => x.Value);
        //        var water_m = water_month.FirstOrDefault(x => x.StatisticalId == item.Id);
        //        if (water_m != null) item.Water = water_m.Result.Sum(x => x.Value);
        //        var elec_y = elec_year.FirstOrDefault(x => x.StatisticalId == item.Id);
        //        if (elec_y != null) item.ElectricYear = elec_y.Result.Sum(x => x.Value);
        //        var water_y = water_year.FirstOrDefault(x => x.StatisticalId == item.Id);
        //        if (water_y != null) item.WaterYear = water_y.Result.Sum(x => x.Value);
        //    }
        //    return list;
        //}

        public static async Task <IEnumerable <StatisticalData> > GetTotal(List <int> targets, int energy, int paramter, TimeUnits unit, DateTime start, DateTime finish)
        {
            var node = new StatisticalNode(targets, energy, new List <int> {
                paramter
            }, unit, start, finish, StatisticalModes.Building, StatisticalWay.Total, null, null);

            var dicBLL   = new DictionaryBLL();
            var meterBLL = new MeterBLL();
            var statBLL  = new MeterResultBLL();
            // 获取参数对象
            var parameter = dicBLL.Get(node.ParameterTypeId).Select(d => d.Id).ToList();

            // 获取关联的一级统计设备
            IList <StatisticalTransfer> meters = await meterBLL.GetStatisticalObj(node);

            // 统计能耗结果
            var result = await statBLL.Statistics(meters, node.TimeUnit.Value, node.StartTime.Value, node.FinishTime.Value, parameter, node.StatWay.Value);

            return(result);
        }
Example #22
0
 internal static extern Result FMOD_System_GetStreamBufferSize(IntPtr systemHandle, ref uint fileBufferSize, ref TimeUnits fileBufferSizeType);
Example #23
0
 /* CLOCK METHODS */
 /// <summary>
 /// Reads the clock and returns the current elapsed time in the desired units (seconds by default).
 /// </summary>
 /// <param name="units">The desired units of time measurement that the elapsed time should be returned in.</param>
 /// <returns>A double-precision value representing the total amount of time that has passed since the clock started.</returns>
 public static double Read(TimeUnits units = TimeUnits.Seconds)
 {
     switch (units)
     {
         case TimeUnits.Days:
             return Watch.Elapsed.TotalDays;
         case TimeUnits.Hours:
             return Watch.Elapsed.TotalHours;
         case TimeUnits.Microseconds:
             return Watch.Elapsed.TotalMilliseconds * 1000d;
         case TimeUnits.Milliseconds:
             return Watch.Elapsed.TotalMilliseconds;
         case TimeUnits.Minutes:
             return Watch.Elapsed.TotalMinutes;
         case TimeUnits.Seconds:
             return Watch.Elapsed.TotalSeconds;
         case TimeUnits.Weeks:
             return Watch.Elapsed.TotalDays / 7d;
         case TimeUnits.Years:
             return Watch.Elapsed.TotalDays / 365d;
         default:
             throw new ArgumentException("Cannot read the clock in units of {0}", units.ToString());
     }
 }
Example #24
0
            public void Load(FileName file)
            {
                string line;
                string[] seps = new string[1];
                string[] tokens;
                string[] header;

                TextFile ts = new TextFile(file);
                ts.OpenToRead();

                try
                {
                   dataColumns.Clear();
                   extraLines.Clear();
                   instants.Clear();

                   //Find Header and columns
                   while ((line = ts.ReadLine()) != null)
                   {
                  line = line.Trim();

                  if (line == "") continue;
                  if (line[0] == '!')
                  {
                     extraLines.Add(line);
                     continue;
                  }

                  seps[0] = ":";
                  tokens = line.Split(seps, 2, StringSplitOptions.RemoveEmptyEntries);

                  if (tokens[0].Trim() == "SERIE_INITIAL_DATA")
                  {
                     string[] tseps = { ".", " " };
                     string[] ttokens = tokens[1].Trim().Split(tseps, StringSplitOptions.RemoveEmptyEntries);
                     startInstant = new DateTime((int)float.Parse(ttokens[0]),
                                                 (int)float.Parse(ttokens[1]),
                                                 (int)float.Parse(ttokens[2]),
                                                 (int)float.Parse(ttokens[3]),
                                                 (int)float.Parse(ttokens[4]),
                                                 (int)float.Parse(ttokens[5])); //DateTime.ParseExact(temp, "yyyy M d H m s", null);
                  }
                  else if (tokens[0].Trim() == "TIME_UNITS")
                  {
                     timeUnits = (TimeUnits)Enum.Parse(typeof(TimeUnits), tokens[1].Trim(), true);
                  }
                  else
                  {
                     seps[0] = " ";
                     tokens = line.Trim().Split(seps, StringSplitOptions.RemoveEmptyEntries);

                     if (tokens[0].Trim() == "<BeginTimeSerie>")
                     {
                        if (extraLines.Count < 1)
                        {
                           ts.Close();
                           throw new Exception("The '" + file.FullName + "' is not a valid time series");
                        }

                        header = extraLines.Last().Trim().Split(seps, StringSplitOptions.RemoveEmptyEntries);
                        instants.Header = header[0];

                        for (int i = 1; i < header.Length; i++)
                        {
                           Column column = new Column();
                           dataColumns.Add(column);
                           column.Header = header[i];
                        }

                        extraLines.Remove(extraLines.Last());
                        break;
                     }
                     else if (tokens[0].Trim() == "<BeginResidual>")
                     {
                        while ((line = ts.ReadLine()) != null)
                        {
                           if (line.Trim() == "<EndResidual>")
                              break;
                        }

                        if (line == null)
                           throw new Exception("Invalid TimeSeries file.");
                     }
                     else
                     {
                        extraLines.Add(line);
                     }
                  }
                   }

                   int index;
                   seps[0] = " ";

                   line = ts.ReadLine();
                   if (line == null)
                  throw new Exception ("Invalid TimeSeries file.");

                   tokens = line.Trim().Split(seps, StringSplitOptions.RemoveEmptyEntries);
                   if (tokens == null)
                  throw new Exception("Invalid TimeSeries file.");

                   index = AddInstant(double.Parse(tokens[0], CultureInfo.InvariantCulture));

                   for (int i = 1; i < tokens.Length; i++)
                   {
                  dataColumns[i - 1].ColumnType = GetColumnType(tokens[i]);

                  if (dataColumns[i - 1].ColumnType == typeof(double))
                     dataColumns[i - 1][index] = double.Parse(tokens[i], CultureInfo.InvariantCulture);
                  else
                     dataColumns[i - 1][index] = tokens[i];
                   }

                   while ((line = ts.ReadLine()) != null)
                   {
                  //line = ts.ReadLine();
                  if (line == null)
                     throw new Exception("Invalid TimeSeries file.");

                  tokens = line.Trim().Split(seps, StringSplitOptions.RemoveEmptyEntries);

                  if (tokens == null)
                     throw new Exception("Invalid TimeSeries file.");

                  if (tokens[0][0] == '<')
                     break;
                  else
                  {
                     index = AddInstant(double.Parse(tokens[0], CultureInfo.InvariantCulture));

                     for (int i = 1; i < tokens.Length; i++)
                        if (dataColumns[i - 1].ColumnType == typeof(double))
                           dataColumns[i - 1][index] = double.Parse(tokens[i], CultureInfo.InvariantCulture);
                        else
                           dataColumns[i - 1][index] = tokens[i];
                  }
                   }

                   while ((line = ts.ReadLine()) != null)
                  extraLines.Add(line);

                   ts.Close();
                }
                catch
                {
                   ts.Close();
                   throw;
                }
            }
Example #25
0
 public void Record(long time, TimeUnits unit, string userValue = null)
 {
 }
Example #26
0
 /// <summary>
 /// A meter measures the rate at which a set of events occur, in a few different ways. 
 /// This metric is suitable for keeping a record of now often something happens ( error, request etc ).
 /// </summary>
 /// <remarks>
 /// The mean rate is the average rate of events. It’s generally useful for trivia, 
 /// but as it represents the total rate for your application’s entire lifetime (e.g., the total number of requests handled, 
 /// divided by the number of seconds the process has been running), it does not offer a sense of recency. 
 /// Luckily, meters also record three different exponentially-weighted moving average rates: the 1-, 5-, and 15-minute moving averages.
 /// </remarks>
 /// <param name="name">Name of the metric. Must be unique across all meters in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="rateUnit">Time unit for rates reporting. Defaults to Second ( occurrences / second ).</param>
 /// <param name="tag">Optional tag that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 public IMeter Meter(string name, Units unit, TimeUnits rateUnit = TimeUnits.Seconds, string tag = null)
 {
     return new Meter(_context.Meter(name, unit.ToString(), (TimeUnit)rateUnit, tag));
 }
Example #27
0
 public ITimer Timer(string name, Units unit, SamplingTypes samplingType, TimeUnits rateUnit, TimeUnits durationUnit, List <KeyValuePair <string, string> > tags = null)
 {
     return(_timer);
 }
Example #28
0
 internal static extern Result FMOD_Sound_GetLoopPoints(IntPtr soundHandle, ref uint loopStart, TimeUnits loopStartType, ref uint loopEnd, TimeUnits loopEndType);
Example #29
0
 public IMeter Meter(string name, Units unit, TimeUnits rateUnit = TimeUnits.Seconds, List <KeyValuePair <string, string> > tags = null)
 {
     return(_meter);
 }
Example #30
0
 public static DateRange RangePrevious(this DateTime? dt, ulong unitCount, TimeUnits unit)
 {
     return unit.Previous(unitCount, dt);
 }
Example #31
0
 public IMeter Meter(string name, string unitName, TimeUnits rateUnit, List <KeyValuePair <string, string> > tags = null)
 {
     return(_meter);
 }
Example #32
0
 public static DateRange RangeToDate(this DateTime? dt, TimeUnits unit)
 {
     return unit.ToDate(dt);
 }
Example #33
0
 public ITimer Timer(string name, Units unit, SamplingTypes samplingType = SamplingTypes.FavorRecent, TimeUnits rateUnit = TimeUnits.Seconds, TimeUnits durationUnit = TimeUnits.Milliseconds, List <KeyValuePair <string, string> > tags = null)
 {
     return(_timer);
 }
		internal static extern Result FMOD_Channel_GetLoopPoints(IntPtr channelHandle, ref uint loopStart, TimeUnits loopStartType, ref uint loopEnd, TimeUnits loopEndType);
Example #35
0
 /// <inheritdoc />
 public IMeter Meter(string name, Units unit, TimeUnits rateUnit = TimeUnits.Seconds, string tag = null)
 {
     return(new Meter(_context.Meter(name, unit.ToString(), (TimeUnit)rateUnit, tag)));
 }
		internal static extern Result FMOD_Sound_GetLoopPoints(IntPtr soundHandle, ref uint loopStart, TimeUnits loopStartType, ref uint loopEnd, TimeUnits loopEndType);
Example #37
0
 /// <inheritdoc />
 public IMeter Meter(string name, string unitName, TimeUnits rateUnit, string tag = null)
 {
     return(new Meter(_context.Meter(name, unitName, (TimeUnit)rateUnit, tag)));
 }
		internal static extern Result FMOD_Channel_GetPosition(IntPtr channelHandle, ref uint position, TimeUnits positionType);
Example #39
0
 /// <inheritdoc />
 public ITimer Timer(string name, Units unit, SamplingTypes samplingType = SamplingTypes.FavorRecent, TimeUnits rateUnit = TimeUnits.Seconds, TimeUnits durationUnit = TimeUnits.Milliseconds, string tag = null)
 {
     return(new Timer(_context.Timer(name, unit.ToString(), (SamplingType)samplingType, (TimeUnit)rateUnit, (TimeUnit)durationUnit, tag)));
 }
Example #40
0
 /// <summary>
 /// A timer is basically a histogram of the duration of a type of event and a meter of the rate of its occurrence.
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all timers in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="samplingType">Type of the sampling to use (see SamplingType for details ).</param>
 /// <param name="rateUnit">Time unit for rates reporting. Defaults to Second ( occurrences / second ).</param>
 /// <param name="durationUnit">Time unit for reporting durations. Defaults to Milliseconds.</param>
 /// <param name="tag">Optional tag that can be associated with the metric.</param>
 /// <returns>
 /// Reference to the metric
 /// </returns>
 public ITimer Timer(string name, Units unit, SamplingTypes samplingType, TimeUnits rateUnit, TimeUnits durationUnit, string tag = null)
 {
     return new Timer(_context.Timer(name, unit.ToString(), (SamplingType)samplingType, (TimeUnit)rateUnit, (TimeUnit)durationUnit, tag));
 }
Example #41
0
 public void SetUpDryingTime(TimeUnits timer)
 {
     this.timer = new CountdownTimer();
     this.timer.SetCountdown(timer);
 }
Example #42
0
 internal static extern Result FMOD_Channel_GetLoopPoints(IntPtr channelHandle, ref uint loopStart, TimeUnits loopStartType, ref uint loopEnd, TimeUnits loopEndType);
Example #43
0
        protected void JoinTimeseriesByFolder(FileName output, string filter, List<FilePath> folders_to_search, bool search_sub_folders = true, bool overwrite = true, TimeUnits tu = TimeUnits.SECONDS)
        {
            try
             {
            if (folders_to_search == null || folders_to_search.Count <= 0)
               throw new Exception("No folders to search timeseries were defined.");

            if (string.IsNullOrWhiteSpace(output.FullPath))
               throw new Exception("No timeseries output was defined");

            if (!System.IO.Directory.Exists(output.Path))
               throw new Exception("The path '" + output.Path + "' doesn't exist.");

            if (System.IO.File.Exists(output.FullPath) && !overwrite)
               throw new Exception("The file '" + output.FullName + "' exists and overwrite is set to false.");

            if (string.IsNullOrWhiteSpace(filter))
               throw new Exception("Filter was not set.");

            int found = 0;
            List<FileName> files = new List<FileName>();
            List<TimeSeries> timeSeries = new List<TimeSeries>();
            System.IO.SearchOption so;

            if (search_sub_folders)
               so = System.IO.SearchOption.AllDirectories;
            else
               so = System.IO.SearchOption.TopDirectoryOnly;

            foreach (FilePath path in folders_to_search)
            {
               found = FindFiles(path, files, filter, so);

               foreach (FileName fi in files)
               {
                  TimeSeries newTS = new TimeSeries();
                  newTS.Load(fi);
                  timeSeries.Add(newTS);
               }
            }

            if (timeSeries.Count <= 0)
               return;

            //Finds the Start Date for the output timeseries in the list of loaded timeseries
            DateTime start = timeSeries[0].StartInstant;
            for (int i = 1; i < timeSeries.Count; i++)
            {
               if (timeSeries[i].StartInstant < start)
                  start = timeSeries[i].StartInstant;
            }

            TimeSeries outTS = new TimeSeries();
            outTS.StartInstant = start;
            outTS.TimeUnits = tu;

            foreach (Column col in timeSeries[0].Columns)
            {
               Column newCol = new Column(col.ColumnType);
               newCol.Header = col.Header;
               outTS.AddColumn(newCol);
            }

            foreach (TimeSeries toJoin in timeSeries)
               outTS.AddTimeSeries(toJoin);

            outTS.Save(output);
             }
             catch (Exception ex)
             {
            exception_raised = true;
            exception = new Exception("ScriptV8.JoinTimeseriesByFolder", ex);
            throw exception;
             }
        }
Example #44
0
 /// <inheritdoc />
 public ITimer Timer(string name, Units unit, SamplingTypes samplingType, TimeUnits rateUnit, TimeUnits durationUnit, List <KeyValuePair <string, string> > tags = null)
 {
     return(MetricsStatic.Timer(_context, name, unit, samplingType, rateUnit, durationUnit, tags));
 }
Example #45
0
 /// <inheritdoc />
 public IMeter Meter(string name, string unitName, TimeUnits rateUnit, List <KeyValuePair <string, string> > tags = null)
 {
     return(MetricsStatic.Meter(_context, name, unitName, rateUnit, tags));
 }
Example #46
0
 /// <summary>
 /// A meter measures the rate at which a set of events occur, in a few different ways.
 /// This metric is suitable for keeping a record of now often something happens ( error, request etc ).
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all meters in this context.</param>
 /// <param name="unitName">A Parent name; child counters can be added to this by specifying the this name</param>
 /// <param name="rateUnit">Time unit for rates reporting. Defaults to Second ( occurrences / second ).</param>
 /// <param name="tag">Optional tag that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 /// <remarks>
 /// The mean rate is the average rate of events. It’s generally useful for trivia,
 /// but as it represents the total rate for your application’s entire lifetime (e.g., the total number of requests handled,
 /// divided by the number of seconds the process has been running), it does not offer a sense of recency.
 /// Luckily, meters also record three different exponentially-weighted moving average rates: the 1-, 5-, and 15-minute moving averages.
 /// </remarks>
 public IMeter Meter(string name, string unitName, TimeUnits rateUnit, string tag = null)
 {
     return new Meter(_context.Meter(name, unitName, (TimeUnit)rateUnit, tag));
 }
Example #47
0
 public static DateRange RangePast(this DateTime dt, ulong unitCount, TimeUnits unit)
 {
     return unit.Past(unitCount, dt);
 }
Example #48
0
 public static double ConvertToPixels(DateTime CurrentTime, TimeUnits timeUnit)
 {
     return converter.ConvertToPixels(CurrentTime,timeUnit);
 }
Example #49
0
 internal static extern Result FMOD_Sound_GetLength(IntPtr soundHandle, ref uint length, TimeUnits lengthType);
        public static bool IsEquivolent(DateTime A, DateTime B, TimeUnits Scale)
        {
            TimeSpan diff = (A - B);

            switch (Scale)
            {
                case TimeUnits.Weeks:
                    return Math.Abs(diff.TotalDays) < 7;

                case TimeUnits.Months:
                    return Math.Abs(diff.TotalDays) < 30;

                case TimeUnits.Hours:
                    return Math.Abs(diff.TotalHours) < 1;

                case TimeUnits.Minutes:
                    return Math.Abs(diff.TotalMinutes) < 1;

                default:
                case TimeUnits.Days:
                    diff = A.Date - B.Date;
                    return Math.Abs(Math.Round(diff.TotalDays)) < 1;
            }
        }
 public DerivedTimeSeries(double[] values, DateTime[] time, TimeUnits inputSeriesTimeUnit)
     : base
         (values, time)
 {
     mInputSeriesTimeUnit = inputSeriesTimeUnit;
 }
Example #52
0
 internal double GetWidth(DateTime time, TimeUnits timeUnit)
 {
     return TimeUnitScalar.GetWidth(CurrentTime, time, timeUnit);
 }
        public NumericalSeriesPair[] Derive(NumericalDataType datatype, TimeUnits outseriesTimeUnit)
        {
            INumericalSeriesPair[] sourcePairs     = SeriesPairs;
            NumericalSeriesPair[]  derivedParis    = null;
            DateTime[]             mDateTimeVector = DateTimes;
            double[] mDataValueVector = Value;

            if (datatype == NumericalDataType.Average || datatype == NumericalDataType.Cumulative)
            {
                if (outseriesTimeUnit == TimeUnits.Week)
                {
                    int      startIndex = 0;
                    DateTime start      = mDateTimeVector[0];
                    foreach (DateTime t in mDateTimeVector)
                    {
                        if (t.DayOfWeek == DayOfWeek.Monday)
                        {
                            start = t;
                            break;
                        }
                        startIndex++;
                    }
                    int weekCount = (mDateTimeVector.Length - startIndex + 1) / 7;
                    if (weekCount > 0)
                    {
                        derivedParis = new NumericalSeriesPair[weekCount];
                        for (int w = 0; w < weekCount; w++)
                        {
                            double weekSum = 0;
                            double max     = startIndex + (w + 1) * 7 > mDateTimeVector.Length ? mDateTimeVector.Length : startIndex + (w + 1) * 7;
                            for (int j = startIndex + w * 7; j < max; j++)
                            {
                                weekSum += mDataValueVector[j];
                            }
                            if (datatype == NumericalDataType.Average)
                            {
                                derivedParis[w] = new NumericalSeriesPair(start.AddDays(w * 7), Math.Round(weekSum / 7, 4));
                            }
                            else if (datatype == NumericalDataType.Cumulative)
                            {
                                derivedParis[w] = new NumericalSeriesPair(start.AddDays(w * 7), weekSum);
                            }
                        }
                    }
                }

                else if (outseriesTimeUnit == TimeUnits.Month)
                {
                    if (datatype == NumericalDataType.Average)
                    {
                        var derivedValues = sourcePairs.GroupBy(t => new { t.DateTime.Year, t.DateTime.Month }).Select(group =>
                                                                                                                       new NumericalSeriesPair(new DateTime(group.Key.Year, group.Key.Month, 1), Math.Round(group.Sum(s => s.Value) / group.Count(), 4)));
                        derivedParis = derivedValues.ToArray();
                    }
                    else if (datatype == NumericalDataType.Cumulative)
                    {
                        var derivedValues = sourcePairs.GroupBy(t => new { t.DateTime.Year, t.DateTime.Month }).Select(group =>
                                                                                                                       new NumericalSeriesPair(new DateTime(group.Key.Year, group.Key.Month, 1), group.Sum(s => s.Value)));
                        derivedParis = derivedValues.ToArray();
                    }
                }
                else if (outseriesTimeUnit == TimeUnits.CommanYear)
                {
                    if (datatype == NumericalDataType.Average)
                    {
                        var derivedValues = sourcePairs.GroupBy(t => new { t.DateTime.Year }).Select(group =>
                                                                                                     new NumericalSeriesPair(new DateTime(group.Key.Year, 1, 1), Math.Round(group.Sum(s => s.Value) / group.Count(), 4)));
                        derivedParis = derivedValues.ToArray();
                    }
                    else if (datatype == NumericalDataType.Cumulative)
                    {
                        var derivedValues = sourcePairs.GroupBy(t => new { t.DateTime.Year }).Select(group =>
                                                                                                     new NumericalSeriesPair(new DateTime(group.Key.Year, 1, 1), group.Sum(s => s.Value)));
                        derivedParis = derivedValues.ToArray();
                    }
                }
                else if (outseriesTimeUnit == TimeUnits.FiveDays)
                {
                    derivedParis = Derive(datatype, 5);
                }
                else if (outseriesTimeUnit == TimeUnits.Day)
                {
                    derivedParis = (NumericalSeriesPair[])sourcePairs;
                }
            }

            return(derivedParis);
        }
Example #54
0
 /// <summary>
 /// Warning: bug found. dt.Offset may be incorrect as offsets could be different if range crosses daylight saving switch, i.e. October - December, or month of November in the EST USA.
 /// </summary>
 /// <param name="dt"></param>
 /// <param name="unitCount"></param>
 /// <param name="unit"></param>
 /// <returns></returns>
 public static TimeMomentRange RangePast(this DateTimeOffset dt, ulong unitCount, TimeUnits unit)
 {
     return unit.Past(unitCount, dt);
 }
 public int GetValues(int[] times, short[] bufferA, short[] bufferB, short[] bufferC, short[] bufferD, out short overflows, TimeUnits timeUnits, int numValues)
 {
     CheckOpened();
     return(ps3000_get_times_and_values(_handle, times, bufferA, bufferB, bufferC, bufferD, out overflows, timeUnits, numValues));
 }