/// <inheritdoc /> public void AddProvider(string name, IMetricProvider provider) { Guard.NotNullOrWhitespace(nameof(name), name); Guard.NotNull(nameof(provider), provider); _providers.AddOrUpdate(name, provider, (currentName, currentProvider) => provider); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Usage ./MetricsDemo.exe {ArmId}"); Console.WriteLine("For VM: ArmId format is /subscriptions/{subscriptionId}/resourceGroups/{RG}/providers/Microsoft.Compute/virtualMachines/{vmName}"); Console.WriteLine("For Storage: ArmId format is /subscriptions/{subsriptionId}/resourcegroups/{RG}/providers/Microsoft.Storage/storageaccounts/{accountName}/services/{serviceType}"); return; } IMetricProvider metricProvier = MetricProviderFactory.GetProvider(); // Query Metircs var resourceId = args[0]; Console.WriteLine(metricProvier.GetMetricsDefinitions(resourceId, "")); var values = metricProvier.GetMetricsValues(resourceId, "").Result; foreach (var value in values) { Console.WriteLine(value); } Console.ReadLine(); }
public void AddMetricProvider(IMetricProvider provider) { this.metricProviders.Add(provider); }
public AccountProductMetricController(IMetricProvider <AccountProductModel> metricProvider, IAppSettings appSettings) { _metricProvider = metricProvider; _appSettings = appSettings; }
public Analyzer(IMetricProvider metricProvider, string[] supportedFileTypesForAnalysis) { _metricsProvider = metricProvider; _supportedFileTypesForAnalysis = supportedFileTypesForAnalysis; }
public static void SetDefaultMetrics(IMetricProvider logProvider) { _current = new MetricStore(logProvider); }
public MetricStore(IMetricProvider provider) { _provider = provider; }
public AccountProductMetric(IMetricProvider <AccountProductModel> metricProviderService, IAppSettings appSettings) { _appSettings = appSettings; Field <ListGraphType <AccountProduct> >("accountProducts", resolve: context => metricProviderService.GetAll(_appSettings.AccountProductMetricEndpoint)); }
public T Sum_MinCurrentMetricSum(T argument, Func <T, int, T> memberFormula, int startIndex, int endIndex, IMetricProvider <T> metricProvider) { // Все храним в LinkedList. LinkedList <KeyValuePair <int, T> > listPositive = new LinkedList <KeyValuePair <int, T> >(); // с положительными метриками LinkedList <KeyValuePair <int, T> > listNegative = new LinkedList <KeyValuePair <int, T> >(); // с отрицательными метриками LinkedList <KeyValuePair <int, T> > listZero = new LinkedList <KeyValuePair <int, T> >(); // с нулевыми метриками IComparer <KeyValuePair <int, T> > comparer = new _ABS_INT_COMPARER().createKVPComparerOnKey <int, T>(); // ---- добавляем в список ----- if (startIndex >= endIndex) { for (int i = startIndex; i <= endIndex; i++) { T res = memberFormula(argument, i); int m = metricProvider.GetMetric(res); if (m > 0) { listPositive.AddLast(new KeyValuePair <int, T>(m, res)); } else if (m < 0) { listNegative.AddLast(new KeyValuePair <int, T>(m, res)); } else { listZero.AddLast(new KeyValuePair <int, T>(0, res)); } } } else { for (int i = endIndex; i >= startIndex; i--) { T res = memberFormula(argument, i); int m = metricProvider.GetMetric(res); if (m > 0) { listPositive.AddLast(new KeyValuePair <int, T>(m, res)); } else if (m < 0) { listNegative.AddLast(new KeyValuePair <int, T>(m, res)); } else { listZero.AddLast(new KeyValuePair <int, T>(0, res)); } } } // ------------------------------ // Сортируем список по возрастающему абсолютному значению ключа. // TODO: сортировка должна выполняться быстрее. listPositive.InsertionSort(comparer); listNegative.InsertionSort(comparer); // нули сортировать не надо :) // ---------- А ВОТ ТЕПЕРЬ СУММАЦИЯ. Сначала все числа с нулевой метрикой - они не увеличат суммы. T sum = this.OperatorPlus(this.Zero, Sum_KeyValueSequence(listZero)); long metricSum = 0; LinkedListNode <KeyValuePair <int, T> > analyzedNode; // ---------- Готово. Приступаем. while (listPositive.Count > 0 || listNegative.Count > 0) { #if DEBUG Console.WriteLine(Math.Abs(metricSum)); #endif // Если кончился отрицательный список - ничем не поможешь. if (listNegative.Count == 0) { return(this.OperatorPlus(sum, Sum_KeyValueSequence(listPositive))); } // Если кончился положительный - тоже else if (listPositive.Count == 0) { return(this.OperatorPlus(sum, Sum_KeyValueSequence(listNegative))); } if (metricSum > 0) { // Ищем ключ в отрицательном списке, чтобы максимально уменьшить абсолютное значение суммы. analyzedNode = listNegative.First; // Первое условие здесь - абсолютное значение // ключа анализируемого узла меньше суммы метрик + абсолютное значение текущего отрицательного узла // Остальные нет смысла проверять - там неоптимально. while (Math.Abs(analyzedNode.Value.Key) <= metricSum && analyzedNode != null) { analyzedNode = analyzedNode.Next; } // Крайний случай - дошли до края. if (analyzedNode == null) { // Одно из двух - или последний отрицательный, или первый положительный. // В зависимости от того, что хуже. long positiveKeySum = metricSum + listPositive.First.Value.Key; long negativeKeySum = metricSum + listNegative.Last.Value.Key; // Если прибавить отрицательное выгоднее. if (Math.Abs(positiveKeySum) > Math.Abs(negativeKeySum)) { metricSum = negativeKeySum; sum = this.OperatorPlus(sum, listNegative.Last.Value.Value); listNegative.RemoveLast(); } else { metricSum = positiveKeySum; sum = this.OperatorPlus(sum, listPositive.First.Value.Value); listPositive.RemoveFirst(); } } // Еще один край - если это первый же узел. if (analyzedNode == listNegative.First) { // Одно из двух - или первый отрицательный, или первый положительный. // В зависимости от того, что хуже. long positiveKeySum = metricSum + listPositive.First.Value.Key; long negativeKeySum = metricSum + listNegative.First.Value.Key; // Если прибавить отрицательное выгоднее. if (Math.Abs(negativeKeySum) < Math.Abs(positiveKeySum)) { metricSum = negativeKeySum; sum = this.OperatorPlus(sum, listNegative.First.Value.Value); listNegative.RemoveFirst(); } else { metricSum = positiveKeySum; sum = this.OperatorPlus(sum, listPositive.First.Value.Value); listPositive.RemoveFirst(); } } // Иначе анализируем одно из трех. else { long positiveKeySum = metricSum + listPositive.First.Value.Key; long negativeKeySum1 = metricSum + analyzedNode.Previous.Value.Key; long negativeKeySum2 = metricSum + analyzedNode.Value.Key; if (Math.Abs(negativeKeySum1) <= Math.Abs(negativeKeySum2) && Math.Abs(negativeKeySum1) <= Math.Abs(positiveKeySum)) { metricSum = negativeKeySum1; sum = this.OperatorPlus(sum, analyzedNode.Previous.Value.Value); listNegative.Remove(analyzedNode.Previous); } else if (Math.Abs(negativeKeySum2) <= Math.Abs(negativeKeySum1) && Math.Abs(negativeKeySum2) <= Math.Abs(positiveKeySum)) { metricSum = negativeKeySum2; sum = this.OperatorPlus(sum, analyzedNode.Value.Value); listNegative.Remove(analyzedNode); } else { metricSum = positiveKeySum; sum = this.OperatorPlus(sum, listPositive.First.Value.Value); listPositive.RemoveFirst(); } } } else if (metricSum < 0) // ищем максимальный по модулю и не превосходящий текущего элемент { // Ищем ключ в положительном списке, чтобы максимально уменьшить абсолютное значение суммы. analyzedNode = listPositive.First; // Первое условие здесь - абсолютное значение // ключа анализируемого узла меньше суммы метрик + абсолютное значение текущего отрицательного узла // Остальные нет смысла проверять - там неоптимально. while (analyzedNode.Value.Key <= Math.Abs(metricSum) && analyzedNode != null) { analyzedNode = analyzedNode.Next; } // Крайний случай - дошли до края. if (analyzedNode == null) { // Одно из двух - или последний положительный, или первый отрицательный. // В зависимости от того, что хуже. long positiveKeySum = metricSum + listPositive.Last.Value.Key; long negativeKeySum = metricSum + listNegative.First.Value.Key; // Если прибавить положительное выгоднее. if (Math.Abs(positiveKeySum) < Math.Abs(negativeKeySum)) { metricSum = positiveKeySum; sum = this.OperatorPlus(sum, listPositive.Last.Value.Value); listPositive.RemoveLast(); } else { metricSum = negativeKeySum; sum = this.OperatorPlus(sum, listNegative.First.Value.Value); listNegative.RemoveFirst(); } } // Еще один край - если это первый же узел. if (analyzedNode == listPositive.First) { // Одно из двух - или первый отрицательный, или первый положительный. // В зависимости от того, что хуже. long positiveKeySum = metricSum + listPositive.First.Value.Key; long negativeKeySum = metricSum + listNegative.First.Value.Key; // Если прибавить отрицательное выгоднее. if (Math.Abs(positiveKeySum) > Math.Abs(negativeKeySum)) { metricSum = negativeKeySum; sum = this.OperatorPlus(sum, listNegative.First.Value.Value); listNegative.RemoveFirst(); } else { metricSum = positiveKeySum; sum = this.OperatorPlus(sum, listPositive.First.Value.Value); listPositive.RemoveFirst(); } } // Иначе анализируем одно из трех. else { long negativeKeySum = metricSum + listNegative.First.Value.Key; long positiveKeySum1 = metricSum + analyzedNode.Previous.Value.Key; long positiveKeySum2 = metricSum + analyzedNode.Value.Key; if (Math.Abs(positiveKeySum1) <= Math.Abs(positiveKeySum2) && Math.Abs(positiveKeySum1) <= Math.Abs(negativeKeySum)) { metricSum = positiveKeySum1; sum = this.OperatorPlus(sum, analyzedNode.Previous.Value.Value); listPositive.Remove(analyzedNode.Previous); } else if (Math.Abs(positiveKeySum2) <= Math.Abs(positiveKeySum1) && Math.Abs(positiveKeySum2) <= Math.Abs(negativeKeySum)) { metricSum = positiveKeySum2; sum = this.OperatorPlus(sum, analyzedNode.Value.Value); listPositive.Remove(analyzedNode); } else { metricSum = negativeKeySum; sum = this.OperatorPlus(sum, listNegative.First.Value.Value); listNegative.RemoveFirst(); } } } else { // сумма метрик равна нулю, уменьшать некуда. Можно не искать, а сразу добавлять. // Смотрим, что хуже. Прибавить первое положительное или первое отрицательное. if (listPositive.First.Value.Key < listNegative.First.Value.Key) { metricSum += listPositive.First.Value.Key; // прибавляем к сумме. sum = this.OperatorPlus(sum, listPositive.First.Value.Value); listPositive.RemoveFirst(); } else { metricSum += listNegative.First.Value.Key; // прибавляем к сумме. sum = this.OperatorPlus(sum, listNegative.First.Value.Value); listNegative.RemoveFirst(); } } } return(sum); }
public T Sum_MinCurrentMetricSum(Func <int, T> memberFormula, int startIndex, int endIndex, IMetricProvider <T> metricProvider) { return(Sum_MinCurrentMetricSum(this.Zero, delegate(T arg, int index) { return memberFormula(index); }, startIndex, endIndex, metricProvider)); }
// -------------------------------------- // ------ By minimum current metric ----- // -------------------------------------- public T Sum_ByMinimumMetricSum(Func <int, T> memberFormula, int startIndex, int endIndex, IMetricProvider <T> metricProvider) { return(default(T)); }
/// <summary> /// Performs the summation of sequence members according to their integer metric provided by a IMetricProvider object. /// The summation is performed starting with lowest metric and ending up with highest. /// Works slower than a simple sequential summation. /// /// Requires a general term formula dependent on both argument and integer index (<paramref name="memberFormula"/>) as well as the current function argument. /// </summary> /// <param name="startIndex">The inclusive beginning index of sequence summation.</param> /// <param name="endIndex">The inclusive ending index of sequence summation.</param> /// <param name="metricProvider">The metric mapping values of type <typeparamref name="T"/> to their integer metric.</param> /// <param name="memberFormula">The general term formula dependent on both argument and integer index.</param> /// <param name="argument">The current argument for the sequence.</param> /// <returns>The result of sequential summation of the sequence starting with index <paramref name="startIndex"/> and ending with index <paramref name="endIndex"/>, both inclusive.</returns> public T Sum_ByIncreasingMetric(T argument, Func <T, int, T> memberFormula, int startIndex, int endIndex, IMetricProvider <T> metricProvider) { IComparer <KeyValuePair <int, T> > comparer = Comparer <int> .Default.createKVPComparerOnKey <int, T>(); IPriorityQueue <KeyValuePair <int, T> > queue = new BinaryHeap <KeyValuePair <int, T> >(comparer); if (startIndex >= endIndex) { for (int i = startIndex; i <= endIndex; i++) { T res = memberFormula(argument, i); queue.Insert(new KeyValuePair <int, T>(metricProvider.GetMetric(res), res)); } } else { for (int i = endIndex; i >= startIndex; i--) { T res = memberFormula(argument, i); queue.Insert(new KeyValuePair <int, T>(metricProvider.GetMetric(res), res)); } } T sum = this.Zero; while (!queue.IsEmpty) { KeyValuePair <int, T> kvp = queue.Pop(); sum = this.OperatorPlus(sum, kvp.Value); } return(sum); }