22
@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016 The First IoT JSR: Units of Measurement JSR-363 Werner Keil @wernerkeil & @UnitAPI https://www.jcp.org/en/jsr/detail?id=363 http://unitsofmeasurement.github.io

Eclipse Science F2F 2016 - JSR 363

Embed Size (px)

Citation preview

Page 1: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

The First IoT JSR: Units of Measurement

JSR-363Werner Keil@wernerkeil & @UnitAPI https://www.jcp.org/en/jsr/detail?id=363http://unitsofmeasurement.github.io

Page 2: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

The First IoT JSR: Units of MeasurementWerner Keil

•Consultant – Coach•Creative Cosmopolitan•Open Source Evangelist•Software Architect•Spec Lead – JSR363, Eclipse UOMo Project Lead•Individual JCP Executive Committee Member

[www.linkedin.com/in/catmedia]

Page 3: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

What are Units of Measurement?

6,089 ??????A Measurement

A Unit

Page 4: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

What is the problem, in code?

int distance = 6089; //in ???float speed = airplane.getSpeed(); //in ???System.out.println(“TTD: “ + (distance/speed) + “ hours”);

6,089 ??????A Measurement

A Unit

Page 5: Eclipse Science F2F 2016 - JSR 363

@YourTwitterHandle#DVXFR14{session hashtag} @wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

LEARNING FROM THE PAST…Some examples of how things can go wrong…

Page 6: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

Some real-life mishaps…NASA “Star Wars” Initiative, 1985

Sea Level

Page 7: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

NASA Mars Climate Orbiter, 1999Some real-life mishaps…[Cost $125M-300M]

“Preliminary findings indicate that one team used US/English units (e.g. inches, feet and pounds) while the other used metric units for a key spacecraft operation.”

Page 8: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

2001: Escape of the 250Kg tortoiseLos Angeles Zoo lent Clarence, a 250-kilogram, 75-

year-old Galapagos tortoise, to the Exotic Animal Training and Management Program at Moorpark College in Moorpark CA.

The first night in his new home, Clarence wrecked it: “He just pushed one of the fence poles right over,” said Moorpark's Chuck Brinkman.

The L.A. Zoo warned that Clarence was big, and needed an enclosure for an animal that “weighs in at about 250”, so that's what the college built.

Unfortunately, they thought the zoo meant 250 pounds, so the enclosure wasn't adequate for holding a 250-kilogram (552 lbs) beast.

Clarence

Page 9: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

Why do we need a specification?There are no specifications or standards for handling units in Java.

The current solution is to use primitives, that don’t provide any Type Safety.

The errors are difficult to find using unit testing: Interface and Internationalization (e.g. radian/degree,

meters/feet);Arithmetic operations (e.g. overflow);Conversion between units (e.g. from same domain);

Page 10: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

What is JSR-363?Interfaces and abstract classes supporting unit operations including:

Checking of unit compatibility;Expression of measurement in various units; andArithmetic operations on units.

Concrete classes implementing standard unit types (base, derived) and unit conversion.

Page 11: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

What is a Unit?c. (a) Any determinate quantity, dimension, or magnitude adopted as

a basis or standard of measurement for other quantities of the same kind and in terms of which their magnitude is calculated or

expressed.Oxford English Dictionary

Or … A well defined standard we all know?Unit DefinitionSecond The duration of 9,192,631,770 periods of the radiation corresponding to the

transition between the two hyperfine levels of the ground state of caesium 133 atom

Kilogram The mass of the international prototype kilogram [a very special lump of metal]

metre The distance travelled by light in a vacuum in 3.3356409519815204957557671447492e-9 seconds

Page 12: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

A Standard Measurement …“The nice thing about standards is that you have so many to choose

from.”Andrew S. Tanenbaum,

Computer Networks 2nd ed., p. 254

Foot

Mile Yard Chain

FathomFurlongInchNautical Mile

