Browse Source

predicates debugging prints stack trace snippet

pull/946/head
Lily He 7 years ago
parent
commit
9ee5025312
  1. 12
      controller/predicates/has_request_errors.js
  2. 13
      controller/predicates/has_request_parameter.js
  3. 10
      controller/predicates/has_response_data.js
  4. 12
      controller/predicates/has_results_at_layers.js
  5. 12
      controller/predicates/is_addressit_parse.js
  6. 8
      controller/predicates/is_admin_only_analysis.js
  7. 7
      controller/predicates/is_coarse_reverse.js
  8. 17
      controller/predicates/is_only_non_admin_layers.js
  9. 16
      controller/predicates/is_request_sources_only_whosonfirst.js

12
controller/predicates/has_request_errors.js

@ -1,5 +1,13 @@
const _ = require('lodash'); const _ = require('lodash');
const Debug = require('../../helper/debug');
const debugLog = new Debug('controller:predicates:has_request_errors');
const stackTraceLine = require('../../helper/stackTraceLine');
module.exports = (request, response) => { module.exports = (req, res) => {
return _.get(request, 'errors', []).length > 0; const has_request_errors = _.get(req, 'errors', []).length > 0;
debugLog.push(req, () => ({
reply: has_request_errors,
stack_trace: stackTraceLine()
}));
return has_request_errors;
}; };

13
controller/predicates/has_request_parameter.js

@ -1,4 +1,15 @@
const _ = require('lodash'); const _ = require('lodash');
const Debug = require('../../helper/debug');
const debugLog = new Debug('controller:predicates:has_request_parameter');
const stackTraceLine = require('../../helper/stackTraceLine');
// returns true IFF req.clean has a key with the supplied name // returns true IFF req.clean has a key with the supplied name
module.exports = (parameter) => (req, res) => (_.has(req, ['clean', parameter])); module.exports = (parameter) => (req, res) => {
const has_request_parameter = _.has(req, ['clean', parameter]);
debugLog.push(req, () => ({
reply: {[parameter]: has_request_parameter},
stack_trace: stackTraceLine()
}));
return has_request_parameter;
};

10
controller/predicates/has_response_data.js

@ -1,5 +1,13 @@
const _ = require('lodash'); const _ = require('lodash');
const Debug = require('../../helper/debug');
const debugLog = new Debug('controller:predicates:has_response_data');
const stackTraceLine = require('../../helper/stackTraceLine');
module.exports = (request, response) => { module.exports = (request, response) => {
return _.get(response, 'data', []).length > 0; const has_response_data = _.get(response, 'data', []).length > 0;
debugLog.push(request, () => ({
reply: has_response_data,
stack_trace: stackTraceLine()
}));
return has_response_data;
}; };

12
controller/predicates/has_results_at_layers.js

@ -1,5 +1,7 @@
const _ = require('lodash'); const _ = require('lodash');
const Debug = require('../../helper/debug');
const debugLog = new Debug('controller:predicates:has_results_at_layers');
const stackTraceLine = require('../../helper/stackTraceLine');
// returns a function that returns true if any result.layer is in any of the // returns a function that returns true if any result.layer is in any of the
// supplied layers using array intersection // supplied layers using array intersection
@ -7,13 +9,19 @@ const _ = require('lodash');
module.exports = (layers) => { module.exports = (layers) => {
return (request, response) => { return (request, response) => {
return !_.isEmpty( const has_results_at_layers = !_.isEmpty(
_.intersection( _.intersection(
// convert layers to an array if it isn't already one // convert layers to an array if it isn't already one
_.castArray(layers), _.castArray(layers),
// pull all the layer properties into an array // pull all the layer properties into an array
_.map(response.data, _.property('layer')) _.map(response.data, _.property('layer'))
)); ));
debugLog.push(request, () => ({
reply: {[layers]: has_results_at_layers},
stack_trace: stackTraceLine()
}));
return has_results_at_layers;
}; };
}; };

12
controller/predicates/is_addressit_parse.js

@ -1,4 +1,14 @@
const _ = require('lodash'); const _ = require('lodash');
const Debug = require('../../helper/debug');
const debugLog = new Debug('controller:predicates:is_addressit_parse');
const stackTraceLine = require('../../helper/stackTraceLine');
// returns true IFF req.clean.parser is addressit // returns true IFF req.clean.parser is addressit
module.exports = (req, res) => (_.get(req, 'clean.parser') === 'addressit'); module.exports = (req, res) => {
const is_addressit_parse = _.get(req, 'clean.parser') === 'addressit';
debugLog.push(req, () => ({
reply: is_addressit_parse,
stack_trace: stackTraceLine()
}));
return is_addressit_parse;
};

