<commit_before>'use strict';

angular.module('sqwiggle-feed.system').controller('StatsController', ['$scope', '$interval', '$timeout', '$location', '$http', 
	function ($scope, $interval, $timeout, $location, $http) {
		$scope.users = [];
		$scope.room = [];
		$scope.allCharacters = 0;
		$scope.userStats = {};
		$scope.totalConversationDuration = 0;
		$scope.probingFactor = 2;
		$scope.toFeed = function() {
			$location.path('/feed');
		}
		$scope.togglemenu = function(){
			$scope.menuactive = !$scope.menuactive;
		}
		$scope.data = {
			series: [''],
			data : [{
				x : "Monday",
				y: [10],
				tooltip:"this is tooltip"
			},
			{
				x : "Tuesday",
				y: [12]
			},
			{
				x : "wednesday",
				y: [2]
			},
			{
				x : "Thursday",
				y: [15]
			},
			{
				x : "Friday",
				y: [4]
			},
			{
				x : "Saturday",
				y: [7]
			},
			{
				x : "Sunday",
				y: [3]
			}]     
		}
		$scope.chartType = 'line';
		$scope.config = {
		  "labels": false,
		  "title": "",
		  "legend": {
			"display": false,
			"position": "right"
		  }
		}

		$http.defaults.timeout = 10000;

		$scope.initialize = function() {
			//$scope.getAllMessages(0);
			$scope.probeMessages(1, false);
			$scope.probeConversations(1);
		}

		$scope.getUsers = function() {
			$http.get('resources/api.php', {
				params: {
					endpoint: 'users'
				}
			}).success(function(e) {
				$scope.users = e;
			}).error(function(e){
				console.log('could not fetch users...');
			});
		}
		$scope.getRooms = function() {
			$http.get('resources/api.php', {
				params: {
					endpoint: 'rooms',
				}, 
			}).success(function(rooms) {
				if(Object.prototype.toString.call(rooms) === '[object Array]') {
					$scope.room = rooms.length > 0 ? rooms.pop() : null;
				}
			}).error(function(e){
				console.log('could not fetch rooms...');
			});
		}
		$scope.getMessages = function() {
			$http.get('resources/api.php', {
				params: {
					endpoint: 'messages'
				}
			}).success(function(e) {
				$scope.users = e;
			}).error(function(e){
				console.log('could not fetch messages...');
			});
		}

		$scope.probeMessages = function(page, finetuning, previousPage) {
			$scope.allMessages = [];
			$http.get('resources/api.php', {
				params: {
					endpoint: 'messages',
					page : page,
					limit: 100
				}
			}).success(function(e) {
				if(Array.isArray(e)) {
					if(finetuning) {
						var lastDifference = page - page / $scope.probingFactor;
						if(Math.abs(page - previousPage) <= 1) {
							$scope.getAllMessages(page);
						}
						else if(e.length > 0) {
							// we have to go up
							$scope.probeMessages(page + (page - previousPage) / $scope.probingFactor, true, page);
						} else {
							// we have to go down
							$scope.probeMessages(page - (page - previousPage) / $scope.probingFactor, true, page);
						}
					} else {
						if(e.length > 0) {
							$scope.probeMessages(page * $scope.probingFactor, false);
						}
						else {
							var lastDifference = page - page / $scope.probingFactor;
							$scope.probeMessages(page - (lastDifference / $scope.probingFactor), true, page - lastDifference);
						}
					}
				}
			});
		}

		$scope.probeConversations = function(page) {
			$scope.allConversations = [];
			$http.get('resources/api.php', {
				params: {
					endpoint: 'conversations',
					page : page,
					limit: 100
				}
			}).success(function(e) {
				if(Array.isArray(e)) {
					if(e.length > 0) {
						$scope.probeConversations(page * 2);
					}
					else {
						$scope.getAllConversations(page);
					}
				}
			});
		}

		$scope.getAllMessages = function(pages) {
			// for all the pages that we probed, send a request
			for(var i = 0; i < pages; i++) {
				$scope.getMessagesForPage(i);
			}
		}

		$scope.getAllConversations = function(pages) {
			// for all the pages that we probed, send a request
			for(var i = 0; i < pages; i++) {
				$scope.getConversationsForPage(i);
			}
		}

		$scope.getMessagesForPage = function(page) {
			$http.get('resources/api.php', {
				params: {
					endpoint: 'messages',
					page : page,
					limit: 100
				}
			}).success(function(e) {
				if(Array.isArray(e)) {
					if(e.length > 0) {
						$scope.allMessages = $scope.allMessages.concat(e);
						for(var key in e) {
							var message = e[key];
							$scope.allCharacters += $scope.countCharacters(message.text);
							$scope.addUserStatsForMessage(message);
						}
					}
				}
			}).error(function(e){
				console.log('could not fetch messages...');
			});
		}

		$scope.getConversationsForPage = function(page) {<commit_msg>redo the request for messages if it is empty. it most likely times out.<commit_after>'use strict';

angular.module('sqwiggle-feed.system').controller('StatsController', ['$scope', '$interval', '$timeout', '$location', '$http', 
	function ($scope, $interval, $timeout, $location, $http) {
		$scope.users = [];
		$scope.room = [];
		$scope.allCharacters = 0;
		$scope.userStats = {};
		$scope.totalConversationDuration = 0;
		$scope.probingFactor = 2;
		$scope.toFeed = function() {
			$location.path('/feed');
		}
		$scope.togglemenu = function(){
			$scope.menuactive = !$scope.menuactive;
		}
		$scope.data = {
			series: [''],
			data : [{
				x : "Monday",
				y: [10],
				tooltip:"this is tooltip"
			},
			{
				x : "Tuesday",
				y: [12]
			},
			{
				x : "wednesday",
				y: [2]
			},
			{
				x : "Thursday",
				y: [15]
			},
			{
				x : "Friday",
				y: [4]
			},
			{
				x : "Saturday",
				y: [7]
			},
			{
				x : "Sunday",
				y: [3]
			}]     
		}
		$scope.chartType = 'line';
		$scope.config = {
		  "labels": false,
		  "title": "",
		  "legend": {
			"display": false,
			"position": "right"
		  }
		}

		$http.defaults.timeout = 10000;

		$scope.initialize = function() {
			//$scope.getAllMessages(0);
			$scope.probeMessages(1, false);
			$scope.probeConversations(1);
		}

		$scope.getUsers = function() {
			$http.get('resources/api.php', {
				params: {
					endpoint: 'users'
				}
			}).success(function(e) {
				$scope.users = e;
			}).error(function(e){
				console.log('could not fetch users...');
			});
		}
		$scope.getRooms = function() {
			$http.get('resources/api.php', {
				params: {
					endpoint: 'rooms',
				}, 
			}).success(function(rooms) {
				if(Object.prototype.toString.call(rooms) === '[object Array]') {
					$scope.room = rooms.length > 0 ? rooms.pop() : null;
				}
			}).error(function(e){
				console.log('could not fetch rooms...');
			});
		}
		$scope.getMessages = function() {
			$http.get('resources/api.php', {
				params: {
					endpoint: 'messages'
				}
			}).success(function(e) {
				$scope.users = e;
			}).error(function(e){
				console.log('could not fetch messages...');
			});
		}

		$scope.probeMessages = function(page, finetuning, previousPage) {
			$scope.allMessages = [];
			$http.get('resources/api.php', {
				params: {
					endpoint: 'messages',
					page : page,
					limit: 100
				}
			}).success(function(e) {
				if(Array.isArray(e)) {
					if(finetuning) {
						var lastDifference = page - page / $scope.probingFactor;
						if(Math.abs(page - previousPage) <= 1) {
							$scope.getAllMessages(page);
						}
						else if(e.length > 0) {
							// we have to go up
							$scope.probeMessages(page + (page - previousPage) / $scope.probingFactor, true, page);
						} else {
							// we have to go down
							$scope.probeMessages(page - (page - previousPage) / $scope.probingFactor, true, page);
						}
					} else {
						if(e.length > 0) {
							$scope.probeMessages(page * $scope.probingFactor, false);
						}
						else {
							var lastDifference = page - page / $scope.probingFactor;
							$scope.probeMessages(page - (lastDifference / $scope.probingFactor), true, page - lastDifference);
						}
					}
				}
			});
		}

		$scope.probeConversations = function(page) {
			$scope.allConversations = [];
			$http.get('resources/api.php', {
				params: {
					endpoint: 'conversations',
					page : page,
					limit: 100
				}
			}).success(function(e) {
				if(Array.isArray(e)) {
					if(e.length > 0) {
						$scope.probeConversations(page * 2);
					}
					else {
						$scope.getAllConversations(page);
					}
				}
			});
		}

		$scope.getAllMessages = function(pages) {
			// for all the pages that we probed, send a request
			for(var i = 0; i < pages; i++) {
				$scope.getMessagesForPage(i);
			}
		}

		$scope.getAllConversations = function(pages) {
			// for all the pages that we probed, send a request
			for(var i = 0; i < pages; i++) {
				$scope.getConversationsForPage(i);
			}
		}

		$scope.getMessagesForPage = function(page) {
			$http.get('resources/api.php', {
				params: {
					endpoint: 'messages',
					page : page,
					limit: 100
				}
			}).success(function(e) {
				if(Array.isArray(e)) {
					if(e.length > 0) {
						$scope.allMessages = $scope.allMessages.concat(e);
						for(var key in e) {
							var message = e[key];
							$scope.allCharacters += $scope.countCharacters(message.text);
							$scope.addUserStatsForMessage(message);
						}
					}
				} else {
					$scope.getMessagesForPage(page);
				}
			}).error(function(e){
				console.log('could not fetch messages...');
			});
		}

		$scope.getConversationsForPage = function(page) {
{'fraction_non_alphanumeric': 0.17799632551604885, 'fraction_numerical': 0.008429698476169891, 'mean_word_length': 2.4401486988847583, 'pattern_counts': {'":': 10, '<': 9, '<?xml version=': 0, '>': 13, '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': '3805423', 'n_tokens_mistral': 4328, 'n_tokens_neox': 3216, 'n_words': 595}