<commit_before>'use strict';

/* Controllers */

angular.module('quantifyApp.controllers', [])
     .controller('QuantifyCtrl', ['$scope', function($scope) {
        //TODO share link resolution G+ & FB
        //TODO CSS
        //TODO paralax scrolling
        //TODO SEO

    }])

    .controller('AuthCtrl', ['$scope', function($scope) {
        $scope.authenticate = function() {
            //build authentication url => https://developer.spotify.com/web-api/authorization-guide/
            //TODO authentication should be a service
            var accountUrl = 'https://accounts.spotify.com/authorize';
            var clientID ='client_id=2877dc4791af41e0b53de799f8cf2472';
            var redirectUri = 'redirect_uri=https%3A%2F%2Fslothtier.github.io%2Fquantify%2Findex.html';
            var authScope = 'scope=playlist-read-private';
            var responseType = 'response_type=token';
            var state = 'state=123';
            window.location.href = accountUrl+'?'+clientID+'&'+redirectUri+'&'+authScope+'&'+responseType+'&'+state;
        };

    }])

    .controller('MainCtrl', function($scope, $http, $rootScope, parseUrl, playlistService, trackService, $q) {
        $scope.invalidUrl = 'enter a valid spotify playlist url or uri.';

        $scope.quantify = function() {

            if (parseUrl.parse($scope.model.url).user === undefined){
                //display error message
                $scope.invalidUrl = parseUrl.parse($scope.model.url);
                //clear input box
                $scope.model.url = '';
                //hide old playlist data
                $scope.showPlaylist = false;
                $scope.errorMessage = '';
            } else {
                //clear error messages
                $scope.invalidUrl = '';
                $scope.errorMessage = '';

                //prepare request for playlist data
                var userID = parseUrl.parse($scope.model.url).user;
                var playlistID = parseUrl.parse($scope.model.url).playlist;
                var apiUrl = 'https://api.spotify.com/v1/users/'+userID+'/playlists/'+playlistID;

                //extract token from url
                var authString = 'Bearer '+ $rootScope.location.match(/([A-Za-z0-9_-]{155})/ig)[0];

                //get request for playlist data
                //TODO parsing playlist response should be a service
                //TODO fix for playlists of >100 tracks





                playlistService.getPlaylist(apiUrl, authString)
                    .then(function (data) {

                        //decompose api response
                        var completeResponse = data;
                        var trackResponse = completeResponse.tracks;

                        //extract playlist name, track count & track items
                        $scope.playlistName = completeResponse.name;
                        $scope.playlistTrackcount = trackResponse.total;
                        $scope.playlistItems = trackResponse.items;


                        $scope.tracksNew = [];
                        var tracklistNew = [];
                        var apiUrlTracks = apiUrl+'/tracks';

                        console.log('trackResponse.total: '+trackResponse.total);
                       ;

                        var apiUrlTracksNew = apiUrlTracks;


                        var defer = $q.defer();


                        //calculate total duration in ms

                        var x = 0
                        var dataHelper = 0;
                        var dataHelper1 = 0;



                        for (x; x < trackResponse.total;) {
                            //console.log('im in the loop: ' + x);
                            //console.log('calling : ' + apiUrlTracksNew);

                            trackService.getTracks(apiUrl, authString)
                                .then(function (data) {
                                    //console.log('result of service: ' + data);
                                    dataHelper = data;

                                    dataHelper1 = dataHelper1 + dataHelper;
                                    console.log('dataHelper1 in loop = ' + dataHelper1);

                                    if (x >= trackResponse.total) {
                                        console.log('dataHelper1 in if = ' + dataHelper1);
                                        //defer.resolve(dataHelper1);

                                    }

                                }, function (error) {
                                    console.log('error :', error.error.status);
                                });

                            x = x + 100;
                            apiUrlTracksNew = apiUrlTracks + '?offset=' + x;
                            //console.log('new url to call: ' + apiUrlTracksNew);
                            console.log('x = ' + x);
                            defer.resolve(dataHelper1);

                       }

                        defer.promise.then(function(dataHelper1){
                            $scope.totalduration = dataHelper1;
                        });

                        var tracks = [];
                        var tracklist = [];

                        //push all items into tracks array
                        angular.forEach(trackResponse.items, function(item) {
                            tracks.push(item);
                        });
                        //push all tracks into tracklist array
                        for(var i=0;i<Object.keys(tracks).length;i++) {
                            tracklist.push(tracks[i].track);
                        }

                        //calculate total playlist duration in ms
                        var durationMs = 0;
                        for(var j=0;j<Object.keys(tracks).length;j++) {
                            durationMs = durationMs + tracklist[j].duration_ms;
                        };

                        //TODO time conversion should be a service
                        function msToTime(dur) {
                            var seconds = parseInt((dur/1000)%60)
                                , minutes = parseInt((dur/(1000*60))%60)
                                , hours = parseInt((dur/(1000*60*60))%24);
                            hours = (hours<10) ? '0' + hours : hours;
                            minutes = (minutes<10) ? '0' + minutes : minutes;<commit_msg>unfucktheworld<commit_after>'use strict';

/* Controllers */

angular.module('quantifyApp.controllers', [])
     .controller('QuantifyCtrl', ['$scope', function($scope) {
        //TODO share link resolution G+ & FB
        //TODO CSS
        //TODO paralax scrolling
        //TODO SEO

    }])

    .controller('AuthCtrl', ['$scope', function($scope) {
        $scope.authenticate = function() {
            //build authentication url => https://developer.spotify.com/web-api/authorization-guide/
            //TODO authentication should be a service
            var accountUrl = 'https://accounts.spotify.com/authorize';
            var clientID ='client_id=2877dc4791af41e0b53de799f8cf2472';
            var redirectUri = 'redirect_uri=https%3A%2F%2Fslothtier.github.io%2Fquantify%2Findex.html';
            var authScope = 'scope=playlist-read-private';
            var responseType = 'response_type=token';
            var state = 'state=123';
            window.location.href = accountUrl+'?'+clientID+'&'+redirectUri+'&'+authScope+'&'+responseType+'&'+state;
        };

    }])

    .controller('MainCtrl', function($scope, $http, $rootScope, parseUrl, playlistService, trackService, $q) {
        $scope.invalidUrl = 'enter a valid spotify playlist url or uri.';

        $scope.quantify = function() {

            if (parseUrl.parse($scope.model.url).user === undefined){
                //display error message
                $scope.invalidUrl = parseUrl.parse($scope.model.url);
                //clear input box
                $scope.model.url = '';
                //hide old playlist data
                $scope.showPlaylist = false;
                $scope.errorMessage = '';
            } else {
                //clear error messages
                $scope.invalidUrl = '';
                $scope.errorMessage = '';

                //prepare request for playlist data
                var userID = parseUrl.parse($scope.model.url).user;
                var playlistID = parseUrl.parse($scope.model.url).playlist;
                var apiUrl = 'https://api.spotify.com/v1/users/'+userID+'/playlists/'+playlistID;

                //extract token from url
                var authString = 'Bearer '+ $rootScope.location.match(/([A-Za-z0-9_-]{155})/ig)[0];

                //get request for playlist data
                //TODO parsing playlist response should be a service
                //TODO fix for playlists of >100 tracks





                playlistService.getPlaylist(apiUrl, authString)
                    .then(function (data) {

                        //decompose api response
                        var completeResponse = data;
                        var trackResponse = completeResponse.tracks;

                        //extract playlist name, track count & track items
                        $scope.playlistName = completeResponse.name;
                        $scope.playlistTrackcount = trackResponse.total;
                        $scope.playlistItems = trackResponse.items;


                        $scope.tracksNew = [];
                        var tracklistNew = [];
                        var apiUrlTracks = apiUrl+'/tracks';

                        console.log('trackResponse.total: '+trackResponse.total);
                       

                        var apiUrlTracksNew = apiUrlTracks;

                        //calculate total duration in ms

                        var x = 0
                        var dataHelper = 0;
                        var dataHelper1 = 0;



                        for (x; x < trackResponse.total;) {
                            //console.log('im in the loop: ' + x);
                            //console.log('calling : ' + apiUrlTracksNew);

                            trackService.getTracks(apiUrl, authString)
                                .then(function (data) {
                                    //console.log('result of service: ' + data);
                                    dataHelper = data;
                                    dataHelper1 = dataHelper1 + dataHelper;
                                    console.log('dataHelper1 in loop = ' + dataHelper1);
                                    $scope.totalduration = dataHelper1;
                                }, function (error) {
                                    console.log('error :', error.error.status);
                                });

                            x = x + 100;
                            apiUrlTracksNew = apiUrlTracks + '?offset=' + x;
                            //console.log('new url to call: ' + apiUrlTracksNew);
                            console.log('x = ' + x);
                            defer.resolve(dataHelper1);

                       }





                        var tracks = [];
                        var tracklist = [];

                        //push all items into tracks array
                        angular.forEach(trackResponse.items, function(item) {
                            tracks.push(item);
                        });
                        //push all tracks into tracklist array
                        for(var i=0;i<Object.keys(tracks).length;i++) {
                            tracklist.push(tracks[i].track);
                        }

                        //calculate total playlist duration in ms
                        var durationMs = 0;
                        for(var j=0;j<Object.keys(tracks).length;j++) {
                            durationMs = durationMs + tracklist[j].duration_ms;
                        };

                        //TODO time conversion should be a service
                        function msToTime(dur) {
                            var seconds = parseInt((dur/1000)%60)
                                , minutes = parseInt((dur/(1000*60))%60)
                                , hours = parseInt((dur/(1000*60*60))%24);
                            hours = (hours<10) ? '0' + hours : hours;
                            minutes = (minutes<10) ? '0' + minutes : minutes;
{'fraction_non_alphanumeric': 0.10547846314269672, 'fraction_numerical': 0.013956846073634396, 'mean_word_length': 1.1801014163315264, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 8, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 25, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '903436', 'n_tokens_mistral': 3208, 'n_tokens_neox': 2897, 'n_words': 617}