Пример #1
0
        public IEnumerable <DynamicJsonValue> AddCurrentToResults(RangeGroup range, double?scale)
        {
            if (_interpolationType != InterpolationType.None)
            {
                foreach (var gap in FillMissingGaps(range, scale))
                {
                    yield return(gap);
                }
            }

            foreach (var kvp in _current)
            {
                var key   = kvp.Key;
                var value = kvp.Value;

                if (value[0].Any == false)
                {
                    continue;
                }

                yield return(ToJson(scale, range.Start, range.End, key, value));

                if (_interpolationType == InterpolationType.None)
                {
                    _pool.Free(value);
                    continue;
                }

                UpdatePrevious(key, range, value);
            }

            _current = null;
        }
Пример #2
0
 /// <summary>
 /// Creates a new range group info.
 /// </summary>
 /// <param name="model">The range group model</param>
 /// <param name="start">The starting group index</param>
 /// <param name="end">The ending group index</param>
 /// <param name="level">The level for the group</param>
 internal RangeGroupInfo(RangeGroup model, int start, int end, int level)
 {
     this.model = model;
     this.Start = start;
     this.End   = end;
     this.Level = level;
 }
Пример #3
0
        public static RangeGroup ParseRangeFromString(string s, DateTime?from = null)
        {
            var range  = new RangeGroup();
            var offset = 0;

            var duration = ParseNumber(s, ref offset);

            ParseRange(s, ref offset, ref range, duration);

            while (offset < s.Length && char.IsWhiteSpace(s[offset]))
            {
                offset++;
            }

            if (offset != s.Length)
            {
                throw new ArgumentException("After range specification, found additional unknown data: " + s);
            }

            if (from != null && range.Ticks != 0)
            {
                var ticks = from.Value.Ticks;
                ticks       -= (ticks % range.AlignedTicks);
                range._start = new DateTime(ticks);
            }

            return(range);
        }
Пример #4
0
        private void UpdatePrevious(object key, RangeGroup range, ITimeSeriesAggregation[] values)
        {
            _previous ??= new Dictionary <object, PreviousAggregation>();
            if (_previous.TryGetValue(key, out var result) == false)
            {
                result = _previous[key] = new PreviousAggregation();
            }
            else
            {
                _pool.Free(result.Data);
            }

            result.Data  = values;
            result.Range = range;
        }
Пример #5
0
        public RangeStringInputViewModel(PreflopStrategy strategy)
        {
            this.strategy = strategy;

            RangeGroups = new List<RangeGroup>();

            foreach (string groupKey in strategy.HandRangeGroupKeys)
            {
                RangeGroup group = new RangeGroup() { Key = groupKey, Ranges = new List<Range>() };

                foreach (string rangeKey in strategy.HandRangeKeys)
                    group.Ranges.Add(new Range() { Key = rangeKey, Value = string.Empty });

                RangeGroups.Add(group);
            }
        }
Пример #6
0
        public void CanGetRangeStartAndNext(string rangeStr, string dateStr, string startStr, string nextStr)
        {
            var rangeSpec = RangeGroup.ParseRangeFromString(rangeStr);
            var date      = DateTime.ParseExact(dateStr, "o", CultureInfo.InvariantCulture).ToUniversalTime();

            rangeSpec.InitializeRange(date);

            Assert.Equal(
                DateTime.ParseExact(startStr, "o", CultureInfo.InvariantCulture).ToUniversalTime(),
                rangeSpec.Start);

            rangeSpec.MoveToNextRange(rangeSpec.End);

            Assert.Equal(
                DateTime.ParseExact(nextStr, "o", CultureInfo.InvariantCulture).ToUniversalTime(),
                rangeSpec.Start);
        }
Пример #7
0
            public static TimeValue LastWithTime(MethodExpression expression, string queryText, BlittableJsonReaderObject parameters)
            {
                try
                {
                    if (expression.Arguments.Count != 2)
                    {
                        throw new InvalidOperationException("Method 'last()' expects two arguments to be provided");
                    }

                    var duration = Helpers.GetLong(expression.Arguments[0], parameters);
                    var timeValueUnitAsString = Helpers.GetString(expression.Arguments[1], parameters);

                    var offset = 0;
                    return(RangeGroup.ParseTimePeriodFromString(duration, timeValueUnitAsString, ref offset));
                }
                catch (Exception e)
                {
                    throw new InvalidQueryException("Could not parse last() method.", queryText, parameters, e);
                }
            }
