<commit_before>/**
 * PortfolioAccountSummaryController
 * @namespace portfolio.account.summary.controller
 */

(function () {
    
    'use strict';

    angular
        .module('portfolio.account.summary')
        .controller('AccountSummaryController', 
                    AccountSummaryController);

    AccountSummaryController.$inject = [ '$timeout', '$q', '$location',
                                         'Positions',
                                         'Securities', 'Accounts',
                                         'Currencies'];

    function AccountSummaryController($timeout, $q, $location, Positions,
                                      Securities, Accounts, Currencies) {
        var vm = this;
        /* Get the account id from URL */
        var accountID = $location.path().split("/")[3];

        var promises = {
            positions: Positions.all(accountID),
            securities: Securities.all(),
            accounts: Accounts.all(),
            currencies: Currencies.all(),
        }

        /* 
           for now, Securities.all() returns an array, dictionary needed to
           be able to easily map ticker to name
        */
        vm.securities_d = {};

        vm.total_mktval = 0;

        activate();

        /**
         * @name activate
         * @desc 
         * @memberOf portfolio.accountsummary.controller.AccountSummaryController
         */
        function activate() {

            $q.all(promises).then(promisesSuccessFn, promisesErrorFn);

            /**
             * @name positionsSuccessFn
             * @desc
             */
            function promisesSuccessFn(data, status, headers, config) {
                vm.positions = data.positions.data;
                vm.securities = data.securities.data;
                vm.accounts = data.accounts.data;
                vm.currencies = data.currencies.data
                getLivePrices();

            }

            function promisesErrorFn(data, status, headers, config) {
                console.log('promisesErrorFn', data);
            }
        }


        function getLivePrices() {
                
            var i, delay;
            var minTime = 1000; // 1 sec
            var maxTime = 4000; // 4 secs
            var refreshRate = 10; // minutes
            var ticker;

            for(i=0; i<vm.securities.length; i++) {
                ticker = vm.securities[i].ticker;
                vm.securities_d[ticker] = vm.securities[i].name;
                delay = Math.floor(Math.random()*(maxTime-minTime+1)+minTime);

                /* call getQuoteForSecurity with 'ticker' argument */
                $timeout(getQuoteForSecurity.bind(null, ticker),
                         delay);
            }

            vm.liveTimer = $timeout(function () {
                getLivePrices();
            }, refreshRate*60*1000);
            
            function getQuoteForSecurity(ticker) {

                Positions.google_quote(ticker)
                    .then(positionsLiveSuccessFn, positionsLiveErrorFn);
            }
                <commit_msg>fix(account summary): $timeout parameters changed in 1.4.x<commit_after>/**
 * PortfolioAccountSummaryController
 * @namespace portfolio.account.summary.controller
 */

(function () {
    
    'use strict';

    angular
        .module('portfolio.account.summary')
        .controller('AccountSummaryController', 
                    AccountSummaryController);

    AccountSummaryController.$inject = [ '$timeout', '$q', '$location',
                                         'Positions',
                                         'Securities', 'Accounts',
                                         'Currencies'];

    function AccountSummaryController($timeout, $q, $location, Positions,
                                      Securities, Accounts, Currencies) {
        var vm = this;
        /* Get the account id from URL */
        var accountID = $location.path().split("/")[3];

        var promises = {
            positions: Positions.all(accountID),
            securities: Securities.all(),
            accounts: Accounts.all(),
            currencies: Currencies.all(),
        }

        /* 
           for now, Securities.all() returns an array, dictionary needed to
           be able to easily map ticker to name
        */
        vm.securities_d = {};

        vm.total_mktval = 0;

        activate();

        /**
         * @name activate
         * @desc 
         * @memberOf portfolio.accountsummary.controller.AccountSummaryController
         */
        function activate() {

            $q.all(promises).then(promisesSuccessFn, promisesErrorFn);

            /**
             * @name positionsSuccessFn
             * @desc
             */
            function promisesSuccessFn(data, status, headers, config) {
                vm.positions = data.positions.data;
                vm.securities = data.securities.data;
                vm.accounts = data.accounts.data;
                vm.currencies = data.currencies.data
                getLivePrices();

            }

            function promisesErrorFn(data, status, headers, config) {
                console.log('promisesErrorFn', data);
            }
        }


        function getLivePrices() {
                
            var i, delay;
            var minTime = 1000; // 1 sec
            var maxTime = 4000; // 4 secs
            var refreshRate = 10; // minutes
            var ticker;

            for(i=0; i<vm.securities.length; i++) {
                ticker = vm.securities[i].ticker;
                vm.securities_d[ticker] = vm.securities[i].name;
                delay = Math.floor(Math.random()*(maxTime-minTime+1)+minTime);

                /* call getQuoteForSecurity with 'ticker' argument */
                $timeout(getQuoteForSecurity, delay, true, ticker);

            }

            vm.liveTimer = $timeout(function () {
                getLivePrices();
            }, refreshRate*60*1000);
            
            function getQuoteForSecurity(ticker) {

                Positions.google_quote(ticker)
                    .then(positionsLiveSuccessFn, positionsLiveErrorFn);
            }
                
{'fraction_non_alphanumeric': 0.10377054463422494, 'fraction_numerical': 0.007412181759587496, 'mean_word_length': 1.4388998035363458, 'pattern_counts': {'":': 0, '<': 5, '<?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': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4151618', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1470, 'n_words': 307}