<commit_before>/**
  Results Controller
*/

//native modules
var util = require("util");

//3rd party modules
var express = require('express');
var mongoose = require('mongoose');
var colors = require('colors');
var JunitParser = require('junit-xml-parser').parser;
var uuid = require('node-uuid');
var async = require('async');
var winston = require('winston');
//own modules
var DefaultController = require('./');

var Controller = function(){

  var Result = mongoose.model('Result');
  var Testcase = mongoose.model('Testcase')
  var defaultCtrl = new DefaultController(Result, 'Result');

  var doDummy = function() {
    //create dummy testcases when db is empty ->
    defaultCtrl.isEmpty( function(yes){
      if( yes === true ){
        var Template = {
            tcid: 'Testcase-',
            cre: { name: 'tmi'},
            job: {
              id: ''
            },
            exec: { 
              verdict: 'pass', 
              framework: { name: 'clitest', ver: '0.0'},
              dut: {
                vendor: 'atmel',
                build: {
                  branch: 'master',
                  commitId: 'abc12345678901234567'
                }
              },
              sut: {
                cut: ['fea-1']
              }
            }
          }
        var _ = require('underscore');
        defaultCtrl.generateDummyData( function(i){
           var _new = {};
           _.extend(_new, Template)
            _new.tcid += i;
            _new.job.id = 'test-job-'+defaultCtrl.randomText(['A','B', 'C']);
            _new.exec.verdict = defaultCtrl.randomText(['pass','fail']);
            _new.exec.duration = defaultCtrl.randomIntInc(0, 500);
            return _new;
        }, 1000, function(err){
          //done
          if(err)console.log(err);
          else console.log('dummy result generated');
        });
      }
    });
  }

  this.paramFormat = defaultCtrl.format();
  this.paramResult = defaultCtrl.modelParam();

  this.all = function(req, res, next){
    // dummy middleman function..
    next(); 
  }
  
  this.get = defaultCtrl.get;
  this.find = defaultCtrl.find;
  this.create = defaultCtrl.create;
  this.update = defaultCtrl.update;
  this.remove = defaultCtrl.remove;  

  Object.resolve = function(path, obj, safe) {
        return path.split('.').reduce(function(prev, curr) {
            return !safe ? prev[curr] : (prev ? prev[curr] : undefined)
        }, obj || self)
    }

  defaultCtrl.on('create', function(data){
    if( data.exec && data.exec.verdict === 'pass' ) {
      //data.exec.duration
      console.log("Got new "+"PASS".green+" result: "+data.tcid);
    } else {
      console.log(data);
      console.log("Got new "+"FAIL".red+" result: "+data.tcid + "("+data._id+")");
    }
    duration =  Object.resolve('exec.duration', data, null);
    if( duration ) {
      Testcase.updateTcDuration(data.tcid, duration);
    }
  });
  
  function streamToString(stream, cb) {
      const chunks = [];
      stream.on('data', function(chunk){
        chunks.push(chunk);
      });
      stream.on('end', function(){
        cb(chunks.join(''));
      });
  }<commit_msg>don't print result object to console when received new one<commit_after>/**
  Results Controller
*/

//native modules
var util = require("util");

//3rd party modules
var express = require('express');
var mongoose = require('mongoose');
var colors = require('colors');
var JunitParser = require('junit-xml-parser').parser;
var uuid = require('node-uuid');
var async = require('async');
var winston = require('winston');
//own modules
var DefaultController = require('./');

var Controller = function(){

  var Result = mongoose.model('Result');
  var Testcase = mongoose.model('Testcase')
  var defaultCtrl = new DefaultController(Result, 'Result');

  var doDummy = function() {
    //create dummy testcases when db is empty ->
    defaultCtrl.isEmpty( function(yes){
      if( yes === true ){
        var Template = {
            tcid: 'Testcase-',
            cre: { name: 'tmi'},
            job: {
              id: ''
            },
            exec: { 
              verdict: 'pass', 
              framework: { name: 'clitest', ver: '0.0'},
              dut: {
                vendor: 'atmel',
                build: {
                  branch: 'master',
                  commitId: 'abc12345678901234567'
                }
              },
              sut: {
                cut: ['fea-1']
              }
            }
          }
        var _ = require('underscore');
        defaultCtrl.generateDummyData( function(i){
           var _new = {};
           _.extend(_new, Template)
            _new.tcid += i;
            _new.job.id = 'test-job-'+defaultCtrl.randomText(['A','B', 'C']);
            _new.exec.verdict = defaultCtrl.randomText(['pass','fail']);
            _new.exec.duration = defaultCtrl.randomIntInc(0, 500);
            return _new;
        }, 1000, function(err){
          //done
          if(err)console.log(err);
          else console.log('dummy result generated');
        });
      }
    });
  }

  this.paramFormat = defaultCtrl.format();
  this.paramResult = defaultCtrl.modelParam();

  this.all = function(req, res, next){
    // dummy middleman function..
    next(); 
  }
  
  this.get = defaultCtrl.get;
  this.find = defaultCtrl.find;
  this.create = defaultCtrl.create;
  this.update = defaultCtrl.update;
  this.remove = defaultCtrl.remove;  

  Object.resolve = function(path, obj, safe) {
        return path.split('.').reduce(function(prev, curr) {
            return !safe ? prev[curr] : (prev ? prev[curr] : undefined)
        }, obj || self)
    }

  defaultCtrl.on('create', function(data){
    if( data.exec && data.exec.verdict === 'pass' ) {
      //data.exec.duration
      console.log("Got new "+"PASS".green+" result: "+data.tcid);
    } else {
      console.log("Got new "+"FAIL".red+" result: "+data.tcid + "("+data._id+")");
    }
    duration =  Object.resolve('exec.duration', data, null);
    if( duration ) {
      Testcase.updateTcDuration(data.tcid, duration);
    }
  });
  
  function streamToString(stream, cb) {
      const chunks = [];
      stream.on('data', function(chunk){
        chunks.push(chunk);
      });
      stream.on('end', function(){
        cb(chunks.join(''));
      });
  }
{'fraction_non_alphanumeric': 0.15896868079721607, 'fraction_numerical': 0.009174311926605505, 'mean_word_length': 2.069417475728155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2102111', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1855, 'n_words': 404}