Пример #8
0
        public static RangeGroup ParseRangeFromString(string s)
        {
            var range  = new RangeGroup();
            var offset = 0;

            var duration = ParseNumber(s, ref offset);

            ParseRange(s, ref offset, ref range, duration);

            while (offset < s.Length && char.IsWhiteSpace(s[offset]))
            {
                offset++;
            }

            if (offset != s.Length)
            {
                throw new ArgumentException("After range specification, found additional unknown data: " + s);
            }

            return(range);
        }
Пример #9
0
        public RangeStringInputViewModel(PreflopStrategy strategy)
        {
            this.strategy = strategy;

            RangeGroups = new List <RangeGroup>();

            foreach (string groupKey in strategy.HandRangeGroupKeys)
            {
                RangeGroup group = new RangeGroup()
                {
                    Key = groupKey, Ranges = new List <Range>()
                };

                foreach (string rangeKey in strategy.HandRangeKeys)
                {
                    group.Ranges.Add(new Range()
                    {
                        Key = rangeKey, Value = string.Empty
                    });
                }

                RangeGroups.Add(group);
            }
        }
Пример #10
0
        private static void ParseRange(string source, ref int offset, ref RangeGroup range, long duration)
        {
            if (offset >= source.Length)
            {
                throw new ArgumentException("Unable to find range specification in: " + source);
            }

            while (char.IsWhiteSpace(source[offset]) && offset < source.Length)
            {
                offset++;
            }

            if (offset >= source.Length)
            {
                throw new ArgumentException("Unable to find range specification in: " + source);
            }

            switch (char.ToLower(source[offset++]))
            {
            case 's':
                if (TryConsumeMatch(source, ref offset, "seconds") == false)
                {
                    TryConsumeMatch(source, ref offset, "second");
                }

                range.Ticks         += duration * TicksInOneSecond;
                range.TicksAlignment = Alignment.Second;
                return;

            case 'm':
                if (TryConsumeMatch(source, ref offset, "minutes") ||
                    TryConsumeMatch(source, ref offset, "minute") ||
                    TryConsumeMatch(source, ref offset, "min"))
                {
                    range.Ticks         += duration * TicksInOneSecond * 60;
                    range.TicksAlignment = Alignment.Minute;
                    return;
                }

                if (TryConsumeMatch(source, ref offset, "ms") ||
                    TryConsumeMatch(source, ref offset, "milliseconds") ||
                    TryConsumeMatch(source, ref offset, "milli"))
                {
                    range.Ticks         += duration * TicksInMillisecond;
                    range.TicksAlignment = Alignment.Millisecond;
                    return;
                }

                if (TryConsumeMatch(source, ref offset, "months") ||
                    TryConsumeMatch(source, ref offset, "month") ||
                    TryConsumeMatch(source, ref offset, "mon") ||
                    TryConsumeMatch(source, ref offset, "mo"))
                {
                    AssertValidDurationInMonths(duration);
                    range.Months += (int)duration;
                    return;
                }
                range.TicksAlignment = Alignment.Minute;
                range.Ticks         += duration * TicksInOneSecond * 60;
                return;

            case 'h':
                if (TryConsumeMatch(source, ref offset, "hours") == false)
                {
                    TryConsumeMatch(source, ref offset, "hour");
                }

                range.Ticks         += duration * TicksInOneSecond * 60 * 60;
                range.TicksAlignment = Alignment.Hour;

                return;

            case 'd':
                if (TryConsumeMatch(source, ref offset, "days") == false)
                {
                    TryConsumeMatch(source, ref offset, "day");
                }
                range.Ticks         += duration * TicksInOneSecond * 60 * 60 * 24;
                range.TicksAlignment = Alignment.Day;

                return;

            case 'q':
                if (TryConsumeMatch(source, ref offset, "quarters") == false)
                {
                    TryConsumeMatch(source, ref offset, "quarter");
                }
                duration *= 3;
                AssertValidDurationInMonths(duration);
                range.Months += (int)duration;
                return;

            case 'y':
                if (TryConsumeMatch(source, ref offset, "years") == false)
                {
                    TryConsumeMatch(source, ref offset, "year");
                }
                duration *= 12;
                AssertValidDurationInMonths(duration);
                range.Months += (int)duration;
                return;

            default:
                throw new ArgumentException($"Unable to understand time range: '{source}'");
            }
        }
