Exemple #1
0
        public override Select Build()
        {
            string columnPath = Parameters.Value <string>("columnName");

            if (string.IsNullOrEmpty(columnPath))
            {
                columnPath = Esq.RootSchema.PrimaryColumn.ColumnValueName;
            }
            EntitySchemaQueryExpression columnExpression = EntitySchemaQuery.CreateSchemaColumnExpression(
                Esq.RootSchema, columnPath);

            columnExpression.UId = Guid.NewGuid();
            AggregationType columnAggregationType = AggregationType.Count;
            string          aggregationType       = Parameters.Value <string>("aggregationType");

            if (!string.IsNullOrEmpty(aggregationType))
            {
                columnAggregationType = (AggregationType)Enum.Parse(typeof(AggregationType),
                                                                    aggregationType);
            }
            var queryFunction = new EntitySchemaAggregationQueryFunction(columnAggregationType.ToStrict(),
                                                                         columnExpression, Esq);

            ColumnDataValueType = GetColumnDataValueType(columnExpression);
            Esq.AddColumn(queryFunction);
            EntityColumnMap = new Dictionary <string, object>();
            EntityColumnMap["valueAlias"]    = queryFunction.QueryAlias;
            EntityColumnMap["dataValueType"] = columnExpression.SchemaColumn.DataValueType;
            string filterData = Parameters.Value <string>("filterData");

            AddFilterByJson(filterData);
            return(base.Build());
        }
Exemple #2
0
        private EntitySchemaQueryColumn AddQueryColumn(JObject columnItem, string columnPath)
        {
            columnPath = DashboardDataUtils.ClearColumnPathSuffix(columnPath);
            string          filterData            = columnItem.Value <string>("serializedFilter");
            string          aggregationType       = columnItem.Value <string>("aggregationType");
            AggregationType columnAggregationType = AggregationType.None;

            if (!string.IsNullOrEmpty(aggregationType))
            {
                columnAggregationType = (AggregationType)Enum.Parse(typeof(AggregationType),
                                                                    aggregationType);
            }
            EntitySchemaQueryColumn column;

            if (columnAggregationType != AggregationType.None && !string.IsNullOrEmpty(filterData))
            {
                EntitySchemaQuery subQuery;
                column = Esq.AddColumn(columnPath, columnAggregationType.ToStrict(), out subQuery);
                var dashboardData = new BaseDashboardItemSelectBuilder(UserConnection, subQuery);
                dashboardData.AddFilterByJson(filterData);
            }
            else
            {
                column = Esq.AddColumn(columnPath);
                if (!string.IsNullOrEmpty(aggregationType))
                {
                    column.SummaryType = columnAggregationType;
                }
            }
            SetColumnOrder(columnItem, column);
            return(column);
        }
        internal AggregatorStore(
            AggregationType aggType,
            AggregationTemporality temporality,
            double[] histogramBounds,
            string[] tagKeysInteresting = null)
        {
            this.metricPoints       = new MetricPoint[MaxMetricPoints];
            this.aggType            = aggType;
            this.temporality        = temporality;
            this.outputDelta        = temporality == AggregationTemporality.Delta ? true : false;
            this.histogramBounds    = histogramBounds;
            this.startTimeExclusive = DateTimeOffset.UtcNow;
            if (tagKeysInteresting == null)
            {
                this.updateLongCallback   = this.UpdateLong;
                this.updateDoubleCallback = this.UpdateDouble;
            }
            else
            {
                this.updateLongCallback   = this.UpdateLongCustomTags;
                this.updateDoubleCallback = this.UpdateDoubleCustomTags;
                var hs = new HashSet <string>(StringComparer.Ordinal);
                foreach (var key in tagKeysInteresting)
                {
                    hs.Add(key);
                }

                this.tagKeysInteresting       = hs;
                this.tagsKeysInterestingCount = hs.Count;
            }
        }
Exemple #4
0
 public FramesMeasurement Definition(string name = "Time", SampleUnit sampleUnit = SampleUnit.Millisecond,
                                     AggregationType aggregationType = AggregationType.Median, double threshold = 0.1D,
                                     bool increaseIsBetter           = false, bool failOnBaseline = true)
 {
     return(Definition(new SampleGroupDefinition(name, sampleUnit, aggregationType, threshold, increaseIsBetter,
                                                 failOnBaseline)));
 }
 public AggregationParameters(string counterCategory, string counterName, AggregationType counterAggregationType, Type counterType)
 {
     CounterCategory = counterCategory;
     CounterName = counterName;
     CounterAggregationType = counterAggregationType;
     CounterType = counterType;
 }
        protected TimeSeriesAggregationBase(AggregationType type, string name)
        {
            Aggregation = type;
            Name        = name ?? Aggregation.ToString();

            _values = new List <double>();
        }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FilteredTimeSeriesQueryRequest" /> class.
 /// </summary>
 /// <param name="metricIdentifier">The metric identifier.</param>
 /// <param name="samplingTypes">The sampling types.</param>
 /// <param name="dimensionFilters">The dimension filters.</param>
 /// <param name="startTimeUtc">The start time UTC.</param>
 /// <param name="endTimeUtc">The end time UTC.</param>
 /// <param name="seriesResolutionInMinutes">The series resolution in minutes.</param>
 /// <param name="aggregationType">Type of the aggregation.</param>
 /// <param name="topPropertyDefinition">The top property definition.</param>
 /// <param name="numberOfResultsToReturn">The number of results to return.</param>
 /// <param name="orderBy">The order by.</param>
 /// <param name="zeroAsNoValueSentinel">Indicates whether zero should be used as no value sentinel, or double.NaN.</param>
 /// <param name="outputDimensionNames">The dimension names to be used for the result time series.  If not set, same as the dimensions in the dimension filter.</param>
 /// <param name="lastValueMode">Indicating if the query should be fulfilled with last value mode. If true, null values in the query range requested will be filled with the last known value.</param>
 public FilteredTimeSeriesQueryRequest(
     MetricIdentifier metricIdentifier,
     IReadOnlyList <SamplingType> samplingTypes,
     IReadOnlyList <DimensionFilter> dimensionFilters,
     DateTime startTimeUtc,
     DateTime endTimeUtc,
     int seriesResolutionInMinutes,
     AggregationType aggregationType,
     PropertyDefinition topPropertyDefinition,
     int numberOfResultsToReturn,
     OrderBy orderBy,
     bool zeroAsNoValueSentinel,
     IReadOnlyList <string> outputDimensionNames = null,
     bool lastValueMode = false)
     : this(
         metricIdentifier,
         null,
         null,
         null,
         samplingTypes,
         dimensionFilters,
         startTimeUtc,
         endTimeUtc,
         seriesResolutionInMinutes,
         aggregationType,
         topPropertyDefinition,
         numberOfResultsToReturn,
         orderBy,
         zeroAsNoValueSentinel,
         false,
         outputDimensionNames,
         lastValueMode)
 {
 }
        private ExplicitAttribute CreateEnumerableOfEnumerableAttribute(AggregationType superOuterAggregation,
                                                                        AggregationType outerAggregation, AggregationType innerAggregation, ValueType data, bool unique)
        {
            var result = Model.New <ExplicitAttribute>(_currentSchema);

            result.Domain = superOuterAggregation;
            superOuterAggregation.UniqueElements = unique;
            superOuterAggregation.ElementType    = outerAggregation;
            outerAggregation.ElementType         = innerAggregation;

            if (data.tokVal == Tokens.TYPE)
            {
                innerAggregation.ElementType = data.val as SimpleType;
            }
            if (data.tokVal == Tokens.IDENTIFIER)
            {
                ToDoActions.Add(() =>
                {
                    innerAggregation.ElementType = Model.Get <NamedType>(t => t.Name == data.strVal).FirstOrDefault() ??
                                                   GetNamedAlias <NamedType>(result.ParentEntity.ParentSchema, data.strVal);
                    if (result.Domain == null)
                    {
                        throw new InstanceNotFoundException();
                    }
                });
            }
            return(result);
        }
        internal void LoadFromXml(XmlNode node)
        {
            MetadataClass metadataClass1 = this.Association.Class;

            try
            {
                MetadataClass metadataClass2 = metadataClass1.Metadata.Classes.Need(XmlUtils.NeedAttr(node, "ref-class"));
                this.FRefProperty           = metadataClass2.Properties.Find(XmlUtils.GetAttr(node, "ref-property")) ?? metadataClass2.IDProperty;
                this.FSelectorValue         = node.Name == "case" ? XmlUtils.NeedAttr(node, "value") : string.Empty;
                this.FAssociationObjectView = XmlUtils.GetAttr(node, "association-object-view", "default");
                if (this.Association.Property.IsAggregation)
                {
                    this.FAggregationRoleMemberName = XmlUtils.GetAttr(node, "role-prog-id", this.Association.Class.IdentName);
                    this.FAggregationBuiltIn        = XmlUtils.GetBoolAttr(node, "is-built-in");
                    this.FAggregationType           = (AggregationType)XmlUtils.GetEnumAttr(node, "aggregation-type", MetadataAssociationRef.FAggregationTypeNames, 0);
                    this.FAggregationObjectView     = XmlUtils.GetAttr(node, "aggregation-object-view", "default");
                    metadataClass2.Childs.Ensure(this);
                }
                metadataClass2.ExternalRefs.Add(this);
            }
            catch (Exception ex)
            {
                throw new MetadataException(string.Format("Ошибка загрузки свойства {0}", (object)this.Association.Property.Name), ex);
            }
        }
