internal async Task CleanupAsync(IStatisticalDataAggregator aggregator, TimeResolution resolution, DateTime startTime, CancellationToken cancel) { var retentionPeriods = aggregator.RetentionPeriods; if (resolution == TimeResolution.Minute) { var recordsRetentionTime = startTime.AddMinutes(-retentionPeriods.Momentary); //_logger.LogTrace($"Cleaning up records for {aggregator.DataType}, resolution {resolution}, starttime {startTime}, retention time {recordsRetentionTime}"); await _statDataProvider.CleanupRecordsAsync(aggregator.DataType, recordsRetentionTime, cancel) .ConfigureAwait(false); } DateTime retentionTime; switch (resolution) { case TimeResolution.Minute: retentionTime = startTime.AddHours(-retentionPeriods.Minutely); break; case TimeResolution.Hour: retentionTime = startTime.AddDays(-retentionPeriods.Hourly); break; case TimeResolution.Day: retentionTime = startTime.AddMonths(-retentionPeriods.Daily); break; case TimeResolution.Month: retentionTime = startTime.AddYears(-retentionPeriods.Monthly); break; default: throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null); } //_logger.LogTrace($"Cleaning up aggregations for {aggregator.DataType}, resolution {resolution}, starttime {startTime}"); await _statDataProvider.CleanupAggregationsAsync(aggregator.DataType, resolution, retentionTime, cancel) .ConfigureAwait(false); }
public static string DateTimeToDatePath(DateTime time, TimeResolution timeResolution, int numYears = 1) { switch (timeResolution) { case TimeResolution.None: { return(""); } case TimeResolution.Year: { int year = time.Year - (time.Year % numYears); return($"{year}"); } case TimeResolution.Month: { return(time.ToString("yyyy/MM")); } case TimeResolution.Day: { return(time.ToString("yyyy/MM/dd")); } default: throw new Exception("Time resolution wasn't found"); } }
public TimeRange RemoveLiveRange() { var livestart = TimeResolution.LiveStartsAt(); var ticks = Math.Min(UtcTo.Ticks, livestart.Ticks); return(new TimeRange(UtcFrom, new DateTime(ticks, DateTimeKind.Utc), TimeResolution)); }
private async Task <bool> TryProcessAggregationsAsync(IStatisticalDataAggregator aggregator, DateTime startTime, DateTime endTimeExclusive, TimeResolution targetResolution, CancellationToken cancel) { var resolution = targetResolution - 1; if (resolution < 0) { return(false); } var aggregations = (await _statDataProvider.LoadAggregatedUsageAsync(aggregator.DataType, resolution, startTime, endTimeExclusive, cancel)) .ToArray(); if (aggregations.Length == 0) { return(false); } //_logger.LogTrace($"Summarizing aggregations for {aggregator.DataType}, resolution: {targetResolution}, count: {aggregations.Length}"); aggregator.Summarize(aggregations); return(true); }
public DatabaseUsageViewModel(IEnumerable <Aggregation> timeLine, DateTime startTime, DateTime endTime, TimeWindow timeWindow, TimeResolution resolution) : base(timeLine, startTime, endTime, timeWindow, resolution) { var count = GetCount(); _dbUsages = new DatabaseUsage[count]; }
public ApiUsageViewModel(IEnumerable <Aggregation> timeLine, DateTime startTime, DateTime endTime, TimeWindow timeWindow, TimeResolution resolution) { _timeLine = timeLine.ToArray(); _startTime = startTime; _endTime = endTime; _timeWindow = timeWindow; _resolution = resolution; }
protected StatisticsViewModelBase(IEnumerable <Aggregation> timeLine, DateTime startTime, DateTime endTime, TimeWindow timeWindow, TimeResolution resolution) { TimeLine = timeLine.ToArray(); StartTime = startTime; EndTime = endTime; TimeWindow = timeWindow; Resolution = resolution; }
public static TimeRange LiveRange(TimeResolution resolution) { //we extend beyond 'now' incase the client clock is not accurate. var units = resolution.LiveTolerance(); var fromNow = DateTime.UtcNow.AddUnits(resolution, -units); var toNow = DateTime.UtcNow.AddUnits(resolution, units); return(new TimeRange(fromNow, toNow, resolution)); }
public void StopSensing() { if (!IsSensing() || sensorValues != null) { throw new NxtControlException(Name, "Could not stop sensing: no event-driven sensing task started or incompatible list of sensor values storing task in progress"); } cancellation.Cancel(); SensorPoller.Wait(TimeResolution.Add(TimeResolution)); SensorPoller = null; }
public async Task AggregateAsync(DateTime startTime, TimeResolution resolution, CancellationToken cancel) { var start = startTime.Truncate(resolution); var end = startTime.Next(resolution); if (resolution == TimeResolution.Minute) { await RepairAsync(start, cancel); } await AggregateAsync(start, end, resolution, true, cancel); }
public async Task RegisterGeneralData(string dataType, TimeResolution resolution, object data, CancellationToken cancel) { var aggregation = new Aggregation { DataType = dataType, Date = DateTime.UtcNow.Truncate(resolution), Resolution = resolution, Data = Serialize(data) }; await _statDataProvider.WriteAggregationAsync(aggregation, cancel); }
public STT.Task CleanupAggregationsAsync(string dataType, TimeResolution resolution, DateTime retentionTime, CancellationToken cancel) { var toDelete = Aggregations .Where(x => x.DataType == dataType && x.Resolution == resolution && x.Date < retentionTime).ToArray(); foreach (var item in toDelete) { Aggregations.Remove(item); } return(STT.Task.CompletedTask); }
private PoloniexTimeInterval ConvertToPoloniexInterval(TimeResolution resolution) { // TODO: AY: implement all TimeResolution cases. switch (resolution) { case TimeResolution.Day: return(PoloniexTimeInterval.Day1); default: throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null); } }
public static DateTime AddPeriods(this DateTime d, int periods, TimeResolution resolution) { switch (resolution) { case TimeResolution.Minute: return(d.AddMinutes(periods)); case TimeResolution.Hour: return(d.AddHours(periods)); case TimeResolution.Day: return(d.AddDays(periods)); case TimeResolution.Month: return(d.AddMonths(periods)); default: throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null); } }
public async Task CleanupAggregationsAsync(string dataType, TimeResolution resolution, DateTime retentionTime, CancellationToken cancellation) { using (var ctx = new MsSqlDataContext(ConnectionString, DataOptions, CancellationToken.None)) { await ctx.ExecuteNonQueryAsync(CleanupAggregationsScript, cmd => { cmd.Parameters.AddRange(new[] { ctx.CreateParameter("@DataType", DbType.String, dataType), ctx.CreateParameter("@Resolution", DbType.AnsiString, resolution.ToString()), ctx.CreateParameter("@RetentionTime", SqlDbType.DateTime2, retentionTime), }); }).ConfigureAwait(false); } }
public static DateTime Next(this DateTime d, TimeResolution timeWindow) { switch (timeWindow) { case TimeResolution.Minute: return(new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, 0).AddMinutes(1)); case TimeResolution.Hour: return(new DateTime(d.Year, d.Month, d.Day, d.Hour, 0, 0).AddHours(1)); case TimeResolution.Day: return(new DateTime(d.Year, d.Month, d.Day, 0, 0, 0).AddDays(1)); case TimeResolution.Month: return(new DateTime(d.Year, d.Month, 1, 0, 0, 0).AddMonths(1)); default: throw new ArgumentOutOfRangeException(nameof(timeWindow), timeWindow, null); } }
public static DateTime Truncate(this DateTime d, TimeResolution resolution) { switch (resolution) { case TimeResolution.Minute: return(new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, 0, DateTimeKind.Utc)); case TimeResolution.Hour: return(new DateTime(d.Year, d.Month, d.Day, d.Hour, 0, 0, DateTimeKind.Utc)); case TimeResolution.Day: return(new DateTime(d.Year, d.Month, d.Day, 0, 0, 0, DateTimeKind.Utc)); case TimeResolution.Month: return(new DateTime(d.Year, d.Month, 1, 0, 0, 0, DateTimeKind.Utc)); default: throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null); } }
public IList <TSensorValue> StopGettingValues() { if (!IsSensing() || sensorValues == null) { throw new NxtControlException(Name, "Could not stop getting: no list of sensor values being stored or incompatible event-driven sensing task in progress"); } cancellation.Cancel(); SensorPoller.Wait(TimeResolution.Add(TimeResolution)); SensorPoller = null; var retValues = sensorValues; sensorValues = null; return(retValues); }
public static DateTime ConformToResolution(this DateTime time, TimeResolution timeResolution) { switch (timeResolution) { case TimeResolution.Day: return(new DateTime(time.Year, time.Month, time.Day, 0, 0, 0, DateTimeKind.Utc)); case TimeResolution.Hour: return(new DateTime(time.Year, time.Month, time.Day, time.Hour, 0, 0, DateTimeKind.Utc)); case TimeResolution.Minute: return(new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, 0, DateTimeKind.Utc)); default: return(time); } }
private string ConvertToBitMexInterval(TimeResolution market) { switch (market) { case TimeResolution.Minute: return("1m"); case TimeResolution.Hour: return("1h"); case TimeResolution.Day: return("1d"); default: throw new ArgumentOutOfRangeException(nameof(market), market, null); } }
private async Task AggregateAsync(DateTime start, DateTime end, TimeResolution resolution, bool cleanup, CancellationToken cancel) { if (start > DateTime.UtcNow) { //_logger.LogTrace($"Skipping statistical aggregation for a future date: {start}"); return; } //_logger.LogTrace($"Aggregating statistical data START: {start}, END: {end}, resolution: {resolution}"); foreach (var aggregator in _aggregators) { aggregator.Clear(); if (!await TryProcessAggregationsAsync(aggregator, start, end, resolution, cancel)) { //_logger.LogTrace($"Aggregator enumerating data: {aggregator.DataType}"); await _statDataProvider.EnumerateDataAsync(aggregator.DataType, start, end, aggregator.Aggregate, cancel); } if (!aggregator.IsEmpty) { var result = new Aggregation { DataType = aggregator.DataType, Date = start, Resolution = resolution, Data = Serialize(aggregator.Data) }; //_logger.LogTrace($"Writing statistical aggregation for {aggregator.DataType}, START: {start}, resolution: {resolution}"); await _statDataProvider.WriteAggregationAsync(result, cancel).ConfigureAwait(false); } if (cleanup) { await CleanupAsync(aggregator, resolution, start, cancel).ConfigureAwait(false); } } //_logger.LogTrace($"Aggregation finished, last gen time: {start}"); _lastGenerationTimes[(int)resolution] = start; }
private string ConvertToBinanceInterval(TimeResolution resolution) { // BUG: API doesn't support seconds and milliseconds. switch (resolution) { case TimeResolution.Minute: return("1m"); case TimeResolution.Hour: return("1h"); case TimeResolution.Day: return("1d"); default: throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null); } }
private KrakenTimeInterval ConvertToKrakenInterval(TimeResolution resolution) { // BUG: Kraken does not support None, MS, S. At this moment it will throw ArgumentOutOfRangeException. switch (resolution) { case TimeResolution.Minute: return(KrakenTimeInterval.Minute1); case TimeResolution.Hour: return(KrakenTimeInterval.Hours1); case TimeResolution.Day: return(KrakenTimeInterval.Day1); default: throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null); } }
private int GetSeconds(TimeResolution market) { switch (market) { case TimeResolution.Second: return(1); case TimeResolution.Minute: return(60); case TimeResolution.Hour: return(3600); case TimeResolution.Day: return(62400); default: throw new ArgumentOutOfRangeException(nameof(market), market, null); } }
public TimeRange(DateTime from, DateTime to, TimeResolution timeResolution) { if (from.Kind != DateTimeKind.Utc) { throw new Exception(nameof(from) + " must be DateTime of DateTimeKind.Utc"); } if (to.Kind != DateTimeKind.Utc) { throw new Exception(nameof(to) + " must be DateTime of DateTimeKind.Utc"); } if (to < from) { throw new Exception(nameof(to) + " must represent a date after " + nameof(from) + " to be used in " + GetType()); } TimeResolution = timeResolution; UtcFrom = from.ConformToResolution(timeResolution); UtcTo = to.ConformToResolution(timeResolution); }
/// <summary> /// Get the Time Resolution's name. /// </summary> /// <param name="resolution">The time resolution type.</param> /// <returns>The name of the time resolution parameter as a string.</returns> public static string GetTimeResolutionName(TimeResolution resolution) { var name = string.Empty; switch (resolution) { case TimeResolution.HOUR: name = "h"; break; case TimeResolution.DAY: name = "d"; break; case TimeResolution.MONTH: name = "m"; break; } return(name); }
public static double GetAxisModifier(this TimeResolution timeResolution) { switch (timeResolution) { case TimeResolution.Second: return(NodaConstants.TicksPerSecond); case TimeResolution.Minute: return(NodaConstants.TicksPerMinute); case TimeResolution.Hour: return(NodaConstants.TicksPerHour); case TimeResolution.Day: return(NodaConstants.TicksPerDay); case TimeResolution.Millisecond: return(NodaConstants.MillisecondsPerDay); default: throw new ArgumentOutOfRangeException(nameof(GetAxisModifier) + " in " + typeof(TimeResolutionExtensionMethods)); } }
public static TimeSpan GetDefaultTimeSpan(this TimeResolution timeResolution) { switch (timeResolution) { case TimeResolution.Second: return(TimeSpan.FromHours(1)); case TimeResolution.Minute: return(TimeSpan.FromHours(4)); case TimeResolution.Hour: return(TimeSpan.FromDays(6)); case TimeResolution.Day: return(TimeSpan.FromDays(120)); case TimeResolution.Millisecond: return(TimeSpan.FromSeconds(1)); default: throw new ArgumentOutOfRangeException(nameof(GetDefaultTimeSpan) + " in " + typeof(TimeResolutionExtensionMethods)); } }
public TimeRange GetTimeRange(TimeResolution timeResolution) { return(Count == 0 ? TimeRange.Empty : new TimeRange(this.Min(x => x.DateTimeUtc), this.Max(x => x.DateTimeUtc), timeResolution)); }
public Task RegisterGeneralData(string dataType, TimeResolution resolution, object data, CancellationToken cancel) { return(Task.CompletedTask); }