Beispiel #1
0
            selects = _.reduce(fields, (result, field, index) => {
                let path = _.toPath(field),
                    table = path.shift(),
                    column = path.shift(),
                    joinModel = inject(table),
                    meta = this['_columns'][`_${table}`] || this['_joins'][`_${table}`];

                if (meta['type'] === 'column') {
                    result = _.concat(result, [`${this['_tableName']}.${this['_columns'][`_${field}`]['value']} col_${index}`]);
                } else if (!!column) {
                    result = _.concat(result, [`${joinModel['_tableName']}.${joinModel['_columns'][`_${column}`]['value']} col_${index}`]);
                } else {
                    result = _.concat(result, _.map(joinModel['_columns'], (column, _index) => `${joinModel['_tableName']}.${column['value']}  col_${index + _index}`));
                }
                return result;
            }, selects);
Beispiel #2
0
 deepDiff(one: Object, two: Object, path: string = ''): IDeepDiff[] {
     let result: IDeepDiff[] = [];
     for (var key of _.keys(one)) {
         let concatPath: string = path ? path + '.' + key : key;
         if (_.isPlainObject(one[key])) {
             if (!_.has(two, key)) {
                 result.push(new DeepDiff('deleted', concatPath, one[key], null));
             } else {
                 result = _.concat(result, this.deepDiff(one[key], two[key], path ? path + '.' + key : key));
             }
         } else if (_.isBoolean(one[key]) || _.isDate(one[key]) || _.isNumber(one[key])
             || _.isNull(one[key]) || _.isRegExp(one[key]) || _.isString(one[key])) {
             if (!_.has(two, key)) {
                 result.push(new DeepDiff('deleted', concatPath, one[key], null));
             } else if (_.get(one, key) !== _.get(two, key)) {
                 result.push(new DeepDiff('edited', concatPath, one[key], two[key]));
             }
         } else if (_.isArray(one[key]) && _.isArray(two[key]) && !_.isEqual(one[key], two[key])) {
             result.push(new DeepDiff('array', concatPath, one[key], two[key]));
         } else if (!_.has(two, key)) {
             result.push(new DeepDiff('deleted', concatPath, one[key], null));
         }
     }
     for (var key of _.keys(two)) {
         let concatPath: string = path ? path + '.' + key : key;
         if (!_.has(one, key)) {
             if (_.isPlainObject(two[key]) || _.isBoolean(two[key]) || _.isDate(two[key]) || _.isNumber(two[key])
                 || _.isNull(two[key]) || _.isRegExp(two[key]) || _.isString(two[key]) || _.isArray(two[key])) {
                 result.push(new DeepDiff('created', concatPath, null, two[key]));
             }
         }
     }
     return result;
 }
Beispiel #3
0
        fields = _.reduce(fields, (result, field, index) => {
            let path = _.toPath(field),
                table = path.shift(),
                column = path.shift(),
                joinModel = inject(table),
                meta = this['_columns'][`_${table}`] || this['_joins'][`_${table}`];

            if (meta['type'] === 'column') {
                result = _.concat(result, field);
            } else if (!!column) {
                result = _.concat(result, field);
            } else {
                result = _.concat(result, _.map(joinModel['_columns'], columnMeta => `${field}.${columnMeta['name']}`));
            }
            return result;
        }, []);
    public build(groupBysDefinition): any[] {
        const groupByTags = [];
        if (!_.isEmpty(groupBysDefinition.tags)) {
            groupByTags.push({name: "tag", tags: this.templatingUtils.replaceAll(groupBysDefinition.tags)});
        }

        const groupByTime = groupBysDefinition.time.map((entry) => {
            return {
                group_count: entry.count,
                name: "time",
                range_size: this.buildRangeSize(
                    this.samplingConverter.isApplicable(entry.interval) ?
                        this.samplingConverter.convert(entry.interval, entry.unit) : entry)
            };
        });

        const groupByValue = groupBysDefinition.value.map((entry) => {
            return {
                name: "value",
                range_size: entry
            };
        });

        return _.concat(groupByTags, groupByTime, groupByValue);
    }
Beispiel #5
0
  @messageListener()
  async attributeGithubActivity() {
    try {
      // If getActivities() takes a long time to run, consider using:
      //    http://dexie.org/docs/WhereClause/WhereClause.startsWith()
      const logs = concat(
        await this.getActivities({ withCreators: false }),
        await this.thanks.filter(t => t.creator_id === undefined).toArray()
      ).filter(a => {
        return a.url.includes('https://github.com/');
      });

      let promises = map(logs, async a => {
        let u = new URL(a.url);
        let user_or_org = u.pathname.split('/')[1];
        if (user_or_org.length > 0 && !isReserved.check(user_or_org)) {
          let creator_url = `https://github.com/${user_or_org}`;
          await this.updateCreator(creator_url, user_or_org);
          await this.connectUrlToCreator(a.url, creator_url);
        }
      });

      await Promise.all(promises);
      return null;
    } catch (err) {
      throw 'Could not attribute Github activity, ' + err;
    }
  }