Statute Mile

astronomical unit (AU)

Light yearParsec(or meter)

Passus (roman)

Hand

ångström

Scots/Welsh/English Mile

Metre fermi micron

Thou (or mil)League

rod/perch/pole

nail

Barleycorn

link

ell Cubitfinger

palm

Poppyseed

Milli Centi Kilo

Page 13: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

DimensionAllows analysis of a quantity by the rational powers of the 7

fundamental dimensions (quantities are compatible when they have the same dimensions):

length (L), mass (M), time (T), electric charge (I), absolute temperature (Θ), amount of substance (N) and luminous intensity (J)

Examples:Speed = length/time - it’s dimensions are L=1,T=-1 (rest 0) (e.g. metre/second - ms-

1)

Acceleration is speed/time (m/s/s or ms-2) L=1, T=-2

Force is mass x acceleration M x ((length/time)/time) or M=1, L=1, T=-2

Molar Entropy: M=1 L=2 T=−2 Θ=−1 N=−1 (trust me!)

Page 14: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

QuantityA physical attribute of a thing. Something that can be measured and

has units. Compatible quantities have the same dimension…

Examples:• Time• Length• Speed• Amount of Substance• Luminous Intensity• Volume• Mass• Force• Power• Electrical Current

• Magnetic Flux Density• Volumetric Flow Rate

• Fuel Economy*• Percentage

• Eggs per carton• Sheep per hour• Bits and bytes …

… ∞

Page 15: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

What is the problem, in code?

int distance = 6089; //in ???float speed = airplane.getSpeed(); //in ??? System.out.println(“TTD: “ + (distance/speed) + “ hours”);

6,089 ??????A Measurement

A Unit

Page 16: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

What is JSR-363, in code?Airplane airplane = new Airplane(“A380”);QuantityFactory<Length> lengthFactory = provider.getQuantityFactory(Length.class);

Quantity<Length> distance = lengthFactory.create(6089d, KILO(METRE));Quantity<Speed> airplaneSpeed = airplane.getSpeed();

Quantity<Time> timeToDest = distance.divide(airplaneSpeed) .asType(Time.class);

System.out.println(“TTD: “ + timeToDest.to(HOUR));

TTD: 6.443381088681372 h

Page 17: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

Who is going to use JSR-363?Java developers who work with physical quantities need to handle measurements in their programs.

Inadequate models of physical measurements can lead to significant programmatic errors.

Platform providers and developers can provide and use a better defined API

Embedded developers can have less error-prone, more self-documented code

Page 18: Eclipse Science F2F 2016 - JSR 363

@YourTwitterHandle#DVXFR14{session hashtag} @wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

Demo

Page 19: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

JSR-363 timelineMarch 11, 2014: SubmittedApril 7, 2014: Creation approvedDec 2014 – Jan 2015: Early Draft (approved)Nov 2015 – Jan 2016: Public Review (approved)Q3/2016 : Final DraftQ3/2016: Final Release

Page 20: Eclipse Science F2F 2016 - JSR 363

@wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

Links to JSR-363Public mailing list(s) / forum(s)Units-Dev on Google Groups: https://groups.google.com/forum/#!forum/units-devUnits-Users on Google Groups:https://groups.google.com/forum/#!forum/units-users

The JSR page on JCP.org: https://jcp.org/en/jsr/detail?id=363

Project website on GitHub: unitsofmeasurement.github.ioGet sample code from our GitHub repositories on https://github.com/unitsofmeasurement/uom-demos.

Page 21: Eclipse Science F2F 2016 - JSR 363

@YourTwitterHandle#DVXFR14{session hashtag} @wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

Q & A

Page 22: Eclipse Science F2F 2016 - JSR 363

@YourTwitterHandle#DVXFR14{session hashtag} @wernerkeil | @UnitAPI #JSR363 | #EclipseScience | #ECE2016

Than

ks!