<commit_before>;(function() {

  angular
    .module('app.controllers.AnalyticsController', [])
    .controller('AnalyticsController', AnalyticsController);
  
  /* @ngInject */
  function AnalyticsController($scope, $stateParams, user, routes) {
    var vm = this;

  
    // form info regarding this route
    vm.formInfo = {
      route: $stateParams.route,
      methodKeys: [],
      methods: {},
      data: [],
      persistence: false,
      businessLogic: ''
    };

    vm.sortType     = 'id'; // set the default sort type
    vm.sortReverse  = false;  // set the default sort order
    vm.searchData   = '';     // set the default search/filter term
  

    vm.tableHead = vm.formInfo.data[0];
    vm.prepareData = prepareData;
    vm.analytics = {};

    activate();


    function activate() {
      // getRoute();
      getRoute().then(function() {
        console.log('route received');
        var data = prepareData();
        renderChart(data);
      });
    }

    function getRoute() {
      return routes.getRoute(vm.formInfo.route)
        .then(function(res) {
          /**
           * The endpoint DB model stores response, headers, status, etc., all
           * on the `methods` property. Here we're separating out method keys from
           * the body for the sake of ng-repeat in view.
           */
          vm.formInfo.methods = res.methods;
          vm.formInfo.persistence = res.persistence;
          vm.formInfo.data = res.data;
          vm.formInfo.methodKeys = Object.keys(vm.formInfo.methods);
          vm.formInfo.businessLogic = res.businessLogic;
          vm.tableHead = vm.formInfo.data[0];
          vm.analytics = res.analytics;
          console.log('analytics data from db' , res.analytics);
          return;
        }).catch(function(err) {
          console.error('error fetching route', vm.formInfo.route);
          console.error('Message:', err);
        });
    }

    function prepareData() {
      var position = {
        'GET': 0,
        'POST': 1,
        'PUT': 2,
        'DELETE': 3
      };

      var defaultValues = {
        '1': 0,
        '2': 0,
        '3': 0,
        '4': 0,
        '5': 0,
        '6': 0,
        '7': 0
      }; 
      
      var methods = ['GET', 'POST', 'PUT', 'DELETE'];
      for(var i = 0; i < methods.length; i++) { 
        var method = methods[i];
        if(!vm.analytics[method]) {
          vm.analytics[method] = defaultValues;
        }
      }

      var data = [];
      for(var currentMethod in vm.analytics) {
        var days = vm.analytics[currentMethod];
        var dataforMethod = [];
        dataforMethod[0] = currentMethod;
        for(var day in days) {
          var calls = days[day];
          dataforMethod[day] = days[day];
        }
        _.defaults(dataforMethod, defaultValues);
        var positionforMethod = position[currentMethod];
        data[positionforMethod] = dataforMethod;
      }

      return data;
    }

    function renderChart(data) {
      //var data = vm.prepareData();
      console.log('data from renderChart', data); 

      var chart = c3.generate({
        bindTo: '#chart',
        size: {
          width: 450,
          height: 300
        },
        color: {
          pattern: ['#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78', '#2ca02c', '#98df8a', '#d62728']
        },
        data: {
          columns: data
          //type : '  ',
          //onclick: function (d, i) { console.log("onclick", d, i); },
          //onmouseover: function (d, i) { console.log("onmouseover", d, i); },
          //onmouseout: function (d, i) { console.log("onmouseout", d, i); }
        },
        axis: {
          y: {
            label: { // ADD
              text: 'API calls',
              position: 'outer-middle'
            }
          },
          x: {
            label: { // ADD
              text: 'Day',
              position: 'middle'
            }
          }
        } 
      });
    }


  }
}).call(this);<commit_msg>create empty objects when no api calls at all<commit_after>;(function() {

  angular
    .module('app.controllers.AnalyticsController', [])
    .controller('AnalyticsController', AnalyticsController);
  
  /* @ngInject */
  function AnalyticsController($scope, $stateParams, user, routes) {
    var vm = this;

  
    // form info regarding this route
    vm.formInfo = {
      route: $stateParams.route,
      methodKeys: [],
      methods: {},
      data: [],
      persistence: false,
      businessLogic: ''
    };

    vm.sortType     = 'id'; // set the default sort type
    vm.sortReverse  = false;  // set the default sort order
    vm.searchData   = '';     // set the default search/filter term
  

    vm.tableHead = vm.formInfo.data[0];
    vm.prepareData = prepareData;
    vm.analytics = {};

    activate();


    function activate() {
      // getRoute();
      getRoute().then(function() {
        console.log('route received');
        var data = prepareData();
        renderChart(data);
      });
    }

    function getRoute() {
      return routes.getRoute(vm.formInfo.route)
        .then(function(res) {
          /**
           * The endpoint DB model stores response, headers, status, etc., all
           * on the `methods` property. Here we're separating out method keys from
           * the body for the sake of ng-repeat in view.
           */
          vm.formInfo.methods = res.methods;
          vm.formInfo.persistence = res.persistence;
          vm.formInfo.data = res.data;
          vm.formInfo.methodKeys = Object.keys(vm.formInfo.methods);
          vm.formInfo.businessLogic = res.businessLogic;
          vm.tableHead = vm.formInfo.data[0];
          if(res.analytics) {
            vm.analytics = res.analytics;
          }
          console.log('analytics data from db' , res.analytics);
          return;
        }).catch(function(err) {
          console.error('error fetching route', vm.formInfo.route);
          console.error('Message:', err);
        });
    }

    function prepareData() {
      var position = {
        'GET': 0,
        'POST': 1,
        'PUT': 2,
        'DELETE': 3
      };

      var defaultValues = {
        '1': 0,
        '2': 0,
        '3': 0,
        '4': 0,
        '5': 0,
        '6': 0,
        '7': 0
      }; 
      
      var methods = ['GET', 'POST', 'PUT', 'DELETE'];

      for(var i = 0; i < methods.length; i++) { 
        var method = methods[i];
        if(!vm.analytics[method]) {
          vm.analytics[method] = defaultValues;
        }
      }

      var data = [];
      for(var currentMethod in vm.analytics) {
        var days = vm.analytics[currentMethod];
        var dataforMethod = [];
        dataforMethod[0] = currentMethod;
        for(var day in days) {
          var calls = days[day];
          dataforMethod[day] = days[day];
        }
        _.defaults(dataforMethod, defaultValues);
        var positionforMethod = position[currentMethod];
        data[positionforMethod] = dataforMethod;
      }

      return data;
    }

    function renderChart(data) {
      //var data = vm.prepareData();
      console.log('data from renderChart', data); 

      var chart = c3.generate({
        bindTo: '#chart',
        size: {
          width: 450,
          height: 300
        },
        color: {
          pattern: ['#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78', '#2ca02c', '#98df8a', '#d62728']
        },
        data: {
          columns: data
          //type : '  ',
          //onclick: function (d, i) { console.log("onclick", d, i); },
          //onmouseover: function (d, i) { console.log("onmouseover", d, i); },
          //onmouseout: function (d, i) { console.log("onmouseout", d, i); }
        },
        axis: {
          y: {
            label: { // ADD
              text: 'API calls',
              position: 'outer-middle'
            }
          },
          x: {
            label: { // ADD
              text: 'Day',
              position: 'middle'
            }
          }
        } 
      });
    }


  }
}).call(this);
{'fraction_non_alphanumeric': 0.14193307625326534, 'fraction_numerical': 0.012439358129120538, 'mean_word_length': 1.672872340425532, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2649267', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2371, 'n_words': 554}