<commit_before>'use strict';

var request = require('request');
var Q = require('q');
var config = require('../config');

const plugins = require('../../plugins');
const geoTagController = plugins.getFirst('geo-tag-controller');
if(!geoTagController) {
  throw new Error('Expected at least one image controller!');
}

function deg(w) {
  w = w % 360;
  return w < 0 ? w + 360 : w;
}

exports.save = function(req, res, next) {
  // Check with the CIP to ensure that the asset has not already been geotagged.
  var collection = req.params.collection;
  var id = req.params.id;
  var latitude = parseFloat(req.body.latitude);
  var longitude = parseFloat(req.body.longitude);
  // Checking if heading is a key in the body, as a valid heading can be 0.
  // Heading is also converted to a degree between 0 and 360
  var heading = 'heading' in req.body ?
      deg(parseFloat(req.body.heading)) :
      null;

  if (!config.features.geotagging) {
    throw new Error('Geotagging is disabled.');
  }

  // Save the new coordinates to the CIP.
  var coords = [latitude, longitude];
  // TODO: Save and update index
  return new Q({
    coords,
    heading,
    collection,
    id
  })
  .then(geoTagController.save)
  .then(geoTagController.updateIndex)
  .then(function() {
    // done
    res.json({
      success: true
    });
  }, next);
};
<commit_msg>Cleaning up some names in the geo-tagging controller<commit_after>'use strict';

var request = require('request');
var Q = require('q');
var config = require('../config');

const plugins = require('../../plugins');
const geoTagController = plugins.getFirst('geo-tag-controller');
if(!geoTagController) {
  throw new Error('Expected at least one image controller!');
}

function deg(w) {
  w = w % 360;
  return w < 0 ? w + 360 : w;
}

exports.save = function(req, res, next) {
  // Check with the CIP to ensure that the asset has not already been geotagged.
  var collection = req.params.collection;
  var id = req.params.id;
  var latitude = parseFloat(req.body.latitude);
  var longitude = parseFloat(req.body.longitude);
  // Checking if heading is a key in the body, as a valid heading can be 0.
  // Heading is also converted to a degree between 0 and 360
  var heading = 'heading' in req.body ?
      deg(parseFloat(req.body.heading)) :
      null;

  if (!config.features.geotagging) {
    throw new Error('Geotagging is disabled.');
  }

  // Save the new coordinates to the CIP.
  var coordinates = [latitude, longitude];
  return new Q({
    collection,
    id,
    coordinates,
    heading
  })
  .then(geoTagController.save)
  .then(geoTagController.updateIndex)
  .then(function() {
    // done
    res.json({
      success: true
    });
  }, next);
};

{'fraction_non_alphanumeric': 0.13107511045655376, 'fraction_numerical': 0.008836524300441826, 'mean_word_length': 3.1864406779661016, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6319868', 'n_tokens_mistral': 880, 'n_tokens_neox': 839, 'n_words': 280}