<commit_before>"use strict";

const gpsSourceFactory = require('./gpsSource');
const Promise = require('bluebird');

var x = gpsSourceFactory.newSource();
var gpsCoordinates = {};
var keyDevice = null;

function prune()
{
  var now = new Date();
  var newGPSCoordinates = {};

  for(id in gpsCoordinates)
  {
    var newSamples = [];
    var deviceSamples = gpsCoordinates[id].samples;

    for(i = 0;i < deviceSamples.length;i++)
    {
      if(now.valueOf() - 5000 < deviceSamples[i].millis) newSamples.push(deviceSamples[i]);
      else console.log("pruned ",deviceSamples[i]);
    }
    if(newSamples.length > 0)
    {
      newGPSCoordinates[id] = {};
      newGPSCoordinates[id].id = gpsCoordinates[id].id;
      newGPSCoordinates[id].name = gpsCoordinates[id].name;
      newGPSCoordinates[id].samples = newSamples;
    }
  }
  gpsCoordinates = newGPSCoordinates;
}

function getFeatureInfo()
{
  let key = keyDevice;
  let center = { lat:0, long:0 };
  let features = [];

  for(let id in gpsCoordinates)
  {
    let deviceInfo = gpsCoordinates[id];
    let name = deviceInfo.name;
    let samples = deviceInfo.src.samples;
    let current = deviceInfo.src.current;

    if(key == null) key = id;
    if(key == id)
    {
       center.lat = current.lat;
       center.long = current.long;
    }

    for(var i = 0;i < samples.length;i++)
    {
      features.push({
        type:"Feature",
        geometry:{ type:"Point", coordinates:[samples[i].long,samples[i].lat] },
        properties:{ title:name }
      });
    }
  }
  return { features:features, center:center };
}


//setInterval(prune,500);

function addGPSCoord(id,name,millis,lat,long,alt)
{
  let locus = gpsCoordinates[id];

  if(locus == null)
  {
      locus =
      {
        id:id,
        name:name,
        src:gpsSourceFactory.newSource(lat,long)
      };

      gpsCoordinates[id] = locus;
  }

  locus.src.addCoordinate(millis,lat,long,alt);
  locus.src.predict().then(function(predictedValue) { locus.src.current = predictedValue; });
}

addGPSCoord("a","b",0,34,56,78);

module.exports =
{
  getGPSCoords: function()
  {
    return gpsCoordinates;
  },
  addGPSCoord: addGPSCoord,
  getKeyDevice: function() { return keyDevice; },
  getKeyDevice: function(id) { keyDevice = id; },
  getFeatureInfo: getFeatureInfo
};
<commit_msg>Remove debugging GPS coord<commit_after>"use strict";

const gpsSourceFactory = require('./gpsSource');
const Promise = require('bluebird');

var x = gpsSourceFactory.newSource();
var gpsCoordinates = {};
var keyDevice = null;

function prune()
{
  var now = new Date();
  var newGPSCoordinates = {};

  for(id in gpsCoordinates)
  {
    var newSamples = [];
    var deviceSamples = gpsCoordinates[id].samples;

    for(i = 0;i < deviceSamples.length;i++)
    {
      if(now.valueOf() - 5000 < deviceSamples[i].millis) newSamples.push(deviceSamples[i]);
      else console.log("pruned ",deviceSamples[i]);
    }
    if(newSamples.length > 0)
    {
      newGPSCoordinates[id] = {};
      newGPSCoordinates[id].id = gpsCoordinates[id].id;
      newGPSCoordinates[id].name = gpsCoordinates[id].name;
      newGPSCoordinates[id].samples = newSamples;
    }
  }
  gpsCoordinates = newGPSCoordinates;
}

function getFeatureInfo()
{
  let key = keyDevice;
  let center = { lat:0, long:0 };
  let features = [];

  for(let id in gpsCoordinates)
  {
    let deviceInfo = gpsCoordinates[id];
    let name = deviceInfo.name;
    let samples = deviceInfo.src.samples;
    let current = deviceInfo.src.current;

    if(key == null) key = id;
    if(key == id)
    {
       center.lat = current.lat;
       center.long = current.long;
    }

    for(var i = 0;i < samples.length;i++)
    {
      features.push({
        type:"Feature",
        geometry:{ type:"Point", coordinates:[samples[i].long,samples[i].lat] },
        properties:{ title:name }
      });
    }
  }
  return { features:features, center:center };
}


//setInterval(prune,500);

function addGPSCoord(id,name,millis,lat,long,alt)
{
  let locus = gpsCoordinates[id];

  if(locus == null)
  {
      locus =
      {
        id:id,
        name:name,
        src:gpsSourceFactory.newSource(lat,long)
      };

      gpsCoordinates[id] = locus;
  }

  locus.src.addCoordinate(millis,lat,long,alt);
  locus.src.predict().then(function(predictedValue) { locus.src.current = predictedValue; });
}

module.exports =
{
  getGPSCoords: function()
  {
    return gpsCoordinates;
  },
  addGPSCoord: addGPSCoord,
  getKeyDevice: function() { return keyDevice; },
  getKeyDevice: function(id) { keyDevice = id; },
  getFeatureInfo: getFeatureInfo
};

{'fraction_non_alphanumeric': 0.14505971769815418, 'fraction_numerical': 0.006731813246471227, 'mean_word_length': 3.2025547445255476, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '3460487', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1572, 'n_words': 282}