Пример #11
0
        public static void SaveColumnHeaderInfo(Worksheet sheet, CopyMoveCellsInfo headerCellsInfo, CopyMoveColumnsInfo columnsInfo, int baseColumn, CopyToOption option)
        {
            int rowCount    = headerCellsInfo.RowCount;
            int columnCount = headerCellsInfo.ColumnCount;

            for (int i = 0; i < rowCount; i++)
            {
                for (int k = 0; k < columnCount; k++)
                {
                    if ((option & CopyToOption.Value) > ((CopyToOption)0))
                    {
                        headerCellsInfo.SaveValue(i, k, sheet.GetValue(i, baseColumn + k, SheetArea.ColumnHeader));
                    }
                    if ((option & CopyToOption.Style) > ((CopyToOption)0))
                    {
                        headerCellsInfo.SaveStyle(i, k, GetStyleObject(sheet, i, baseColumn + k, SheetArea.ColumnHeader));
                    }
                    if ((option & CopyToOption.Tag) > ((CopyToOption)0))
                    {
                        headerCellsInfo.SaveTag(i, k, sheet.GetTag(i, baseColumn + k, SheetArea.ColumnHeader));
                    }
                }
            }
            if ((option & CopyToOption.Value) > ((CopyToOption)0))
            {
                for (int m = 0; m < columnCount; m++)
                {
                    if (sheet.IsColumnBound(baseColumn + m))
                    {
                        columnsInfo.SaveBindingField(m, sheet.GetDataColumnName(baseColumn + m));
                    }
                }
            }
            if ((option & CopyToOption.Span) > ((CopyToOption)0))
            {
                IEnumerator enumerator = sheet.ColumnHeaderSpanModel.GetEnumerator(0, baseColumn, rowCount, columnCount);
                while (enumerator.MoveNext())
                {
                    headerCellsInfo.SaveSpan((CellRange)enumerator.Current);
                }
            }
            columnCount = columnsInfo.ColumnCount;
            for (int j = 0; j < columnCount; j++)
            {
                columnsInfo.SaveWidth(j, sheet.GetColumnWidth(baseColumn + j));
                columnsInfo.SaveVisible(j, sheet.GetColumnVisible(baseColumn + j));
                columnsInfo.SaveResizable(j, sheet.GetColumnResizable(baseColumn + j));
                columnsInfo.SaveTag(j, sheet.GetTag(-1, baseColumn + j));
            }
            if ((option & CopyToOption.Style) > ((CopyToOption)0))
            {
                for (int n = 0; n < columnCount; n++)
                {
                    columnsInfo.SaveViewportColumnStyle(n, GetStyleObject(sheet, -1, baseColumn + n, SheetArea.Cells));
                    columnsInfo.SaveHeaderColumnStyle(n, GetStyleObject(sheet, -1, baseColumn + n, SheetArea.ColumnHeader));
                }
            }
            if ((option & CopyToOption.RangeGroup) > ((CopyToOption)0))
            {
                RangeGroup columnRangeGroup = sheet.ColumnRangeGroup;
                if ((columnRangeGroup != null) && !columnRangeGroup.IsEmpty())
                {
                    for (int num8 = 0; num8 < columnCount; num8++)
                    {
                        columnsInfo.SaveRangeGroup(num8, columnRangeGroup.Data.GetLevel(baseColumn + num8), columnRangeGroup.Data.GetCollapsed(baseColumn + num8));
                    }
                }
            }
        }