Exemple #10
0
        private static double?InterpretMetricValue(AggregationType metricAggregation, MetricValue relevantMetricValue)
        {
            switch (metricAggregation)
            {
            case AggregationType.Average:
                return(relevantMetricValue.Average);

            case AggregationType.Count:
                return(relevantMetricValue.Count);

            case AggregationType.Maximum:
                return(relevantMetricValue.Maximum);

            case AggregationType.Minimum:
                return(relevantMetricValue.Minimum);

            case AggregationType.Total:
                return(relevantMetricValue.Total);

            case AggregationType.None:
                return(0);

            default:
                throw new Exception($"Unable to determine the metrics value for aggregator '{metricAggregation}'");
            }
        }
Exemple #11
0
        /// <summary>
        /// Add a new data interval.
        /// </summary>
        /// <param name="security">The security.</param>
        /// <param name="resolution">The resolution.</param>
        /// <param name="aggregation">The aggregation.</param>
        /// <returns></returns>
        public DataAggregator AddInterval(Security security, Resolution resolution, AggregationType aggregation = AggregationType.QuoteBar)
        {
            //Get correct aggregator
            DataAggregator aggregator = null;

            switch (aggregation)
            {
            case AggregationType.QuoteBar:
                aggregator = resolution.IsTick
                        ? new QuoteBarAggregator(Convert.ToInt32(resolution.Ticks))
                        : new QuoteBarAggregator(resolution.TimeSpan.Value);
                break;

            case AggregationType.RenkoBar:
                aggregator = null;
                //aggregator = new RenkoAggregator(Convert.ToInt32(resolution.Ticks), null); //TODO: set renko type
                break;

            case AggregationType.TradeBar:
                aggregator = resolution.IsTick
                        ? new TradeAggregator(Convert.ToInt32(resolution.Ticks))
                        : new TradeAggregator(resolution.TimeSpan.Value);
                break;
            }

            //Add aggregator and return
            return(AddInterval(security, aggregator));
        }
Exemple #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type">MIN,MAX,AVERAGE</param>
        /// <returns></returns>
        public static IAggregation CreateSimpleAggregation(AggregationType type)
        {
            IAggregation aggregation = null;

            switch (type)
            {
            case AggregationType.MIN:
            {
                aggregation = new Min();
                break;
            }

            case AggregationType.MAX:
            {
                aggregation = new Max();
                break;
            }

            case AggregationType.AVERAGE:
            {
                aggregation = new Average();
                break;
            }

            default:
            {
                throw new NotImplementedException("Not supported yet.");
            }
            }
            return(aggregation);
        }
Exemple #13
0
        private EntitySchemaQueryColumn AddAggregatedColumn(JObject yAxisConfig)
        {
            AggregationType columnAggregationType = AggregationType.Count;
            string          aggregationType       = SerieParameters.Value <string>("func");

            if (!string.IsNullOrEmpty(aggregationType))
            {
                columnAggregationType = (AggregationType)Enum.Parse(typeof(AggregationType),
                                                                    aggregationType);
            }
            EntitySchemaQueryExpression columnExpression = EntitySchemaQuery.CreateSchemaColumnExpression(
                Esq.RootSchema, GroupColumnPath);

            columnExpression.UId = Guid.NewGuid();
            var queryFunction = new EntitySchemaAggregationQueryFunction(columnAggregationType.ToStrict(),
                                                                         columnExpression, Esq);

            if (columnAggregationType == AggregationType.Count)
            {
                queryFunction.AggregationEvalType = AggregationEvalType.Distinct;
            }
            EntitySchemaQueryColumn column = Esq.AddColumn(queryFunction);
            var columnMap = new Dictionary <string, object>();

            columnMap["valueAlias"]           = column.ValueExpression.Function.QueryAlias;
            columnMap["dataValueType"]        = columnExpression.SchemaColumn.DataValueType;
            entityColumnsMap[GroupColumnPath] = columnMap;
            yAxisConfig["dataValueType"]      = GetColumnDataValueType(columnExpression);
            return(column);
        }
