diff --git a/decisions/log/0039-consistent-typing-real-numbers.md b/decisions/log/0039-consistent-typing-real-numbers.md new file mode 100644 index 00000000..b2e1cb77 --- /dev/null +++ b/decisions/log/0039-consistent-typing-real-numbers.md @@ -0,0 +1,72 @@ +# 39. Consistent typing of real numbers + +Date: 2024-09-23 + +## Context + +As the PACT data model evolved, numerous properties have been added, some of them denoting real numbers, like percentages and ratings (in contrast to integers which are always whole numbers). + +As there +is a certain amount of ambiguity in the JSON format regarding real numbers, this has +resulted in several properties having different ways of representing numbers. This +can lead to confusion for implementors and users of the data. + +This proposal aims to remedy that by uniformly typing these numbers and adding +guidelines for future expansion of the specs. + +## Background + +The JSON data format does not specify any precision for numbers. The representation of +these have been delegated to implementors. As a result, JSON parsers in different programming languages +thus have several ways of interpreting and storing real numbers. Although rare, in worst case, this could result in (some) data loss. + +In order not to be dependent on technical implementations, PACT has choosen to represent +numeric emission data (carbon footprint emissions) as decimal numbers formatted as strings. + +Example: + + { + "fossilGhgEmissions": "12345.6789" + } + +This way no precision is lost, although the burden of interpreting these numbers is +now relegated to the implementors of the PACT API. This is, however, in most cases +trivial and most programming languages have support for Decimal type numbers +specially purposed for scientific and financial calculations. + +## Proposal + +Based on discussion both with the community (Takuro Okada of NRI) and internally, we propose the following for consultation and revision. + +- Change the type of the following attributes (properties) from Number to "Decimal" (string): + - `pcf.exemptedEmissionsPercent` + - `pcf.primaryDataShare` + - `pcf.dqi.coveragePercent` + - `pcf.dqi.technologicalDQR` + - `pcf.dqi.temporalDQR` + - `pcf.dqi.geographicalDQR` + - `pcf.dqi.completenessDQR` + - `pcf.dqi.reliabilityDQR` + +- Note: property `version` will stay a Number as it will always be an integer. + +- Add a guideline to the Tech Specs, aiding the addition of future properties, as well +as guiding the types in data extensions: + - For integers (*and only* for integers) use the JSON **Number** type and include the `integer` format specifier in the OpenAPI schema. + + { counter: 1 } + + - For real numbers *ALWAYS* use the **Decimal** type: an arbitrary sized number, formatted as a string, with a '.' (dot) as decimal point, *without* any thousands separators. + + { temperature: "12.3" } + +## Consequences + +As this would break backwards compatibility with version 2.x these changes should - if accepted - be included from version 3 upwards. + +## Status + +Proposed +Presented in the Tech Working Group meeting of Sept 25, 2024. +Feedback to be collected. + diff --git a/spec/v3/examples/get-footprint-response.json b/spec/v3/examples/get-footprint-response.json index ab96c9c9..1ab32045 100644 --- a/spec/v3/examples/get-footprint-response.json +++ b/spec/v3/examples/get-footprint-response.json @@ -57,19 +57,19 @@ "version": "3.1" } ], - "exemptedEmissionsPercent": 0, + "exemptedEmissionsPercent": "0", "exemptedEmissionsDescription": "", "packagingEmissionsIncluded": false, "allocationRulesDescription": "Using mass allocation following the product specific rule as per PACT Framework decision-making tree", "uncertaintyAssessmentDescription": "A model of corn production is involved in predicting emissions from the production of the corn feedstock. Emissions of N2O due to application of nitrogen fertilizers are based on a linear modeling of interactions of the fertilizer with the soil and plant systems. As these interactions are more complicated than the model assumes, there is uncertainty regarding the emissions resulting from this model", - "primaryDataShare": 12.9, + "primaryDataShare": "12.9", "dqi": { - "coveragePercent": 78, - "technologicalDQR": 1.6, - "temporalDQR": 2.6, - "geographicalDQR": 1.8, - "completenessDQR": 1.7, - "reliabilityDQR": 2.1 + "coveragePercent": "78", + "technologicalDQR": "1.6", + "temporalDQR": "2.6", + "geographicalDQR": "1.8", + "completenessDQR": "1.7", + "reliabilityDQR": "2.1" }, "assurance": { "assurance": false, diff --git a/spec/v3/examples/invalid-response-all-properties.json b/spec/v3/examples/invalid-response-all-properties.json index 79437606..62769c7b 100644 --- a/spec/v3/examples/invalid-response-all-properties.json +++ b/spec/v3/examples/invalid-response-all-properties.json @@ -64,20 +64,20 @@ "version": "1.2.3" } ], - "exemptedEmissionsPercent": 0.0, + "exemptedEmissionsPercent": "0.0", "exemptedEmissionsDescription": "", "packagingEmissionsIncluded": true, "packagingGhgEmissions": "2.123", "allocationRulesDescription": "Allocation rules description", "uncertaintyAssessmentDescription": "Uncertainty assessment description", - "primaryDataShare": 10.4, + "primaryDataShare": "10.4", "dqi": { - "coveragePercent": 100, - "technologicalDQR": 1.13, - "temporalDQR": 2.57, - "geographicalDQR": 1, - "completenessDQR": 2.6, - "reliabilityDQR": 1.79 + "coveragePercent": "100", + "technologicalDQR": "1.13", + "temporalDQR": "2.57", + "geographicalDQR": "1", + "completenessDQR": "2.6", + "reliabilityDQR": "1.79" }, "assurance": { "coverage": "product line", diff --git a/spec/v3/examples/list-footprints-response.json b/spec/v3/examples/list-footprints-response.json index b8f700cc..72c87035 100644 --- a/spec/v3/examples/list-footprints-response.json +++ b/spec/v3/examples/list-footprints-response.json @@ -58,19 +58,19 @@ "version": "3.1" } ], - "exemptedEmissionsPercent": 0, + "exemptedEmissionsPercent": "0", "exemptedEmissionsDescription": "", "packagingEmissionsIncluded": false, "allocationRulesDescription": "Using mass allocation following the product specific rule as per PACT Framework decision-making tree", "uncertaintyAssessmentDescription": "A model of corn production is involved in predicting emissions from the production of the corn feedstock. Emissions of N2O due to application of nitrogen fertilizers are based on a linear modeling of interactions of the fertilizer with the soil and plant systems. As these interactions are more complicated than the model assumes, there is uncertainty regarding the emissions resulting from this model", - "primaryDataShare": 12.9, + "primaryDataShare": "12.9", "dqi": { - "coveragePercent": 78, - "technologicalDQR": 1.6, - "temporalDQR": 2.6, - "geographicalDQR": 1.8, - "completenessDQR": 1.7, - "reliabilityDQR": 2.1 + "coveragePercent": "78", + "technologicalDQR": "1.6", + "temporalDQR": "2.6", + "geographicalDQR": "1.8", + "completenessDQR": "1.7", + "reliabilityDQR": "2.1" }, "assurance": { "assurance": false, diff --git a/spec/v3/examples/pf-response-event.json b/spec/v3/examples/pf-response-event.json index ca536e78..b82481e0 100644 --- a/spec/v3/examples/pf-response-event.json +++ b/spec/v3/examples/pf-response-event.json @@ -65,19 +65,19 @@ "version": "3.1" } ], - "exemptedEmissionsPercent": 0, + "exemptedEmissionsPercent": "0", "exemptedEmissionsDescription": "", "packagingEmissionsIncluded": false, "allocationRulesDescription": "Using mass allocation following the product specific rule as per PACT Framework decision-making tree", "uncertaintyAssessmentDescription": "A model of corn production is involved in predicting emissions from the production of the corn feedstock. Emissions of N2O due to application of nitrogen fertilizers are based on a linear modeling of interactions of the fertilizer with the soil and plant systems. As these interactions are more complicated than the model assumes, there is uncertainty regarding the emissions resulting from this model", - "primaryDataShare": 12.9, + "primaryDataShare": "12.9", "dqi": { - "coveragePercent": 78, - "technologicalDQR": 1.6, - "temporalDQR": 2.6, - "geographicalDQR": 1.8, - "completenessDQR": 1.7, - "reliabilityDQR": 2.1 + "coveragePercent": "78", + "technologicalDQR": "1.6", + "temporalDQR": "2.6", + "geographicalDQR": "1.8", + "completenessDQR": "1.7", + "reliabilityDQR": "2.1" }, "assurance": { "assurance": false, diff --git a/spec/v3/index.bs b/spec/v3/index.bs index eadc34c7..0a1dbd5d 100644 --- a/spec/v3/index.bs +++ b/spec/v3/index.bs @@ -788,13 +788,12 @@ The mass (in kg) of the product per the provided <{CarbonFootprint/declaredUnit| If no secondary data is used, this property MUST BE `undefined`.