<commit_before>var PoguesActions = require('../actions/pogues-actions');
var QuestionnaireListStore = require('../stores/questionnaire-list-store');
var QuestionnaireModel = require('../models/Questionnaire');
var SequenceModel = require('../models/Sequence');
var QuestionModel = require('../models/Question');
var Config = require('../config/config');
var request = require('superagent');

var DataUtils = {

  loadQuestionnaireList: function() {

    if (!Config.poguesURL) {


    } else return this.mock.loadQuestionnaireList();
  },

  loadQuestionnaire: function(index) {

    // if (!Config.poguesURL) {

    // } else return this.mock.loadDeepQuestionnaire();
    // For now we don't mock this function
    this.mock.loadDeepQuestionnaire();
  },

  createQuestionnaireOnServer: function(questionnaire) {

  },
  saveQuestionnaire: function(questionnaire) {
    request.put(Config.poguesURL + '/questionnaire/' + questionnaire.id).send(questionnaire).set('Content-Type', 'text/html').end(function(err, res) {
      if (res.ok) {
        console.log(res.body);
      } else {
        console.log(res.body);
      }
    });
  }

  mock: {

    loadQuestionnaireList: function() {
      var numberOfQuestionnaires = Math.floor(Math.random() * 30);
      var timeout = Math.random() * 5;
      var fail = (Math.random() < 0.001);
      console.log('Creating ' + numberOfQuestionnaires + ' questionnaires in ' + timeout + ' ms will ' + (fail ? 'fail' : 'succeed'));
      setTimeout(function() {
        if (fail) PoguesActions.loadQuestionnaireListFailed();
        else {<commit_msg>Refactoring data utils, part 2<commit_after>var PoguesActions = require('../actions/pogues-actions');
var QuestionnaireListStore = require('../stores/questionnaire-list-store');
var QuestionnaireModel = require('../models/Questionnaire');
var SequenceModel = require('../models/Sequence');
var QuestionModel = require('../models/Question');
var Config = require('../config/config');
var request = require('superagent');

var DataUtils = {

  loadQuestionnaireList: function() {

    if (!Config.poguesURL) {


    } else return this.mock.loadQuestionnaireList();
  },

  loadQuestionnaire: function(index) {

    // if (!Config.poguesURL) {

    // } else return this.mock.loadDeepQuestionnaire();
    // For now we don't mock this function
    this.mock.loadDeepQuestionnaire(index);
  },

  createQuestionnaireOnServer: function(questionnaire) {

  },
  saveQuestionnaire: function(questionnaire) {
    request.put(Config.poguesURL + '/questionnaire/' + questionnaire.id).send(questionnaire).set('Content-Type', 'text/html').end(function(err, res) {
      if (res.ok) {
        console.log(res.body);
      } else {
        console.log(res.body);
      }
    });
  }

  mock: {

    loadQuestionnaireList: function() {
      var numberOfQuestionnaires = Math.floor(Math.random() * 30);
      var timeout = Math.random() * 5;
      var fail = (Math.random() < 0.001);
      console.log('Creating ' + numberOfQuestionnaires + ' questionnaires in ' + timeout + ' ms will ' + (fail ? 'fail' : 'succeed'));
      setTimeout(function() {
        if (fail) PoguesActions.loadQuestionnaireListFailed();
        else {
{'fraction_non_alphanumeric': 0.1534375, 'fraction_numerical': 0.0046875, 'mean_word_length': 3.5275813295615275, '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': '3485917', 'n_tokens_mistral': 979, 'n_tokens_neox': 928, 'n_words': 182}