Exemple #14
0
 public Header(AggregationType aggregationType, long maxRetention, double xFilesFactor, List <ArchiveInfo> archiveList)
 {
     this.AggregationType = aggregationType;
     this.MaxRetention    = maxRetention;
     this.xFilesFactor    = xFilesFactor;
     this.ArchiveList     = archiveList;
 }
        private double Aggregate(AggregationType aggregationType, IEnumerable <double> inputs)
        {
            switch (aggregationType)
            {
            case AggregationType.Sum:
                return(inputs.Sum());

            case AggregationType.Avg:
                return(inputs.Average());

            case AggregationType.Multiply:
                return(inputs.Aggregate(1.0, (x, y) => x * y));

            case AggregationType.Max:
                return(inputs.Max());

            case AggregationType.Min:
                return(inputs.Min());

            case AggregationType.MinAbs:
                return(inputs.Min());

            case AggregationType.MaxAbs:
                return(inputs.Max());
            }

            throw new ArgumentException();
        }
Exemple #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type">OWA,OWG</param>
        /// <param name="weights">required</param>
        /// <returns></returns>
        public static IAggregation CreateWeightAggregation(AggregationType type, List <decimal> weights)
        {
            IAggregation aggregation = null;

            switch (type)
            {
            case AggregationType.OWA:
            {
                aggregation = new OWA(weights);
                break;
            }

            case AggregationType.OWG:
            {
                aggregation = new OWG(weights);
                break;
            }

            default:
            {
                throw new NotImplementedException("Not supported yet.");
            }
            }
            return(aggregation);
        }
Exemple #17
0
        internal MetricPoint(
            AggregationType aggType,
            DateTimeOffset startTime,
            string[] keys,
            object[] values,
            double[] histogramExplicitBounds)
        {
            Debug.Assert((keys?.Length ?? 0) == (values?.Length ?? 0), "Key and value array lengths did not match.");
            Debug.Assert(histogramExplicitBounds != null, "Histogram explicit Bounds was null.");

            this.aggType           = aggType;
            this.StartTime         = startTime;
            this.Tags              = new ReadOnlyTagCollection(keys, values);
            this.EndTime           = default;
            this.runningValue      = default;
            this.snapshotValue     = default;
            this.deltaLastValue    = default;
            this.MetricPointStatus = MetricPointStatus.NoCollectPending;

            if (this.aggType == AggregationType.Histogram)
            {
                this.histogramBuckets = new HistogramBuckets(histogramExplicitBounds);
            }
            else if (this.aggType == AggregationType.HistogramSumCount)
            {
                this.histogramBuckets = new HistogramBuckets(null);
            }
            else
            {
                this.histogramBuckets = null;
            }
        }
Exemple #18
0
        /// <summary>
        ///     Queries Azure Monitor to get the latest value for a specific metric
        /// </summary>
        /// <param name="metricName">Name of the metric</param>
        /// <param name="aggregationType">Aggregation for the metric to use</param>
        /// <param name="aggregationInterval">Interval that is used to aggregate metrics</param>
        /// <param name="resourceId">Id of the resource to query</param>
        /// <param name="metricFilter">Optional filter to filter out metrics</param>
        /// <returns>Latest representation of the metric</returns>
        public async Task <double> QueryMetricAsync(string metricName, AggregationType aggregationType, TimeSpan aggregationInterval,
                                                    string resourceId, string metricFilter = null)
        {
            Guard.NotNullOrWhitespace(metricName, nameof(metricName));
            Guard.NotNullOrWhitespace(resourceId, nameof(resourceId));

            // Get all metrics
            var metricsDefinitions = await _authenticatedAzureSubscription.MetricDefinitions.ListByResourceAsync(resourceId);

            var metricDefinition = metricsDefinitions.SingleOrDefault(definition => definition.Name.Value.ToUpper() == metricName.ToUpper());

            if (metricDefinition == null)
            {
                throw new MetricNotFoundException(metricName);
            }

            var recordDateTime = DateTime.UtcNow;

            var closestAggregationInterval = DetermineAggregationInterval(metricName, aggregationInterval, metricDefinition.MetricAvailabilities);

            // Get the most recent metric
            var relevantMetric = await GetRelevantMetric(metricName, aggregationType, closestAggregationInterval, metricFilter, metricDefinition, recordDateTime);

            // Get the most recent value for that metric
            var mostRecentMetricValue = GetMostRecentMetricValue(metricName, relevantMetric.Timeseries, recordDateTime);

            // Get the metric value according to the requested aggregation type
            var requestMetricAggregate = InterpretMetricValue(aggregationType, mostRecentMetricValue);

            return(requestMetricAggregate);
        }
 internal AggregatorStore(
     string name,
     AggregationType aggType,
     AggregationTemporality temporality,
     int maxMetricPoints,
     double[] histogramBounds,
     string[] tagKeysInteresting = null)
 {
     this.name                     = name;
     this.maxMetricPoints          = maxMetricPoints;
     this.metricPointCapHitMessage = $"Maximum MetricPoints limit reached for this Metric stream. Configured limit: {this.maxMetricPoints}";
     this.metricPoints             = new MetricPoint[maxMetricPoints];
     this.currentMetricPointBatch  = new int[maxMetricPoints];
     this.aggType                  = aggType;
     this.temporality              = temporality;
     this.outputDelta              = temporality == AggregationTemporality.Delta ? true : false;
     this.histogramBounds          = histogramBounds;
     this.startTimeExclusive       = DateTimeOffset.UtcNow;
     if (tagKeysInteresting == null)
     {
         this.updateLongCallback   = this.UpdateLong;
         this.updateDoubleCallback = this.UpdateDouble;
     }
     else
     {
         this.updateLongCallback   = this.UpdateLongCustomTags;
         this.updateDoubleCallback = this.UpdateDoubleCustomTags;
         var hs = new HashSet <string>(tagKeysInteresting, StringComparer.Ordinal);
         this.tagKeysInteresting       = hs;
         this.tagsKeysInterestingCount = hs.Count;
     }
 }
Exemple #20
0
        public GroupByOperator(int groupByIndex, int aggregationIndex, string aggregationFunction)
        {
            this.GroupByIndex     = groupByIndex;
            this.AggregationIndex = aggregationIndex;
            switch (aggregationFunction)
            {
            case "max":
                this.Aggregation = AggregationType.Max;
                break;

            case "min":
                this.Aggregation = AggregationType.Min;
                break;

            case "sum":
                this.Aggregation = AggregationType.Sum;
                break;

            case "avg":
                this.Aggregation = AggregationType.Average;
                break;

            case "count":
                this.Aggregation = AggregationType.Count;
                break;

            default:
                this.Aggregation = AggregationType.Count;
                break;
            }
        }
        protected string AggregateFunc(AggregationType type)
        {
            switch (type)
            {
            case AggregationType.Sum:
                return("Sum");

            case AggregationType.Avg:
                return("Average");

            case AggregationType.Count:
                return("Count");

            case AggregationType.First:
                return("First");

            case AggregationType.Last:
                return("Last");

            case AggregationType.Min:
                return("Min");

            case AggregationType.Max:
                return("Max");

            default:
                return("Sum");
            }
        }
