JSON Schema for algorithmic unit analysis
Encodes unit-analysis definitions based on the blog post "Algorithmic Unit Analysis"
A unit analysis schema is an array of unit definitions.
The following example shows some "base"
and "derived"
unit definitions.
[
{"unit": "base", "name": "meter", "abbv": "m"},
{"unit": "base", "name": "second", "abbv": "s"},
{"unit": "derived", "name": "minute", "coef": 60, "expr": "second"},
{"unit": "derived",
"name": "liter", "abbv": "L",
"coef": {"coef": "rational", "num": 1, "den": 1000},
"expr": {"lhs": "meter", "op": "^", "rhs": 3}
},
{"unit": "derived",
"name": "gravity", "abbv": "g",
"coef": 9.8,
"expr": {"lhs": "meter", "op": "/", "rhs": {"lhs": "second", "op": "^", "rhs": 2}}
},
{"unit": "derived", "name": "kilo", "coef": 1000, "expr": "unitless"}
]
Here is an Avro schema augmented with unit expressions:
{
"type": "record",
"name": "demo_units",
"fields": [
{ "name": "distance", "type": "float", "unit": "meter" },
{ "name": "velocity",
"type": "float",
"unit": {"lhs": "meter", "op": "/", "rhs": "second"} }
]
}