<commit_before>var module = angular.module('royal-hub.processor', []);

module.provider('processor', function () {
  var listeners = [];
  this.addListener = function (listener) {
    listeners.push(listener);
  };

  this.$get = function (rating) {
    return {
      addEvent: function (githubEvent) {
        listeners.forEach(function (listener) {
          listener(githubEvent, rating);
        });
      }
    };
  };
});

module.service('rating', function () {
  this.rating = {};
  this.badges = {};

  this.getUserRating = function (githubUser) {
    var userRating = this.rating[githubUser.id];
    if (userRating == null) {
      userRating = {
        user: githubUser,
        events: [],
        badges: {},
        points: 0
      };
      this.rating[githubUser.id] = userRating;
    }
    return userRating;
  };

  this.addEvent = function (githubUser, event) {
    var userRating = this.getUserRating(githubUser);
    userRating.events.push(event);
    userRating.points += event.points;
  };

  this.addBadge = function (githubUser, badge) {
    this.addEvent(githubUser, {
      type: 'Badge',
      badge: badge.key,
      points: 5,
      message: badge.message,
      timestamp: badge.timestamp
    });
    var userRating = this.getUserRating(githubUser);
    userRating.badges[badge.key] = badge.description;
  };

  this.hasBadge = function (githubUser, badgeKey) {
    var userRating = this.rating[githubUser.id];
    return !!(userRating && userRating.badges[badgeKey]);
  };
});

/**
 * Score commits
 */
module.config(function (processorProvider) {
  processorProvider.addListener(function (githubEvent, rating) {
    if (githubEvent.type === 'PushEvent') {
      rating.addEvent(githubEvent.actor, {
        type: 'Push',
        points: githubEvent.payload.size,
        message: 'Pushed ' + githubEvent.payload.size + ' commit(s)',
        timestamp: githubEvent.created_at
      });
    }
  });
});

/**
 * Score issue resolve
 */
module.config(function (processorProvider) {
  processorProvider.addListener(function (githubEvent, rating) {
    if (githubEvent.type === 'IssuesEvent' && githubEvent.payload.action === 'closed') {
      rating.addEvent(githubEvent.actor, {
        type: 'IssueResolve',
        points: 3,
        message: 'Resolved issue ' + githubEvent.payload.issue.title,
        timestamp: githubEvent.created_at
      });
    }
  });
});

/**
 * <NAME> badge
 * User has committed smth with a long message
 */
module.config(function (processorProvider) {
  var LONG_COMMIT_MESSAGE_LENGTH = 400;
  var BADGE_KEY = 'tolstoy';

  processorProvider.addListener(function (githubEvent, rating) {
    if (githubEvent.type === 'PushEvent' && !rating.hasBadge(githubEvent.actor, BADGE_KEY)) {
      githubEvent.payload.commits.forEach(function (commit) {
        if (commit.message && commit.message.length > LONG_COMMIT_MESSAGE_LENGTH) {
          rating.addBadge(githubEvent.actor, {
            key: BADGE_KEY,
            message: 'You know how to put words together! Ah, classic!',
            description: 'That commit comment is a true masterpiece. It deserves its own award, but we better praise you, the author!',
            timestamp: githubEvent.created_at
          });
        }
      });
    }
  });
});

/**
 * Ouroboros badge
 * User has created an issue for herself
 */
module.config(function (processorProvider) {
  var BADGE_KEY = 'ouroboros';

  processorProvider.addListener(function (githubEvent, rating) {
    if (githubEvent.type === 'IssuesEvent' && !rating.hasBadge(githubEvent.actor, BADGE_KEY)) {
      var issue = githubEvent.payload.issue;
      var assignee = issue.assignee;
      if (githubEvent.payload.action === 'opened'&& assignee && issue.user.id === assignee.id) {
        rating.addBadge(githubEvent.actor, {
          key: BADGE_KEY,
          message: 'All by myself\' is your motto! You create tasks for yourself and you fix them.',
          description: 'All by myself is your motto! You create tasks for yourself and you fix them. And if not you who?',
          timestamp: githubEvent.created_at
        });
      }
    }
  });
});
<commit_msg>Route 66 badge<commit_after>var module = angular.module('royal-hub.processor', []);

module.provider('processor', function () {
  var listeners = [];
  this.addListener = function (listener) {
    listeners.push(listener);
  };

  this.$get = function (rating) {
    return {
      addEvent: function (githubEvent) {
        listeners.forEach(function (listener) {
          listener(githubEvent, rating);
        });
      }
    };
  };
});

