<commit_before>// api/controllers/interaction.js

var mongoose = require("mongoose");
var Interaction = mongoose.model("Interaction");
var Device = mongoose.model("Device");
var deviceManager = require("./deviceManager");
var async = require("async");

var devQueryFields = "-_fetchComplete -_nActions -_nEvents -_nInteractions -_maxInteractions -__v -events._id -actions._id";
var interQueryFields = "-__v";

/*
	New interaction object format;
	{
		_id: id
		event_device: Device,
		event: Number,
		action_device: Device,
		action: Number,
		param: Number,
		_n: Number
	}

	*action_device is always known, because is the one that has the interaction 
	in memory, however, event_device could be unknown, in this case we pass an
	empty device with just its address. 
*/

// modifies interaction for the new format.
// callback(err, interaction)
var formatInteraction = function(interaction, callback)
{
	if(!interaction) return callback(null, interaction);
	var newInteraction = {
		_id: interaction._id,
		event_device: null,
		event: interaction.event,
		action_device: null,
		action: interaction.action,
		param: interaction.param,
		_n: interaction.number
	};

	Device.findOne({"address": interaction.action_address}, devQueryFields, function(err, action_device)
		{
			//console.log(action_device);
			if(err) return callback(err);
			if(!action_device) return callback(new Error("Couldn't get action_device with address " + interaction.action_address));

			newInteraction.action_device = action_device;

			Device.findOne({"address": interaction.event_device}, devQueryFields, function(err, event_device)
				{
					if(err) return callback(err);
					//console.log(event_device);

					if(!event_device)
					{
						event_device = {<commit_msg>Fixed bug on interactiosn, where the event_device was always blank even when known<commit_after>// api/controllers/interaction.js

var mongoose = require("mongoose");
var Interaction = mongoose.model("Interaction");
var Device = mongoose.model("Device");
var deviceManager = require("./deviceManager");
var async = require("async");

var devQueryFields = "-_fetchComplete -_nActions -_nEvents -_nInteractions -_maxInteractions -__v -events._id -actions._id";
var interQueryFields = "-__v";

/*
	New interaction object format;
	{
		_id: id
		event_device: Device,
		event: Number,
		action_device: Device,
		action: Number,
		param: Number,
		_n: Number
	}

	*action_device is always known, because is the one that has the interaction 
	in memory, however, event_device could be unknown, in this case we pass an
	empty device with just its address. 
*/

// modifies interaction for the new format.
// callback(err, interaction)
var formatInteraction = function(interaction, callback)
{
	if(!interaction) return callback(null, interaction);
	var newInteraction = {
		_id: interaction._id,
		event_device: null,
		event: interaction.event,
		action_device: null,
		action: interaction.action,
		param: interaction.param,
		_n: interaction.number
	};

	Device.findOne({"address": interaction.action_address}, devQueryFields, function(err, action_device)
		{
			//console.log(action_device);
			if(err) return callback(err);
			if(!action_device) return callback(new Error("Couldn't get action_device with address " + interaction.action_address));

			newInteraction.action_device = action_device;

			Device.findOne({"address": interaction.event_address}, devQueryFields, function(err, event_device)
				{
					if(err) return callback(err);
					//console.log(event_device);

					if(!event_device)
					{
						event_device = {
{'fraction_non_alphanumeric': 0.11207378423700391, 'fraction_numerical': 0.0, 'mean_word_length': 4.6899841017488075, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, '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': '3491974', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1063, 'n_words': 296}