From 6853fd209fa80f8788951e6105ccfe8e5c8b30c6 Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Thu, 13 May 2021 14:29:27 +1000 Subject: additional logging --- bin/reduceOverlap.js | 4 ++-- lib/unitsToRanges.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/reduceOverlap.js b/bin/reduceOverlap.js index bc3dbd0..c5da852 100755 --- a/bin/reduceOverlap.js +++ b/bin/reduceOverlap.js @@ -131,7 +131,7 @@ const reduce = new Transform({ } this.push(featureGroup.filter(f => 'addr:unit' in f.properties)[0]) } else { - nonUnitFeature.properties['addr:flats'] = unitsToRanges(allOtherUnits) + nonUnitFeature.properties['addr:flats'] = unitsToRanges(allOtherUnits, featureGroup) // TODO should we set addr:flats:prefix from addr:unit:prefix? this.push(nonUnitFeature) } @@ -149,7 +149,7 @@ const reduce = new Transform({ const feature = cloneDeep(featureGroup[0]) delete feature.properties['addr:unit'] - feature.properties['addr:flats'] = unitsToRanges(units) + feature.properties['addr:flats'] = unitsToRanges(units, featureGroup) this.push(feature) } } else if (featureGroup.length === 1) { diff --git a/lib/unitsToRanges.js b/lib/unitsToRanges.js index 11e867f..cd572f7 100644 --- a/lib/unitsToRanges.js +++ b/lib/unitsToRanges.js @@ -6,10 +6,11 @@ * 1,2,3a-5a => 1-2;3a-5a * * @param {Array} units + * @param {Array} [sourceAddresses] - the source addresses where these units came from, used for debugging * * @returns {string} addr:flats list */ -module.exports = (units) => { +module.exports = (units, sourceAddresses) => { const regexp = /^(?
\D*)(?\d*)(?\D*)$/
 
   // expand out any existing ranges which may be mixed into the input
@@ -30,11 +31,17 @@ module.exports = (units) => {
         } else {
           // prefix/suffix don't match in the from-to, so just pass as is
           console.log(`passed a range with different prefix/suffix: ${rangeParts[0]}-${rangeParts[1]}`)
+          if (sourceAddresses) {
+            console.log(JSON.stringify(sourceAddresses, null, 2))
+          }
           acc.push(cur)
         }
       } else if (rangeParts.length > 2) {
         // 1-2-3 not sure if this ever occures, but just pass as is
         console.log(`Unsupported range ${cur}`)
+        if (sourceAddresses) {
+          console.log(JSON.stringify(sourceAddresses, null, 2))
+        }
         acc.push(cur)
       } else {
         // was not a range
@@ -65,6 +72,9 @@ module.exports = (units) => {
 
       if (!curParts) {
         console.log(`"${cur}" didn't match regexp for prefix number suffix`)
+        if (sourceAddresses) {
+          console.log(JSON.stringify(sourceAddresses, null, 2))
+        }
         return acc
       }
 
-- 
cgit v1.2.3