public void test_time_ask_past_index() { var date1 = DateTime.Now.AddDays(1).Date.AddSeconds(-1); var date2 = DateTime.Now.AddDays(1); var index = TimeIndex.GetIndex(date1); TimeIndex.GetIndex(date2); var indexToCompare = TimeIndex.GetIndex(date1); indexToCompare.Should().Be(index); }
public void time_index_order_test() { var yearTotalSeconds = TimeSpan.FromDays(366).TotalSeconds; var refDate = DateTime.Now.AddDays(30); var prevValue = 0; for (int i = 0; i < yearTotalSeconds; i++) { var index = TimeIndex.GetIndex(refDate.AddSeconds(i)); index.Should().BeGreaterThan(prevValue); prevValue = index; } }
internal CalculatorResult Calculate(TimeSpan forTime) { var minIdx = TimeIndex.GetIndex(DateTime.Now - forTime); var maxIdx = TimeIndex.GetIndex(DateTime.Now - TimeSpan.FromSeconds(1)); var splitCounters = _counters.Where(kv => kv.Key >= minIdx && kv.Key <= maxIdx).Select(kv => kv.Value).ToList(); if (splitCounters.Any() == false) { return new CalculatorResult { Count = 0, AverageTime = TimeSpan.MinValue } } ; var totalCount = splitCounters.Sum(c => c.Count); var totalTime = splitCounters.Sum(c => c.TotalMilliseconds); return(new CalculatorResult { Count = totalCount, AverageTime = TimeSpan.FromMilliseconds(totalTime / totalCount) }); } }