<commit_before>import { Class, d3 } from 'shared'

export var VisUnemploymentSex = Class.extend({
  init: function(divId, city_id, unemplAgeData) {
    this.container = divId;
    this.data = null;
    this.unemplAgeData = unemplAgeData;
    this.tbiToken = window.populateData.token;
    this.popUrl = window.populateData.endpoint + '/datasets/ds-poblacion-activa-municipal-sexo.json?sort_asc_by=date&filter_by_location_id=' + city_id;
    this.unemplUrl = window.populateData.endpoint + '/datasets/ds-personas-paradas-municipio-sexo.json?sort_asc_by=date&filter_by_location_id=' + city_id;
    this.parseTime = d3.timeParse('%Y-%m');
    this.pctFormat = d3.format('.1%');
    this.isMobile = window.innerWidth <= 768;

    // Chart dimensions
    this.margin = {top: 25, right: 50, bottom: 25, left: 20};
    this.width = this._width() - this.margin.left - this.margin.right;
    this.height = this._height() - this.margin.top - this.margin.bottom;

    // Scales & Ranges
    this.xScale = d3.scaleTime();
    this.yScale = d3.scaleLinear();
    this.color = d3.scaleOrdinal();

    // Create axes
    this.xAxis = d3.axisBottom();
    this.yAxis = d3.axisLeft();

    // Chart objects
    this.svg = null;
    this.chart = null;

    // Create main elements
    this.svg = d3.select(this.container)
      .append('svg')
      .attr('width', this.width + this.margin.left + this.margin.right)
      .attr('height', this.height + this.margin.top + this.margin.bottom)
      .append('g')
      .attr('class', 'chart-container')
      .attr('transform', 'translate(' + this.margin.left + ',' + this.margin.top + ')');

    // Append axes containers
    this.svg.append('g').attr('class','x axis');
    this.svg.append('g').attr('class','y axis');

    d3.select(window).on('resize.' + this.container, this._resize.bind(this));
  },
  getData: function() {
    var pop = d3.json(this.popUrl)
      .header('authorization', 'Bearer ' + this.tbiToken)

    var unemployed = d3.json(this.unemplUrl)
      .header('authorization', 'Bearer ' + this.tbiToken)

    d3.queue()
      .defer(pop.get)
      .defer(unemployed.get)
      .await(function (error, population, unemployment) {
        if (error) throw error;

        var nested = d3.nest()
          .key(function(d) { return d.date; })
          .rollup(function(v) { return d3.sum(v, function(d) { return d.value; }); })
          .entries(population);

        var temp = {};
        nested.forEach(function(k) {
          temp[k.key] = k.value
        });
        nested = temp;
<commit_msg>Adjust active population<commit_after>import { Class, d3 } from 'shared'

export var VisUnemploymentSex = Class.extend({
  init: function(divId, city_id, unemplAgeData) {
    this.location_id = parseInt(city_id);
    this.container = divId;
    this.data = null;
    this.unemplAgeData = unemplAgeData;
    this.tbiToken = window.populateData.token;
    this.popUrl = window.populateData.endpoint + '/datasets/ds-poblacion-activa-municipal-sexo.json?sort_asc_by=date&filter_by_location_id=' + city_id;
    this.unemplUrl = window.populateData.endpoint + '/datasets/ds-personas-paradas-municipio-sexo.json?sort_asc_by=date&filter_by_location_id=' + city_id;
    this.parseTime = d3.timeParse('%Y-%m');
    this.pctFormat = d3.format('.1%');
    this.isMobile = window.innerWidth <= 768;

    // Chart dimensions
    this.margin = {top: 25, right: 50, bottom: 25, left: 20};
    this.width = this._width() - this.margin.left - this.margin.right;
    this.height = this._height() - this.margin.top - this.margin.bottom;

    // Scales & Ranges
    this.xScale = d3.scaleTime();
    this.yScale = d3.scaleLinear();
    this.color = d3.scaleOrdinal();

    // Create axes
    this.xAxis = d3.axisBottom();
    this.yAxis = d3.axisLeft();

    // Chart objects
    this.svg = null;
    this.chart = null;

    // Create main elements
    this.svg = d3.select(this.container)
      .append('svg')
      .attr('width', this.width + this.margin.left + this.margin.right)
      .attr('height', this.height + this.margin.top + this.margin.bottom)
      .append('g')
      .attr('class', 'chart-container')
      .attr('transform', 'translate(' + this.margin.left + ',' + this.margin.top + ')');

    // Append axes containers
    this.svg.append('g').attr('class','x axis');
    this.svg.append('g').attr('class','y axis');

    d3.select(window).on('resize.' + this.container, this._resize.bind(this));
  },
  getData: function() {
    var pop = d3.json(this.popUrl)
      .header('authorization', 'Bearer ' + this.tbiToken)

    var unemployed = d3.json(this.unemplUrl)
      .header('authorization', 'Bearer ' + this.tbiToken)

    d3.queue()
      .defer(pop.get)
      .defer(unemployed.get)
      .await(function (error, population, unemployment) {
        if (error) throw error;

        if(this.location_id === 8077) {
          let factor = 0.7786712568;
          population.forEach((d) => {
            d.value = d.value * factor;
          })
        }

        var nested = d3.nest()
          .key(function(d) { return d.date; })
          .rollup(function(v) { return d3.sum(v, function(d) { return d.value; }); })
          .entries(population);

        var temp = {};
        nested.forEach(function(k) {
          temp[k.key] = k.value
        });
        nested = temp;

{'fraction_non_alphanumeric': 0.16216216216216217, 'fraction_numerical': 0.01295045045045045, 'mean_word_length': 2.7714083510261855, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, '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': '6124876', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1783, 'n_words': 315}