<commit_before>mongoose = require 'mongoose'
Measurement  = mongoose.model 'Measurement'

exports.distanceKm = (lat1, lon1, lat2, lon2) -> 
  R = 6371
  dLat = (lat2 - lat1) * Math.PI / 180
  dLon = (lon2 - lon1) * Math.PI / 180
  a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * Math.sin(dLon / 2) * Math.sin(dLon / 2)
  c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
  d = R * c
  return d

exports.createOrReplaceMeasurement = (measurements, req) ->
	# if there is a too close measurement
	if measurements.length == 0
	  # add a new measurement
	  return new Measurement(
	    type: req.body.type
	    signalDBm: req.body.signalDBm
	    wifiAPs: req.body.wifiAPs
	    location: 
	      type: 'Point'
	      coordinates: [req.body.lat, req.body.lng]
	  )
	else
	  # avg the measurement
	  measurement = measurements[0]
	  measurement.signalDBm = Math.floor((req.body.signalDBm + measurement.signalDBm) / 2)
	  measurement.wifiAPs = Math.floor((req.body.wifiAPs + measurement.wifiAPs) / 2)
	  measurement.type = req.body.type
	  return measurement

exports.validateParameters = (req,res,next) ->
  if(measurementLib.distanceKm(req.query.nelat, req.query.nelng, req.query.swlat, req.query.swlng) > 10.0)
    res.json([])
    return
  if req.query.nelat is undefined or req.query.swlat is undefined or req.query.nelng is undefined or req.query.swlng is undefined
    res.json([])
    return
  next()<commit_msg>fixing library bug<commit_after>mongoose = require 'mongoose'
Measurement  = mongoose.model 'Measurement'

exports.distanceKm = (lat1, lon1, lat2, lon2) -> 
  R = 6371
  dLat = (lat2 - lat1) * Math.PI / 180
  dLon = (lon2 - lon1) * Math.PI / 180
  a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * Math.sin(dLon / 2) * Math.sin(dLon / 2)
  c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
  d = R * c
  return d

exports.createOrReplaceMeasurement = (measurements, req) ->
	# if there is a too close measurement
	if measurements.length == 0
	  # add a new measurement
	  return new Measurement(
	    type: req.body.type
	    signalDBm: req.body.signalDBm
	    wifiAPs: req.body.wifiAPs
	    location: 
	      type: 'Point'
	      coordinates: [req.body.lat, req.body.lng]
	  )
	else
	  # avg the measurement
	  measurement = measurements[0]
	  measurement.signalDBm = Math.floor((req.body.signalDBm + measurement.signalDBm) / 2)
	  measurement.wifiAPs = Math.floor((req.body.wifiAPs + measurement.wifiAPs) / 2)
	  measurement.type = req.body.type
	  return measurement

exports.validateParameters = (req, res, next) ->
  if(distanceKm(req.query.nelat, req.query.nelng, req.query.swlat, req.query.swlng) > 10.0)
    res.json([])
    return
  if req.query.nelat is undefined or req.query.swlat is undefined or req.query.nelng is undefined or req.query.swlng is undefined
    res.json([])
    return
  next()
{'fraction_non_alphanumeric': 0.1327223353699932, 'fraction_numerical': 0.027155465037338764, 'mean_word_length': 3.0930555555555554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5814475', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1085, 'n_words': 255}