MetricType
The type of a Metric.
Defines the MetricValueType and the applicable Units.
See also: Registering Items
Properties
| Property | Type | Restrictions | Description |
|---|---|---|---|
| Id | string | Required Length: 1 - 256Pattern: ^[\w\.\-]+$ | The unique identifier of the type. |
| Label | string | Required Length: 1 - 64 | The textual label of the type. Longer labels are truncated. |
| ValueType | MetricValueType | Required | The MetricValueType the values of this type must conform to. |
| Description | string? | Max length: 256 | An optional textual description of the type. |
| Icon | string? | Length: 1 - 256Pattern: ^[\w\.\-]+$ | An optional icon (the ID of a registered Icon). |
| BaseUnit | Unit? | - | The optional base unit. Numeric values must always be provided in this unit. |
| Units | IEnumerable<Unit>? | Max. 32 units | Additional 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.
| Type | Accepted Value |
|---|---|
| Custom | A custom value (currently not supported). |
| String | A string. HTML tags are removed and the value is truncated to 128 characters. |
| Numeric | A number (any C# numeric type), or a string that can be parsed as a number. |
| Duration | An ISO 8601 duration string or a C# TimeSpan object. |
| DateTime | An ISO 8601 date-time string or a C# DateTime/DateTimeOffset. |
| DateOnly | An ISO 8601 date string or a C# DateOnly object. |
| TimeOnly | An ISO 8601 time string or a C# TimeOnly object. |
| Resource | The ID of a registered Resource (e.g., icon, image). |
| Currency | A number, same as Numeric. |
| Boolean | A C# bool, or the string "true" or "false". |
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.
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.
| Type | Base Unit | MetricValueType | Description |
|---|---|---|---|
| ElectricCurrent | Ampere | Numeric | Electric current |
| ElectricPotential | Volt | Numeric | Electric potential difference |
| ElectricResistance | Ohm | Numeric | Electric resistance |
| DataFlow | Bits per second | Numeric | Data transfer rate (bitrate). |
| Data | Bytes | Numeric | Data capacity. |
| Duration | Seconds | Duration | The elapsed time between two events. |
| Frequency | Hertz | Numeric | Number of occurrences per unit of time. |
| Multiplier | Multiplier (x) | Numeric | A multiplier. |
| Numeric | - | Numeric | A simple numeric value. |
| Power | Watt | Numeric | Electric power output. |
| Rotation | Rotations per minute | Numeric | Rotational speed. |
| Temperature | Degrees Celsius | Numeric | Temperature measurement. |
| Text | - | String | A simple text value. |
| Usage | Percentage | Numeric | Usage or utilization percentage. |
| Pressure | Pascal | Numeric | Applied force on a surface. |
| Volume | Cubic metre | Numeric | A volumetric measurement. |
| VolumeFlow | Cubic metre per second | Numeric | Volume movement per unit of time. |
| DateTime | - | DateTime | A date and time value. |
| Length | Metres | Numeric | A measure of distance. |
| Speed | Metres per second | Numeric | Speed as distance per unit of time. |
| Mass | Kilograms | Numeric | The quantity of matter. |
| Area | Square metre | Numeric | The extent of a region. |
| Date | - | DateOnly | A date (without a time component). |
| Time | - | TimeOnly | A time (without a date component). |
| Icon | - | Resource | An icon resource. |
| Image | - | Resource | An image resource. |
| Angle | Degrees | Numeric | An angular measurement. |
| Boolean | - | Boolean | A 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 Type | Currency |
|---|---|
| AUD | Australian dollar |
| AZN | Azerbaijani manat |
| BAM | Bosnia and Herzegovina convertible mark |
| BGN | Bulgarian lev |
| CAD | Canadian dollar |
| CHF | Swiss franc |
| CNY | Renminbi |
| CZK | Czech koruna |
| DKK | Danish krone |
| EUR | Euro |
| GBP | Pound sterling |
| GEL | Georgian lari |
| HUF | Hungarian forint |
| INR | Indian rupee |
| ISK | Icelandic króna |
| JPY | Japanese yen |
| MDL | Moldovan leu |
| MKD | Macedonian denar |
| NOK | Norwegian krone |
| PLN | Polish złoty |
| RON | Romanian leu |
| RSD | Serbian dinar |
| SEK | Swedish krona |
| TRY | Turkish lira |
| UAH | Ukrainian hryvnia |
| USD | United 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();
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
| Property | Type | Restrictions | Description |
|---|---|---|---|
| Label | string | Required Length: 1 - 64 | The name of the unit. |
| Abbreviation | string | Required Length: 1 - 64 | The abbreviation of the unit. |
| Description | string? | Max length: 256 | An optional textual description of the unit. |
| FromBaseFormula | string | Required Length: 1 - 64 | The formula converting a value from the base unit to this unit (e.g., x * 10). |
| ToBaseFormula | string | Required 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.