LogoLogo
HomePricingDocumentation
  • 💿Getting Started
    • Installation and Project Setup
    • Hello Perigee!
    • Perigee Application Design
    • Hello Configuration
    • Hello Logs
    • Hello Integration
    • Troubleshooting
    • Case Studies
  • 📃License + Notice
    • 📂Licensing
    • Notice of Third Party Agreements
  • 🚀Perigee and Beyond
    • Extending - Threads
    • Extending - Loaders
    • ⏳All about CRON
  • 🔮API Generation
    • What is API Generation?
    • API Builder
  • 🗺️Architecting YOUR App
    • Design and Requirements
    • Define Sources
    • Requirements
  • 🧩Core Modules
    • 🌐PerigeeApplication
    • 🪡Thread Registry
    • Event Sources
      • Scheduled/Logic
        • CRON Thread
        • Scheduler
        • Sync Agent
      • Watchers
        • SalesForce
        • Sharepoint
        • Directory Watch
        • Directory Notifier
        • IMAP
    • Credential Management
      • Connection Strings
      • Custom Refresh Logic
      • RestSharp Authenticator
      • Credential Store SDK
      • ⁉️Troubleshooting Credentials
    • Integration Utilities
      • HTTP(S) - RestSharp
      • Transaction Coordinator
      • Limiter
      • Watermarking
    • Alert Managers
      • SMS
      • Email
      • Discord
      • Teams
    • File Formats
      • Excel
      • CSV
    • 📁File System Storage
      • File Revision Store
      • Concurrent File Store
      • FileSync + Cache
    • Third Party
      • SmartSheets
      • Microsoft Graph
    • Perigee In Parallel
      • Parallel Processing Reference
      • Extensions
      • GroupProcessor
      • SingleProcessor
    • 🧱Utility Classes
      • Metrics
      • F(x) Expressions
      • Multi-Threaded Processor (Scatter Gather)
      • OpenAI - GPT
      • XML Converter
      • Dynamic Data Table
      • Debounce
      • Thread Conditions
      • Perigee Utility Class
      • Network Utility
      • Lists
      • FileUtil
      • Inclusive2DRange
      • Strings, Numbers, Dates
      • Nested Sets
      • Behavior Trees
      • JsonCompress
      • Topological Sorting
      • DBDownloader
    • 🈁Bit Serializer
  • 📣Examples and Demos
    • API + Perigee
    • 📰Excel Quick Load
    • SalesForce Watcher
    • Report Scheduler
    • Agent Data Synchronization
    • 📩IMAP Echo bot
    • Watch and load CSVs
    • Graph Delegated Authorization + DataVerse
    • Coordinator Demo
    • Azure Service Bus
    • QuickBooks Online
  • 📘Blueprints
    • Perigee With .NET Hosting
    • Web Host Utilities
    • 🔌Plugin Load Context
  • 🎞️Transforms
    • 🌟What is Transforms?
    • 📘Terminology
    • 🦾The Mapping Document
    • 👾Transformation Process
    • 😎Profile
    • 🎒Automation
      • 🕓Package Options
      • 🔳Configuration
    • 🔧Utilities
      • 🧹Clean
      • 📑Map File
      • 🔎File Identification
      • 🗺️Map Generation
      • 🪅Insert Statement Generation
  • 🗃️Transform SDK
    • 👋Quick Start Guide
    • 🥳MapTo
    • 🔌Authoring Plugins
      • 🔘File IO Process
      • 📢Data Quality
      • 🟢Transform Process
    • SDK Reference
      • 🔘FileIOProcessData
      • 📢DataQualityContext
      • 🎛️TransformDataContext
      • 🏅TransformResult
Powered by GitBook
On this page
  • Metrics Classes
  • MetricDecimal
  • Properties
  • MetricName
  • MetricType
  • Methods
  • AddMetric(decimal metric, int precision)
  • AddMetric(decimal metric)
  • Average()
  • Max()
  • Median()
  • Min()
  • Percentile(decimal k, bool Interpolate = false)
  • PercentileRank(decimal k)
  • Sum()
  • FromJson(string json)
  • AsJson(bool valuesOnly = true)
  • AsJObject(bool valuesOnly = true)
Export as PDF
  1. Core Modules
  2. Utility Classes

Metrics

Metrics Classes

There are two metrics classes currently, MetricDecimal and MetricInteger. They work identically and only store their respective types internally.

The Metrics classes employs a bucketed approach to metric calculations, meaning it only stores unique metric values along with their frequency counts rather than keeping every individual metric entry. This method significantly reduces the amount of memory and storage needed, as repeated values are aggregated into a single entry with an associated count. Consequently, even with large streams of data, the class can track and compute statistics like averages, percentiles, and medians efficiently without the overhead of managing vast amounts of duplicate data.

MetricDecimal