Пример #12
0
        public static List <SingleResult> GetAggregatedValues(TimeSeriesReader reader, RangeGroup rangeSpec, AggregationMode mode)
        {
            var aggStates = new TimeSeriesAggregation(mode); // we always will aggregate here by Min, Max, First, Last, Sum, Count, Mean
            var results   = new List <SingleResult>();

            foreach (var it in reader.SegmentsOrValues())
            {
                if (it.IndividualValues != null)
                {
                    AggregateIndividualItems(it.IndividualValues);
                }
                else
                {
                    //We might need to close the old aggregation range and start a new one
                    MaybeMoveToNextRange(it.Segment.Start);

                    // now we need to see if we can consume the whole segment, or
                    // if the range it cover needs to be broken up to multiple ranges.
                    // For example, if the segment covers 3 days, but we have group by 1 hour,
                    // we still have to deal with the individual values
                    if (it.Segment.End > rangeSpec.End)
                    {
                        AggregateIndividualItems(it.Segment.Values);
                    }
                    else
                    {
                        var span = it.Segment.Summary.SegmentValues.Span;
                        aggStates.Segment(span);
                    }
                }
            }

            if (aggStates.Any)
            {
                var result = new SingleResult
                {
                    Timestamp = rangeSpec.Start,
                    Values    = new Memory <double>(aggStates.Values.ToArray()),
                    Status    = TimeSeriesValuesSegment.Live,
                    Type      = SingleResultType.RolledUp
                                // TODO: Tag = ""
                };
                TimeSeriesStorage.AssertNoNanValue(result);
                results.Add(result);
            }

            return(results);

            void MaybeMoveToNextRange(DateTime ts)
            {
                if (rangeSpec.WithinRange(ts))
                {
                    return;
                }

                if (aggStates.Any)
                {
                    var result = new SingleResult
                    {
                        Timestamp = rangeSpec.Start,
                        Values    = new Memory <double>(aggStates.Values.ToArray()),
                        Status    = TimeSeriesValuesSegment.Live,
                        Type      = SingleResultType.RolledUp
                                    // TODO: Tag = ""
                    };
                    TimeSeriesStorage.AssertNoNanValue(result);
                    results.Add(result);
                }

                rangeSpec.MoveToNextRange(ts);
                aggStates.Init();
            }

            void AggregateIndividualItems(IEnumerable <SingleResult> items)
            {
                foreach (var cur in items)
                {
                    if (cur.Status == TimeSeriesValuesSegment.Dead)
                    {
                        continue;
                    }

                    MaybeMoveToNextRange(cur.Timestamp);

                    aggStates.Step(cur.Values.Span);
                }
            }
        }
Пример #13
0
            private void RollupOne(DocumentsOperationContext context, Table table, RollupState item, TimeSeriesPolicy policy, TimeSeriesCollectionConfiguration config)
            {
                var tss = context.DocumentDatabase.DocumentsStorage.TimeSeriesStorage;

                var rawTimeSeries  = item.Name.Split(TimeSeriesConfiguration.TimeSeriesRollupSeparator)[0];
                var intoTimeSeries = policy.GetTimeSeriesName(rawTimeSeries);
                var rollupStart    = item.NextRollup.Add(-policy.AggregationTime);

                if (config.MaxRetention < TimeValue.MaxValue)
                {
                    var next             = new DateTime(NextRollup(_now.Add(-config.MaxRetention), policy)).Add(-policy.AggregationTime);
                    var rollupStartTicks = Math.Max(rollupStart.Ticks, next.Ticks);
                    rollupStart = new DateTime(rollupStartTicks);
                }

                var intoReader           = tss.GetReader(context, item.DocId, intoTimeSeries, rollupStart, DateTime.MaxValue);
                var previouslyAggregated = intoReader.AllValues().Any();

                if (previouslyAggregated)
                {
                    var changeVector = intoReader.GetCurrentSegmentChangeVector();
                    if (ChangeVectorUtils.GetConflictStatus(item.ChangeVector, changeVector) == ConflictStatus.AlreadyMerged)
                    {
                        // this rollup is already done
                        table.DeleteByKey(item.Key);
                        return;
                    }
                }

                if (_isFirstInTopology == false)
                {
                    return;
                }

                var rollupEnd = new DateTime(NextRollup(_now, policy)).Add(-policy.AggregationTime).AddMilliseconds(-1);
                var reader    = tss.GetReader(context, item.DocId, item.Name, rollupStart, rollupEnd);

                if (previouslyAggregated)
                {
                    var hasPriorValues = tss.GetReader(context, item.DocId, item.Name, DateTime.MinValue, rollupStart).AllValues().Any();
                    if (hasPriorValues == false)
                    {
                        table.DeleteByKey(item.Key);
                        var first = tss.GetReader(context, item.DocId, item.Name, rollupStart, DateTime.MaxValue).First();
                        if (first == default)
                        {
                            return;
                        }

                        if (first.Timestamp > item.NextRollup)
                        {
                            // if the 'source' time-series doesn't have any values it is retained.
                            // so we need to aggregate only from the next time frame
                            using (var slicer = new TimeSeriesSliceHolder(context, item.DocId, item.Name, item.Collection))
                            {
                                tss.Rollups.MarkForPolicy(context, slicer, policy, first.Timestamp);
                            }

                            return;
                        }
                    }
                }

                // rollup from the the raw data will generate 6-value roll up of (first, last, min, max, sum, count)
                // other rollups will aggregate each of those values by the type
                var mode      = item.Name.Contains(TimeSeriesConfiguration.TimeSeriesRollupSeparator) ? AggregationMode.FromAggregated : AggregationMode.FromRaw;
                var rangeSpec = new RangeGroup();

                switch (policy.AggregationTime.Unit)
                {
                case TimeValueUnit.Second:
                    rangeSpec.Ticks          = TimeSpan.FromSeconds(policy.AggregationTime.Value).Ticks;
                    rangeSpec.TicksAlignment = RangeGroup.Alignment.Second;
                    break;

                case TimeValueUnit.Month:
                    rangeSpec.Months = policy.AggregationTime.Value;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(policy.AggregationTime.Unit), $"Not supported time value unit '{policy.AggregationTime.Unit}'");
                }

                rangeSpec.InitializeRange(rollupStart);

                var values = GetAggregatedValues(reader, rangeSpec, mode);

                if (previouslyAggregated)
                {
                    // if we need to re-aggregate we need to delete everything we have from that point on.
                    var removeRequest = new TimeSeriesStorage.DeletionRangeRequest
                    {
                        Collection = item.Collection,
                        DocumentId = item.DocId,
                        Name       = intoTimeSeries,
                        From       = rollupStart,
                        To         = DateTime.MaxValue,
                    };

                    tss.DeleteTimestampRange(context, removeRequest);
                }

                var before = context.LastDatabaseChangeVector;
                var after  = tss.AppendTimestamp(context, item.DocId, item.Collection, intoTimeSeries, values, verifyName: false);

                if (before != after)
                {
                    RolledUp++;
                }

                table.DeleteByKey(item.Key);

                var stats = tss.Stats.GetStats(context, item.DocId, item.Name);

                if (stats.End > rollupEnd)
                {
                    // we know that we have values after the current rollup and we need to mark them
                    var nextRollup = rollupEnd.AddMilliseconds(1);
                    intoReader = tss.GetReader(context, item.DocId, item.Name, nextRollup, DateTime.MaxValue);
                    if (intoReader.Init() == false)
                    {
                        Debug.Assert(false, "We have values but no segment?");
                        return;
                    }

                    using (var slicer = new TimeSeriesSliceHolder(context, item.DocId, item.Name, item.Collection))
                    {
                        tss.Rollups.MarkForPolicy(context, slicer, policy, intoReader.First().Timestamp);
                    }
                }
            }
