<commit_before>var _ = require('lodash')
var random_name = require('node-random-name');
var Firebase = require('firebase');
// Boulder
var city_location = {
    lat: 40.015,
    lon: -105.27
}
var radius = 0.03
    // simualate a random person entering, staying for a duration, and leaving
function simulate() {
    // generate a random person with a random name,
    // random location, and random duration
    var name = random_name();
    var duration = 1 + 60 * Math.random();
    var lat = city_location.lat + radius * (Math.random() - 0.5) * 2;
    var lon = city_location.lon + radius * (Math.random() - 0.5) * 2;
    var isGroupOwner = Math.random() < 0.5 ? true : false;
   

    var person = {
        name: name,
        duration: duration,
        lat: lat,
        lon: lon,
        isGroupOwner: isGroupOwner
    };

    // simulate this person entering
    enter(person);

    movement();

    // simulate this person leaving after 'duration' seconds
    setTimeout(function() {
        leave(person);
    }, duration * 1000);

}

function enter(person) {
    console.log('enter', person.name);
    // Put this person in the Firebase
    var ref = new Firebase('https://drinktogether.firebaseio.com/users');
    ref.child(person.name).set({
        duration: person.duration,
        lat: person.lat,
        lon: person.lon,
        name: person.name,
        isGroupOwner: person.isGroupOwner
    });
}

function movement() {

    console.log("movement called!");

    var ref = new Firebase('https://drinktogether.firebaseio.com/');

    ref.child('users').once('value', function(snapshot) {
        snapshot.forEach(function(childSnapshot) {
            var user = childSnapshot.val();
            var childKey = childSnapshot.key();
            console.log(user);

            var latmov = 0;
            var lonmov = 0;

            if (Math.random() < 0.5) {
                latmov = Math.random() * (0.0005).toFixed(4);
                latmov *= Math.floor(Math.random() * 2) == 1 ? 1 : -1;
            } else {
                lonmov = Math.random() * (0.0005).toFixed(4);
                lonmov *= Math.floor(Math.random() * 2) == 1 ? 1 : -1;
            };
           
            var lat = latmov + user.lat;
            var lon = lonmov + user.lon;

            // console.log("Lat: " + lat + " CNG: " + (user.lat-lat));
            // console.log("Lon: " + lon + " CNG: " + (user.lon-lon));

            ref.child('users/' + user.name).set({
                lat: lat,
                lon: lon,
                duration: user.duration,
                name: user.name,
                isGroupOwner: provider.isGroupOwner
            });

        });
    });
}


function leave(person) {
    console.log('leave', person)
    var ref = new Firebase('https://drinktogether.firebaseio.com/users')
    var onComplete = function(error) {
        if (error) {
            console.log('Leave Synchronization failed');
        } else {
            console.log('Leave Synchronization succeeded');
        }
    };
    ref.child(person.name).remove(onComplete);
}

function clear() {
    // TODO: remove all people from the Firebase
    var ref = new Firebase('https://drinktogether.firebaseio.com/users')
    var onComplete = function(error) {<commit_msg>simulator<commit_after>var _ = require('lodash')
var random_name = require('node-random-name');
var Firebase = require('firebase');


// Boulder
var city_location = {
    lat: 40.015,
    lon: -105.27
}
var radius = 0.03
    // simualate a random person entering, staying for a duration, and leaving
function simulate() {
    // generate a random person with a random name,
    // random location, and random duration
    var name = random_name();
    var duration = 1 + 60 * Math.random();
    var lat = city_location.lat + radius * (Math.random() - 0.5) * 2;
    var lon = city_location.lon + radius * (Math.random() - 0.5) * 2;
    var isGroupOwner = Math.random() < 0.5 ? true : false;
   

    var person = {
        name: name,
        duration: duration,
        lat: lat,
        lon: lon,
        isGroupOwner: isGroupOwner
    };

    // simulate this person entering
    enter(person);

    movement();

    // simulate this person leaving after 'duration' seconds
    setTimeout(function() {
        leave(person);
    }, duration * 1000);

}

function enter(person) {
    console.log('enter', person.name);
    // Put this person in the Firebase
    var ref = new Firebase('https://drinktogether.firebaseio.com/users');
    ref.child(person.name).set({
        duration: person.duration,
        lat: person.lat,
        lon: person.lon,
        name: person.name,
        isGroupOwner: person.isGroupOwner
    });
}

function movement() {

    console.log("movement called!");

    var ref = new Firebase('https://drinktogether.firebaseio.com/');

    ref.child('users').once('value', function(snapshot) {
        snapshot.forEach(function(childSnapshot) {
            var user = childSnapshot.val();
            var childKey = childSnapshot.key();
            console.log(user);

            var latmov = 0;
            var lonmov = 0;

            if (Math.random() < 0.5) {
                latmov = Math.random() * (0.0005).toFixed(4);
                latmov *= Math.floor(Math.random() * 2) == 1 ? 1 : -1;
            } else {
                lonmov = Math.random() * (0.0005).toFixed(4);
                lonmov *= Math.floor(Math.random() * 2) == 1 ? 1 : -1;
            };
           
            var lat = latmov + user.lat;
            var lon = lonmov + user.lon;

            // console.log("Lat: " + lat + " CNG: " + (user.lat-lat));
            // console.log("Lon: " + lon + " CNG: " + (user.lon-lon));

            ref.child('users/' + user.name).set({
                lat: lat,
                lon: lon,
                duration: user.duration,
                name: user.name,
                isGroupOwner: user.isGroupOwner
            });

        });
    });
}


function leave(person) {
    console.log('leave', person)
    var ref = new Firebase('https://drinktogether.firebaseio.com/users')
    var onComplete = function(error) {
        if (error) {
            console.log('Leave Synchronization failed');
        } else {
            console.log('Leave Synchronization succeeded');
        }
    };
    ref.child(person.name).remove(onComplete);
}

function clear() {
    // TODO: remove all people from the Firebase
    var ref = new Firebase('https://drinktogether.firebaseio.com/users')
    var onComplete = function(error) {
{'fraction_non_alphanumeric': 0.14036697247706423, 'fraction_numerical': 0.015902140672782873, 'mean_word_length': 1.9881224303334857, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 8, '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': '5493463', 'n_tokens_mistral': 2042, 'n_tokens_neox': 1914, 'n_words': 474}