<commit_before>/**
 * Converts role database entries to Blockly blocks.
 * @author <NAME> (<EMAIL>)
 */

if (!Blockly.Language) Blockly.Language = {};

/* To avoid namespace collisions, sub-category for us */
Blockly.Belphanior={};

/* Role name to hue converter, to create consistent colors for
 * roles. This simply sums the character codes in the role names and
 * converts the resulting sum into a 0-360 "hue" value.
 */
Blockly.Belphanior.nameToHue = function(name) {
  accum = 0;
  for(var i = 0; i < name.length; i++) {
    accum += name.charCodeAt(i);
  }
  return accum % 360;
}

/* Converts a role JSON to blocks in Blockly */
  Blockly.Belphanior.rolesToBlocks = function(rolesJson) {
    $.each(rolesJson, function (idx, roleJson) {
	var role = new Role(roleJson.model, roleJson.url);
	var category = role.name();
	var roleUid = role.url;
	var roleHue = Blockly.Belphanior.nameToHue(roleUid);

	$.each(role.role.commands, function(cmdIdx, command) {
	var newBlock = {
	  category: category,
	  init: function () {
	    this.setColour(roleHue);
	    this.appendTitle(command["name"]);
	    if ('return' in command) {
	      this.setOutput(true, String);
	    } else {
	      this.setPreviousStatement(true);
	      this.setNextStatement(true);
	    }
	    var thisBlock = this;
	    var argDescriptions = "";
	    $.each(command['arguments'], function(argIdx, argument) {
		var argName = argument['name'];
		// Shorten for args that are essentially direct objects.
		if (command['arguments'].length == 1) {
		  argName = "";
		}

		thisBlock.appendInput(argName,
				      Blockly.INPUT_VALUE,
				      "INPUT" + argIdx,
				      null);
		argDescriptions += argument['name']
		  + ": " + argument["description"] + "\n";
	      });

	    this.setTooltip(function () {
		return command['description'] + "\n\n" + argDescriptions;
	      });
	  }
	};
	Blockly.Language["belphanior_" + roleUid + "|" + command["name"]] = newBlock;
	  });
      });
  };

// TODO(mtomczak): Block names will need to be computed from command identifiers, but they should be able to use all of the symbols that are valid for both role URLs and names.<commit_msg>Visually offset role block groups.'<commit_after>/**
 * Converts role database entries to Blockly blocks.
 * @author <NAME> (<EMAIL>)
 */

if (!Blockly.Language) Blockly.Language = {};

/* To avoid namespace collisions, sub-category for us */
Blockly.Belphanior={};

/* Role name to hue converter, to create consistent colors for
 * roles. This simply sums the character codes in the role names and
 * converts the resulting sum into a 0-360 "hue" value.
 */
Blockly.Belphanior.nameToHue = function(name) {
  accum = 0;
  for(var i = 0; i < name.length; i++) {
    accum += name.charCodeAt(i);
  }
  return accum % 360;
}

/* Converts a role JSON to blocks in Blockly */
  Blockly.Belphanior.rolesToBlocks = function(rolesJson) {
    $.each(rolesJson, function (idx, roleJson) {
	var role = new Role(roleJson.model, roleJson.url);
	var category = "+ " + role.name();
	var roleUid = role.url;
	var roleHue = Blockly.Belphanior.nameToHue(roleUid);

	$.each(role.role.commands, function(cmdIdx, command) {
	var newBlock = {
	  category: category,
	  init: function () {
	    this.setColour(roleHue);
	    this.appendTitle(command["name"]);
	    if ('return' in command) {
	      this.setOutput(true, String);
	    } else {
	      this.setPreviousStatement(true);
	      this.setNextStatement(true);
	    }
	    var thisBlock = this;
	    var argDescriptions = "";
	    $.each(command['arguments'], function(argIdx, argument) {
		var argName = argument['name'];
		// Shorten for args that are essentially direct objects.
		if (command['arguments'].length == 1) {
		  argName = "";
		}

		thisBlock.appendInput(argName,
				      Blockly.INPUT_VALUE,
				      "INPUT" + argIdx,
				      null);
		argDescriptions += argument['name']
		  + ": " + argument["description"] + "\n";
	      });

	    this.setTooltip(function () {
		return command['description'] + "\n\n" + argDescriptions;
	      });
	  }
	};
	Blockly.Language["belphanior_" + roleUid + "|" + command["name"]] = newBlock;
	  });
      });
  };

// TODO(mtomczak): Block names will need to be computed from command identifiers, but they should be able to use all of the symbols that are valid for both role URLs and names.
{'fraction_non_alphanumeric': 0.13906213906213907, 'fraction_numerical': 0.00462000462000462, 'mean_word_length': 3.2492639842983317, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 7, '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': '6407555', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1342, 'n_words': 379}