Exemple #22
0
        public GroupByFinalOperator(string aggregationFunction)
        {
            switch (aggregationFunction)
            {
            case "max":
                this.Aggregation = AggregationType.Max;
                break;

            case "min":
                this.Aggregation = AggregationType.Min;
                break;

            case "sum":
                this.Aggregation = AggregationType.Sum;
                break;

            case "avg":
                this.Aggregation = AggregationType.Average;
                break;

            case "count":
                this.Aggregation = AggregationType.Count;
                break;

            default:
                this.Aggregation = AggregationType.Count;
                break;
            }
        }
 public TimeSeriesAggregation(AggregationType type, string name = null) : base(type, name)
 {
     if (type >= AggregationType.Average)
     {
         throw new ArgumentException(nameof(type));
     }
 }
Exemple #24
0
 public AtomicIntAggregator(Allocator allocator, AggregationType type = AggregationType.Sum)
 {
     mAllocator = allocator;
     mAggType   = (byte)(type);
     mDataPtr   = (Data *)UnsafeUtility.Malloc(12, 16, allocator);
     Reset();
 }
Exemple #25
0
        private decimal checkASPOWAAggregationType(AggregationType type, decimal oldValue, decimal newValue)
        {
            decimal result = 0;

            switch (type)
            {
            case AggregationType.ASPOWA_MIN:
            {
                result = Math.Min(oldValue, newValue);
                break;
            }

            case AggregationType.ASPOWA_MAX:
            {
                result = Math.Max(oldValue, newValue);
                break;
            }

            case AggregationType.ASPOWA_MEAN:
            {
                result = (oldValue + newValue) / 2m;
                break;
            }
            }
            return(result);
        }
        internal MetricPoint(
            AggregatorStore aggregatorStore,
            AggregationType aggType,
            string[] keys,
            object[] values,
            double[] histogramExplicitBounds)
        {
            Debug.Assert(aggregatorStore != null, "AggregatorStore was null.");
            Debug.Assert((keys?.Length ?? 0) == (values?.Length ?? 0), "Key and value array lengths did not match.");
            Debug.Assert(histogramExplicitBounds != null, "Histogram explicit Bounds was null.");

            this.aggType           = aggType;
            this.Tags              = new ReadOnlyTagCollection(keys, values);
            this.runningValue      = default;
            this.snapshotValue     = default;
            this.deltaLastValue    = default;
            this.MetricPointStatus = MetricPointStatus.NoCollectPending;

            if (this.aggType == AggregationType.Histogram)
            {
                this.histogramBuckets = new HistogramBuckets(histogramExplicitBounds);
            }
            else if (this.aggType == AggregationType.HistogramSumCount)
            {
                this.histogramBuckets = new HistogramBuckets(null);
            }
            else
            {
                this.histogramBuckets = null;
            }

            // Note: Intentionally set last because this is used to detect valid MetricPoints.
            this.aggregatorStore = aggregatorStore;
        }
Exemple #27
0
        private void AggregateAffectedPermissions(PermissionTypeBase permission, AggregationType aggregationType, Dictionary <int, PermissionTypeBase> aggregation)
        {
            if (aggregation.ContainsKey(permission.Index))
            {
                return;
            }

            aggregation[permission.Index] = permission;
            PermissionTypeBase[] morePermissions;
            switch (aggregationType)
            {
            case AggregationType.Allow:
                morePermissions = permission.Allows;
                break;

            case AggregationType.Deny:
                morePermissions = permission.Denies.ToArray();
                break;

            default:
                throw new NotSupportedException("Unknown AggregationType: " + aggregationType);
            }

            if (morePermissions?.Length > 0)
            {
                foreach (var perm in morePermissions)
                {
                    if (perm != null)
                    {
                        AggregateAffectedPermissions(perm, aggregationType, aggregation);
                    }
                }
            }
        }
Exemple #28
0
        private bool TryGetAggregationType(string methodName, out AggregationType aggregationType)
        {
            switch (methodName)
            {
            case "Average":
                aggregationType = AggregationType.Average;
                return(true);

            case "Count":
            case "LongCount":
            case "Sum":
                aggregationType = AggregationType.Sum;
                return(true);

            case "First":
                aggregationType = AggregationType.First;
                return(true);

            case "Last":
                aggregationType = AggregationType.Last;
                return(true);

            case "Max":
                aggregationType = AggregationType.Max;
                return(true);

            case "Min":
                aggregationType = AggregationType.Min;
                return(true);
            }

            aggregationType = 0; // dummy assignment to appease compiler
            return(false);
        }
