<commit_before>#!/usr/bin/env node

'use strict';

const fs = require('fs');
const http = require('http');
const process = require('process');
const cla = require('command-line-args');
const clu = require('command-line-usage');
const ansi = require('ansi-escape-sequences');
const turf = require('turf');
const jp = require('jsonpath');
const csv_stringify = require('csv-stringify/lib/sync');

const run_query = (query_options, filters, callback) => {
    let tic = () => 0.;
    http.request(query_options, function (res) {
        let body = '', ttfb = tic();
        if (res.statusCode != 200)
            return callback(query_options.path, res.statusCode, ttfb);

        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            body += chunk;
        });
        res.on('end', function () {
            const elapsed = tic();
            const json = JSON.parse(body);
            Promise.all(filters.map(filter => jp.query(json, filter)))
                .then(values => callback(query_options.path, res.statusCode, ttfb, elapsed, values));
        });
    }).on('socket', function (/*res*/) {
        tic = ((toc) => { return () => { const t = process.hrtime(toc); return t[0] * 1000 + t[1] / 1000000; }; })(process.hrtime());
    }).on('error', function (res) {<commit_msg>Don't handle response errors separately in osrm-runner<commit_after>#!/usr/bin/env node

'use strict';

const fs = require('fs');
const http = require('http');
const process = require('process');
const cla = require('command-line-args');
const clu = require('command-line-usage');
const ansi = require('ansi-escape-sequences');
const turf = require('turf');
const jp = require('jsonpath');
const csv_stringify = require('csv-stringify/lib/sync');

const run_query = (query_options, filters, callback) => {
    let tic = () => 0.;
    http.request(query_options, function (res) {
        let body = '', ttfb = tic();

        res.setEncoding('utf8');
        res.on('data', function (chunk) {
            body += chunk;
        });
        res.on('end', function () {
            const elapsed = tic();
            const json = JSON.parse(body);
            Promise.all(filters.map(filter => jp.query(json, filter)))
                .then(values => callback(query_options.path, res.statusCode, ttfb, elapsed, values));
        });
    }).on('socket', function (/*res*/) {
        tic = ((toc) => { return () => { const t = process.hrtime(toc); return t[0] * 1000 + t[1] / 1000000; }; })(process.hrtime());
    }).on('error', function (res) {
{'fraction_non_alphanumeric': 0.18467583497053044, 'fraction_numerical': 0.012966601178781925, 'mean_word_length': 2.9968602825745685, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6054127', 'n_tokens_mistral': 822, 'n_tokens_neox': 768, 'n_words': 187}