@hestia-earth/data-validation 0.41.12 → 0.41.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1287,6 +1287,15 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1287
1287
  const sentences = utils.unique(errors.map(({ params }) => params == null ? void 0 : params.source)).map((source) => distributionSourceMessage[source]).filter(Boolean);
1288
1288
  return sentences.length ? `${sentences.join(r.lineBreak)}${r.lineBreak}` : "";
1289
1289
  };
1290
+ const outlierSubject = ({ dataPath, params }, value, errorCount) => {
1291
+ var _a;
1292
+ const shownValue = errorCount === 1 ? ` ${code(value)}` : "";
1293
+ return dataPath.includes("product") ? `The product value${shownValue}` : ((_a = params == null ? void 0 : params.termIds) == null ? void 0 : _a.length) ? `The total of ${joinWithAnd(params.termIds.map((id) => termLink({ id })))}, ${code(value)},` : (params == null ? void 0 : params.group) ? `The total of all ${code(params.group)} inputs of this Cycle${shownValue}` : `The input value${shownValue}`;
1294
+ };
1295
+ const outlierGroupNote = (errors) => errors.some(({ dataPath, params }) => {
1296
+ var _a;
1297
+ return !dataPath.includes("product") && (((_a = params == null ? void 0 : params.termIds) == null ? void 0 : _a.length) || (params == null ? void 0 : params.group));
1298
+ }) ? `This total adds up every input checked together, including the nutrient content of fertilisers recorded in kg, so it can be higher than the value of a single input.${r.lineBreak}` : "";
1290
1299
  const customErrorMessage = {
1291
1300
  "this field is required": ({ dataPath }, _errorCount, allErrors) => {
1292
1301
  const parts = parseDataPath(dataPath);
@@ -1696,22 +1705,24 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1696
1705
  Please, use a term with termType ${glossaryTypeLink(schema.TermTermType.landCover)} instead.
1697
1706
  This will help us gap-fill the amount of grass consumed by the herd.`,
1698
1707
  "the sum of all pastureGrass values must be 100": ({ params }) => `The sum of all ${termLink(pastureGrass)} values must be equal to ${params.expected}%.`,
1699
- "is outside confidence interval": (error, errorCount, allErrors) => `${utils.unique(
1700
- (allErrors.length ? allErrors : [error]).flatMap(
1701
- ({ dataPath, params }) => {
1702
- var _a;
1703
- return (_a = params == null ? void 0 : params.outliers) == null ? void 0 : _a.map(
1704
- (value) => {
1708
+ "is outside confidence interval": (error, errorCount, allErrors) => {
1709
+ const errors = allErrors.length ? allErrors : [error];
1710
+ return `${utils.unique(
1711
+ errors.flatMap(
1712
+ (current) => {
1713
+ var _a, _b;
1714
+ return (_b = (_a = current.params) == null ? void 0 : _a.outliers) == null ? void 0 : _b.map((value) => {
1705
1715
  var _a2;
1706
- return `The ${dataPath.includes("product") ? "product" : "input"} value ${errorCount === 1 ? `${code(value)} ` : ""}is ${value > (params == null ? void 0 : params.min) ? "above" : "below"} ${(params == null ? void 0 : params.threshold) ? `${code(`${(Number(params.threshold) + (1 - Number(params.threshold)) / 2) * 100}%`)} of` : ""} all ${(params == null ? void 0 : params.group) ? code(params.group) : code((_a2 = params == null ? void 0 : params.term) == null ? void 0 : _a2.name)} data in ${code(
1716
+ const { params } = current;
1717
+ return `${outlierSubject(current, value, errorCount)} is ${value > (params == null ? void 0 : params.min) ? "above" : "below"} ${(params == null ? void 0 : params.threshold) ? `${code(`${(Number(params.threshold) + (1 - Number(params.threshold)) / 2) * 100}%`)} of` : ""} all ${(params == null ? void 0 : params.group) ? code(params.group) : code((_a2 = params == null ? void 0 : params.term) == null ? void 0 : _a2.name)} data in ${code(
1707
1718
  params == null ? void 0 : params.country.name
1708
1719
  )} on the HESTIA platform.`;
1709
- }
1710
- );
1711
- }
1712
- )
1713
- ).join(r.lineBreak)}${r.lineBreak}${distributionSources(allErrors.length ? allErrors : [error])}
1714
- Please double-check these values before submitting.`,
1720
+ });
1721
+ }
1722
+ )
1723
+ ).join(r.lineBreak)}${r.lineBreak}${outlierGroupNote(errors)}${distributionSources(errors)}
1724
+ Please double-check these values before submitting.`;
1725
+ },
1715
1726
  "should be equal to boundary": ({ params }) => `The calculated ${schemaLink("Site#area", "area")} from ${code("boundary")} is ${code(params == null ? void 0 : params.expected)} ha.
1716
1727
  This may be an error if the boundary represents the area under cultivation.`,
1717
1728
  "must specify the fate of cropResidue": ({ params }) => `For sites of type ${params.siteType.map(code).join(" or ")},
@@ -1719,7 +1730,7 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1719
1730
  true
1720
1731
  )} for crop residue, the fates and quantities of the residue must be specified.
1721
1732
  ${r.lineBreak}
1722
- The quantity must include both above and below ground crop residue, where the sum of above ground crop residue and below ground crop residue must be greater than zero.
1733
+ The quantity must include both above and below ground crop residue, where the above ground crop residue must be greater than zero, unless the crop produces no crop residue (e.g. mushrooms).
1723
1734
  This can be added using the terms:
1724
1735
  ${formatList([
1725
1736
  `${termLink({ id: "belowGroundCropResidue", name: "Below ground crop residue" })}; and`,
@@ -1285,6 +1285,15 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1285
1285
  const sentences = unique(errors.map(({ params }) => params == null ? void 0 : params.source)).map((source) => distributionSourceMessage[source]).filter(Boolean);
1286
1286
  return sentences.length ? `${sentences.join(r.lineBreak)}${r.lineBreak}` : "";
1287
1287
  };
1288
+ const outlierSubject = ({ dataPath, params }, value, errorCount) => {
1289
+ var _a;
1290
+ const shownValue = errorCount === 1 ? ` ${code(value)}` : "";
1291
+ return dataPath.includes("product") ? `The product value${shownValue}` : ((_a = params == null ? void 0 : params.termIds) == null ? void 0 : _a.length) ? `The total of ${joinWithAnd(params.termIds.map((id) => termLink({ id })))}, ${code(value)},` : (params == null ? void 0 : params.group) ? `The total of all ${code(params.group)} inputs of this Cycle${shownValue}` : `The input value${shownValue}`;
1292
+ };
1293
+ const outlierGroupNote = (errors) => errors.some(({ dataPath, params }) => {
1294
+ var _a;
1295
+ return !dataPath.includes("product") && (((_a = params == null ? void 0 : params.termIds) == null ? void 0 : _a.length) || (params == null ? void 0 : params.group));
1296
+ }) ? `This total adds up every input checked together, including the nutrient content of fertilisers recorded in kg, so it can be higher than the value of a single input.${r.lineBreak}` : "";
1288
1297
  const customErrorMessage = {
1289
1298
  "this field is required": ({ dataPath }, _errorCount, allErrors) => {
1290
1299
  const parts = parseDataPath(dataPath);
@@ -1694,22 +1703,24 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1694
1703
  Please, use a term with termType ${glossaryTypeLink(TermTermType.landCover)} instead.
1695
1704
  This will help us gap-fill the amount of grass consumed by the herd.`,
1696
1705
  "the sum of all pastureGrass values must be 100": ({ params }) => `The sum of all ${termLink(pastureGrass)} values must be equal to ${params.expected}%.`,
1697
- "is outside confidence interval": (error, errorCount, allErrors) => `${unique(
1698
- (allErrors.length ? allErrors : [error]).flatMap(
1699
- ({ dataPath, params }) => {
1700
- var _a;
1701
- return (_a = params == null ? void 0 : params.outliers) == null ? void 0 : _a.map(
1702
- (value) => {
1706
+ "is outside confidence interval": (error, errorCount, allErrors) => {
1707
+ const errors = allErrors.length ? allErrors : [error];
1708
+ return `${unique(
1709
+ errors.flatMap(
1710
+ (current) => {
1711
+ var _a, _b;
1712
+ return (_b = (_a = current.params) == null ? void 0 : _a.outliers) == null ? void 0 : _b.map((value) => {
1703
1713
  var _a2;
1704
- return `The ${dataPath.includes("product") ? "product" : "input"} value ${errorCount === 1 ? `${code(value)} ` : ""}is ${value > (params == null ? void 0 : params.min) ? "above" : "below"} ${(params == null ? void 0 : params.threshold) ? `${code(`${(Number(params.threshold) + (1 - Number(params.threshold)) / 2) * 100}%`)} of` : ""} all ${(params == null ? void 0 : params.group) ? code(params.group) : code((_a2 = params == null ? void 0 : params.term) == null ? void 0 : _a2.name)} data in ${code(
1714
+ const { params } = current;
1715
+ return `${outlierSubject(current, value, errorCount)} is ${value > (params == null ? void 0 : params.min) ? "above" : "below"} ${(params == null ? void 0 : params.threshold) ? `${code(`${(Number(params.threshold) + (1 - Number(params.threshold)) / 2) * 100}%`)} of` : ""} all ${(params == null ? void 0 : params.group) ? code(params.group) : code((_a2 = params == null ? void 0 : params.term) == null ? void 0 : _a2.name)} data in ${code(
1705
1716
  params == null ? void 0 : params.country.name
1706
1717
  )} on the HESTIA platform.`;
1707
- }
1708
- );
1709
- }
1710
- )
1711
- ).join(r.lineBreak)}${r.lineBreak}${distributionSources(allErrors.length ? allErrors : [error])}
1712
- Please double-check these values before submitting.`,
1718
+ });
1719
+ }
1720
+ )
1721
+ ).join(r.lineBreak)}${r.lineBreak}${outlierGroupNote(errors)}${distributionSources(errors)}
1722
+ Please double-check these values before submitting.`;
1723
+ },
1713
1724
  "should be equal to boundary": ({ params }) => `The calculated ${schemaLink("Site#area", "area")} from ${code("boundary")} is ${code(params == null ? void 0 : params.expected)} ha.
1714
1725
  This may be an error if the boundary represents the area under cultivation.`,
1715
1726
  "must specify the fate of cropResidue": ({ params }) => `For sites of type ${params.siteType.map(code).join(" or ")},
@@ -1717,7 +1728,7 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1717
1728
  true
1718
1729
  )} for crop residue, the fates and quantities of the residue must be specified.
1719
1730
  ${r.lineBreak}
1720
- The quantity must include both above and below ground crop residue, where the sum of above ground crop residue and below ground crop residue must be greater than zero.
1731
+ The quantity must include both above and below ground crop residue, where the above ground crop residue must be greater than zero, unless the crop produces no crop residue (e.g. mushrooms).
1721
1732
  This can be added using the terms:
1722
1733
  ${formatList([
1723
1734
  `${termLink({ id: "belowGroundCropResidue", name: "Below ground crop residue" })}; and`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/data-validation",
3
- "version": "0.41.12",
3
+ "version": "0.41.13",
4
4
  "description": "HESTIA Data Validation library",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",