Exemple #29
0
 public Header(AggregationType aggregationType, long maxRetention, double xFilesFactor, List<ArchiveInfo> archiveList)
 {
     this.AggregationType = aggregationType;
     this.MaxRetention = maxRetention;
     this.xFilesFactor = xFilesFactor;
     this.ArchiveList = archiveList;
 }
        public void AggregationFunctions(AggregationType type)
        {
            var queryJson = new QueryJson
            {
                Select = new List <string> {
                    "Vendor.VendorName"
                },
                Aggregations = new List <AggregationJson>
                {
                    new AggregationJson
                    {
                        Column   = "Invoice.Amount",
                        Function = type
                    }
                },
                Skip = 5,
                Take = 10
            };

            var query        = new Query(queryJson, Schema);
            var filterParams = new DictionaryFilterParameters();

            AssertSameSql(query.ToSql(Formatter, filterParams, Enumerable.Empty <Filter>()), $@"
                select |tbl0|!|VendorName| Select0, {type}(|tbl1|!|Amount|) Value0
                from |TestSchema|!|Invoice| tbl1
                join |TestSchema|!|Vendor| tbl0 on |tbl0|!|Id| = |tbl1|!|VendorId|
                group by |tbl0|!|VendorName|
                order by {type}(|tbl1|!|Amount|) desc
                skip:5 take:10
            ");
            filterParams.Names.Should().HaveCount(0);
        }
Exemple #31
0
        public virtual ActionResult FillProbabilities(int id, AggregationType aggregationType, FillRatingsViewModel viewModel)
        {
            Project project = _projectService.Get(id);

            if (ModelState.IsValid)
            {
                foreach (var rating in viewModel.Ratings)
                {
                    var weight  = project.WeightGenerationResults.Single(x => x.WeightGenerationResultId == rating.WeightId);
                    var factors = weight.GetFirstAlternativeFactors().ToList();

                    for (int i = 0; i < factors.Count; i++)
                    {
                        weight.Items.Where(x => x.FactorId == factors[i].FactorId).ToList().ForEach(x => x.Probability = rating.Values[i].GetValue());
                    }
                }

                _projectService.Update(project);

                return(RedirectToAction(MVC.Projects.DoAggregation(id, aggregationType)));
            }

            viewModel     = GetFillRatingsViewModel(project, viewModel);
            ViewBag.Title = ViewTitles.FillProbabilities;
            return(View(Views.FillRatings, viewModel));
        }
Exemple #32
0
        private IWithMetricsQueryExecute CreateMetricsQuery(AggregationType metricAggregation, TimeSpan metricsInterval, string metricFilter, string metricDimension,
                                                            int?metricLimit, IMetricDefinition metricDefinition, DateTime recordDateTime)
        {
            var historyStartingFromInHours = _azureMonitorIntegrationConfiguration.Value.History.StartingFromInHours;
            var metricQuery = metricDefinition.DefineQuery()
                              .StartingFrom(recordDateTime.AddHours(-historyStartingFromInHours))
                              .EndsBefore(recordDateTime)
                              .WithAggregation(metricAggregation.ToString())
                              .WithInterval(metricsInterval);

            var queryLimit = metricLimit ?? Defaults.MetricDefaults.Limit;

            if (string.IsNullOrWhiteSpace(metricFilter) == false)
            {
                var filter = metricFilter.Replace("/", "%2F");
                metricQuery.WithOdataFilter(filter);
                metricQuery.SelectTop(queryLimit);
            }

            if (string.IsNullOrWhiteSpace(metricDimension) == false)
            {
                metricQuery.WithOdataFilter($"{metricDimension} eq '*'");
                metricQuery.SelectTop(queryLimit);
            }

            return(metricQuery);
        }
 public AggregationOperationResult(AggregationType aggregationType, IEnumerable<Tuple<string, double>> list)
     : this(aggregationType)
 {
     foreach (Tuple<string, double> tuple in list)
     {
         Value.Add(new KeyValuePair<string, double>(tuple.Item1, tuple.Item2));
     }
 }
 public AggregatedSkillResult(string displayName, bool isHeal, AggregationType type, ISyncedCollection<SkillResult> skillLog)
 {
     DisplayName = displayName;
     IsHeal = isHeal;
     AggregationType = type;
     SkillLog = skillLog;
     SkillLog.CollectionChanged += SkillLog_CollectionChanged;
 }
 public TotalAggregationResult(string counterCategory, string counterName, AggregationType counterAggregationType, IEnumerable<GroupAggregationResult> groupAggregationResults)
 {
     CounterCategory = counterCategory;
     CounterName = counterName;
     CounterAggregationType = counterAggregationType;
     ResultGroups = groupAggregationResults;
     AllSources = groupAggregationResults.Select(g => g.CounterGroup.Source).Distinct().Where(g => g != "ALL_SOURCES");
     AllInstances = groupAggregationResults.Select(g => g.CounterGroup.Instance).Distinct().Where(g => g != "ALL_INSTANCES");
     AllExtendedDatas = groupAggregationResults.Select(g => g.CounterGroup.ExtendedData).Distinct().Where(g => g != "ALL_EXTDATA");
 }
        private DerivedUnit(Unit left, Unit right, AggregationType aggregation)
        {
            if (left == null)
                throw new ArgumentNullException("left");

            if (right == null)
                throw new ArgumentNullException("right");

            this.left = left;
            this.right = right;
            this.aggregation = aggregation;
        }
        public static bool TryParse(string value, out AggregationType aggregationType)
        {
            aggregationType = AggregationType.Count;
            if (value == null)
                return false;
            if (_dic.ContainsKey(value.ToLower()))
            {
                aggregationType = _dic[value.ToLower()];
                return true;

            }
            return false;
        }
        public CounterAggregator(string counterCategory, string counterName, AggregationType aggregationType, Type inputType, string percentileAndDistributionParameters)
        {
            if (String.IsNullOrEmpty(counterCategory) || String.IsNullOrEmpty(counterName))
                throw new ArgumentException("counterCategory and counterName must not be empty");

            switch (aggregationType)
            {
                case AggregationType.Percentile:
                    {
                        _percentileParameters =
                            percentileAndDistributionParameters.Split('|').Select(Double.Parse).ToList();
                        break;
                    }
                case AggregationType.ValueDistributionGroups:
                    {

                        var t1 = percentileAndDistributionParameters.Split('|');
                        if (t1.All(t => t.Contains("-")))
                        {
                            _distributionParameters = t1.Select(
                                t =>
                                new Tuple<UniversalValue, UniversalValue>(
                                    UniversalValue.ParseFromString(inputType, t.Split('-')[0]),
                                    UniversalValue.ParseFromString(inputType, t.Split('-')[1]))).ToList();
                        }
                        else
                        {
                            _distributionParameters =
                                FromListToGroup(t1.Select(t => UniversalValue.ParseFromString(inputType, t)).ToList());
                        }



                        break;
                    }

            }
            //_percentileParameters = new List<double>() { 25, 50, 75 };
    
            CounterCategory  = counterCategory;
            CounterName = counterName;
            AggregationType = aggregationType;
            EventSelector = CreateEventSelector();
            AggregationAction = CreateAggregationAction();
            InputType = inputType;
            _onResult = OnResult();
            

        }
 public AggregationAttribute(AggregationType at)
 {
     Type = at;
     DISTINCT = false;
 }
 public  AggregationAttribute(AggregationType at,bool dist)
 {
     Type = at;
     DISTINCT = dist;
 }
Exemple #41
0
 public static double Aggregate(AggregationType aggregationType, IEnumerable<double> knownValues)
 {
     switch (aggregationType)
     {
         case AggregationType.Average:
             return knownValues.Average();
         case AggregationType.Sum:
             return knownValues.Sum();
         case AggregationType.Last:
             return knownValues.Last();
         case AggregationType.Max:
             return knownValues.Max();
         case AggregationType.Min:
             return knownValues.Min();
         default:
             throw new InvalidAggregationMethodException(string.Format("Unrecognized aggregation method {0}", aggregationType));
     }
 }
 public virtual ActionResult FillRatings(int id, AggregationType aggregationType)
 {
     var project = _projectService.Get(id);
     FillRatingsViewModel vm = GetFillRatingsViewModel(project);
     ViewBag.Title = ViewTitles.FillRatings;
     return View(vm);
 }
 protected string AggregateFunc(AggregationType type)
 {
     switch (type)
     {
         case AggregationType.Sum:
             return "Sum";
         case AggregationType.Avg:
             return "Average";
         case AggregationType.Count:
             return "Count";
         case AggregationType.First:
             return "First";
         case AggregationType.Last:
             return "Last";
         case AggregationType.Min:
             return "Min";
         case AggregationType.Max:
             return "Max";
         default:
             return "Sum";
     }
 }
        public virtual ActionResult InputLambda(int id, AggregationType aggregationType, InputLambdaViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                return RedirectToAction(MVC.Projects.DoAggregation(id, aggregationType, viewModel.GetValue()));
            }

            return View(viewModel);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type">MIN,MAX,AVERAGE</param>
        /// <returns></returns>
        public static IAggregation CreateSimpleAggregation(AggregationType type)
        {
            IAggregation aggregation = null;

            switch (type)
            {
                case AggregationType.MIN:
                    {
                        aggregation = new Min();
                        break;
                    }
                case AggregationType.MAX:
                    {
                        aggregation = new Max();
                        break;
                    }
                case AggregationType.AVERAGE:
                    {
                        aggregation = new Average();
                        break;
                    }
                default:
                    {
                        throw new NotImplementedException("Not supported yet.");
                    }
            }
            return aggregation;
        }
 public static bool IsSameSkillAs(this SkillResult skillResult, SkillResult other, AggregationType type)
 {
     return skillResult.AggregatedSkillName(type) == other.AggregatedSkillName(type) &&
            skillResult.IsHeal == other.IsHeal;
 }
 private static string AggregatedSkillName(this SkillResult skillResult, AggregationType type)
 {
     switch (type)
     {
         case AggregationType.Id:
             return skillResult.SkillNameDetailed;
         case AggregationType.Name:
             return skillResult.SkillShortName;
         default:
             return string.Empty;
     }
 }
 public static Unit CreateInstance(Unit left, Unit right, AggregationType aggregation)
 {
     return new DerivedUnit(left, right, aggregation);
 }
 public virtual void Init()
 {
     newTS = new TimeSeries();
     newTS.TimeUnits = Core.TimeUnits.DAYS;
     aggType = AggregationType.AVERAGE;
 }
Exemple #50
0
		public GroupExpr (ExprSingle left, ExprSingle right, AggregationType aggrType)
			: base (left, right)
		{
			this.aggrType = aggrType;
		}
        private IEnumerable<AggregationResult> GetAggregationResult(Project project, AggregationType aggregationType, decimal? lambda = null)
        {
            var aggregationResult = new AggregationResult();
            aggregationResult.Items = new List<AggregationResultItem>();
            aggregationResult.Project = project;

            IAggregation aggregation = null;

            switch (aggregationType)
            {
                case AggregationType.MIN:
                case AggregationType.MAX:
                case AggregationType.AVERAGE:
                    aggregation = AggregationFactory.CreateSimpleAggregation(aggregationType);
                    foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId))
                    {
                        var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId)
                            .OrderBy(x => x.FactorId).ToList();
                        var points = row.Select(x => x.Points).ToList();

                        var calculatedAggregation = aggregation.Calc(points);
                        aggregationResult.Items.Add(new AggregationResultItem()
                        {
                            Alternative = alternative,
                            Aggregation = calculatedAggregation,
                        });
                    }
                    break;
                case AggregationType.OWA:
                case AggregationType.OWG:
                    foreach (var weight in project.WeightGenerationResults)
                    {
                        aggregationResult = new AggregationResult();
                        aggregationResult.Items = new List<AggregationResultItem>();
                        aggregationResult.Project = project;
                        aggregationResult.Weight = weight;

                        foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId))
                        {
                            var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId)
                                .OrderBy(x => x.FactorId).ToList();
                            var points = row.Select(x => x.Points).ToList();

                            List<decimal> weights = weight.GetWeights(alternative);

                            aggregation = AggregationFactory.CreateWeightAggregation(aggregationType, weights.ToList());

                            var calculatedAggregation = aggregation.Calc(points);
                            aggregationResult.Items.Add(new AggregationResultItem()
                            {
                                Alternative = alternative,
                                Aggregation = calculatedAggregation
                            });
                        }

                        yield return aggregationResult;
                    }
                    break;

                case AggregationType.IOWA:
                case AggregationType.IOWG:
                    foreach (var weight in project.WeightGenerationResults)
                    {
                        aggregationResult = new AggregationResult();
                        aggregationResult.Items = new List<AggregationResultItem>();
                        aggregationResult.Project = project;
                        aggregationResult.Weight = weight;

                        foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId))
                        {
                            var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId)
                                .OrderBy(x => x.FactorId).ToList();
                            var points = row.Select(x => x.Points).ToList();

                            List<decimal> weights = weight.GetWeights(alternative);
                            List<decimal> ratings = weight.GetRatings(alternative);

                            aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), ratings);

                            var calculatedAggregation = aggregation.Calc(points);
                            aggregationResult.Items.Add(new AggregationResultItem()
                            {
                                Alternative = alternative,
                                Aggregation = calculatedAggregation
                            });
                        }

                        yield return aggregationResult;
                    }
                    break;
                case AggregationType.IGOWA:
                    foreach (var weight in project.WeightGenerationResults)
                    {
                        aggregationResult = new AggregationResult();
                        aggregationResult.Items = new List<AggregationResultItem>();
                        aggregationResult.Project = project;
                        aggregationResult.Weight = weight;

                        foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId))
                        {
                            var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId)
                                .OrderBy(x => x.FactorId).ToList();
                            var points = row.Select(x => x.Points).ToList();

                            List<decimal> weights = weight.GetWeights(alternative);
                            List<decimal> ratings = weight.GetRatings(alternative);

                            aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), ratings, lambda.Value);

                            var calculatedAggregation = aggregation.Calc(points);
                            aggregationResult.Items.Add(new AggregationResultItem()
                            {
                                Alternative = alternative,
                                Aggregation = calculatedAggregation
                            });
                        }

                        yield return aggregationResult;
                    }
                    break;
                case AggregationType.GOWA:
                    foreach (var weight in project.WeightGenerationResults)
                    {
                        aggregationResult = new AggregationResult();
                        aggregationResult.Items = new List<AggregationResultItem>();
                        aggregationResult.Project = project;
                        aggregationResult.Weight = weight;
                        aggregationResult.Lambda = lambda;

                        foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId))
                        {
                            var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId)
                                .OrderBy(x => x.FactorId).ToList();
                            var points = row.Select(x => x.Points).ToList();

                            List<decimal> weights = weight.GetWeights(alternative);

                            aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), lambda.Value);

                            var calculatedAggregation = aggregation.Calc(points);
                            aggregationResult.Items.Add(new AggregationResultItem()
                            {
                                Alternative = alternative,
                                Aggregation = calculatedAggregation
                            });
                        }

                        yield return aggregationResult;
                    }
                    break;
                case AggregationType.POWA:
                    foreach (var weight in project.WeightGenerationResults)
                    {
                        aggregationResult = new AggregationResult();
                        aggregationResult.Items = new List<AggregationResultItem>();
                        aggregationResult.Project = project;
                        aggregationResult.Weight = weight;
                        aggregationResult.Lambda = lambda;

                        foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId))
                        {
                            var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId)
                                .OrderBy(x => x.FactorId).ToList();
                            var points = row.Select(x => x.Points).ToList();

                            List<decimal> weights = weight.GetWeights(alternative);

                            List<decimal> probabilities = weight.GetProbabilities(alternative);

                            aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), probabilities, lambda);

                            var calculatedAggregation = aggregation.Calc(points);
                            aggregationResult.Items.Add(new AggregationResultItem()
                            {
                                Alternative = alternative,
                                Aggregation = calculatedAggregation
                            });
                        }

                        yield return aggregationResult;
                    }
                    break;
                case AggregationType.ASPOWA_MIN:
                case AggregationType.ASPOWA_MAX:
                case AggregationType.ASPOWA_MEAN:
                    foreach (var weight in project.WeightGenerationResults)
                    {
                        aggregationResult = new AggregationResult();
                        aggregationResult.Items = new List<AggregationResultItem>();
                        aggregationResult.Project = project;
                        aggregationResult.Weight = weight;
                        aggregationResult.Lambda = lambda;

                        foreach (var alternative in project.Alternatives.OrderBy(x => x.AlternativeId))
                        {
                            var row = project.FinalAssessment.Items.Where(x => x.AlternativeId == alternative.AlternativeId)
                                .OrderBy(x => x.FactorId).ToList();
                            var points = row.Select(x => x.Points).ToList();

                            List<decimal> weights = weight.GetWeights(alternative);

                            List<decimal> possibilities = weight.GetPossibilities(alternative);

                            aggregation = AggregationFactory.CreateParamAggregation(aggregationType, weights.ToList(), possibilities, lambda);

                            var calculatedAggregation = aggregation.Calc(points);
                            aggregationResult.Items.Add(new AggregationResultItem()
                            {
                                Alternative = alternative,
                                Aggregation = calculatedAggregation
                            });
                        }

                        yield return aggregationResult;
                    }
                    break;
            }

            yield return aggregationResult;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type">OWA,OWG</param>
        /// <param name="weights">required</param>
        /// <returns></returns>
        public static IAggregation CreateWeightAggregation(AggregationType type, List<decimal> weights)
        {
            IAggregation aggregation = null;

            switch (type)
            {
                case AggregationType.OWA:
                    {
                        aggregation = new OWA(weights);
                        break;
                    }
                case AggregationType.OWG:
                    {
                        aggregation = new OWG(weights);
                        break;
                    }
                default:
                    {
                        throw new NotImplementedException("Not supported yet.");
                    }
            }
            return aggregation;
        }
 public virtual ActionResult InputLambda(int id, AggregationType aggregationType)
 {
     return View(new InputLambdaViewModel());
 }
        /// <summary>
        ///  Aggregations: 
        ///    GOWA    - aditional parameters [alfa] 
        ///    POWA    - aditional parameters [beta, points]
        ///    IOWA    - aditional parameters [ratings] 
        ///    IGOWA   - aditional parameters [ratings, alfa] 
        ///    IOWG    - aditional parameters [ratings] 
        ///   ASPOWA  - aditional parameters [probability]
        /// Necessary parameter: weights
        /// </summary>
        /// <param name="type"></param>
        /// <param name="weights"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static IAggregation CreateParamAggregation(AggregationType type, List<decimal> weights, params Object[] param)
        {
            IAggregation aggregation = null;

            switch (type)
            {
                case AggregationType.GOWA:
                    {
                        if (param[0] is decimal)
                        {
                            decimal p = (decimal)param[0];
                            aggregation = new GOWA(weights, p);
                        }
                        else
                        {
                            throw new ArgumentException("Invalid Parameter");
                        }
                        break;
                    }
                case AggregationType.POWA:
                    {
                        if ((param.Length == 2) && (param[0] is List<decimal>) && (param[1] is decimal))
                        {
                            List<decimal> p = (List<decimal>)param[0];
                            decimal beta = (decimal)param[1];
                            aggregation = new POWA(weights, p, beta);
                        }
                        else
                        {
                            throw new ArgumentException("Invalid Parameter");
                        }
                        break;
                    }
                case AggregationType.IOWA:
                    {
                        if (param[0] is List<decimal>)
                        {
                            List<decimal> p = (List<decimal>)param[0];

                            IOWA iowa = new IOWA(weights);
                            iowa.Ratings = p;
                            aggregation = iowa;
                        }
                        else
                        {
                            throw new ArgumentException("Invalid Parameter");
                        }
                        break;
                    }

                case AggregationType.IGOWA:
                    {
                        if ((param.Length == 2) && (param[0] is List<decimal>) && (param[1] is decimal))
                        {
                            List<decimal> rating = (List<decimal>)param[0];
                            decimal p = (decimal)param[1];
                            IGOWA igowa = new IGOWA(weights, p);
                            igowa.Ratings = rating;
                            aggregation = igowa;
                        }
                        else
                        {
                            throw new ArgumentException("Invalid Parameter");
                        }
                        break;
                    }
                case AggregationType.IOWG:
                    {
                        if ((param.Length == 1) && (param[0] is List<decimal>))
                        {
                            List<decimal> rating = (List<decimal>)param[0];
                            IOWG iowg = new IOWG(weights);
                            iowg.Ratings = rating;
                            aggregation = (IOWG)iowg;
                        }
                        else
                        {
                            throw new ArgumentException("Invalid Parameter");
                        }
                        break;
                    }
                case AggregationType.ASPOWA_MIN:
                    {
                        if (param[0] is List<decimal>)
                        {
                            List<decimal> p = (List<decimal>)param[0];
                            aggregation = new ASPOWA(weights, p, (decimal)param[1], AggregationType.ASPOWA_MIN);
                        }
                        else
                        {
                            throw new ArgumentException("Invalid Parameter");
                        }
                        break;
                    }
                case AggregationType.ASPOWA_MAX:
                    {
                        if (param[0] is List<decimal>)
                        {
                            List<decimal> p = (List<decimal>)param[0];
                            aggregation = new ASPOWA(weights, p, (decimal)param[1], AggregationType.ASPOWA_MAX);
                        }
                        else
                        {
                            throw new ArgumentException("Invalid Parameter");
                        }
                        break;
                    }
                case AggregationType.ASPOWA_MEAN:
                    {
                        if (param[0] is List<decimal>)
                        {
                            List<decimal> p = (List<decimal>)param[0];
                            aggregation = new ASPOWA(weights, p, (decimal)param[1], AggregationType.ASPOWA_MEAN);
                        }
                        else
                        {
                            throw new ArgumentException("Invalid Parameter");
                        }
                        break;
                    }
                default:
                    {
                        throw new NotImplementedException("Not supported yet.");
                    }
            }
            return aggregation;
        }
        public virtual ActionResult FillRatings(int id, AggregationType aggregationType, FillRatingsViewModel viewModel)
        {
            Project project = _projectService.Get(id);

            if (ModelState.IsValid)
            {
                foreach (var rating in viewModel.Ratings)
                {
                    var weight = project.WeightGenerationResults.Single(x => x.WeightGenerationResultId == rating.WeightId);
                    var factors = weight.GetFirstAlternativeFactors().ToList();

                    for (int i = 0; i < factors.Count; i++)
                    {
                        weight.Items.Where(x => x.FactorId == factors[i].FactorId).ToList().ForEach(x => x.Rating = rating.Values[i].GetValue());
                    }
                }

                _projectService.Update(project);

                return RedirectToAction(MVC.Projects.DoAggregation(id, aggregationType));
            }

            viewModel = GetFillRatingsViewModel(project, viewModel);
            ViewBag.Title = ViewTitles.FillRatings;
            return View(viewModel);
        }
