<commit_before>var data = require('./database').collection('data');
var moment = require('moment');

module.exports = function(params, callback) {

  // Loop through parameters to update device sensor data
  var updates = {};
  updates.timestamp = moment().toISOString()

  for (var param in params) {
    var parsed;
    try {
      parsed = JSON.parse(params[param]);
    } catch (e) {
      parsed = params[param];
    }
    updates[param] = parsed.toString();
  }

  delete updates.token;

  data.save(updates, function(err, saved) {
    // if(err || saved === 0) {
    if(err) {
      var regdata = {
        "error": {
          "message": "Device not registered",
          "code": 500
        }
      };
      // require('./logEvent')(400, regdata);
      callback(regdata);
    } else {
      console.log('Sensor data logged:', JSON.stringify(updates));

      updates._id.toString();
      delete updates._id;

      require('./logEvent')(700, updates);<commit_msg>ensure timestamp is saved as mongo friendly ISODate<commit_after>var data = require('./database').collection('data');
var moment = require('moment');

module.exports = function(params, callback) {

  // Loop through parameters to update device sensor data
  var updates = {};
  updates.timestamp = new Date()

  for (var param in params) {
    var parsed;
    try {
      parsed = JSON.parse(params[param]);
    } catch (e) {
      parsed = params[param];
    }
    updates[param] = parsed.toString();
  }

  delete updates.token;

  data.save(updates, function(err, saved) {
    // if(err || saved === 0) {
    if(err) {
      var regdata = {
        "error": {
          "message": "Device not registered",
          "code": 500
        }
      };
      // require('./logEvent')(400, regdata);
      callback(regdata);
    } else {
      console.log('Sensor data logged:', JSON.stringify(updates));

      updates._id.toString();
      delete updates._id;

      require('./logEvent')(700, updates);
{'fraction_non_alphanumeric': 0.15536437246963564, 'fraction_numerical': 0.010121457489878543, 'mean_word_length': 2.5815217391304346, 'pattern_counts': {'":': 6, '<': 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': '1946467', 'n_tokens_mistral': 600, 'n_tokens_neox': 581, 'n_words': 143}