<commit_before>angular.module('app.AIControl', ['starter.factory', 'hljs', 'starter.utils'])
  .controller('AIControl', function ($scope, $ionicModal, $storageServices, $analytics, $http, $ionicLoading, utilsFactory) {
    $analytics.trackView('AI Controller');
    $ionicLoading.show({
      template: 'Computing...'
    });

    $scope.improves = [];
    $scope.goodSkills = [];
    $scope.aiTodoLists = TODO_LISTS;
    var todoMenuKeys = Object.keys(TODO_LISTS);

    angular.forEach(todoMenuKeys, function (listsKey) {
      $storageServices.get(listsKey + 'Finish', function (result) {
        if (result !== 'true') {
          var todoItems = $scope.aiTodoLists[listsKey].basic;
          var suggest = todoItems[utilsFactory.getRandomInt(todoItems.length)];
          $scope.improves.push(suggest);
        } else if (result === 'true') {
          $scope.goodSkills.push(listsKey);
        }
      });
    });

    var serverSkill = 0;
    var frontSkill = 0;
    var devOpsSkill = 0;
    var codingSkill = 0;
    var analyticsSkill = 0;

    if ($scope.goodSkills.indexOf('front') !== -1) {
      frontSkill = 5;
    }

    if ($scope.goodSkills.indexOf('mvc') !== -1) {
      serverSkill = 5;
    }

    if ($scope.goodSkills.indexOf('refactor') !== -1) {
      codingSkill = 5;
    }

    if ($scope.goodSkills.indexOf('analytics') !== -1) {
      analyticsSkill = 5;
    }

    if ($scope.goodSkills.indexOf('container') !== -1 && $scope.goodSkills.indexOf('ci') !== -1) {
      devOpsSkill = 5;
    }

    var skills = {
      server: serverSkill,
      front: frontSkill,
      devops: devOpsSkill,
      coding: codingSkill,
      analytics: analyticsSkill
    };

    $http.get('rules/rules.nools').then(function (response) {
      var flow;
      if (nools.getFlow("AI Flow") === undefined) {
        flow = nools.compile(response.data, {
          name: 'AI Flow'
        });
      } else {
        flow = nools.getFlow("AI Flow");
      }

      var SkillCal = flow.getDefined("skillcal");

      $scope.finallyWords = "你是一个";

      var session = flow.getSession(new SkillCal(skills))
        .on("modify", function (fact) {
          $scope.finallyWords += fact.text;
        })
        .on("fire", function (ruleName) {
          //alert(ruleName);
          console.log(ruleName);
        });

      session.match(function (err) {
        $ionicLoading.hide();
        if (err) {
          console.error(err.stack);
        } else {
          console.log("done");
        }
      });
    });
  });<commit_msg>refactory ai<commit_after>angular.module('app.AIControl', ['starter.factory', 'hljs', 'starter.utils'])
  .controller('AIControl', function ($scope, $ionicModal, $storageServices, $analytics, $http, $ionicLoading, utilsFactory) {
    $analytics.trackView('AI Controller');
    $ionicLoading.show({
      template: 'Computing...'
    });

    $scope.improves = [];
    $scope.goodSkills = [];
    $scope.aiTodoLists = TODO_LISTS;
    var todoMenuKeys = Object.keys(TODO_LISTS);

    angular.forEach(todoMenuKeys, function (listsKey) {
      $storageServices.get(listsKey + 'Finish', function (result) {
        if (result !== 'true') {
          var todoItems = $scope.aiTodoLists[listsKey].basic;
          var suggest = todoItems[utilsFactory.getRandomInt(todoItems.length)];
          $scope.improves.push(suggest);
        } else if (result === 'true') {
          $scope.goodSkills.push(listsKey);
        }
      });
    });

    var skills = {
      server: 0,
      front: 0,
      devops: 0,
      coding: 0,
      analytics: 0
    };

    if ($scope.goodSkills.indexOf('front') !== -1) {
      skills.front = 5;
    }

    if ($scope.goodSkills.indexOf('mvc') !== -1) {
      skills.server = 5;
    }

    if ($scope.goodSkills.indexOf('refactor') !== -1) {
      skills.coding = 5;
    }

    if ($scope.goodSkills.indexOf('analytics') !== -1) {
      skills.analytics = 5;
    }

    if ($scope.goodSkills.indexOf('container') !== -1 && $scope.goodSkills.indexOf('ci') !== -1) {
      skills.devops = 5;
    }

    $http.get('rules/rules.nools').then(function (response) {
      var flow;
      if (nools.getFlow("AI Flow") === undefined) {
        flow = nools.compile(response.data, {
          name: 'AI Flow'
        });
      } else {
        flow = nools.getFlow("AI Flow");
      }

      var SkillCal = flow.getDefined("skillcal");

      $scope.finallyWords = "你是一个";

      var session = flow.getSession(new SkillCal(skills))
        .on("modify", function (fact) {
          $scope.finallyWords += fact.text;
        })
        .on("fire", function (ruleName) {
          console.log('AI Analytics: ' + ruleName);
        });

      session.match(function (err) {
        $ionicLoading.hide();
        if (err) {
          console.error(err.stack);
        } else {
          console.log("AI Analytics: done");
        }
      });
    });
  });
{'fraction_non_alphanumeric': 0.16595223515003063, 'fraction_numerical': 0.006531945294958155, 'mean_word_length': 2.313049357674104, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2340513', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1576, 'n_words': 279}