Пример #14
0
            protected override long ExecuteCmd(DocumentsOperationContext context)
            {
                var tss = context.DocumentDatabase.DocumentsStorage.TimeSeriesStorage;

                RollupSchema.Create(context.Transaction.InnerTransaction, TimeSeriesRollupTable, 16);
                var table = context.Transaction.InnerTransaction.OpenTable(RollupSchema, TimeSeriesRollupTable);

                foreach (var item in _states)
                {
                    if (_configuration == null)
                    {
                        return(RolledUp);
                    }

                    if (_configuration.Collections.TryGetValue(item.Collection, out var config) == false)
                    {
                        continue;
                    }

                    if (config.Disabled)
                    {
                        continue;
                    }

                    if (table.ReadByKey(item.Key, out var current) == false)
                    {
                        continue;
                    }

                    var policy = config.GetPolicyByName(item.RollupPolicy, out _);
                    if (policy == null)
                    {
                        table.DeleteByKey(item.Key);
                        continue;
                    }

                    if (item.Etag != DocumentsStorage.TableValueToLong((int)RollupColumns.Etag, ref current))
                    {
                        continue; // concurrency check
                    }
                    var rawTimeSeries  = item.Name.Split(TimeSeriesConfiguration.TimeSeriesRollupSeparator)[0];
                    var intoTimeSeries = policy.GetTimeSeriesName(rawTimeSeries);
                    var rollupStart    = item.NextRollup.Add(-policy.AggregationTime);

                    if (config.MaxRetention < TimeValue.MaxValue)
                    {
                        var next             = new DateTime(NextRollup(_now.Add(-config.MaxRetention), policy)).Add(-policy.AggregationTime);
                        var rollupStartTicks = Math.Max(rollupStart.Ticks, next.Ticks);
                        rollupStart = new DateTime(rollupStartTicks);
                    }

                    var intoReader           = tss.GetReader(context, item.DocId, intoTimeSeries, rollupStart, DateTime.MaxValue);
                    var previouslyAggregated = intoReader.AllValues().Any();
                    if (previouslyAggregated)
                    {
                        var changeVector = intoReader.GetCurrentSegmentChangeVector();
                        if (ChangeVectorUtils.GetConflictStatus(item.ChangeVector, changeVector) == ConflictStatus.AlreadyMerged)
                        {
                            // this rollup is already done
                            table.DeleteByKey(item.Key);
                            continue;
                        }
                    }

                    if (_isFirstInTopology == false)
                    {
                        continue; // we execute the actual rollup only on the primary node to avoid conflicts
                    }
                    var rollupEnd = new DateTime(NextRollup(_now, policy)).Add(-policy.AggregationTime).AddMilliseconds(-1);
                    var reader    = tss.GetReader(context, item.DocId, item.Name, rollupStart, rollupEnd);

                    if (previouslyAggregated)
                    {
                        var hasPriorValues = tss.GetReader(context, item.DocId, item.Name, DateTime.MinValue, rollupStart).AllValues().Any();
                        if (hasPriorValues == false)
                        {
                            table.DeleteByKey(item.Key);
                            var first = tss.GetReader(context, item.DocId, item.Name, rollupStart, DateTime.MaxValue).First();
                            if (first == default)
                            {
                                continue; // nothing we can do here
                            }
                            if (first.Timestamp > item.NextRollup)
                            {
                                // if the 'source' time-series doesn't have any values it is retained.
                                // so we need to aggregate only from the next time frame
                                using (var slicer = new TimeSeriesSliceHolder(context, item.DocId, item.Name, item.Collection))
                                {
                                    tss.Rollups.MarkForPolicy(context, slicer, policy, first.Timestamp);
                                }
                                continue;
                            }
                        }
                    }

                    // rollup from the the raw data will generate 6-value roll up of (first, last, min, max, sum, count)
                    // other rollups will aggregate each of those values by the type
                    var mode      = item.Name.Contains(TimeSeriesConfiguration.TimeSeriesRollupSeparator) ? AggregationMode.FromAggregated : AggregationMode.FromRaw;
                    var rangeSpec = new RangeGroup();
                    switch (policy.AggregationTime.Unit)
                    {
                    case TimeValueUnit.Second:
                        rangeSpec.Ticks          = TimeSpan.FromSeconds(policy.AggregationTime.Value).Ticks;
                        rangeSpec.TicksAlignment = RangeGroup.Alignment.Second;
                        break;

                    case TimeValueUnit.Month:
                        rangeSpec.Months = policy.AggregationTime.Value;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(policy.AggregationTime.Unit), $"Not supported time value unit '{policy.AggregationTime.Unit}'");
                    }
                    rangeSpec.InitializeRange(rollupStart);

                    List <SingleResult> values = null;
                    try
                    {
                        values = GetAggregatedValues(reader, rangeSpec, mode);
                    }
                    catch (RollupExceedNumberOfValuesException e)
                    {
                        var name  = item.Name;
                        var docId = item.DocId;
                        try
                        {
                            var document = context.DocumentDatabase.DocumentsStorage.Get(context, item.DocId, throwOnConflict: false);
                            docId = document?.Id ?? docId;
                            name  = tss.GetOriginalName(context, docId, name);
                        }
                        catch
                        {
                            // ignore
                        }
                        var msg = $"Rollup '{item.RollupPolicy}' for time-series '{name}' in document '{docId}' failed.";
                        if (_logger.IsInfoEnabled)
                        {
                            _logger.Info(msg, e);
                        }

                        var alert = AlertRaised.Create(context.DocumentDatabase.Name, "Failed to perform rollup because the time-series has more than 5 values", msg,
                                                       AlertType.RollupExceedNumberOfValues, NotificationSeverity.Warning, $"{item.DocId}/{item.Name}", new ExceptionDetails(e));

                        context.DocumentDatabase.NotificationCenter.Add(alert);

                        continue;
                    }

                    if (previouslyAggregated)
                    {
                        // if we need to re-aggregate we need to delete everything we have from that point on.
                        var removeRequest = new TimeSeriesStorage.DeletionRangeRequest
                        {
                            Collection = item.Collection,
                            DocumentId = item.DocId,
                            Name       = intoTimeSeries,
                            From       = rollupStart,
                            To         = DateTime.MaxValue,
                        };

                        tss.DeleteTimestampRange(context, removeRequest);
                    }

                    var before = context.LastDatabaseChangeVector;
                    var after  = tss.AppendTimestamp(context, item.DocId, item.Collection, intoTimeSeries, values, verifyName: false);
                    if (before != after)
                    {
                        RolledUp++;
                    }

                    table.DeleteByKey(item.Key);

                    var stats = tss.Stats.GetStats(context, item.DocId, item.Name);
                    if (stats.End > rollupEnd)
                    {
                        // we know that we have values after the current rollup and we need to mark them
                        var nextRollup = rollupEnd.AddMilliseconds(1);
                        intoReader = tss.GetReader(context, item.DocId, item.Name, nextRollup, DateTime.MaxValue);
                        if (intoReader.Init() == false)
                        {
                            Debug.Assert(false, "We have values but no segment?");
                            continue;
                        }

                        using (var slicer = new TimeSeriesSliceHolder(context, item.DocId, item.Name, item.Collection))
                        {
                            tss.Rollups.MarkForPolicy(context, slicer, policy, intoReader.First().Timestamp);
                        }
                    }
                }

                return(RolledUp);
            }