Exemple #56
0
 /// <summary>
 /// 
 /// </summary>
 /// <remarks></remarks>
 /// <seealso cref=""/>
 /// <param name="value"></param>
 /// <returns></returns>
 public static string GetAggregationTypeAsString(AggregationType value)
 {
     switch (value)
     {
         case AggregationType.Distinct: return "distinct";
         case AggregationType.Union: return "union";
         default: return "distinct";
     }
 }
        public virtual ActionResult DoAggregation(int id, AggregationType aggregationType, decimal? lambda = null)
        {
            var project = _projectService.Get(id);

            //check weights

            if ((new AggregationType[] { AggregationType.IOWG, AggregationType.IOWA, AggregationType.IGOWA }).Contains(aggregationType) &&
                project.WeightGenerationResults.Any(x => x.Items.First().Rating == null))
            {
                return RedirectToAction(MVC.Projects.FillRatings(id, aggregationType));
            }

            if (aggregationType == AggregationType.POWA &&
            project.WeightGenerationResults.Any(x => x.Items.First().Probability == null))
            {
                return RedirectToAction(MVC.Projects.FillProbabilities(id, aggregationType));
            }

            if ((new AggregationType[] { AggregationType.ASPOWA_MIN, AggregationType.ASPOWA_MAX, AggregationType.ASPOWA_MEAN }).Contains(aggregationType) &&
            project.WeightGenerationResults.Any(x => x.Items.First().Possibility == null))
            {
                return RedirectToAction(MVC.Projects.FillPossibilities(id, aggregationType));
            }

            if ((aggregationType == AggregationType.IGOWA ||
                aggregationType == AggregationType.GOWA ||
                aggregationType == AggregationType.POWA ||
                aggregationType == AggregationType.ASPOWA_MIN ||
                aggregationType == AggregationType.ASPOWA_MEAN ||
                aggregationType == AggregationType.ASPOWA_MAX) && !lambda.HasValue)
            {
                return RedirectToAction(MVC.Projects.InputLambda(id, aggregationType));
            }

            var aggregationResult = GetAggregationResult(project, aggregationType, lambda);

            foreach (var item in aggregationResult)
            {
                item.AggregationType = aggregationType;
                project.AggregationResults.Add(item);
            }

            _projectService.Update(project);

            return Redirect(Url.Action(MVC.Projects.Details(id)) + "#aggregation-tab");
        }
