Skip to content

Unit Conversion

This section describes how HortiView deals with units and unit conversions throughout the platform.

Rationale

Thanks to decades of standardization, converting between different quantities is simple. Converting between the metric and imperial system is not difficult either. Consistent use of units in an application, on the other hand, is a tricky business. Especially when multiple software vendors contribute to the platform.

The ability to consistently render values for different quantities, such as length, area, temperature etc. can be complex, given the multitude of combinations of quantity, unit system and the actual value used. For example, when the backend returns the value 42 for an area without specifying the unit associated with that value, it will be difficult to work with, even if we know the context we are operating in.

In HortiView we want to make life as easy as possible for developers and help eliminate conversion errors. Therefore we defined 3 principles to support our goal:

  1. The HortiView Backend will store and return values for specific quantities using SI base units and SI coherent derived units.
  2. Organizations can define what quantities should be converted to specific units.
  3. The frontend is responsible for conversion since vendors know the context their modules operate in best.

The following descriptions only apply to values returned by platform services

The HortiView platform will always work as described below. Modules can be sure that we will return values in the expected unit. For example, areas are always stored as square meters. However, modules that implement their own backend (as described in "Use your own Backend") may handle units and quantities differently.

Unit Systems

In HortiView we store values in SI base units and SI coherent derived units, with one exception: temperature is stored in Celsius (C) instead of the thermodynamic quantity Kelvin (K).

By default, we use the following SI base units:

Name Typical symbol Name Symbol
Time t second s
Length l, x, r, etc. meter m
Mass m kilogram kg
Temperature T celsius C
Area A square meter m^2
Frequency f hertz hz
Pressure P pascal Pa
Force F newton N
Electric current I, i ampere A
Amount of substance n mole mol
Luminous intensity Iv candela cd

Support for the Imperial System

Although HortiView prefers the metric system, we allow organizations to use the Imperial System, if desired.

Conversion Process

Since the HortiView backend is agnostic about the target unit a value is about to be converted to, it will always return values in standard units derived from SI base units. For example, if an entity has the property area it will respond to requests with the unit sqm (square meters):

{
    "measurement" {
        "area": "42",
        "unit": "sqm"
    }
}
The unit property ensures that receivers of the response know what unit of measure the value corresponds to.

The following figure illustrates the process:

Unit conversion process.

Unit conversion process.

Examples

Since the frontend is responsible for the conversion, HortiView offers a simple interface to interact with the conversion library. The library is a wrapper for convert.js, a well known and mature unit conversion library for frontend developers.

yarn add hv-convert

Simple Operations

import c7 from "hv-convert";
import measures as m from "hv-convert";

c7(5, m.kilometers).to(m.miles);     // -> 
c7(12, m.kilograms).to(m.pounds);    // ->
c7(81, m.gallons).to(m.liters);      // ->
c7(10, m.atmospheres).to(m.kPa);     // ->
c7(451, m.fahrenheit).to(m.celsius); // ->
c7(360, m.seconds).to(m.minutes);    // -> 6

Mapping Between Unit Systems

By convention, HortiView stores values in SI units using the metric system. Depending on the user preferences the mapping to the imperial system is possible, but must be performed by the frontend.

Quantity Backend Metric system Imperial system Alternates
Length meter meter foot
Area square meter square meter square foot
Temperature Celsius Celsius Fahrenheit

<< Describe how we can read user prefs and convert to metric/imperial automatically>>

Overview of SI Base Units

Name Typical symbol Name Symbol Description
Time t second s The duration of 9192631770 periods of the radiation corresponding to the transition between the two hyperfine levels of the ground state of the caesium-133 atom
Length l, x, r, etc. meter m The distance traveled by light in vacuum in 1/299792458 second
Mass m kilogram kg The kilogram is defined by setting the Planck constant h to 6.62607015×10−34 J⋅s (J = kg⋅m2⋅s−2), given the definitions of the metre and the second.
Electric current I, i ampere A The flow of 1/1.602176634×10−19 times the elementary charge e per second, which is approximately 6.2415090744×1018 elementary charges per second.
Thermodynamic temperature T kelvin K The kelvin is defined by setting the fixed numerical value of the Boltzmann constant k to 1.380649×10−23 J⋅K−1, (J = kg⋅m2⋅s−2), given the definition of the kilogram, the metre, and the second.
Amount of substance n mole mol The amount of substance of 6.02214076×1023 elementary entities. This number is the fixed numerical value of the Avogadro constant, NA, when expressed in the unit mol−1.
Luminous intensity Iv candela cd The luminous intensity, in a given direction, of a source that emits monochromatic radiation of frequency 5.4×1014 hertz and that has a radiant intensity in that direction of 1/683 watt per steradian.