Пример #15
0
 public static void SaveRowHeaderInfo(Worksheet sheet, CopyMoveCellsInfo headerCellsInfo, CopyMoveRowsInfo rowsInfo, int baseRow, CopyToOption option)
 {
     if ((option & CopyToOption.All) > ((CopyToOption)0))
     {
         int rowCount    = headerCellsInfo.RowCount;
         int columnCount = headerCellsInfo.ColumnCount;
         for (int i = 0; i < rowCount; i++)
         {
             for (int k = 0; k < columnCount; k++)
             {
                 if ((option & CopyToOption.Value) > ((CopyToOption)0))
                 {
                     headerCellsInfo.SaveValue(i, k, sheet.GetValue(baseRow + i, k, SheetArea.CornerHeader | SheetArea.RowHeader));
                 }
                 if ((option & CopyToOption.Style) > ((CopyToOption)0))
                 {
                     headerCellsInfo.SaveStyle(i, k, GetStyleObject(sheet, baseRow + i, k, SheetArea.CornerHeader | SheetArea.RowHeader));
                 }
                 if ((option & CopyToOption.Tag) > ((CopyToOption)0))
                 {
                     headerCellsInfo.SaveTag(i, k, sheet.GetTag(baseRow + i, k, SheetArea.CornerHeader | SheetArea.RowHeader));
                 }
             }
         }
         if ((option & CopyToOption.Span) > ((CopyToOption)0))
         {
             IEnumerator enumerator = sheet.RowHeaderSpanModel.GetEnumerator(baseRow, 0, rowCount, columnCount);
             while (enumerator.MoveNext())
             {
                 headerCellsInfo.SaveSpan((CellRange)enumerator.Current);
             }
         }
         rowCount = rowsInfo.RowCount;
         for (int j = 0; j < rowCount; j++)
         {
             rowsInfo.SaveHeight(j, sheet.GetRowHeight(baseRow + j));
             rowsInfo.SaveVisible(j, sheet.GetRowVisible(baseRow + j));
             rowsInfo.SaveResizable(j, sheet.GetRowResizable(baseRow + j));
             rowsInfo.SaveTag(j, sheet.GetTag(baseRow + j, -1));
         }
         if ((option & CopyToOption.Style) > ((CopyToOption)0))
         {
             for (int m = 0; m < rowCount; m++)
             {
                 rowsInfo.SaveViewportRowStyle(m, GetStyleObject(sheet, baseRow + m, -1, SheetArea.Cells));
                 rowsInfo.SaveHeaderRowStyle(m, GetStyleObject(sheet, baseRow + m, -1, SheetArea.CornerHeader | SheetArea.RowHeader));
             }
         }
         if ((option & CopyToOption.RangeGroup) > ((CopyToOption)0))
         {
             RangeGroup rowRangeGroup = sheet.RowRangeGroup;
             if ((rowRangeGroup != null) && !rowRangeGroup.IsEmpty())
             {
                 for (int n = 0; n < rowCount; n++)
                 {
                     rowsInfo.SaveRangeGroup(n, rowRangeGroup.Data.GetLevel(baseRow + n), rowRangeGroup.Data.GetCollapsed(baseRow + n));
                 }
             }
         }
     }
 }
