<commit_before>var map, currentMapSources = {}, oldMapSources = {};

function renderMap(){
  var mapOptions = {
    zoom: 3,
    center: new google.maps.LatLng(0, 0),
  };
  map = new google.maps.Map(document.getElementById("map"), mapOptions);
}

function renderInfluencesInMap(influences){
  var influencers = [], events = [];
  $(influences).each(function(i, influence){
    if(influence.kind == "event"){
      events.push(influence);
    } else if (influence.kind == "person"){
      influencers.push(influence);
    }
  });

  _renderInfluencers(influencers);
  _renderEvents(events);
}

function _renderInfluencers(influencers){
  oldMapSources = currentMapSources;
  currentMapSources = {};

  $(influencers).each(function(i, influencer){
    if(oldMapSources[influencer.id] == undefined){
      influencer.shouldRender = true;
    } else {
      // Retrieves marker for this influencer
      influencer.marker = oldMapSources[influencer.id].marker;
    }

    currentMapSources[influencer.id] = influencer;
    delete oldMapSources[influencer.id];
  });

  $.each(currentMapSources, function(influencerId, influencer){
    // Add new Markers
    if(influencer.shouldRender == true){
      influencer.marker = _createMarker(influencer);
      currentMapSources[influencerId] = influencer;
    } else {
      // Update existent marker
      influencer.marker.infowindow.setContent(_createInfoWindowContent(influencer));
    }
  });

  // Remove Markers
  $.each(oldMapSources, function(influencerId, influencer){
    influencer.marker.setMap(null);
  });
}

function _renderEvents(mapEvents){
  var locations = [];
  $(mapEvents).each(function(i, mapEvent){
    var location = new google.maps.LatLng(mapEvent.latlng[0], mapEvent.latlng[1]);
    locations.push({
      location: location, weight: mapEvent.density
    });
  });
  _createHeatmap(locations);
}

function _createHeatmap(locations) {
  var heatmap = new google.maps.visualization.HeatmapLayer({
    data: locations,
    map: map
  });
  heatmap.set('radius', 20);
}

function _createMarker(influencer) {
  var influencerLocation = influencer.locations[0];
  var myLatlng = new google.maps.LatLng(influencerLocation.latlng[0],
                                        influencerLocation.latlng[1]);
  var infowindow = new google.maps.InfoWindow({
    content: _createInfoWindowContent(influencer)
  });

  var marker = new google.maps.Marker({
    position: myLatlng,
    animation: google.maps.Animation.DROP,
    map: map,
    title: influencer.name,
    icon: '/assets/pin-' + influencer.gender + '2.png'
  });

  marker.addListener('click', function() {
    infowindow.open(map, marker);
  });
  infowindow.open(map, marker);

  marker.infowindow = infowindow;
  return marker;
}

function _createInfoWindowContent(influencer) {
  return influencer.name + " (" + influencer.age + "y)";
}<commit_msg>Fix setPosition for new marker position of the same influencer<commit_after>var map, currentMapSources = {}, oldMapSources = {};

function renderMap(){
  map = new google.maps.Map(document.getElementById("map"),
                            { zoom: 3, center: new google.maps.LatLng(0, 0) });
}

function renderInfluencesInMap(influences){
  var influencers = [];

  $(influences).each(function(i, inf){ influencers.push(inf) });

  _renderInfluencers(influencers);
}

function _renderInfluencers(influencers){
  oldMapSources = currentMapSources;
  currentMapSources = {};

  $(influencers).each(function(i, influencer){

    if(oldMapSources[influencer.id] == undefined){
      influencer.marker = _createMarker(influencer);
    } else {
      influencer.marker = oldMapSources[influencer.id].marker;
      _moveMarker(influencer.marker, influencer.locations[0]);
    }

    influencer.marker.infowindow.setContent(_createInfoWindowContent(influencer));

    currentMapSources[influencer.id] = influencer;
    delete oldMapSources[influencer.id];
  });

  // Remove Markers
  $.each(oldMapSources, function(id, influencer){ influencer.marker.setMap(null) });
}

function _moveMarker(marker, newLocation){
  var newLatLng = new google.maps.LatLng(newLocation.latlng[0],
                                         newLocation.latlng[1]);
  marker.setPosition(newLatLng)
}

function _createMarker(influencer) {
  var influencerLocation = influencer.locations[0];
  var myLatlng = new google.maps.LatLng(influencerLocation.latlng[0],
                                        influencerLocation.latlng[1]);
  var infowindow = new google.maps.InfoWindow();

  var marker = new google.maps.Marker({
    position: myLatlng,
    animation: google.maps.Animation.DROP,
    map: map,
    title: influencer.name,
    icon: '/assets/pin-' + influencer.gender + '2.png'
  });

  marker.addListener('click', function() { infowindow.open(map, marker) });
  infowindow.open(map, marker);

  marker.infowindow = infowindow;
  return marker;
}

function _createInfoWindowContent(influencer) {
  return influencer.name + " (" + influencer.age + "y)";
}
{'fraction_non_alphanumeric': 0.1314, 'fraction_numerical': 0.0042, 'mean_word_length': 3.804034582132565, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6883089', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1585, 'n_words': 272}