Exemple #58
0
 public ASPOWA(List<decimal> weights, List<decimal> p, decimal beta, AggregationType type)
     : base(weights, p, beta)
 {
     this.type = type;
 }
Exemple #59
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <param name="archiveList"></param>
        /// <param name="xFilesFactor">specifies the fraction of data points in a propagation interval that must have known values for a propagation to occur</param>
        /// <param name="aggregationType">the function to use when propagating data</param>
        /// <param name="sparse"></param>
        public static void Create(
            string path
            , List<ArchiveInfo> archiveList
            , double xFilesFactor = 0.5
            , AggregationType aggregationType = AggregationType.Average
            , bool sparse = false)
        {
            ValidateArchiveList(archiveList);

            if (File.Exists(path))
            {
                throw new InvalidConfigurationException(string.Format("File {0} already exists!", path));
            }

            using (var fh = File.Open(path, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
            {
                try
                {
                    using (var writer = new EndianBinaryWriter(EndianBitConverter.Big, new NonClosingStreamWrapper(fh)))
                    {
                        writer.Write((long)aggregationType);
                        var maxRetention = archiveList.Max(x => x.Retention);
                        writer.Write(maxRetention);
                        writer.Write(xFilesFactor);
                        writer.Write((long)archiveList.Count);
                        var headerSize = MetadataSize + (ArchiveInfoSize * archiveList.Count);
                        long archiveOffsetPointer = headerSize;

                        foreach (var archive in archiveList) // should be sorted by ValidateArchiveList
                        {
                            writer.Write(archiveOffsetPointer);
                            writer.Write(archive.SecondsPerPoint);
                            writer.Write(archive.Points);
                            archiveOffsetPointer += archive.Points * PointSize;
                        }

                        if (sparse)
                        {
                            fh.Seek(archiveOffsetPointer - 1, SeekOrigin.Begin);
                            writer.Write((long)0);
                        }
                        else
                        {
                            var remaining = archiveOffsetPointer - headerSize;
                            var buffer = new byte[8];
                            writer.BitConverter.CopyBytes((long)0, buffer, 0);
                            // create a 16k buffer to ZERO the file
                            var chunkBuffer = new byte[16384];
                            for (int i = 0; i < chunkBuffer.Length; i += buffer.Length)
                            {
                                buffer.CopyTo(chunkBuffer, i);
                            }
                            while (remaining > chunkBuffer.Length)
                            {
                                writer.Write(chunkBuffer);
                                remaining -= chunkBuffer.Length;
                            }
                            writer.Write(chunkBuffer, 0, (int)remaining);
                        }
                    }
                    fh.Flush(AutoFlush);
                }
                finally
                {
                    fh.Close();
                }
            }
        }
Exemple #60
0
 private decimal checkASPOWAAggregationType(AggregationType type, decimal oldValue, decimal newValue)
 {
     decimal result = 0;
     switch (type)
     {
         case AggregationType.ASPOWA_MIN:
             {
                 result = Math.Min(oldValue, newValue);
                 break;
             }
         case AggregationType.ASPOWA_MAX:
             {
                 result = Math.Max(oldValue, newValue);
                 break;
             }
         case AggregationType.ASPOWA_MEAN:
             {
                 result = (oldValue + newValue) / 2m;
                 break;
             }
     }
     return result;
 }