module.service('rating', function () {
  this.rating = {};
  this.badges = {};

  this.getUserRating = function (githubUser) {
    var userRating = this.rating[githubUser.id];
    if (userRating == null) {
      userRating = {
        user: githubUser,
        events: [],
        badges: {},
        points: 0
      };
      this.rating[githubUser.id] = userRating;
    }
    return userRating;
  };

  this.addEvent = function (githubUser, event) {
    var userRating = this.getUserRating(githubUser);
    userRating.events.push(event);
    userRating.points += event.points;
  };

  this.addBadge = function (githubUser, badge) {
    this.addEvent(githubUser, {
      type: 'Badge',
      badge: badge.key,
      points: 5,
      message: badge.message,
      timestamp: badge.timestamp
    });
    var userRating = this.getUserRating(githubUser);
    userRating.badges[badge.key] = badge.description;
  };

  this.hasBadge = function (githubUser, badgeKey) {
    var userRating = this.rating[githubUser.id];
    return !!(userRating && userRating.badges[badgeKey]);
  };
});

/**
 * Score commits
 */
module.config(function (processorProvider) {
  processorProvider.addListener(function (githubEvent, rating) {
    if (githubEvent.type === 'PushEvent') {
      rating.addEvent(githubEvent.actor, {
        type: 'Push',
        points: githubEvent.payload.size,
        message: 'Pushed ' + githubEvent.payload.size + ' commit(s)',
        timestamp: githubEvent.created_at
      });
    }
  });
});

/**
 * Score issue resolve
 */
module.config(function (processorProvider) {
  processorProvider.addListener(function (githubEvent, rating) {
    if (githubEvent.type === 'IssuesEvent' && githubEvent.payload.action === 'closed') {
      rating.addEvent(githubEvent.actor, {
        type: 'IssueResolve',
        points: 3,
        message: 'Resolved issue ' + githubEvent.payload.issue.title,
        timestamp: githubEvent.created_at
      });
    }
  });
});

/**
 * Leo Tolstoy badge
 * User has committed smth with a long message
 */
module.config(function (processorProvider) {
  var LONG_COMMIT_MESSAGE_LENGTH = 400;
  var BADGE_KEY = 'tolstoy';

  processorProvider.addListener(function (githubEvent, rating) {
    if (githubEvent.type === 'PushEvent' && !rating.hasBadge(githubEvent.actor, BADGE_KEY)) {
      githubEvent.payload.commits.forEach(function (commit) {
        if (commit.message && commit.message.length > LONG_COMMIT_MESSAGE_LENGTH) {
          rating.addBadge(githubEvent.actor, {
            key: BADGE_KEY,
            message: 'You know how to put words together! Ah, classic!',
            description: 'That commit comment is a true masterpiece. It deserves its own award, but we better praise you, the author!',
            timestamp: githubEvent.created_at
          });
        }
      });
    }
  });
});

/**
 * Ouroboros badge
 * User has created an issue for herself
 */
module.config(function (processorProvider) {
  var BADGE_KEY = 'ouroboros';

  processorProvider.addListener(function (githubEvent, rating) {
    if (githubEvent.type === 'IssuesEvent' && !rating.hasBadge(githubEvent.actor, BADGE_KEY)) {
      var issue = githubEvent.payload.issue;
      var assignee = issue.assignee;
      if (githubEvent.payload.action === 'opened'&& assignee && issue.user.id === assignee.id) {
        rating.addBadge(githubEvent.actor, {
          key: BADGE_KEY,
          message: 'All by myself\' is your motto! You create tasks for yourself and you fix them.',
          description: 'All by myself is your motto! You create tasks for yourself and you fix them. And if not you who?',
          timestamp: githubEvent.created_at
        });
      }
    }
  });
});

/**
 * Route 66 badge
 * User made 66 commits
 */
module.config(function (processorProvider) {
  var BADGE_KEY = 'route66';

  var user2commits = {};

  processorProvider.addListener(function (githubEvent, rating) {
    if (githubEvent.type === 'PushEvent' && !rating.hasBadge(githubEvent.actor, BADGE_KEY)) {
      var currentRide = user2commits[githubEvent.actor.id] || 0;
      currentRide += githubEvent.payload.size;
      if (currentRide >= 66) {
        delete user2commits[githubEvent.actor.id];
        rating.addBadge(githubEvent.actor, {
          key: BADGE_KEY,
          message: 'Hey, mate, 66 commits! Wow, what a ride!',
          description: 'It\'s your 66th commit! What a ride!',
          timestamp: githubEvent.created_at
        });
      } else {
        user2commits[githubEvent.actor.id] = currentRide;
      }
    }
  });
});

{'fraction_non_alphanumeric': 0.13138606279400503, 'fraction_numerical': 0.00339131386062794, 'mean_word_length': 2.8985074626865672, 'pattern_counts': {'":': 0, '<': 4, '<?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': '5283392', 'n_tokens_mistral': 2844, 'n_tokens_neox': 2707, 'n_words': 609}