<commit_before>'use strict';

var _ = require('lodash');

var UPDATE_THROTTLE = 1000;

function boot (env) {

  function setupMongo (ctx, next) {
    require('./storage')(env, function ready ( err, store ) {
      // FIXME, error is always null, if there is an error, the storage.js will throw an exception
      console.log('Storage system ready');
      ctx.store = store;

      next( );
    });
  }

  function setupInternals (ctx, next) {
    ///////////////////////////////////////////////////
    // api and json object variables
    ///////////////////////////////////////////////////
    ctx.plugins = require('./plugins')().registerServerDefaults().init(env.settings);

    ctx.pushover = require('./plugins/pushover')(env);
    ctx.maker = require('./plugins/maker')(env);
    ctx.pushnotify = require('./pushnotify')(env, ctx);

    ctx.entries = require('./entries')(env, ctx);
    ctx.treatments = require('./treatments')(env, ctx);
    ctx.devicestatus = require('./devicestatus')(env.devicestatus_collection, ctx);
    ctx.profile = require('./profile')(env.profile_collection, ctx);
    ctx.pebble = require('./pebble')(env, ctx);
    ctx.bus = require('./bus')(env, ctx);
    ctx.data = require('./data')(env, ctx);
    ctx.notifications = require('./notifications')(env, ctx);

    next( );
  }

  function ensureIndexes (ctx, next) {
    console.info('Ensuring indexes');
    ctx.store.ensureIndexes(ctx.entries( ), ctx.entries.indexedFields);
    ctx.store.ensureIndexes(ctx.treatments( ), ctx.treatments.indexedFields);
    ctx.store.ensureIndexes(ctx.devicestatus( ), ctx.devicestatus.indexedFields);
    ctx.store.ensureIndexes(ctx.profile( ), ctx.profile.indexedFields);

    next( );
  }

  function setupBridge (ctx, next) {
    ctx.bridge = require('./plugins/bridge')(env);

    if (ctx.bridge) {
      ctx.bridge.opts.callback = function bridged (err, glucose) {
        if (err) {
          console.error('Bridge error: ', err);
        } else {
          ctx.entries.create(glucose, function stored (err, docs) {
            if (err) {
              console.error('Bridge storage error: ', err);
            } else {
              console.info('>>>>>docs', docs);
            }
          });
        }
      };
      ctx.bridge.engine(ctx.bridge.opts);<commit_msg>removed debug<commit_after>'use strict';

var _ = require('lodash');

var UPDATE_THROTTLE = 1000;

function boot (env) {

  function setupMongo (ctx, next) {
    require('./storage')(env, function ready ( err, store ) {
      // FIXME, error is always null, if there is an error, the storage.js will throw an exception
      console.log('Storage system ready');
      ctx.store = store;

      next( );
    });
  }

  function setupInternals (ctx, next) {
    ///////////////////////////////////////////////////
    // api and json object variables
    ///////////////////////////////////////////////////
    ctx.plugins = require('./plugins')().registerServerDefaults().init(env.settings);

    ctx.pushover = require('./plugins/pushover')(env);
    ctx.maker = require('./plugins/maker')(env);
    ctx.pushnotify = require('./pushnotify')(env, ctx);

    ctx.entries = require('./entries')(env, ctx);
    ctx.treatments = require('./treatments')(env, ctx);
    ctx.devicestatus = require('./devicestatus')(env.devicestatus_collection, ctx);
    ctx.profile = require('./profile')(env.profile_collection, ctx);
    ctx.pebble = require('./pebble')(env, ctx);
    ctx.bus = require('./bus')(env, ctx);
    ctx.data = require('./data')(env, ctx);
    ctx.notifications = require('./notifications')(env, ctx);

    next( );
  }

  function ensureIndexes (ctx, next) {
    console.info('Ensuring indexes');
    ctx.store.ensureIndexes(ctx.entries( ), ctx.entries.indexedFields);
    ctx.store.ensureIndexes(ctx.treatments( ), ctx.treatments.indexedFields);
    ctx.store.ensureIndexes(ctx.devicestatus( ), ctx.devicestatus.indexedFields);
    ctx.store.ensureIndexes(ctx.profile( ), ctx.profile.indexedFields);

    next( );
  }

  function setupBridge (ctx, next) {
    ctx.bridge = require('./plugins/bridge')(env);

    if (ctx.bridge) {
      ctx.bridge.opts.callback = function bridged (err, glucose) {
        if (err) {
          console.error('Bridge error: ', err);
        } else {
          ctx.entries.create(glucose, function stored (err, docs) {
            if (err) {
              console.error('Bridge storage error: ', err);
            }
          });
        }
      };
      ctx.bridge.engine(ctx.bridge.opts);
{'fraction_non_alphanumeric': 0.20247568523430592, 'fraction_numerical': 0.0017683465959328027, 'mean_word_length': 2.448932926829268, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '1253828', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1313, 'n_words': 263}