Skip to content

erikerlandson/unit-analysis-json-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

unit-analysis-json-schema

JSON Schema for algorithmic unit analysis

Encodes unit-analysis definitions based on the blog post "Algorithmic Unit Analysis"

examples

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"} }
     ]
}

Releases

No releases published

Packages

No packages published