Пример #16
0
        public static void UndoRowsInfo(Worksheet sheet, CopyMoveRowsInfo rowsInfo, int baseRow)
        {
            int rowCount = rowsInfo.RowCount;

            if (rowsInfo.IsHeightSaved())
            {
                for (int i = 0; i < rowCount; i++)
                {
                    sheet.SetRowHeight(baseRow + i, SheetArea.Cells, rowsInfo.GetHeight(i));
                }
            }
            if (rowsInfo.IsVisibleSaved())
            {
                for (int j = 0; j < rowCount; j++)
                {
                    sheet.SetRowVisible(baseRow + j, SheetArea.Cells, rowsInfo.GetVisible(j));
                }
            }
            if (rowsInfo.IsResizableSaved())
            {
                for (int k = 0; k < rowCount; k++)
                {
                    sheet.SetRowResizable(baseRow + k, SheetArea.Cells, rowsInfo.GetResizable(k));
                }
            }
            if (rowsInfo.IsTagSaved())
            {
                for (int m = 0; m < rowCount; m++)
                {
                    sheet.SetTag(baseRow + m, -1, SheetArea.Cells, rowsInfo.GetTag(m));
                }
            }
            if (rowsInfo.IsViewportRowStyleSaved())
            {
                for (int n = 0; n < rowCount; n++)
                {
                    SetStyleObject(sheet, baseRow + n, -1, SheetArea.Cells, rowsInfo.GetViewportRowStyle(n));
                }
            }
            if (rowsInfo.IsHeaderRowStyleSaved())
            {
                for (int num7 = 0; num7 < rowCount; num7++)
                {
                    SetStyleObject(sheet, baseRow + num7, -1, SheetArea.CornerHeader | SheetArea.RowHeader, rowsInfo.GetHeaderRowStyle(num7));
                }
            }
            if (rowsInfo.IsRangeGroupSaved())
            {
                RangeGroup rowRangeGroup = sheet.RowRangeGroup;
                if (rowRangeGroup != null)
                {
                    for (int num9 = 0; num9 < rowCount; num9++)
                    {
                        int  num8;
                        bool flag;
                        rowsInfo.GetRangeGroup(num9, out num8, out flag);
                        rowRangeGroup.Data.SetLevel(baseRow + num9, num8);
                        rowRangeGroup.Data.SetCollapsed(baseRow + num9, flag);
                    }
                }
            }
        }
