<commit_before>/**
 * Utilities for handling device entries in the DB
 * 
 * These now all return promises, so usage is e.g.:
 * 
 * 		var devutils = require('deviceUtils');
 * 		devutils.insertDevice(device).then(success, error);
 * 
 */

var db = require('../mongodb');
var RSVP = require('rsvp');

exports.insertDevice = function(device)
{
	var promise = new RSVP.Promise(function(resolve, reject) 
	{
		db.devices.insert(device, function(err, saved) {
			if (err)
			{
				console.log("deviceUtils: error inserting device: " + JSON.stringify(err));
				reject(err);
			}
			else
			{
//				console.log("deviceUtils: insertDevice succeeded, returning saved: " + saved +
//						" in JSON: " + JSON.stringify(saved));
				resolve(saved[0]); // for some reason, 'saved' is a list here
			}
		});
	});
	
	return promise;
};

exports.updateDevice = function(device)
{
	var promise = new RSVP.Promise(function(resolve, reject) <commit_msg>jshint fixes<commit_after>/**
 * Utilities for handling device entries in the DB
 * 
 * These now all return promises, so usage is e.g.:
 * 
 *      var devutils = require('deviceUtils');
 *      devutils.insertDevice(device).then(success, error);
 * 
 */

var db = require('../mongodb');
var RSVP = require('rsvp');

exports.insertDevice = function(device)
{
	var promise = new RSVP.Promise(function(resolve, reject) 
	{
		db.devices.insert(device, function(err, saved) {
			if (err)
			{
				console.log("deviceUtils: error inserting device: " + JSON.stringify(err));
				reject(err);
			}
			else
			{
//				console.log("deviceUtils: insertDevice succeeded, returning saved: " + saved +
//						" in JSON: " + JSON.stringify(saved));
				resolve(saved[0]); // for some reason, 'saved' is a list here
			}
		});
	});
	
	return promise;
};

exports.updateDevice = function(device)
{
	var promise = new RSVP.Promise(function(resolve, reject) 
{'fraction_non_alphanumeric': 0.15007982969664715, 'fraction_numerical': 0.0010643959552953698, 'mean_word_length': 3.4976076555023923, 'pattern_counts': {'":': 0, '<': 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': '721860', 'n_tokens_mistral': 674, 'n_tokens_neox': 590, 'n_words': 151}