8
controller/predicates/is_admin_only_analysis.js

@ -1,10 +1,11 @@
const _ = require('lodash'); const _ = require('lodash');
const Debug = require('../../helper/debug'); const Debug = require('../../helper/debug');
const debugLog = new Debug('controller:predicates:is_admin_only_analysis'); const debugLog = new Debug('controller:predicates:is_admin_only_analysis');
const stackTraceLine = require('../../helper/stackTraceLine');
module.exports = (request, response) => { module.exports = (request, response) => {
if (!request.clean.hasOwnProperty('parsed_text')) { if (!request.clean.hasOwnProperty('parsed_text')) {
debugLog.push(request, false + '(no parsed_text)'); debugLog.push(request, false + ' (no parsed_text)');
return false; return false;
} }
@ -13,6 +14,9 @@ module.exports = (request, response) => {
return _.isEmpty(request.clean.parsed_text[prop]); return _.isEmpty(request.clean.parsed_text[prop]);
}); });
debugLog.push(request, is_admin_only_analysis); debugLog.push(request, () => ({
reply: is_admin_only_analysis,
stack_trace: stackTraceLine()
}));
return is_admin_only_analysis; return is_admin_only_analysis;
}; };

7
controller/predicates/is_coarse_reverse.js

@ -2,12 +2,15 @@ const _ = require('lodash');
const Debug = require('../../helper/debug'); const Debug = require('../../helper/debug');
const debugLog = new Debug('controller:predicates:is_coarse_reverse'); const debugLog = new Debug('controller:predicates:is_coarse_reverse');
const non_coarse_layers = ['address', 'street', 'venue']; const non_coarse_layers = ['address', 'street', 'venue'];
const stackTraceLine = require('../../helper/stackTraceLine');
module.exports = (req, res) => { module.exports = (req, res) => {
// returns true if layers is undefined, empty, or contains 'address', 'street', or 'venue' // returns true if layers is undefined, empty, or contains 'address', 'street', or 'venue'
const is_coarse_reverse = !_.isEmpty(req.clean.layers) && const is_coarse_reverse = !_.isEmpty(req.clean.layers) &&
_.isEmpty(_.intersection(req.clean.layers, non_coarse_layers)); _.isEmpty(_.intersection(req.clean.layers, non_coarse_layers));
debugLog.push(req, () => ({
debugLog.push(req, is_coarse_reverse); reply: is_coarse_reverse,
stack_trace: stackTraceLine()
}));
return is_coarse_reverse; return is_coarse_reverse;
}; };

17
controller/predicates/is_only_non_admin_layers.js

@ -1,7 +1,16 @@
const _ = require('lodash'); const _ = require('lodash');
const Debug = require('../../helper/debug');
const debugLog = new Debug('controller:predicates:is_only_non_admin_layers');
const stackTraceLine = require('../../helper/stackTraceLine');
// return true IFF req.clean.layers is empty OR there are non-venue/address/street layers // return true IFF req.clean.layers is empty OR there are non-venue/address/street layers
module.exports = (req, res) => ( module.exports = (req, res) => {
!_.isEmpty(_.get(req, 'clean.layers', [])) && const is_only_non_admin_layers = !_.isEmpty(_.get(req, 'clean.layers', [])) &&
_.isEmpty(_.difference(req.clean.layers, ['venue', 'address', 'street'])) _.isEmpty(_.difference(req.clean.layers, ['venue', 'address', 'street']));
);
debugLog.push(req, () => ({
reply: is_only_non_admin_layers,
stack_trace: stackTraceLine()
}));
return is_only_non_admin_layers;
};

16
controller/predicates/is_request_sources_only_whosonfirst.js

@ -1,9 +1,17 @@
const _ = require('lodash'); const _ = require('lodash');
const Debug = require('../../helper/debug');
const debugLog = new Debug('controller:predicates:is_request_sources_only_whosonfirst');
const stackTraceLine = require('../../helper/stackTraceLine');
// returns true IFF 'whosonfirst' is the only requested source // returns true IFF 'whosonfirst' is the only requested source
module.exports = (req, res) => ( module.exports = (req, res) => {
_.isEqual( const is_request_sources_only_whosonfirst = _.isEqual(
_.get(req, 'clean.sources', []), _.get(req, 'clean.sources', []),
['whosonfirst'] ['whosonfirst']
) );
); debugLog.push(req, () => ({
reply: is_request_sources_only_whosonfirst,
stack_trace: stackTraceLine()
}));
return is_request_sources_only_whosonfirst;
};

Loading…
Cancel
Save