Beispiel #6
0
        function(err: any, realImgInfo: {watermarks: number[][], thumbnails: number[][]}) {

          // Let the neural net do its magic
          console.log('Outputting final image...');
          let realFinalPixels = brain.activate(_.concat(realImgInfo.watermarks[0], realImgInfo.thumbnails[0]));
          outputImage(mainDir + realDir + '001.jpg', trainingImgInfo.finalDimensions.width, trainingImgInfo.finalDimensions.height, realFinalPixels);
          console.log('done');
        }
Beispiel #7
0
 test('getLeveragePositions paging', async () => {
   const api = new BrokerApi('', '');
   const pos1 = await api.getLeveragePositions({ status: 'open', limit: 4, order: 'desc' });
   const pos2 = await api.getLeveragePositions({ status: 'open', limit: 4, order: 'desc', starting_after: _.last(pos1.data).id });
   const pos3 = await api.getLeveragePositions({ status: 'open', limit: 4, order: 'desc', starting_after: _.last(pos2.data).id });
   const positions = _.concat(pos1.data, pos2.data, pos3.data);
   expect(positions.length).toBe(9);
   expect(positions[1].new_order.created_at.toISOString()).toBe('2017-10-20T22:41:59.000Z');
 });
Beispiel #8
0
async function main(sources: string[]) {
  let fixtures = allFixtures;
  const fixturesFromCmdline = process.env.FIXTURE;
  if (fixturesFromCmdline) {
    const fixtureNames = fixturesFromCmdline.split(",");
    fixtures = _.filter(fixtures, fixture => _.some(fixtureNames, name => fixture.runForName(name)));
  } else {
    fixtures = affectedFixtures();
    if (allFixtures.length !== fixtures.length) {
      console.error(`* Running a subset of fixtures: ${fixtures.map(f => f.name).join(", ")}`);
    }
  }
  // Get an array of all { sample, fixtureName } objects we'll run.
  // We can't just put the fixture in there because these WorkItems
  // will be sent in a message, removing all code.
  const samples = _.map(fixtures, fixture => ({
    fixtureName: fixture.name,
    samples: fixture.getSamples(sources)
  }));
  const priority = _.flatMap(samples, x =>
    _.map(x.samples.priority, s => ({ fixtureName: x.fixtureName, sample: s }))
  );
  const others = _.flatMap(samples, x =>
    _.map(x.samples.others, s => ({ fixtureName: x.fixtureName, sample: s }))
  );

  const tests = divideParallelJobs(_.concat(priority, others));

  await inParallel({
    queue: tests,
    workers: CPUs,

    setup: async () => {
      testCLI();

      console.error(`* Running ${tests.length} tests between ${fixtures.length} fixtures`);

      for (const fixture of fixtures) {
        await execAsync(`rm -rf test/runs`);
        await execAsync(`mkdir -p test/runs`);

        await fixture.setup();
      }
    },

    map: async ({ sample, fixtureName }: WorkItem, index) => {
      let fixture = _.find(fixtures, { name: fixtureName }) as Fixture;
      try {
        await fixture.runWithSample(sample, index, tests.length);
      } catch (e) {
        console.trace(e);
        exit(1);
      }
    }
  });
}
Beispiel #9
0
  parseQueryResult(): any {
    let data: any[] = [];
    let columns: any[] = [];
    for (let i = 0; i < this.results.length; i++) {
      if (this.results[i].result.data.tables.length === 0) {
        continue;
      }
      columns = this.results[i].result.data.tables[0].columns;
      const rows = this.results[i].result.data.tables[0].rows;

      if (this.results[i].query.resultFormat === 'time_series') {
        data = _.concat(data, this.parseTimeSeriesResult(this.results[i].query, columns, rows));
      } else {
        data = _.concat(data, this.parseTableResult(this.results[i].query, columns, rows));
      }
    }

    return data;
  }
Beispiel #10
0
  constructor(iteratees = [], orders: SortOrder[] = [SortOrder.ASC]) {
    this.iteratees = iteratees;
    this.orders = orders;

    if (this.iteratees.length > this.orders.length) {
      let diff = this.iteratees.length - this.orders.length;
      let pad = this.orders[this.orders.length - 1];
      this.orders = _.concat(this.orders, _.fill(Array(diff), pad));
    }
  }