<commit_before>require([
  '$api/models',
  'js/controllers/controller#controller'
], function(models, Controller) {
  var TagsMenu = new Class({
    Extends: Controller,

    initialize: function(name, config) {
      this.parent(name, config);

      this.commonTags = [];
    }
  });

  TagsMenu.implement({
    afterLoad: function(graphcontroller) {
      this.graphcontroller = graphcontroller;

      this.bindEvents();
    },
    updateView: function() {
      var nodes = this.graphcontroller.artistGraph.data.nodes;

      function ajaxDone(index, data) {
        node.tags = data.response.terms;

        this.commonTags = _.union(this.commonTags, node.tags);
      }

      for (var i = 0; i < nodes.length; ++i) {
        var node = nodes[i];
        var url =
          "http://developer.echonest.com/api/v4/artist/" +
          "terms?api_key=29N71ZBQUW4XN0QXF&format=json&sort=weight&name=" +
          encodeURIComponent(node.label);

        $.ajax({
          url: url,
          context: this,
          async: false
        }).done(ajaxDone.bind(this, i));
      }

      // TODO parse commonTags
    },
    bindEvents: function() {
      this.graphcontroller
        .addCustomGraphEvent('update', this.updateView.bind(this));
    }
  });

  exports.tagsmenu = TagsMenu;
});<commit_msg>count of tags from graph done.<commit_after>require([
  '$api/models',
  'js/controllers/controller#controller'
], function(models, Controller) {
  var TagsMenu = new Class({
    Extends: Controller,

    initialize: function(name, config) {
      this.parent(name, config);

      this.commonTags = [];
    }
  });

  TagsMenu.implement({
    afterLoad: function(graphcontroller) {
      this.graphcontroller = graphcontroller;

      this.bindEvents();
    },
    updateView: function() {
      var nodes = this.graphcontroller.artistGraph.data.nodes;

      function ajaxDone(index, data) {
        node.tags = data.response.terms;

        this.commonTags = _.union(this.commonTags, node.tags);
      }

      for (var i = 0; i < nodes.length; ++i) {
        var node = nodes[i];
        var url =
          "http://developer.echonest.com/api/v4/artist/" +
          "terms?api_key=29N71ZBQUW4XN0QXF&format=json&sort=weight&name=" +
          encodeURIComponent(node.label);

        $.ajax({
          url: url,
          context: this,
          async: false
        }).done(ajaxDone.bind(this, i));
      }

      // TODO parse commonTags

      this.commonTags = _.sortBy(_.map(_.countBy(this.commonTags, function(tag) {
        return tag.name;
      }), function(num, key) {
        var value = {
          name: key,
          count: num
        };
        return value;
      }), 'count').reverse();

      console.log(this.commonTags);
    },
    bindEvents: function() {
      this.graphcontroller
        .addCustomGraphEvent('update', this.updateView.bind(this));
    }
  });

  exports.tagsmenu = TagsMenu;
});
{'fraction_non_alphanumeric': 0.13974096796182686, 'fraction_numerical': 0.0054533060668029995, 'mean_word_length': 2.323895809739524, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6688107', 'n_tokens_mistral': 933, 'n_tokens_neox': 900, 'n_words': 162}