<commit_before>/**
 * Fantasy Football drafting bot
 *
 * Data & config variables should be included on the page
 */
(function(document, window, undefined) {
 'use strict';

window.FantasyDrafter = function(config) {
    // events
    var GOT_INFO = "gotDraftInfo"
    , DATA_CHANGE = "dataChange"
    , DRAFTED_PLAYER = "drafted"
    , AFTER_UPDATE = "onAfterUpdate"

    // info about the draft
    , teamId
    , draftInfo
    , roster // Roster manager
    , myPicks = []

    , playerEstimates = {}
    , idsToPlayers = {} // map of player id -> player object

    , call = makeCall(config) // API interacting function

    , pick = function( player ) {
        var pickUrl = ["pick_player", player.id].join("/")
        ;
        log("trying to draft: " + player.first_name + " " + player.last_name);
        call(pickUrl, function(data) {
            log("drafted player, got msg back: " + data.message +
                " (" + data.code + ")");
            // player already picked, try again
            if (data.code === 410) {
                pickIfActive();
            }
            // success!
            else if (data.code == 200) {
                refresh();
            }
        });
    }

    , drawPotentials = function() {
        vopos(playerEstimates, draftInfo.numTeams);
        render("potentials", {
            'players': playersByVorp(playerEstimates)
        }, "#players");
        highlightBest();
        $(window).trigger(AFTER_UPDATE);
    }

    , updatePlayerAvailability = function(callback) {
        call("draft", function(data) {
            var selections = data && data.selections || [];
            $.each(selections, function(i, s) {
                var id = s.player.id
                , player = idsToPlayers[id]
                ;
                if (player) {
                    player.taken = true;
                    player.free = false;
                }
            });
            // anyone not already picked is free
            forEveryPlayer(playerEstimates, function(p) {
                if (p.id && !p.taken) {
                    p.free = true;
                }
            });
            $(window).trigger(DATA_CHANGE);

            if ($.isFunction(callback)) {
                callback();
            }
        });
    }

    , updatePicks = function() {
        call("picks", function(data) {
            var myTeam = function(ele) {
                return ele.team.id == teamId;
            };
            myPicks = data.picks.filter(myTeam);
            render("pickList", {'mine': myPicks}, "#picks");
        });
    }

    , pickIfActive = function() {
        var pickFunc = function() {
            log("Active! Picking...");
            updatePlayerAvailability(function() {
                var player = getTopPlayer();
                if (player) {
                    pick(player);
                }
            });
        };
        $.each(myPicks, function(i, pick) {<commit_msg>Don't queue up tons of pick requests<commit_after>/**
 * Fantasy Football drafting bot
 *
 * Data & config variables should be included on the page
 */
(function(document, window, undefined) {
 'use strict';

window.FantasyDrafter = function(config) {
    // events
    var GOT_INFO = "gotDraftInfo"
    , DATA_CHANGE = "dataChange"
    , DRAFTED_PLAYER = "drafted"
    , AFTER_UPDATE = "onAfterUpdate"

    // info about the draft
    , teamId
    , draftInfo
    , roster // Roster manager
    , myPicks = []

    , playerEstimates = {}
    , idsToPlayers = {} // map of player id -> player object

    , currentlyPicking = false

    , call = makeCall(config) // API interacting function

    , pick = function( player ) {
        var pickUrl = ["pick_player", player.id].join("/")
        ;
        log("trying to draft: " + player.first_name + " " + player.last_name);
        call(pickUrl, function(data) {
            log("drafted player, got msg back: " + data.message +
                " (" + data.code + ")");
            // player already picked, try again
            if (data.code === 410) {
                pickIfActive();
            }
            // success!
            else if (data.code == 200) {
                refresh();
            }
        });
    }

    , drawPotentials = function() {
        vopos(playerEstimates, draftInfo.numTeams);
        render("potentials", {
            'players': playersByVorp(playerEstimates)
        }, "#players");
        highlightBest();
        $(window).trigger(AFTER_UPDATE);
    }

    , updatePlayerAvailability = function(callback) {
        call("draft", function(data) {
            var selections = data && data.selections || [];
            $.each(selections, function(i, s) {
                var id = s.player.id
                , player = idsToPlayers[id]
                ;
                if (player) {
                    player.taken = true;
                    player.free = false;
                }
            });
            // anyone not already picked is free
            forEveryPlayer(playerEstimates, function(p) {
                if (p.id && !p.taken) {
                    p.free = true;
                }
            });
            $(window).trigger(DATA_CHANGE);

            if ($.isFunction(callback)) {
                callback();
            }
        });
    }

    , updatePicks = function() {
        call("picks", function(data) {
            var myTeam = function(ele) {
                return ele.team.id == teamId;
            };
            myPicks = data.picks.filter(myTeam);
            render("pickList", {'mine': myPicks}, "#picks");
        });
    }

    , pickIfActive = function() {
        var pickFunc = function() {
            if (currentlyPicking) {
              return;
            }
            currentlyPicking = true;
            log("Active! Picking...");
            updatePlayerAvailability(function() {
                var player = getTopPlayer();
                if (player) {
                    pick(player);
                }
                currentlyPicking = false;
            });
        };
        $.each(myPicks, function(i, pick) {
{'fraction_non_alphanumeric': 0.1276526281423441, 'fraction_numerical': 0.0019588638589618022, 'mean_word_length': 1.4735567218409367, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1492744', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1625, 'n_words': 359}