Skip to main content

MetricType

The type of a Metric.
Defines the MetricValueType and the applicable Units.

See also: Registering Items


Properties

PropertyTypeRestrictionsDescription
IdstringRequired
Length: 1 - 256
Pattern: ^[\w\.\-]+$
The unique identifier of the type.
LabelstringRequired
Length: 1 - 64
The textual label of the type. Longer labels are truncated.
ValueTypeMetricValueTypeRequiredThe MetricValueType the values of this type must conform to.
Descriptionstring?Max length: 256An optional textual description of the type.
Iconstring?Length: 1 - 256
Pattern: ^[\w\.\-]+$
An optional icon (the ID of a registered Icon).
BaseUnitUnit?-The optional base unit. Numeric values must always be provided in this unit.
UnitsIEnumerable<Unit>?Max. 32 unitsAdditional units the base unit can be converted into (e.g. for display to the user).

MetricValueType

A MetricType must always specify a MetricValueType.
This type imposes restrictions on acceptable values for a Metric of this type.

TypeAccepted Value
CustomA custom value (currently not supported).
StringA string. HTML tags are removed and the value is truncated to 128 characters.
NumericA number (any C# numeric type), or a string that can be parsed as a number.
DurationAn ISO 8601 duration string or a C# TimeSpan object.
DateTimeAn ISO 8601 date-time string or a C# DateTime/DateTimeOffset.
DateOnlyAn ISO 8601 date string or a C# DateOnly object.
TimeOnlyAn ISO 8601 time string or a C# TimeOnly object.
ResourceThe ID of a registered Resource (e.g., icon, image).
CurrencyA number, same as Numeric.
BooleanA C# bool, or the string "true" or "false".
note

When updating a numerical MetricValue, the value must be provided in the base unit as defined by the metric's MetricType to ensure accurate unit conversions.


CoreMetricType

The SDK provides several common metric types that are automatically registered by MoBro.
These types include predefined units, conversion formulas, and translations for all languages currently supported by MoBro. They can't be overwritten by a custom type with the same ID.

tip

Use core metric types whenever applicable. This ensures you'll benefit from future additions of supported languages or units without needing to update your code or publish a new plugin version.

TypeBase UnitMetricValueTypeDescription
ElectricCurrentAmpereNumericElectric current
ElectricPotentialVoltNumericElectric potential difference
ElectricResistanceOhmNumericElectric resistance
DataFlowBits per secondNumericData transfer rate (bitrate).
DataBytesNumericData capacity.
DurationSecondsDurationThe elapsed time between two events.
FrequencyHertzNumericNumber of occurrences per unit of time.
MultiplierMultiplier (x)NumericA multiplier.
Numeric-NumericA simple numeric value.
PowerWattNumericElectric power output.
RotationRotations per minuteNumericRotational speed.
TemperatureDegrees CelsiusNumericTemperature measurement.
Text-StringA simple text value.
UsagePercentageNumericUsage or utilization percentage.
PressurePascalNumericApplied force on a surface.
VolumeCubic metreNumericA volumetric measurement.
VolumeFlowCubic metre per secondNumericVolume movement per unit of time.
DateTime-DateTimeA date and time value.
LengthMetresNumericA measure of distance.
SpeedMetres per secondNumericSpeed as distance per unit of time.
MassKilogramsNumericThe quantity of matter.
AreaSquare metreNumericThe extent of a region.
Date-DateOnlyA date (without a time component).
Time-TimeOnlyA time (without a date component).
Icon-ResourceAn icon resource.
Image-ResourceAn image resource.
AngleDegreesNumericAn angular measurement.
Boolean-BooleanA simple boolean value.

CoreMetricTypeCurrency

The SDK also provides core metric types for the Currency MetricValueType.
These currency types are predefined with labels, descriptions, currency symbols, and translations for all supported languages in MoBro.

Core TypeCurrency
AUDAustralian dollar
AZNAzerbaijani manat
BAMBosnia and Herzegovina convertible mark
BGNBulgarian lev
CADCanadian dollar
CHFSwiss franc
CNYRenminbi
CZKCzech koruna
DKKDanish krone
EUREuro
GBPPound sterling
GELGeorgian lari
HUFHungarian forint
INRIndian rupee
ISKIcelandic króna
JPYJapanese yen
MDLMoldovan leu
MKDMacedonian denar
NOKNorwegian krone
PLNPolish złoty
RONRomanian leu
RSDSerbian dinar
SEKSwedish krona
TRYTurkish lira
UAHUkrainian hryvnia
USDUnited States dollar

Custom Types

If no core type suits the metric, plugins can create and register a custom MetricType like any other IMoBroItem.

The MoBroItem.CreateMetricType() builder expects the ID, the label and the value type first. The icon, the base unit and any number of derived units are optional:

// A custom type for coins (1 Gold = 100 Silver)
var coinType = MoBroItem
.CreateMetricType()
.WithId("coin_type")
.WithLabel("Coins")
.OfValueType(MetricValueType.Numeric)
.WithBaseUnit(baseUnit => baseUnit
.WithLabel("Gold")
.WithAbbreviation("G")
.Build())
.WithDerivedUnit(derivedUnit => derivedUnit
.WithConversionFormula("x * 100", "x / 100") // from base unit, to base unit
.WithLabel("Silver")
.WithAbbreviation("S")
.Build())
.Build();
note

When registering a custom MetricType of Currency, the label must be a 3-character currency code following the ISO 4217 standard.


Unit

A Unit represents the measurement unit for a Metric (e.g., degrees Celsius for temperature). Each unit is specific to a MetricType.

Properties

PropertyTypeRestrictionsDescription
LabelstringRequired
Length: 1 - 64
The name of the unit.
AbbreviationstringRequired
Length: 1 - 64
The abbreviation of the unit.
Descriptionstring?Max length: 256An optional textual description of the unit.
FromBaseFormulastringRequired
Length: 1 - 64
The formula converting a value from the base unit to this unit (e.g., x * 10).
ToBaseFormulastringRequired
Length: 1 - 64
The formula converting a value from this unit back to the base unit (e.g., x / 10).

Both formulas must use x as the placeholder for the value. The formulas of the base unit itself are always x.