<commit_before>/**
 * Populate DB with sample data on server start
 * to disable, edit config/environment/index.js, and set `seedDB: false`
 */

'use strict';

var User = require('../models/user.model.js');
var Beacon = require('../models/beacon.model.js');
var Agent = require('../models/agent.model.js');
var BeaconDetection = require('../models/beacon-detection.model.js');
var beaconDetectionService = require('../service/beacon-detection.service.js');

module.exports = function (complete) {

    //[<NAME>:9/29/14] TODO: there is probably a better way to do this - promises I'm assuming
    var usersLoaded = false;
    var agentsLoaded = false;
    var detectionsLoaded = false;

    User.find({}).remove(function () {
        User.create({
                provider: 'local',
                name: '<NAME>',
                email: '<EMAIL>',
                password: '<PASSWORD>'
            }, {
                provider: 'local',
                role: 'admin',
                name: 'Admin',
                email: '<EMAIL>',
                password: '<PASSWORD>'
            }, function () {
                console.log('finished populating users');
                usersLoaded = true;
                if (agentsLoaded === true && detectionsLoaded === true) {
                    complete();
                }
            }
        );
    });

    Agent.find({}).remove(function () {
        Agent.create({
                name: 'Agent 1',
                location: 'entry way',
                capabilities: ['audio'],
                approvedStatus: 'Pending',
                operationalStatus: 'Success'
            }, {
                name: 'Agent 2',
                location: 'great room',
                capabilities: ['audio'],
                approvedStatus: 'Approved',
                operationalStatus: 'Success'
            }, {
                name: 'Agent 3',
                location: 'situation room',
                capabilities: ['audio'],
                approvedStatus: 'Denied',
                operationalStatus: 'Failure'
            }, function () {
                console.log('finished populating agents');
                agentsLoaded = true;
                if (usersLoaded === true && detectionsLoaded === true) {
                    complete();
                }
            }
        );
    });

    BeaconDetection.find({}).remove(function () {
        var sampleDetections = [
            {
                time: Date.now(),
                uuid: '0000000',
                major: 11111,
                minor: 22222,
                tx: 3,
                rssi: 1,
                distance: 1.2
            },
            {
                time: Date.now(),
                uuid: '0000001',
                major: 11112,
                minor: 22223,
                tx: 4,
                rssi: 2,
                distance: 2.2
            },
            {
                time: Date.now(),
                uuid: '8uf98asu',
                major: 1,
                minor: 1,
                tx: -65,
                rssi: -75,
                distance: 3.7
            }
        ];

        beaconDetectionService.createDetections(sampleDetections, function () {
            console.log('finished populating detections');
            detectionsLoaded = true;
            if (usersLoaded === true && agentsLoaded === true) {
                complete();
            }
        });
    });
}
<commit_msg>change seed data file to use promises<commit_after>/**
 * Populate DB with sample data on server start
 * to disable, edit config/environment/index.js, and set `seedDB: false`
 */

'use strict';

var User = require('../models/user.model.js');
var Beacon = require('../models/beacon.model.js');
var Agent = require('../models/agent.model.js');
var BeaconDetection = require('../models/beacon-detection.model.js');
var mongoose = require('mongoose');

module.exports = function (complete) {

    // delete users
    User.find({}).remove().exec()
        // then populate users
        .then(function () {
            var promise = new mongoose.Promise;
            User.create({
                    provider: 'local',
                    name: '<NAME>',
                    email: '<EMAIL>',
                    password: '<PASSWORD>'
                }, {
                    provider: 'local',
                    role: 'admin',
                    name: 'Admin',
                    email: '<EMAIL>',
                    password: '<PASSWORD>'
                }
                , function (err) {
                    if (err) {
                        promise.reject(err);
                    } else {
                        console.log('finished populating users');
                        promise.resolve();
                    }
                });
            return promise;
        })
        // then delete agents
        .then(function () {
            return Agent.find({}).remove().exec();
        })
        // then populate agents
        .then(function () {
            var promise = new mongoose.Promise;
            Agent.create({
                    name: '<NAME>',
                    location: 'entry way',
                    capabilities: ['audio'],
                    approvedStatus: 'Pending',
                    operationalStatus: 'Success'
                }, {
                    name: 'Agent 2',
                    location: 'great room',
                    capabilities: ['audio'],
                    approvedStatus: 'Approved',
                    operationalStatus: 'Success'
                }, {
                    name: 'Agent 3',
                    location: 'situation room',
                    capabilities: ['audio'],
                    approvedStatus: 'Denied',
                    operationalStatus: 'Failure'
                }, function (err) {
                    if (err) {
                        promise.reject(err);
                    } else {
                        console.log('finished populating agents');
                        promise.resolve();
                    }
                }
            );
            return promise;
        })
        // then delete detections
        .then(function () {
            return BeaconDetection.find({}).remove().exec();
        })
        // then populate detections
        .then(function () {
            var promise = new mongoose.Promise;
            BeaconDetection.create({
                    time: Date.now(),
                    uuid: '0000000',
                    major: 11111,
                    minor: 22222,
                    tx: 3,
                    rssi: 1,
                    distance: 1.2
                },
                {
                    time: Date.now(),
                    uuid: '0000001',
                    major: 11112,
                    minor: 22223,
                    tx: 4,
                    rssi: 2,
                    distance: 2.2
                },
                {
                    time: Date.now(),
                    uuid: '8uf98asu',
                    major: 1,
                    minor: 1,
                    tx: -65,
                    rssi: -75,
                    distance: 3.7
                }, function (err) {
                    if (err) {
                        promise.reject(err);
                    } else {
                        console.log('finished populating beacon detections');
                        promise.resolve();
                    }
                }
            );
            return promise;
        }
    )
        .then(function () {
            console.log('done populating seed data');
            complete();
        }, function (err) {
            console.log('error loading seed data: ' + err);
        });
}

{'fraction_non_alphanumeric': 0.11763949601439959, 'fraction_numerical': 0.014913859604011315, 'mean_word_length': 1.0353218210361068, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6399049', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1777, 'n_words': 430}