<commit_before>import Measures from './measures.js';
import { Random } from 'meteor/random';
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
const Expressions = {};

Expressions.types = [
  {
    name: 'attribute',
    icon: 'fa fa-tag',
    possibleFollowers: ['operator'],
  },
  {
    name: 'measure',
    icon: 'fa fa-balance-scale',
    possibleFollowers: ['operator'],
  },
  {
    name: 'operator',
    icon: 'fa fa-calculator',
    characteristics: [{ name: '+' }, { name: '-' }, { name: '*' }, { name: '/' }],
    possibleFollowers: ['attribute', 'measure', 'func'],
  },
  {
    name: 'func',
    icon: 'fa fa-code',
    possibleFollowers: ['operator'],
  },
];

Expressions.operators = {};
Expressions.operators.types = [
];

Expressions.types.get = (typeName) => {
  return Expressions.types.find((type) => type.name === typeName);
};

Expressions.add = (measureId, typeName) => {
  Measures.collection.update(
    measureId,
    { $push: { expressions: { _id: Random.id(), typeName, name: '' } } }
  );
};

Expressions.removeLast = (measureId) => {
  Measures.collection.update(
    measureId,
    { $pop: { expressions: 1 } }
  );
};

Meteor.methods({
  'Measures.Expressions.setName': (measureId, expressionId, name) => {
    check(measureId, String);
    check(expressionId, String);
    check(name, String);
    Measures.collection.update(
      { _id: measureId, 'expressions._id': expressionId },
      { $set: { 'expressions.$.name': name } }
    );
  },

  'Measures.Expressions.setMeasure': (measureId, expressionId, measureIdToSet) => {
    check(measureId, String);
    check(expressionId, String);
    check(measureIdToSet, String);<commit_msg>Make expressios.add() return the expressionId<commit_after>import Measures from './measures.js';
import { Random } from 'meteor/random';
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
const Expressions = {};

Expressions.types = [
  {
    name: 'attribute',
    icon: 'fa fa-tag',
    possibleFollowers: ['operator'],
  },
  {
    name: 'measure',
    icon: 'fa fa-balance-scale',
    possibleFollowers: ['operator'],
  },
  {
    name: 'operator',
    icon: 'fa fa-calculator',
    characteristics: [{ name: '+' }, { name: '-' }, { name: '*' }, { name: '/' }],
    possibleFollowers: ['attribute', 'measure', 'func'],
  },
  {
    name: 'func',
    icon: 'fa fa-code',
    possibleFollowers: ['operator'],
  },
];

Expressions.operators = {};
Expressions.operators.types = [
];

Expressions.types.get = (typeName) => {
  return Expressions.types.find((type) => type.name === typeName);
};

Expressions.add = (measureId, typeName) => {
  const expressionId = Random.id();

  Measures.collection.update(
    measureId,
    { $push: { expressions: { _id: expressionId, typeName, name: '' } } }
  );

  return expressionId;
};

Expressions.removeLast = (measureId) => {
  Measures.collection.update(
    measureId,
    { $pop: { expressions: 1 } }
  );
};

Meteor.methods({
  'Measures.Expressions.setName': (measureId, expressionId, name) => {
    check(measureId, String);
    check(expressionId, String);
    check(name, String);
    Measures.collection.update(
      { _id: measureId, 'expressions._id': expressionId },
      { $set: { 'expressions.$.name': name } }
    );
  },

  'Measures.Expressions.setMeasure': (measureId, expressionId, measureIdToSet) => {
    check(measureId, String);
    check(expressionId, String);
    check(measureIdToSet, String);
{'fraction_non_alphanumeric': 0.18213058419243985, 'fraction_numerical': 0.000572737686139748, 'mean_word_length': 3.5719895287958114, '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': '6977031', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1150, 'n_words': 226}