<commit_before>var ACTIVE_LOCALE = window.ACTIVE_LOCALE;
if (ACTIVE_LOCALE !== 'en') {
  require('moment/locale/' + ACTIVE_LOCALE);
}
var Locale = require('../../locale/index');
var Polyglot = require('node-polyglot');
var polyglot = new Polyglot({
  locale: ACTIVE_LOCALE, // Needed for pluralize behaviour
  phrases: Locale[ACTIVE_LOCALE]
});
window._t = polyglot.t.bind(polyglot);

var $ = require('jquery');
var _ = require('underscore');
var Backbone = require('backbone');
var ConfigModel = require('./data/config-model');
var TableModel = require('./data/table-model');
var DatasetContentView = require('./dataset/dataset-content/dataset-content-view');
var DatasetOptionsView = require('./dataset/dataset-options/dataset-options-view');
var QueryGeometryModel = require('./data/query-geometry-model');
var QuerySchemaModel = require('./data/query-schema-model');
var ModalsServiceModel = require('./components/modals/modals-service-model');
var MetricsTracker = require('./components/metrics/metrics-tracker');
var SynchronizationModel = require('./data/synchronization-model');
var LayerDefinitionModel = require('./data/layer-definition-model');
var VisTableModel = require('./data/visualization-table-model');
var DatasetUnlockModalView = require('./dataset/dataset-unlock-modal-view');
var EditorModel = require('./data/editor-model');
var UserModel = require('./data/user-model');
var HeaderView = require('./dataset/dataset-header/dataset-header-view');
var Notifier = require('./components/notifier/notifier');
var UserGroupFetcher = require('./data/users-group-fetcher');
var SQLUtils = require('./helpers/sql-utils');
var BuilderActivatedNotification = require('./components/onboardings/builder-activated/builder-activated-notification-view');
var UserNotifications = require('./data/user-notifications');

var userData = window.userData;
var visData = window.visualizationData;
var tableData = window.tableData;
var layersData = window.layersData;
var frontendConfig = window.frontendConfig;
var authTokens = window.authTokens;
var dashboardNotifications = window.dashboardNotifications;

var configModel = new ConfigModel(
  _.defaults(
    {
      base_url: userData.base_url,
      api_key: userData.api_key,
      auth_tokens: authTokens
    },
    frontendConfig
  )
);
var userModel = new UserModel(userData, { configModel: configModel });

var modals = new ModalsServiceModel();
var tableModel = new TableModel(tableData, { parse: true, configModel: configModel });
var visModel = new VisTableModel(visData, { configModel: configModel });
var syncModel = new SynchronizationModel(visData.synchronization, { configModel: configModel });
var layersCollection = new Backbone.Collection(layersData);
var layerDataModel = layersCollection.find(function (mdl) {
  var kind = mdl.get('kind');
  return kind !== 'tiled' && kind !== 'plain';
});

var layerModel = new LayerDefinitionModel(layerDataModel.toJSON(), {
  configModel: configModel,
  parse: true
});

layerModel.url = function () {
  var baseUrl = configModel.get('base_url');
  return baseUrl + '/api/v1/maps/' + visData.map_id + '/layers/' + layerModel.id;
};

UserGroupFetcher.track({
  userModel: userModel,
  configModel: configModel,
  acl: visModel.getPermissionModel().acl
});

var defaultQuery = SQLUtils.getDefaultSQL(
  tableModel.getUnqualifiedName(),
  tableModel.get('permission').owner.username,
  userModel.isInsideOrg()
);

var query = layerModel.get('sql') || defaultQuery;
var isDefaultQuery = SQLUtils.isSameQuery(query, defaultQuery);

var queryGeometryModel = new QueryGeometryModel({
  query: query,
  ready: true
}, {
  configModel: configModel
});
// Request geometries is case that the sql is custom, if not, follow
// what table info provides
if (isDefaultQuery) {
  var simpleGeom = tableModel.getGeometryType();
  queryGeometryModel.set({
    status: 'fetched',
    simple_geom: simpleGeom && simpleGeom[0]
  });
} else {
  queryGeometryModel.fetch();
}

