@servicetitan/acquisition-functions 0.6.1 → 0.8.0

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.
@@ -449,3 +449,6 @@ export declare const MOCK: ({
449
449
  modifiedon: string;
450
450
  location: string;
451
451
  })[];
452
+ export declare const filtersToIgnoreMOCK: {
453
+ name: string;
454
+ }[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MOCK = void 0;
3
+ exports.filtersToIgnoreMOCK = exports.MOCK = void 0;
4
4
  exports.MOCK = [
5
5
  {
6
6
  attomid: 154817956,
@@ -455,3 +455,22 @@ exports.MOCK = [
455
455
  location: '33.97984,-118.25633',
456
456
  },
457
457
  ];
458
+ exports.filtersToIgnoreMOCK = [
459
+ { name: 'vacant land - exempt' },
460
+ { name: 'residential - vacant land' },
461
+ { name: 'industrial - vacant land' },
462
+ { name: 'rural residence' },
463
+ { name: 'multi-family - vacant land' },
464
+ { name: 'waste land, marsh, swamp, submerged - vacant land' },
465
+ { name: 'vacant land - unspecified improvement' },
466
+ { name: 'planned unit development (pud)' },
467
+ { name: 'row house' },
468
+ { name: 'agricultural (unimproved) - vacant land' },
469
+ { name: 'water area (lakes, river, shore) - vacant land' },
470
+ { name: 'recreational - vacant land' },
471
+ { name: 'vacant land - destroyed/uninhabitable improvement' },
472
+ { name: 'institutional - vacant land' },
473
+ { name: 'vacant land' },
474
+ { name: 'government - vacant land' },
475
+ { name: 'private preserve, open space - vacant land' },
476
+ ];
@@ -1,5 +1,5 @@
1
1
  import { Property } from '../types';
2
- export declare const calculateFilterCount: (properties: Property[]) => {
2
+ export declare const calculateFilterCount: (properties: Property[], filtersToIgnore: string[]) => {
3
3
  propertyusegroupCounts: {
4
4
  name: string;
5
5
  count: number;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateFilterCount = void 0;
4
4
  const utils_1 = require("../utils/utils");
5
- const calculateFilterCount = (properties) => {
5
+ const calculateFilterCount = (properties, filtersToIgnore) => {
6
6
  const filterCount = {
7
7
  propertyusegroup: {},
8
8
  propertyusestandardized: {},
@@ -11,9 +11,10 @@ const calculateFilterCount = (properties) => {
11
11
  utilitieswatersource: {},
12
12
  flooringmaterialprimary: {},
13
13
  };
14
+ const { isValidFilterName } = (0, utils_1.FilterNameValidator)(filtersToIgnore, utils_1.UNKNOWN);
14
15
  properties.forEach(p => {
15
- if (p.propertyusestandardized.toLowerCase() !== utils_1.UNKNOWN &&
16
- p.propertyusegroup.toLowerCase() !== utils_1.UNKNOWN) {
16
+ if (isValidFilterName(p.propertyusestandardized.toLowerCase()) &&
17
+ isValidFilterName(p.propertyusegroup.toLowerCase())) {
17
18
  const propertyUseKey = p.propertyusestandardized + utils_1.SEPARATOR_CHARACTER + p.propertyusegroup;
18
19
  filterCount.propertyusestandardized[propertyUseKey] =
19
20
  filterCount.propertyusestandardized[propertyUseKey] || 0;
@@ -22,22 +23,22 @@ const calculateFilterCount = (properties) => {
22
23
  filterCount.propertyusegroup[p.propertyusegroup] || 0;
23
24
  filterCount.propertyusegroup[p.propertyusegroup] += 1;
24
25
  }
25
- if (p.hvaccoolingdetail.toLowerCase() !== utils_1.UNKNOWN) {
26
+ if (isValidFilterName(p.hvaccoolingdetail.toLowerCase())) {
26
27
  filterCount.hvaccoolingdetail[p.hvaccoolingdetail] =
27
28
  filterCount.hvaccoolingdetail[p.hvaccoolingdetail] || 0;
28
29
  filterCount.hvaccoolingdetail[p.hvaccoolingdetail] += 1;
29
30
  }
30
- if (p.hvacheatingdetail.toLowerCase() !== utils_1.UNKNOWN) {
31
+ if (isValidFilterName(p.hvacheatingdetail.toLowerCase())) {
31
32
  filterCount.hvacheatingdetail[p.hvacheatingdetail] =
32
33
  filterCount.hvacheatingdetail[p.hvacheatingdetail] || 0;
33
34
  filterCount.hvacheatingdetail[p.hvacheatingdetail] += 1;
34
35
  }
35
- if (p.utilitieswatersource.toLowerCase() !== utils_1.UNKNOWN) {
36
+ if (isValidFilterName(p.utilitieswatersource.toLowerCase())) {
36
37
  filterCount.utilitieswatersource[p.utilitieswatersource] =
37
38
  filterCount.utilitieswatersource[p.utilitieswatersource] || 0;
38
39
  filterCount.utilitieswatersource[p.utilitieswatersource] += 1;
39
40
  }
40
- if (p.flooringmaterialprimary.toLowerCase() !== utils_1.UNKNOWN) {
41
+ if (isValidFilterName(p.flooringmaterialprimary.toLowerCase())) {
41
42
  filterCount.flooringmaterialprimary[p.flooringmaterialprimary] =
42
43
  filterCount.flooringmaterialprimary[p.flooringmaterialprimary] || 0;
43
44
  filterCount.flooringmaterialprimary[p.flooringmaterialprimary] += 1;
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFilterFetcherProcessor = void 0;
4
4
  const calc_filter_count_1 = require("./calc-filter-count");
5
5
  function getFilterFetcherProcessor(db) {
6
+ let invalidFilters;
7
+ let fetchInvalidFiltersInProgress = null;
6
8
  const getFiltersCollection = async () => {
7
9
  return db.collection('filters');
8
10
  };
@@ -39,6 +41,30 @@ function getFilterFetcherProcessor(db) {
39
41
  })
40
42
  .toArray();
41
43
  };
44
+ const getInvalidFilters = async () => {
45
+ if (invalidFilters !== undefined) {
46
+ return invalidFilters;
47
+ }
48
+ if (!fetchInvalidFiltersInProgress) {
49
+ fetchInvalidFiltersInProgress = db
50
+ .collection('badFilters')
51
+ .find({}, {
52
+ projection: {
53
+ _id: 0,
54
+ name: 1,
55
+ },
56
+ })
57
+ .toArray()
58
+ .then(results => {
59
+ invalidFilters = results.map(doc => doc.name);
60
+ })
61
+ .finally(() => {
62
+ fetchInvalidFiltersInProgress = null;
63
+ });
64
+ }
65
+ await fetchInvalidFiltersInProgress;
66
+ return invalidFilters;
67
+ };
42
68
  return async function processZip(zip, errors) {
43
69
  const meta = {
44
70
  requests: 0,
@@ -50,10 +76,13 @@ function getFilterFetcherProcessor(db) {
50
76
  return meta;
51
77
  }
52
78
  try {
53
- const properties = await getProperties(zip);
79
+ const [properties, invalidFilters] = await Promise.all([
80
+ getProperties(zip),
81
+ getInvalidFilters(),
82
+ ]);
54
83
  meta.requests += 1;
55
84
  meta.properties += properties.length;
56
- const filters = (0, calc_filter_count_1.calculateFilterCount)(properties);
85
+ const filters = (0, calc_filter_count_1.calculateFilterCount)(properties, invalidFilters);
57
86
  await deleteZipFilter(zip);
58
87
  meta.requests += 1;
59
88
  await addZipFilters({
@@ -243,3 +243,6 @@ export declare const convertStringToDate: (props: Property[], propName: keyof Pr
243
243
  location: string;
244
244
  _id: import("bson").ObjectID;
245
245
  }[];
246
+ export declare function FilterNameValidator(filtersToIgnore: string[], unknownCharacter: string): {
247
+ isValidFilterName(filterName: string, checkIgnoredFilters?: boolean): boolean;
248
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertStringToDate = exports.convertToZipString = exports.convertObjectToArray = exports.extractUniqueFilterNames = exports.isEmptyField = exports.isNotFullProperty = exports.UNKNOWN = exports.SEPARATOR_CHARACTER = void 0;
3
+ exports.FilterNameValidator = exports.convertStringToDate = exports.convertToZipString = exports.convertObjectToArray = exports.extractUniqueFilterNames = exports.isEmptyField = exports.isNotFullProperty = exports.UNKNOWN = exports.SEPARATOR_CHARACTER = void 0;
4
4
  exports.SEPARATOR_CHARACTER = '___';
5
5
  exports.UNKNOWN = 'unknown';
6
6
  const isNotFullProperty = (property) => {
@@ -78,3 +78,12 @@ const convertStringToDate = (props, propName) => {
78
78
  .map(p => ({ ...p, [propName]: new Date(p[propName]) }));
79
79
  };
80
80
  exports.convertStringToDate = convertStringToDate;
81
+ function FilterNameValidator(filtersToIgnore, unknownCharacter) {
82
+ return {
83
+ isValidFilterName(filterName, checkIgnoredFilters = true) {
84
+ const isValidFilter = !checkIgnoredFilters || !filtersToIgnore.includes(filterName);
85
+ return filterName !== unknownCharacter && isValidFilter;
86
+ },
87
+ };
88
+ }
89
+ exports.FilterNameValidator = FilterNameValidator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/acquisition-functions",
3
- "version": "0.6.1",
3
+ "version": "0.8.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "./dist/index.d.ts",
@@ -28,5 +28,5 @@
28
28
  "cli": {
29
29
  "webpack": false
30
30
  },
31
- "gitHead": "722e4224af6b19d0a4a410bdcfa071557e2b3af7"
31
+ "gitHead": "04c06c606f59be9507544c0ac0a9e0a19538dbf0"
32
32
  }