Metrics are set of classes that implements a metric collection for values. It provides functionality to add metric values and compute various statistics such as average, median, percentiles, minimum, maximum, and sum. In addition, it supports serialization and deserialization of the metric data to and from JSON formats.

Properties

MetricName

Represents the name of the metric. This property is used to identify the metric collection.

MetricType

Indicates the type of the metric. For this class, it is set to "Decimal".

Methods

AddMetric(decimal metric, int precision)

Adds a new metric value to the collection after rounding it to the specified number of decimal places. In addition to updating the internal bucket of values, this method updates the maximum, minimum, and sum accordingly.

Parameters:

  • metric: The decimal value to add.

  • precision: The number of decimal places used for rounding the metric value.

AddMetric(decimal metric)

Adds a new metric value to the collection after rounding it to 2 decimal places. This method updates the internal bucket as well as the maximum, minimum, and cumulative sum values.

Parameters:

  • metric: The decimal value to add.

Average()

Calculates and returns the average of the metric values. The average is computed by dividing the cumulative sum of metric values by the total count of entries in the collection.

Max()

Returns the maximum metric value that has been added to the collection.

Median()

Computes and returns the median of the collected metric values. This method identifies the middle value by using the frequencies from the bucket of values. In cases where the cumulative frequency exactly equals the midpoint, the previous value is used.

Min()

Returns the minimum metric value recorded in the collection.

Percentile(decimal k, bool Interpolate = false)

Calculates the kth percentile of the recorded metric values. If k is 50, the method delegates to the Median() calculation. For other percentiles, it determines the appropriate index within the ordered set of unique metric values. If the computed index is a whole number, it returns the average of the two adjacent values; otherwise, it may compute an interpolated result based on the Interpolate parameter or return the ceiling value.

Parameters:

  • k: The percentile value to compute (e.g., 25, 50, 75).

  • Interpolate (optional): A boolean flag that, if true, forces interpolation between adjacent values. The default value is false.

PercentileRank(decimal k)

Calculates the percentile rank of a specific metric value k. The percentile rank is computed with the formula:

(cf_l + 0.5 f_i) / N * 100%

where cf_l is the cumulative frequency of values less than k, f_i is the frequency of the value k, and N is the total count of all entries.

Parameters:

  • k: The metric value for which the percentile rank is to be determined.

Sum()

Returns the cumulative sum of all metric values added to the collection.

FromJson(string json)

Reconstructs the MetricDecimal instance from a JSON string representation of the metric data. This method updates the sum, minimum, maximum, and bucket of frequencies based on the JSON content.

Parameters:

  • json: A JSON formatted string representing the metric data.

AsJson(bool valuesOnly = true)

Serializes the current state of metric data into a JSON string. Basic statistical information such as sum, min, max, average, median, and count are always included. If the valuesOnly parameter is false, then the full bucket containing all metric frequencies is also included.

Parameters:

  • valuesOnly (optional): A boolean flag indicating whether only basic stats should be serialized (true by default).

Returns:

  • A JSON formatted string representing the metric data.

AsJObject(bool valuesOnly = true)

Serializes the metric data into a JObject. Similar to AsJson, it always includes the basic statistical information. When the valuesOnly parameter is false, the complete bucket data is also inserted into the JObject.

Parameters:

  • valuesOnly (optional): A boolean flag indicating whether only basic stats should be included in the JObject (true by default).

Returns:

  • A JObject containing the metric data.

Example:

// Create a new MetricDecimal instance
MetricDecimal metricDecimal = new MetricDecimal("ResponseTime");

// Add metrics with and without precision
metricDecimal.AddMetric(123.4567M, 2);
metricDecimal.AddMetric(89.123M);
metricDecimal.AddMetric(101.789M, 1);

// Calculate and display statistical values
Console.WriteLine("Average: " + metricDecimal.Average());
Console.WriteLine("Max: " + metricDecimal.Max());
Console.WriteLine("Median: " + metricDecimal.Median());
Console.WriteLine("Min: " + metricDecimal.Min());
Console.WriteLine("Sum: " + metricDecimal.Sum());

// Calculate percentiles
Console.WriteLine("40th Percentile (no interpolation): " + metricDecimal.Percentile(40));
Console.WriteLine("95th Percentile (interpolated): " + metricDecimal.Percentile(95, true));

// Calculate percentile rank for a specific value
Console.WriteLine("Percentile Rank for 100: " + metricDecimal.PercentileRank(100));

// Serialize to JSON
string json = metricDecimal.AsJson(false);
Console.WriteLine("Serialized JSON: " + json);

// Reconstruct from JSON
metricDecimal.FromJson(json);
JObject jObject = metricDecimal.AsJObject(false);
Console.WriteLine("Reconstructed JObject: " + jObject.ToString());
PreviousUtility ClassesNextF(x) Expressions

Last updated 12 days ago

🧩
🧱
Page cover image