<commit_before>'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
	Schema = mongoose.Schema,
  MediaSchema = require('./media.server.model').schema,
  _ = require('lodash');

/**
 * ExperimentSchema Schema
 */
var ExperimentSchemaSchema = new Schema({
	trialCount: {
    type: Number,
    required: true
  },
  mediaPool: [{
      type: Schema.Types.ObjectId,
      ref: 'Media'
  }]
});

// Validator that requires the value is an array and contains at least one entry
function requiredArrayValidator(value) {
  return Object.prototype.toString.call(value) === '[object Array]' && value.length > 0;
}

// Use the above validator for `mediaPool`
ExperimentSchemaSchema.path('mediaPool').validate(requiredArrayValidator);

ExperimentSchemaSchema.methods.buildExperiment = function(callback) {

  // Populate mediaPool
  this.populate('mediaPool');

  var selectedMedia = _.sample(this.mediaPool, this.trialCount);

  if (typeof callback === 'function') {
    return callback(null, {media: selectedMedia});
  } else {
    return {media: selectedMedia};
  }
};

// Register schema for `ExperimentSchema` model
mongoose.model('ExperimentSchema', ExperimentSchemaSchema);<commit_msg>Return structure and sensors with ExperimentSchema<commit_after>'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
	Schema = mongoose.Schema,
  MediaSchema = require('./media.server.model').schema,
  _ = require('lodash');

/**
 * ExperimentSchema Schema
 */
var ExperimentSchemaSchema = new Schema({
  structure: {},
  sensors: [String],
	trialCount: {
    type: Number,
    required: true
  },
  mediaPool: [{
      type: Schema.Types.ObjectId,
      ref: 'Media'
  }]
});

// Validator that requires the value is an array and contains at least one entry
function requiredArrayValidator(value) {
  return Object.prototype.toString.call(value) === '[object Array]' && value.length > 0;
}

// Use the above validator for `mediaPool`
ExperimentSchemaSchema.path('mediaPool').validate(requiredArrayValidator);

ExperimentSchemaSchema.methods.buildExperiment = function(callback) {

  // Populate mediaPool
  this.populate('mediaPool');

  var selectedMedia = _.sample(this.mediaPool, this.trialCount);

  var schemaSubset = {
    _id: this._id,
    structure: this.structure,
    sensors: this.sensors,
    media: selectedMedia,
  };

  if (typeof callback === 'function') {
    return callback(null, schemaSubset);
  } else {
    return schemaSubset;
  }
};

// Register schema for `ExperimentSchema` model
mongoose.model('ExperimentSchema', ExperimentSchemaSchema);
{'fraction_non_alphanumeric': 0.13156885308784044, 'fraction_numerical': 0.0007671653241273494, 'mean_word_length': 4.333333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5991063', 'n_tokens_mistral': 763, 'n_tokens_neox': 743, 'n_words': 185}