<commit_before>define('app/controllers/monitoring', [
    'ember'
    ],
    /**
     * Monitoring Controller
     *
     * @returns Class
     */
    function() {
        return Ember.ObjectController.extend({

            machine : null,
            machineNotResponding: false,
            lastMeasurmentTime: null,
            view: null,

            step: 0,

            // This one is called from view
            initController: function(machine,view){
                this.machine = machine;
                this.view = view;
            },

            /**
            * Method: setupDataRequest
            * Receives first data and set time interval for
            * next reuqests
            */
            setupDataRequest: function(timeToRequestms,step){

                var SECONDS_INTERVAL = 10000;

                var self = this;
                var timeGap = 60;


                // First Data Request
                self.machine.set('pendingStats', true);

                var stop = (new Date()).getTime() - timeGap * 1000;
                var start = stop - timeToRequestms;
                self.step = step;


                console.log("Stop: " + (new Date(stop)));
                console.log("Start: " + (new Date(start)));
                self.receiveData(start, stop, self.step);


                // Update Request Every SECONDS_INTERVAL miliseconds
                window.monitoringInterval = window.setInterval(function() {

                    var start = (new Date()).getTime() - (timeGap+10) * 1000;
                    var stop =  (new Date()).getTime() - timeGap * 1000; 

                    // Ask all the datat that we didn't receive
                    if(self.machineNotResponding){

                        // Get last time from a graph
                        if(self.lastMeasurmentTime.getTime() < start)
                            start = self.lastMeasurmentTime.getTime();

                        machineNotResponding = false;
                    }

                    self.receiveData(start, stop, self.step);

                },SECONDS_INTERVAL);
            },

            updateDataRequest: function(timeToRequestms,step){
                window.clearInterval(window.monitoringInterval);
                this.setupDataRequest(timeToRequestms,step);
            },

            finishedGraphUpdate: function(){
                // Runs After All Graphs Are Updated
                // Do Some Stuff Here                
            },


            /**
            * Method: receiveData
            * Makes an ajax request to served, receives measurements
            * creates custom data objects and updates graphs
            */
            receiveData: function(start,stop,step){

                var self = this;

                // start: date/time we want to receive data from
                // stop:  date/time we want to receeive data until
                // step:  miliseconds we want to split data
                $.ajax({
                    url: URL_PREFIX + '/backends/' + this.machine.backend.id +
                         '/machines/' + this.machine.id + '/stats',
                    type: 'GET',
                    async: true,
                    dataType: 'jsonp',
                    data: {'start': Math.floor(start / 1000), 
                            'stop': Math.floor(stop / 1000),
                            'step': step,
                            'auth_key': Mist.auth_key},
                    timeout: 8000,
                    success: function (data, status, xhr){
                        
                        var controller = Mist.monitoringController;

                        try {

                            var measurmentsExpected = Math.floor((stop-start) / step) ;

                            if(data.load.length == 0)
                                throw "Error, Received none measurements";
                            else if(data.load.length > measurmentsExpected)
                                throw "Error, Received more measurements than expected";

                            console.log("Measurement Expected: " + measurmentsExpected);
                            console.log("Measurement Received: " + data.load.length);

                            var disks = [];
                            var netInterfaces = [];

                            // Get Disks Names
                            for(disk in data['disk']['read'])
                            {
                                disks.push(disk);
                            }

                            // Get Network Interfaces Names
                            for(netInterface in data['network'])
                            {
                                 netInterfaces.push(netInterface);
                            }


                            var receivedData = {
                                cpuCores:   0,
                                cpu:       [],
                                load:      [],
                                memory:    [],
                                diskRead:  [],
                                diskWrite: [],
                                netRX:     [],
                                netTX:     []
                            };
                            console.log("Received: " + data.load.length + " measurements");
                            console.log("Step:" + step);


                            // Set CPU Cores
                            receivedData.cpuCores =  data['cpu']['cores'];

                            // Create a date with first measurement time
                            var metricTime = new Date(start);

                            // Create Custom Objects From Data
                            for(var i=0; i < data.load.length; i++ )
                            {

                                var cpuObj = {
                                    time : metricTime,
                                    value: ( (data['cpu']['utilization'][i] * data['cpu']['cores']) * 100)<commit_msg>Important Fix For data Request (Also fixed 0 values returned)<commit_after>define('app/controllers/monitoring', [
    'ember'
    ],
    /**
     * Monitoring Controller
     *
     * @returns Class
     */
    function() {
        return Ember.ObjectController.extend({

            machine : null,
            machineNotResponding: false,
            lastMeasurmentTime: null,
            view: null,

            step: 0,

            // This one is called from view
            initController: function(machine,view){
                this.machine = machine;
                this.view = view;
            },

            /**
            * Method: setupDataRequest
            * Receives first data and set time interval for
            * next reuqests
            */
            setupDataRequest: function(timeToRequestms,step){

                var SECONDS_INTERVAL = 10000;

                var self = this;
                var timeGap = 60;


                // First Data Request
                self.machine.set('pendingStats', true);

                var stop = (new Date()).getTime() - timeGap * 1000;
                var start = stop - timeToRequestms;
                self.step = step;

                // Last measurement must be the first measurement
                self.lastMeasurmentTime = new Date(start);

                console.log("Stop : " + (new Date(stop)));
                console.log("Start: " + (new Date(start)));
                self.receiveData(start, stop, self.step);


                // Update Request Every SECONDS_INTERVAL miliseconds
                window.monitoringInterval = window.setInterval(function() {

                    var start = self.lastMeasurmentTime.getTime();
                    var stop =  (new Date()).getTime() - timeGap * 1000; 

                    console.log("Last Mes: " + self.lastMeasurmentTime);
                    console.log("Start: " + new Date(start));
                    console.log("Stop : " + new Date(stop ));

                    machineNotResponding = false;

                    self.receiveData(start, stop, self.step);

                },SECONDS_INTERVAL);
            },

            updateDataRequest: function(timeToRequestms,step){
                window.clearInterval(window.monitoringInterval);
                this.setupDataRequest(timeToRequestms,step);
            },

            finishedGraphUpdate: function(){
                // Runs After All Graphs Are Updated
                // Do Some Stuff Here                
            },


            /**
            * Method: receiveData
            * Makes an ajax request to served, receives measurements
            * creates custom data objects and updates graphs
            */
            receiveData: function(start,stop,step){

                var self = this;

                // start: date/time we want to receive data from
                // stop:  date/time we want to receeive data until
                // step:  miliseconds we want to split data
                $.ajax({
                    url: URL_PREFIX + '/backends/' + this.machine.backend.id +
                         '/machines/' + this.machine.id + '/stats',
                    type: 'GET',
                    async: true,
                    dataType: 'jsonp',
                    data: {'start': Math.floor(start / 1000), 
                            'stop': Math.floor(stop / 1000),
                            'step': step,
                            'auth_key': Mist.auth_key},
                    timeout: 8000,
                    success: function (data, status, xhr){
                        
                        var controller = Mist.monitoringController;

                        try {

                            var measurmentsExpected = Math.floor((stop-start) / step) ;

                            if(data.load.length == 0)
                                throw "Error, Received none measurements";
                            else if(data.load.length > measurmentsExpected)
                                throw "Error, Received more measurements than expected";

                            console.log("Measurement Expected: " + measurmentsExpected);
                            console.log("Measurement Received: " + data.load.length);

                            var disks = [];
                            var netInterfaces = [];

                            // Get Disks Names
                            for(disk in data['disk']['read'])
                            {
                                disks.push(disk);
                            }

                            // Get Network Interfaces Names
                            for(netInterface in data['network'])
                            {
                                 netInterfaces.push(netInterface);
                            }


                            var receivedData = {
                                cpuCores:   0,
                                cpu:       [],
                                load:      [],
                                memory:    [],
                                diskRead:  [],
                                diskWrite: [],
                                netRX:     [],
                                netTX:     []
                            };
                            console.log("Received: " + data.load.length + " measurements");
                            console.log("Step:" + step);


                            // Set CPU Cores
                            receivedData.cpuCores =  data['cpu']['cores'];

                            // Create a date with first measurement time
                            var metricTime = new Date(start + step);

                            // Create Custom Objects From Data
                            for(var i=0; i < data.load.length; i++ )
                            {

                                var cpuObj = {
                                    time : metricTime,
                                    value: ( (data['cpu']['utilization'][i] * data['cpu']['cores']) * 100)
{'fraction_non_alphanumeric': 0.08930921052631578, 'fraction_numerical': 0.006167763157894737, 'mean_word_length': 0.9545162327225972, 'pattern_counts': {'":': 0, '<': 6, '<?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': 19, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6641613', 'n_tokens_mistral': 2851, 'n_tokens_neox': 2573, 'n_words': 640}