var querySchemaModel = new QuerySchemaModel({
  query: query,
  status: 'unfetched',
  ready: true
}, {
  configModel: configModel
});
var editorModel = new EditorModel();
var Router = new Backbone.Router();

Notifier.init({
  editorModel: editorModel
});

MetricsTracker.init({
  userId: userModel.get('id'),
  visId: visModel.get('id'),
  configModel: configModel
});

var headerView = new HeaderView({
  router: Router,
  modals: modals,
  configModel: configModel,
  userModel: userModel,
  tableModel: tableModel,
  visModel: visModel,
  syncModel: syncModel,
  querySchemaModel: querySchemaModel,
  layerDefinitionModel: layerModel
});
$('.js-info').append(headerView.render().el);

var datasetContentView = new DatasetContentView({
  el: $('.js-table'),
  modals: modals,
  userModel: userModel,
  tableModel: tableModel,
  syncModel: syncModel,
  configModel: configModel,
  queryGeometryModel: queryGeometryModel,
  querySchemaModel: querySchemaModel
});
datasetContentView.render();

var datasetOptionsView = new DatasetOptionsView({
  el: $('.js-datasetOptions'),
  editorModel: editorModel,
  router: Router,
  modals: modals,
  configModel: configModel,
  userModel: userModel,
  tableModel: tableModel,
  visModel: visModel,
  syncModel: syncModel,
  queryGeometryModel: queryGeometryModel,
  querySchemaModel: querySchemaModel,
  layerDefinitionModel: layerModel
});

datasetOptionsView.render();

var notifierView = Notifier.getView();
$('.js-notifier').append(notifierView.render().el);

var rootUrl = configModel.get('base_url').replace(window.location.origin, '') + '/dataset/';<commit_msg>Using analysisDefinitionNodeModel instead of instances of query-schema-model or query-geometry-model<commit_after>var ACTIVE_LOCALE = window.ACTIVE_LOCALE;
if (ACTIVE_LOCALE !== 'en') {
  require('moment/locale/' + ACTIVE_LOCALE);
}
var Locale = require('../../locale/index');
var Polyglot = require('node-polyglot');
var polyglot = new Polyglot({
  locale: ACTIVE_LOCALE, // Needed for pluralize behaviour
  phrases: Locale[ACTIVE_LOCALE]
});
window._t = polyglot.t.bind(polyglot);

var $ = require('jquery');
var _ = require('underscore');
var Backbone = require('backbone');
var ConfigModel = require('./data/config-model');
var DatasetContentView = require('./dataset/dataset-content/dataset-content-view');
var DatasetOptionsView = require('./dataset/dataset-options/dataset-options-view');
var ModalsServiceModel = require('./components/modals/modals-service-model');
var MetricsTracker = require('./components/metrics/metrics-tracker');
var AnalysisDefinitionNodeSourceModel = require('./data/analysis-definition-node-source-model');
var LayerDefinitionModel = require('./data/layer-definition-model');
var VisTableModel = require('./data/visualization-table-model');
var DatasetUnlockModalView = require('./dataset/dataset-unlock-modal-view');
var EditorModel = require('./data/editor-model');
var UserModel = require('./data/user-model');
var HeaderView = require('./dataset/dataset-header/dataset-header-view');
var Notifier = require('./components/notifier/notifier');
var UserGroupFetcher = require('./data/users-group-fetcher');
var BuilderActivatedNotification = require('./components/onboardings/builder-activated/builder-activated-notification-view');
var UserNotifications = require('./data/user-notifications');

var userData = window.userData;
var visData = window.visualizationData;
var tableData = window.tableData;
var layersData = window.layersData;
var frontendConfig = window.frontendConfig;
var authTokens = window.authTokens;
var dashboardNotifications = window.dashboardNotifications;

