public static (double Value, TimeUnit Unit) ConvertTicksToTime(long ticks)
        {
            TimeUnit optimalTimeUnit = GetFloorTimeUnit(ticks);
            double   time            = ticks / (double)optimalTimeUnit.GetTimeUnitDuration();

            return(time, optimalTimeUnit);
        }
Example #2
0
        private string GetDisplayedText(long labelTime, TimeUnit minTimeUnit)
        {
            if (labelTime == 0)
            {
                return("0");
            }


            TimeUnit bestTimeUnit, currentTimeUnit = minTimeUnit;
            long     bestTimeUnitDuration, currentDuration = minTimeUnit.GetTimeUnitDuration();

            do
            {
                bestTimeUnitDuration = currentDuration;
                bestTimeUnit         = currentTimeUnit;
                if (currentTimeUnit == TimeUnit.Hour)
                {
                    break;
                }
                currentTimeUnit = (TimeUnit)((byte)currentTimeUnit << 1);
            }while (labelTime % (currentDuration = currentTimeUnit.GetTimeUnitDuration()) == 0);

            if (labelTime % currentDuration == 0)
            {
                return($"{labelTime / bestTimeUnitDuration}{bestTimeUnit.GetTimeUnitAsString()}");
            }

            return($"{labelTime % currentDuration / bestTimeUnitDuration}{bestTimeUnit.GetTimeUnitAsString()}");
        }
Example #3
0
        private void ShowZoomInfo()
        {
            _timer.Stop();
            TimeUnit timeUnit = TimeUnitHelpers.GetFloorTimeUnit(SegmentSize);
            double   segmentSizeInTimeUnits = SegmentSize / (double)timeUnit.GetTimeUnitDuration();

            ZoomInfoLabel.Content    = $"Segment size: {SegmentSize} ({segmentSizeInTimeUnits, 0:0.##}{timeUnit.GetTimeUnitAsString()})";
            ZoomInfoPanel.Visibility = Visibility.Visible;
            _timer.Start();
        }
        private double GetAverageDensity(uint start, ushort hintCount, TimeUnit densityHintType)
        {
            var duration = densityHintType.GetTimeUnitDuration();

            IDirectedEnumerable <C5.KeyValuePair <uint, double> > range;

            switch (densityHintType)
            {
            case TimeUnit.Second:
                range = _seconds.RangeFromTo(start, start + hintCount);
                break;

            case TimeUnit.Minute:
                range = _minutes.RangeFromTo(start, start + hintCount);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(densityHintType));
            }

            return(range.Take(hintCount).Sum(kvp => kvp.Value) / hintCount);
        }
        public static SegmentSize[] GetPreferredSegmentSizes(long startTime, long endTime, ushort segmentsCount)
        {
            if (endTime < startTime)
            {
                throw new ArgumentException(nameof(endTime));
            }

            var      list                = new List <SegmentSize>();
            long     maxSegmentSize      = (long)Math.Ceiling((endTime - startTime) / (double)segmentsCount);
            TimeUnit currentTimeUnit     = TimeUnit.Microsecond;
            long     segmentSize         = currentTimeUnit.GetTimeUnitDuration();
            long     previousSegmentSize = segmentSize;

            list.Add(new SegmentSize(1));
            while (segmentSize < maxSegmentSize)
            {
                previousSegmentSize = segmentSize;
                list.Add(new SegmentSize(segmentSize));
                switch (currentTimeUnit)
                {
                case TimeUnit.Second:
                case TimeUnit.Minute:
                    if (segmentSize % (20 * currentTimeUnit.GetTimeUnitDuration()) == 0)
                    {
                        segmentSize = segmentSize / 20 * 30;
                    }
                    else if (GetFirstDigit(segmentSize) == 4)
                    {
                        segmentSize = segmentSize / 4 * 10;
                    }
                    else
                    {
                        segmentSize *= 2;
                    }
                    break;

                default:
                    if (GetFirstDigit(segmentSize) == 4)
                    {
                        segmentSize = segmentSize / 4 * 10;
                    }
                    else
                    {
                        segmentSize *= 2;
                    }
                    break;
                }


                TimeUnit nextTimeUnit = (TimeUnit)((byte)currentTimeUnit << 1);
                if (currentTimeUnit < TimeUnit.Hour && segmentSize >= nextTimeUnit.GetTimeUnitDuration())
                {
                    currentTimeUnit = nextTimeUnit;
                }
            }

            if (segmentSize > maxSegmentSize)
            {
                list.Add(new SegmentSize(previousSegmentSize, maxSegmentSize));
            }

            return(list.ToArray());
        }