<commit_before>DELIMITER $$

DROP PROCEDURE IF EXISTS `GetUpcomingBadges` $$

CREATE PROCEDURE `GetUpcomingBadges`(IN `agent_name` VARCHAR(15))
    READS SQL DATA
BEGIN

DROP TABLE IF EXISTS UpcomingBadges;

CREATE TEMPORARY TABLE UpcomingBadges (
    stat VARCHAR(20),
    badge VARCHAR(20),
    next VARCHAR(10),
    progress DOUBLE(3,2),
    days_remaining DOUBLE(5,1)
);

SELECT MAX(date) INTO @latest_submission
  FROM Data 
 WHERE agent = agent_name;

INSERT INTO UpcomingBadges (stat, badge, next, progress, days_remaining)
  SELECT b.stat, 
         b.name,
         b.level,
         d.value / b.amount_required,
         ((b.amount_required - d.value) / GetRateForAgentAndStat(agent_name, b.stat)) remaining
    FROM Data d
    JOIN Badges b ON d.stat = b.stat
    JOIN Stats s ON d.stat = s.stat<commit_msg>Possible fix for issue #75<commit_after>DELIMITER $$

DROP PROCEDURE IF EXISTS `GetUpcomingBadges` $$

CREATE PROCEDURE `GetUpcomingBadges`(IN `agent_name` VARCHAR(15))
    READS SQL DATA
BEGIN

DROP TABLE IF EXISTS UpcomingBadges;

CREATE TEMPORARY TABLE UpcomingBadges (
    stat VARCHAR(20),
    badge VARCHAR(20),
    next VARCHAR(10),
    progress DOUBLE(3,2),
    days_remaining DOUBLE(5,1)
);

SELECT MAX(date) INTO @latest_submission
  FROM Data 
 WHERE agent = agent_name;

INSERT INTO UpcomingBadges (stat, badge, next, progress, days_remaining)
  SELECT b.stat, 
         b.name,
         b.level,
         d.value / b.amount_required,
         COALESCE(((b.amount_required - d.value) / GetRateForAgentAndStat(agent_name, b.stat)),9999.9) remaining
    FROM Data d
    JOIN Badges b ON d.stat = b.stat
    JOIN Stats s ON d.stat = s.stat
{'fraction_non_alphanumeric': 0.09423769507803122, 'fraction_numerical': 0.018607442977190875, 'mean_word_length': 3.4100529100529102, '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': '5438415', 'n_tokens_mistral': 614, 'n_tokens_neox': 566, 'n_words': 157}