Example #1
0
 Promise.all(shapePromises).then(geometries => {
   const shapeBundles = zip(shapeIds, shapeIds.map(shapeId => shapes[shapeId][0].route), geometries)
   const geoJSON = {type: "FeatureCollection", features: shapeBundles.map(toFeature)}
   this.tileIndex = geojsonVt(geoJSON, {maxZoom: 20, buffer: 512}); //TODO: this should be configurable
   console.log("all ready")
   callback(null, this)
 }).catch((err) => {
  constructPath(innerPoints, intermediatePoints1, intermediatePoints2, controlPoints1, controlPoints2) {
    const points = zip(innerPoints, intermediatePoints1, controlPoints1, controlPoints2, intermediatePoints2)

    const sectionStrings = points.map(([inner, intermediate1, control1, control2, intermediate2]) =>
      `${inner} L ${intermediate1} C ${control1} ${control2} ${intermediate2}`)
    return `M ${sectionStrings.join(' L ')} Z`
  }
Example #3
0
var zipBridgeResponse = function(raw){
    var headings = Object.keys(raw).filter(k => (raw[k] instanceof Array));
    var zipped = _.zip.apply(_, headings.map(head => raw[head]));
    return {
        recordCount: raw.recordCount,
        rows: zipped.map(line => _.zipObject(headings, line))
    };
};
Example #4
0
 (err, stats) => {
   // send a json response
   res.json(
     reduce(zip(files, stats), (ret, file) => {
       ret[file[0]] = statsToJson(file[1])
       return ret
     }, {})
   )
 }
Example #5
0
function addPlainTextTable(data, result) {
  let headers = _.map(result.columns, 'name'),
    rows = [headers].concat(_.take(result.rows, 100)),
    pivot = _.zip.apply(_, rows),
    columnWidths = _.map(pivot, textUtil.longestLength),
    textTable = _.map(rows, row => _.map(row, (cellContent, columnIndex) => textUtil.padRight(cellContent, columnWidths[columnIndex])));

  data['text/plain'] = textTable.join('\n');
}
Example #6
0
  // TODO: In real tetris the tetrimino should rotate around the center,
  //       instead of keeping the same position on the board.
  rotate () {
    this.shape = zip.apply(null, this.shape).map(row => {
      return row.reverse();
    });

    this.height = this.shape.length;
    this.width = this.shape[0].length;

    return this;
  }
Example #7
0
  /**
   * Returns an array of key/value pairs for the defined keys.
   * This method is super helpful when your HTML forms sends
   * an array of values and you want them as individual
   * objects to be saved directly via Lucid models.
   *
   * # Note
   * This method always returns a stable array by setting value for
   * `undefined` keys to `null`. For example your data payload has
   * 3 emails and 2 usernames, the final array will have 3
   * objects with all the emails and the last object will
   * have `username` set to `null`.
   *
   * @method collect
   *
   * @param  {Array} keys
   *
   * @return {Array}
   *
   * @example
   * ```js
   * // data {username: ['virk', 'nikk'], age: [26, 25]}
   * const users = request.collect(['username', 'age'])
   * // returns [{username: '******', age: 26}, {username: '******', age: 25}]
   * ```
   */
  collect (keys) {
    /**
     * Making sure to wrap strings as an array.
     */
    const selectedValues = _(this.only(keys)).values().map((value) => {
      return Array.isArray(value) ? value : [value]
    }).value()

    const values = _.zip.apply(_, selectedValues)

    return _.map(values, (item, index) => {
      return _.transform(keys, (result, k, i) => {
        result[keys[i]] = item[i] || null
        return result
      }, {})
    })
  }
Example #8
0
function displayApps (apps, appsMetrics) {
  const zip = require('lodash.zip')
  const time = require('../lib/time')

  let owner = (owner) => owner.email.endsWith('@herokumanager.com') ? owner.email.split('@')[0] : owner.email

  for (let a of zip(apps, appsMetrics)) {
    let app = a[0]
    let metrics = a[1]
    cli.log(cli.color.app(app.app.name))
    cli.log(`  ${label('Owner:')} ${owner(app.app.owner)}`)
    if (app.pipeline) {
      cli.log(`  ${label('Pipeline:')} ${app.pipeline.pipeline.name}`)
    }
    displayFormation(app.formation)
    cli.log(`  ${label('Last release:')} ${time.ago(new Date(app.app.released_at))}`)
    displayMetrics(metrics)
    displayErrors(metrics)
    cli.log()
  }
}
      sparkpostWebhooks.processAndSendMetrics(testEvent, function (e) {
        if (e) return done(e);

        try {
          // test stathat endpoint
          sinon.assert.callCount(stathat.trackEZCountWithTime, 3);

          var calledWith = _.map(_.range(3), function (n) {
            return stathat.trackEZCountWithTime.getCall(n).args;
          });

          var groupedArgs = _.zip.apply(this, calledWith);

          // the 2nd argument to the endpoint should be the name
          _.forEach([
            'transactionalEmailEvent.count',
            'transactionalEmailEvent.count.category.message_event',
            'transactionalEmailEvent.count.type.click'
          ], function (value) {
            should(groupedArgs[1]).containEql(value);
          });

          // the 3rd argument to the endpoint should be a value (values)
          should(groupedArgs[2]).deepEqual([1, 1, 1]);

          // the 4th argument to the endpoint is a timestamp in seconds
          should(groupedArgs[3]).containEql(1234567890);

          // the 5th argument is a callback function
          _.forEach(groupedArgs[4], function (arg) {
            should(arg).be.Function();
          });

          return done();
        } catch (e) {
          return done(e);
        }
      });
        statsService.stat(data, function (e) {
          if (e) return done(e);

          try {
            // test influx endpoint
            sinon.assert.calledOnce(influx.InfluxDB.prototype.writeMeasurement);
            var measurement = influx.InfluxDB.prototype.writeMeasurement.getCall(0).args[0];
            var points = influx.InfluxDB.prototype.writeMeasurement.getCall(0).args[1];
            should(points.length).eql(1);
            var point = points[0];

            should(measurement).eql('test');
            should(point).have.propertyByPath('fields', 'count').eql(1);
            should(point).have.propertyByPath('fields', 'value').eql(2);
            should(point).not.have.property('timestamp');

            // test stathat endpoint
            // there are 3 points sent to stathat for count and value
            // 1 default and 1 for each tag (2)
            sinon.assert.callCount(stathat.trackEZCount, 3);
            sinon.assert.callCount(stathat.trackEZValue, 3);

            // collect the output from the stubbed stathat functions
            var countsCalledWith = _.map(_.range(3), function (i) {
              return stathat.trackEZCount.getCall(i).args;
            });
            var valuesCalledWith = _.map(_.range(3), function (i) {
              return stathat.trackEZValue.getCall(i).args;
            });

            var calledWith = _.concat(countsCalledWith, valuesCalledWith);

            // the first argument to the endpoint should be the stathat key
            // the 4th argument should be a callback function
            _.forEach(calledWith, function (args) {
              should(args[0]).equal(config.stathat.key);
              should(args[3]).be.Function();
            });

            // the second argument to the endpoint should be the name.tagname
            // we're not sure about the order in which they'll call the endpoint

            // separate the nth arguments into groups
            // the arguments grouped by their position
            // [1st arguments[], 2nd[], 3rd[], ...]
            var countGroupArgs = _.zip.apply(this, countsCalledWith);
            var valueGroupArgs = _.zip.apply(this, valuesCalledWith);

            // *** counts ***
            _.forEach([
              // the expected names
              'test.count',
              'test.count.tag1.string1',
              'test.count.tag2.string2'
            ], function (value) {
              // the 2nd arguments of the countsCalledWith
              should(countGroupArgs[1]).containEql(value);
            });

            // the third argument should be a value
            // here array of values from each call
            should(countGroupArgs[2]).deepEqual([1, 1, 1]);


            // *** values ***
            _.forEach([
              // the expected names
              'test.value',
              'test.value.tag1.string1',
              'test.value.tag2.string2'
            ], function (value) {
              // the 2nd arguments of the countsCalledWith
              should(valueGroupArgs[1]).containEql(value);
            });

            // the third argument should be a value
            // here array of values from each call
            should(valueGroupArgs[2]).deepEqual([2, 2, 2]);

            return done();
          } catch (e) {
            return done(e);
          }
        });
Example #11
0
					.thru(function(ts) {
						return _.zip.apply(null, ts);
					})
Example #12
0
export function sumAllocated(hosts) {
  return _.zip.apply(_, _.map(hosts, 'allocated')).map(_.sum);
}
Example #13
0
export function sumRequirements(hosts) {
  return _.zip.apply(_, _.map(hosts, 'requirements')).map(_.sum);
}