Пример #17
0
        public static void UndoColumnsInfo(Worksheet sheet, CopyMoveColumnsInfo columnsInfo, int baseColumn)
        {
            int columnCount = columnsInfo.ColumnCount;

            if (columnsInfo.IsBindingFieldSaved())
            {
                for (int i = 0; i < columnCount; i++)
                {
                    string str;
                    if (columnsInfo.GetBindingField(i, out str))
                    {
                        sheet.BindDataColumn(baseColumn + i, str);
                    }
                }
            }
            else
            {
                for (int j = 0; j < columnCount; j++)
                {
                    sheet.BindDataColumn(baseColumn + j, null);
                }
            }
            if (columnsInfo.IsWidthSaved())
            {
                for (int k = 0; k < columnCount; k++)
                {
                    sheet.SetColumnWidth(baseColumn + k, SheetArea.Cells, columnsInfo.GetWidth(k));
                }
            }
            if (columnsInfo.IsVisibleSaved())
            {
                for (int m = 0; m < columnCount; m++)
                {
                    sheet.SetColumnVisible(baseColumn + m, SheetArea.Cells, columnsInfo.GetVisible(m));
                }
            }
            if (columnsInfo.IsResizableSaved())
            {
                for (int n = 0; n < columnCount; n++)
                {
                    sheet.SetColumnResizable(baseColumn + n, SheetArea.Cells, columnsInfo.GetResizable(n));
                }
            }
            if (columnsInfo.IsTagSaved())
            {
                for (int num7 = 0; num7 < columnCount; num7++)
                {
                    sheet.SetTag(-1, baseColumn + num7, SheetArea.Cells, columnsInfo.GetTag(num7));
                }
            }
            if (columnsInfo.IsViewportColumnStyleSaved())
            {
                for (int num8 = 0; num8 < columnCount; num8++)
                {
                    SetStyleObject(sheet, -1, baseColumn + num8, SheetArea.Cells, columnsInfo.GetViewportColumnStyle(num8));
                }
            }
            if (columnsInfo.IsHeaderColumnStyleSaved())
            {
                for (int num9 = 0; num9 < columnCount; num9++)
                {
                    SetStyleObject(sheet, -1, baseColumn + num9, SheetArea.ColumnHeader, columnsInfo.GetHeaderColumnStyle(num9));
                }
            }
            if (columnsInfo.IsRangeGroupSaved())
            {
                RangeGroup columnRangeGroup = sheet.ColumnRangeGroup;
                if (columnRangeGroup != null)
                {
                    for (int num11 = 0; num11 < columnCount; num11++)
                    {
                        int  num10;
                        bool flag;
                        columnsInfo.GetRangeGroup(num11, out num10, out flag);
                        columnRangeGroup.Data.SetLevel(baseColumn + num11, num10);
                        columnRangeGroup.Data.SetCollapsed(baseColumn + num11, flag);
                    }
                }
            }
        }