<commit_before>var cdb = require('cartodb.js-v3');
var Carto = require('../../carto-node/index.js.babel');
var AssetsVersionHelper = require('../helpers/assets_version');
var MapOptionsHelper = require('../helpers/map_options');
var PublicMapWindow = require('./public_map_window_static');

var PACKAGE = require('../../../../../package.json');
var VERSION = PACKAGE.version;
var MAP_ID = 'map';

window.StaticConfig = window.StaticConfig || {};
window.CartoConfig = window.CartoConfig || {};

var InitPublicMap = function () {
  cdb.init(function () {
    function dataLoaded () {
      var data = window.CartoConfig.data;
      var vizdata = window.CartoConfig.vizdata;
      var visualizations = window.CartoConfig.visualizations;

      var currentUser = data.user_data
        ? new cdb.admin.User(data.user_data)
        : null;

      var mapOwnerUser = vizdata.permission.owner
        ? new cdb.admin.User(vizdata.permission.owner)
        : null;

      cdb.templates.namespace = 'cartodb/';
      cdb.config.set(data.config);

      if (currentUser) {
        cdb.config.set('user', currentUser);
        cdb.config.set('url_prefix', currentUser.get('base_url'));
      }

      this.publicMapView = new PublicMapWindow({
        assetsVersion: AssetsVersionHelper.getAssetsVersion(VERSION),
        collection: new cdb.admin.Visualizations(),
        config: cdb.config,
        currentUser: currentUser,
        mapOwnerUser: mapOwnerUser,
        data: data,
        el: '#app',
        isMobileDevice: MapOptionsHelper.isMobileDevice(),
        mapId: MAP_ID,
        mapOptions: {},
        vizdata: vizdata,
        visualizations: visualizations
      });
    }

    if (window.CartoConfig.data && window.CartoConfig.vizdata) {
      dataLoaded();
    } else {
      var client = new Carto.AuthenticatedClient();
      var vizUrl = MapOptionsHelper.getVizUrl('public_map');
      var visualizationsNumber = 3;

      var getConfig = function () {
        client.getConfig(function (err, response, data) {
          if (err) {
            console.error(err);
            return err;
          } else {
            window.CartoConfig.data = data;
            getVisualization();
          }
        });
      }

      var getVisualization = function () {
        client.getVisualization(vizUrl, function (err, response, vizdata) {
          if (err) {
            console.error(err);
            return err;
          } else {
            window.CartoConfig.vizdata = vizdata;
            getDerivedVisualizations();
          }
        });
      }

      var getDerivedVisualizations = function () {
        client.getDerivedVisualizations(visualizationsNumber, function (err, response, data) {
          if (err) {
            console.error(err);
            return err;
          } else {
            window.CartoConfig.visualizations = data.visualizations;
            dataLoaded();
          }
        });
      }
    }

    getConfig();
  });
};

InitPublicMap();<commit_msg>fix remove current map from related visualizations<commit_after>var _ = require('underscore');
var cdb = require('cartodb.js-v3');
var Carto = require('../../carto-node/index.js.babel');
var AssetsVersionHelper = require('../helpers/assets_version');
var MapOptionsHelper = require('../helpers/map_options');
var PublicMapWindow = require('./public_map_window_static');

var PACKAGE = require('../../../../../package.json');
var VERSION = PACKAGE.version;
var MAP_ID = 'map';

window.StaticConfig = window.StaticConfig || {};
window.CartoConfig = window.CartoConfig || {};

var InitPublicMap = function () {
  cdb.init(function () {
    function dataLoaded () {
      var data = window.CartoConfig.data;
      var vizdata = window.CartoConfig.vizdata;
      var visualizations = window.CartoConfig.visualizations;

      var currentUser = data.user_data
        ? new cdb.admin.User(data.user_data)
        : null;

      var mapOwnerUser = vizdata.permission.owner
        ? new cdb.admin.User(vizdata.permission.owner)
        : null;

      cdb.templates.namespace = 'cartodb/';
      cdb.config.set(data.config);

      if (currentUser) {
        cdb.config.set('user', currentUser);
        cdb.config.set('url_prefix', currentUser.get('base_url'));
      }

      this.publicMapView = new PublicMapWindow({
        assetsVersion: AssetsVersionHelper.getAssetsVersion(VERSION),
        collection: new cdb.admin.Visualizations(),
        config: cdb.config,
        currentUser: currentUser,
        mapOwnerUser: mapOwnerUser,
        data: data,
        el: '#app',
        isMobileDevice: MapOptionsHelper.isMobileDevice(),
        mapId: MAP_ID,
        mapOptions: {},
        vizdata: vizdata,
        visualizations: visualizations
      });
    }

    if (window.CartoConfig.data && window.CartoConfig.vizdata) {
      dataLoaded();
    } else {
      var client = new Carto.AuthenticatedClient();
      var vizUrl = MapOptionsHelper.getVizUrl('public_map');
      var visualizationsNumber = 3;

      var getConfig = function () {
        client.getConfig(function (err, response, data) {
          if (err) {
            console.error(err);
            return err;
          } else {
            window.CartoConfig.data = data;
            getVisualization();
          }
        });
      }

      var getVisualization = function () {
        client.getVisualization(vizUrl, function (err, response, vizdata) {
          if (err) {
            console.error(err);
            return err;
          } else {
            window.CartoConfig.vizdata = vizdata;
            getDerivedVisualizations(vizdata);
          }
        });
      }

      var getDerivedVisualizations = function (vizdata) {
        client.getDerivedVisualizations(visualizationsNumber, function (err, response, data) {
          if (err) {
            console.error(err);
            return err;
          } else {
            window.CartoConfig.visualizations = _.filter(data.visualizations,
              function (visualization) {
                return visualization.id !== vizdata.id;
              });
            dataLoaded();
          }
        });
      }
    }

    getConfig();
  });
};

InitPublicMap();
{'fraction_non_alphanumeric': 0.1235483870967742, 'fraction_numerical': 0.0006451612903225806, 'mean_word_length': 2.2296875, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4886190', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1750, 'n_words': 329}