<commit_before>/* global angular */
(function () { 'use strict';

var baseURL = 'http://demo.apiserver.cloudbrain.rocks';

angular.module('cloudbrain')

.controller('chartController',
           ['$scope','$http','$interval','$log','apiService','dataService',
function   ( $scope , $http , $interval , $log , apiService , dataService ) {

    $scope.model = {
      deviceIds: [],
      deviceNames: [],
    };

    $scope.changeColor = function () {
        var color_val = 'rgba(255, 255, 255, 0.8)';
        $scope.chartPolar.options.chart.backgroundColor = color_val;
        $scope.chartBar.options.chart.backgroundColor = color_val;
      };


    apiService.refreshDeviceIds().then(function(response) {
      angular.copy(response.data, $scope.model.deviceIds);
    });

    apiService.refreshPhysicalDeviceNames().then(function(response) {
      angular.copy(response.data, $scope.model.deviceNames);
    });


      var setChannelSeries = function(data){
        var keys = Object.keys(data[0]);

        keys.forEach(function(key){
          if (key != 'timestamp'){
            for (var a=[],i=0;i<500;++i) a[i]=0;
            $scope.chartStock.series.push({name: key, data: a, id: key});
          }
        });
      };

      // FIXME: considering only the first point right now...
      function updatePowerBandGraph(graphName, data) {
          if (data.length) {
              $scope[graphName].series[0].data.length = 0;
              $scope[graphName].series[0].data.push(data[0].gamma);
              $scope[graphName].series[0].data.push(data[0].delta);
              $scope[graphName].series[0].data.push(data[0].theta);
              $scope[graphName].series[0].data.push(data[0].beta);
              $scope[graphName].series[0].data.push(data[0].alfa);
          }
      }

      //$scope.url = 'http://mock.cloudbrain.rocks/data?device_name=openbci&metric=eeg&device_id=marion&callback=JSON_CALLBACK';
      $scope.showClick = false;
      $scope.chartMuse = false;
      $scope.getData = function (device, url) {

        dataService.startPowerBand(device.name, device.id, function(data) {
          updatePowerBandGraph('chartPolar', data);
          updatePowerBandGraph('chartBar', data);
        });

        $scope.chartPolar.title.text = device.name + ' ' + device.id;
        $scope.chartBar.title.text = device.name + ' ' + device.id;
        $scope.chartStock.title.text = device.name + ' ' + device.id;
        $scope.showClick=true;
        if ('muse' === device.name){
          $scope.chartMuse = true;
        }
        var metric = 'eeg';
        $scope.lastTimestamp = Date.now() * 1000; //microseconds
        $scope.cloudbrain = baseURL + '/data?device_name='+device.name+'&metric='+metric+'&device_id='+device.id+'&callback=JSON_CALLBACK&start='+$scope.lastTimestamp;
        $scope.chart3 = $scope.chartStock.getHighcharts();

        //initialize series data for charts
        $http.jsonp($scope.cloudbrain)
          .then(function(response){
            setChannelSeries(response.data);
          }, function(response){
            $log.log('fail');
        });

        $interval(function () {
          $http.jsonp($scope.cloudbrain)
          .then(function(response){
            $scope.lastTimestamp = response.data[response.data.length - 1].timestamp;

            response.data.forEach(function (dataPoints) {
              delete dataPoints.timestamp;

              for(var channel in dataPoints){
                $scope.chartStock.series[channel.split('_')[1]].data.push(dataPoints[channel]);
                if($scope.chartStock.series[channel.split('_')[1]].data.length > 300){
                  $scope.chartStock.series[channel.split('_')[1]].data.shift();
                }
              }

            });

          },
          function(response){
            $log.log('fail');
          });
        }, 100);
      };



      $scope.chartStock = {
        options: {
          chart: {
            zoomType: 'x',
            type: 'spline'
          },
          tooltip: {
            enabled: false
          },
          legend: {
            enabled: true
          },
          rangeSelector: {
            buttons: [{
              count: 100,
              type: 'millisecond',
              text: '2S'
            }, {
              count: 300,
              type: 'millisecond',
              text: '30S'<commit_msg>UI-TWEAKS Temporarily slow down data pulling<commit_after>/* global angular */
(function () { 'use strict';

var baseURL = 'http://demo.apiserver.cloudbrain.rocks';

angular.module('cloudbrain')

.controller('chartController',
           ['$scope','$http','$interval','$log','apiService','dataService',
function   ( $scope , $http , $interval , $log , apiService , dataService ) {

    $scope.model = {
      deviceIds: [],
      deviceNames: [],
    };

    $scope.changeColor = function () {
        var color_val = 'rgba(255, 255, 255, 0.8)';
        $scope.chartPolar.options.chart.backgroundColor = color_val;
        $scope.chartBar.options.chart.backgroundColor = color_val;
      };


    apiService.refreshDeviceIds().then(function(response) {
      angular.copy(response.data, $scope.model.deviceIds);
    });

    apiService.refreshPhysicalDeviceNames().then(function(response) {
      angular.copy(response.data, $scope.model.deviceNames);
    });


      var setChannelSeries = function(data){
        var keys = Object.keys(data[0]);

        keys.forEach(function(key){
          if (key != 'timestamp'){
            for (var a=[],i=0;i<500;++i) a[i]=0;
            $scope.chartStock.series.push({name: key, data: a, id: key});
          }
        });
      };

      // FIXME: considering only the first point right now...
      function updatePowerBandGraph(graphName, data) {
          if (data.length) {
              $scope[graphName].series[0].data.length = 0;
              $scope[graphName].series[0].data.push(data[0].gamma);
              $scope[graphName].series[0].data.push(data[0].delta);
              $scope[graphName].series[0].data.push(data[0].theta);
              $scope[graphName].series[0].data.push(data[0].beta);
              $scope[graphName].series[0].data.push(data[0].alfa);
          }
      }

      //$scope.url = 'http://mock.cloudbrain.rocks/data?device_name=openbci&metric=eeg&device_id=marion&callback=JSON_CALLBACK';
      $scope.showClick = false;
      $scope.chartMuse = false;
      $scope.getData = function (device, url) {

        dataService.startPowerBand(device.name, device.id, function(data) {
          updatePowerBandGraph('chartPolar', data);
          updatePowerBandGraph('chartBar', data);
        });

        $scope.chartPolar.title.text = device.name + ' ' + device.id;
        $scope.chartBar.title.text = device.name + ' ' + device.id;
        $scope.chartStock.title.text = device.name + ' ' + device.id;
        $scope.showClick=true;
        if ('muse' === device.name){
          $scope.chartMuse = true;
        }
        var metric = 'eeg';
        $scope.lastTimestamp = Date.now() * 1000; //microseconds
        $scope.cloudbrain = baseURL + '/data?device_name='+device.name+'&metric='+metric+'&device_id='+device.id+'&callback=JSON_CALLBACK&start='+$scope.lastTimestamp;
        $scope.chart3 = $scope.chartStock.getHighcharts();

        //initialize series data for charts
        $http.jsonp($scope.cloudbrain)
          .then(function(response){
            setChannelSeries(response.data);
          }, function(response){
            $log.log('fail');
        });

        $interval(function () {
          $http.jsonp($scope.cloudbrain)
          .then(function(response){
            $scope.lastTimestamp = response.data[response.data.length - 1].timestamp;

            response.data.forEach(function (dataPoints) {
              delete dataPoints.timestamp;

              for(var channel in dataPoints){
                $scope.chartStock.series[channel.split('_')[1]].data.push(dataPoints[channel]);
                if($scope.chartStock.series[channel.split('_')[1]].data.length > 300){
                  $scope.chartStock.series[channel.split('_')[1]].data.shift();
                }
              }

            });

          },
          function(response){
            $log.log('fail');
          });
        }, 500);
      };



      $scope.chartStock = {
        options: {
          chart: {
            zoomType: 'x',
            type: 'spline'
          },
          tooltip: {
            enabled: false
          },
          legend: {
            enabled: true
          },
          rangeSelector: {
            buttons: [{
              count: 100,
              type: 'millisecond',
              text: '2S'
            }, {
              count: 300,
              type: 'millisecond',
              text: '30S'
{'fraction_non_alphanumeric': 0.15572190087331292, 'fraction_numerical': 0.01202222978337303, 'mean_word_length': 2.0692655760529064, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3738456', 'n_tokens_mistral': 2703, 'n_tokens_neox': 2566, 'n_words': 368}