var configModel = new ConfigModel(
  _.defaults(
    {
      base_url: userData.base_url,
      api_key: userData.api_key,
      auth_tokens: authTokens
    },
    frontendConfig
  )
);
var userModel = new UserModel(userData, { configModel: configModel });

var modals = new ModalsServiceModel();
var editorModel = new EditorModel();
var Router = new Backbone.Router();

// var tableModel = new TableModel(tableData, { parse: true, configModel: configModel });
var visModel = new VisTableModel(visData, { configModel: configModel });

var layersCollection = new Backbone.Collection(layersData);
var layerDataModel = layersCollection.find(function (mdl) {
  var kind = mdl.get('kind');
  return kind !== 'tiled' && kind !== 'plain';
});

var layerModel = new LayerDefinitionModel(layerDataModel.toJSON(), {
  configModel: configModel,
  parse: true
});

layerModel.url = function () {
  var baseUrl = configModel.get('base_url');
  return baseUrl + '/api/v1/maps/' + visData.map_id + '/layers/' + layerModel.id;
};

var analysisDefinitionNodeModel = new AnalysisDefinitionNodeSourceModel({
  table_name: tableData.name,
  query: layerModel.get('sql'),
  id: 'dummy-id'
}, {
  configModel: configModel,
  userModel: userModel,
  tableData: _.extend(
    tableData,
    {
      synchronization: visData.synchronization || {}
    }
  )
});

var tableModel = analysisDefinitionNodeModel.getTableModel();
var querySchemaModel = analysisDefinitionNodeModel.querySchemaModel;
var queryGeometryModel = analysisDefinitionNodeModel.queryGeometryModel;

querySchemaModel.fetch();

UserGroupFetcher.track({
  userModel: userModel,
  configModel: configModel,
  acl: visModel.getPermissionModel().acl
});

// Request geometries is case that the sql is custom, if not, follow
// what table info provides
if (!analysisDefinitionNodeModel.isCustomQueryApplied()) {
  var simpleGeom = tableModel.getGeometryType();
  queryGeometryModel.set({
    status: 'fetched',
    simple_geom: simpleGeom && simpleGeom[0]
  });
} else {
  queryGeometryModel.fetch();
}

Notifier.init({
  editorModel: editorModel
});

MetricsTracker.init({
  userId: userModel.get('id'),
  visId: visModel.get('id'),
  configModel: configModel
});

var headerView = new HeaderView({
  router: Router,
  modals: modals,
  configModel: configModel,
  userModel: userModel,
  visModel: visModel,
  analysisDefinitionNodeModel: analysisDefinitionNodeModel,
  layerDefinitionModel: layerModel
});
$('.js-info').append(headerView.render().el);

var datasetContentView = new DatasetContentView({
  el: $('.js-table'),
  modals: modals,
  userModel: userModel,
  analysisDefinitionNodeModel: analysisDefinitionNodeModel,
  configModel: configModel
});
datasetContentView.render();

var datasetOptionsView = new DatasetOptionsView({
  el: $('.js-datasetOptions'),
  editorModel: editorModel,
  router: Router,
  modals: modals,
  configModel: configModel,
  userModel: userModel,
  visModel: visModel,
  analysisDefinitionNodeModel: analysisDefinitionNodeModel,
  layerDefinitionModel: layerModel
});

datasetOptionsView.render();

var notifierView = Notifier.getView();
$('.js-notifier').append(notifierView.render().el);

var rootUrl = configModel.get('base_url').replace(window.location.origin, '') + '/dataset/';
{'fraction_non_alphanumeric': 0.13499308437067772, 'fraction_numerical': 0.00036883356385431073, 'mean_word_length': 5.56140350877193, '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': '6638989', 'n_tokens_mistral': 3197, 'n_tokens_neox': 3190, 'n_words': 694}