<commit_before>import angular from 'angular';
import _ from 'underscore';

angular.module('dimApp')
  .factory('dimDestinyTrackerService', DestinyTrackerService);

function DestinyTrackerService($q,
                               $http) {
    //todo: save/restore JWT from session storage
    var _remoteJwt = {};
    var _gunListBuilder = {};

    function getBulkWeaponData(gunList) {
      return {
        method: 'POST',
        url: 'https://www.destinytracker.com/api/weaponChecker/fetch',
        data: { weaponList: gunList },
        dataType: 'json'
      };
    }

    function handleErrors(response) {
        //DTR-specific handling goes here
    }

    return {
        init: function() {
            _gunListBuilder = gunListBuilder();
        },
        authenticate: function() {  
        },
        bulkFetch: function(membershipType, membershipId, stores) {
            var weaponList = _gunListBuilder.getWeaponList(stores);

            var bulkCollection = { 
                membershipType: membershipType,
                membershipId: membershipId,
                weaponCollection: weaponList
            };

            var promise = $q
                .when(getBulkWeaponData(weaponList))
                .then($http)
                .then(handleErrors, handleErrors)
                .then((response) => response.data.Response.data);

            return promise;
        }
    }
}

function gunListBuilder() {
    var glb = {};

    function getAllItems(stores) {
        var allItems = [];

        stores.forEach(function(store) {
            allItems = allItems.concat(store.items);
        });

        return allItems;
    }

    function getGuns(stores) {
        var allItems = getAllItems(stores);

        var guns = [];

        allItems.forEach(function(item) {
            if (!item.primStat) {
                return;
            }

            if (item.primStat.statHash === 368428387) {
                guns.push(item);
            }
        });
        
        return guns;
    }

    glb.getWeaponList = function(stores) {
        var guns = getGuns(stores);

        var newList = [];

        guns.forEach(function(gun) {
            if(isKnownGun(newList, gun)) {
                newList.forEach(function(listGun) {
                    if(listGun.hash == gun.hash) {
                        var newPerk = {
                            roll: getGunRoll(gun),
                            instanceIds: [ gun.id ]
                        };

                        listGun.talentPerks.push(newPerk);
                        return true;
                    }
                });
            } else {
                var perk = {
                    roll: getGunRoll(gun),
                    instanceIds: [ gun.id ]
                };

                var listGun = {
                    hash: gun.hash,
                    talentPerks: [ perk ] <commit_msg>Hey, underscore is a thing that exists.<commit_after>import angular from 'angular';
import _ from 'underscore';

angular.module('dimApp')
  .factory('dimDestinyTrackerService', DestinyTrackerService);

function DestinyTrackerService($q,
                               $http) {
    //todo: save/restore JWT from session storage
    var _remoteJwt = {};
    var _gunListBuilder = {};

    function getBulkWeaponData(gunList) {
      return {
        method: 'POST',
        url: 'https://www.destinytracker.com/api/weaponChecker/fetch',
        data: { weaponList: gunList },
        dataType: 'json'
      };
    }

    function handleErrors(response) {
        //DTR-specific handling goes here
    }

    return {
        init: function() {
            _gunListBuilder = gunListBuilder();
        },
        authenticate: function() {  
        },
        bulkFetch: function(membershipType, membershipId, stores) {
            var weaponList = _gunListBuilder.getWeaponList(stores);

            var bulkCollection = { 
                membershipType: membershipType,
                membershipId: membershipId,
                weaponCollection: weaponList
            };

            var promise = $q
                .when(getBulkWeaponData(weaponList))
                .then($http)
                .then(handleErrors, handleErrors)
                .then((response) => response.data.Response.data);

            return promise;
        }
    }
}

function gunListBuilder() {
    var glb = {};

    function getAllItems(stores) {
        var allItems = [];

        stores.forEach(function(store) {
            allItems = allItems.concat(store.items);
        });

        return allItems;
    }

    function getGuns(stores) {
        var allItems = getAllItems(stores);

        return _.filter(allItems,
                        function(item) {
                            if(!item.primStat) {
                                return false;
                            }

                            return (item.primStat.statHash === 368428387);
                        });
    }

    glb.getWeaponList = function(stores) {
        var guns = getGuns(stores);

        var newList = [];

        guns.forEach(function(gun) {
            if(isKnownGun(newList, gun)) {
                newList.forEach(function(listGun) {
                    if(listGun.hash == gun.hash) {
                        var newPerk = {
                            roll: getGunRoll(gun),
                            instanceIds: [ gun.id ]
                        };

                        listGun.talentPerks.push(newPerk);
                        return true;
                    }
                });
            } else {
                var perk = {
                    roll: getGunRoll(gun),
                    instanceIds: [ gun.id ]
                };

                var listGun = {
                    hash: gun.hash,
                    talentPerks: [ perk ] 
{'fraction_non_alphanumeric': 0.099522021167634, 'fraction_numerical': 0.0030727210652099694, 'mean_word_length': 1.3268467037331215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '7056316', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1499, 'n_words': 281}