<commit_before>var _ = require('lodash')
var Chance = require('chance')
var random_name = require('node-random-name');
var Firebase = require('firebase');
var ref_Group = new Firebase("https://wetravel.firebaseio.com/Groups")
var ref_User = new Firebase("https://wetravel.firebaseio.com/Users")
//get the current time for message useage
var d = new Date()
var hour = d.getHours()
var minute = d.getMinutes()
var time = hour+':'+minute

// simualate a random person entering, staying for a duration, and leaving
function simulate(){
  // random user name
  var chance = new Chance()
  var name = random_name()
  var duration = 1 + 5 * Math.random()
  var user = {
    name: name,
    status: 'online'
  }
   login(user)
   joinGroup(user, 'CS_Grad_Trip')

  // random message
  var message = chance.word() + " " + chance.word() + " " +chance.word()
  // random schedule
  var Day = "Day" + Math.floor(duration).toString()
  var budget = Math.random()*50+1
  var place = chance.word() + " " + chance.word()
  var startTime  = Math.floor(Math.random()*22)+1
  var endTime  = startTime+2
  var time = startTime.toString() + ':' + endTime.toString()
  var traffic = ['Rent car', 'Taxi', 'Bus', 'Metro', 'Bike', 'Walk']
  var transportation = traffic[Math.floor(Math.random()*traffic.length)]
  var schedule = {
    Day: Day,
    budget: budget,
    place: place,
    time: time,
    transportation: transportation
  }
  setTimeout(function(){
    chat('CS_Grad_Trip',user, message, time)
    addSchedule('CS_Grad_Trip', schedule)

    canvas('CS_Grad_Trip')
    //clickonMap()
  }, duration * 1000)

  // simulate this person login
  // simulate this person logout after 'duration' seconds
  setTimeout(function(){
    //clickonMap()
   }, duration * 1000)

  // simulate this person login
  // simulate this person logout after 'duration' seconds
   setTimeout(function(){
    logout(user)
  }, duration * 1000)

}
function login(user){
  console.log('login', user)
  ref_User.once('value', function(snapshot){
    var users = snapshot.val()
    users = Object.keys(users)
    if (user in users){
      ref_User.child(user.name).update({status:online})
    }
    else{
      ref_User.child(user.name).set({
        name: user.name,
        status: user.status
      })
    }
  })

}

function logout(user){
  console.log('logout', user)
  ref_User.child(user.name).update({status: 'offline'});
}

function joinGroup(user, group){
  ref_User.child(group).child('member').child(user.name).set({
    name: user.name,
    status: user.status
  })
}

function chat(group,user, message, time){<commit_msg>week8 re<commit_after>var _ = require('lodash')
var Chance = require('chance')
var random_name = require('node-random-name');
var Firebase = require('firebase');
var ref_Group = new Firebase("https://wetravel.firebaseio.com/Groups")
var ref_User = new Firebase("https://wetravel.firebaseio.com/Users")
//get the current time for message useage
var d = new Date()
var hour = d.getHours()
var minute = d.getMinutes()
var time = hour+':'+minute

// simualate a random person entering, staying for a duration, and leaving
function simulate(){
  // random user name
  var chance = new Chance()
  var name = random_name()
  var duration = 1 + 5 * Math.random()
  var user = {
    name: name,
    status: 'online'
  }
   login(user)
   joinGroup(user, 'CS_Grad_Trip')

  // random message
  var message = chance.word() + " " + chance.word() + " " +chance.word()
  // random schedule
  var Day = "Day" + Math.floor(duration).toString()
  var budget = Math.random()*50+1
  var place = chance.word() + " " + chance.word()
  var startTime  = Math.floor(Math.random()*22)+1
  var endTime  = startTime+2
  var time = startTime.toString() + ':' + endTime.toString()
  var traffic = ['Rent car', 'Taxi', 'Bus', 'Metro', 'Bike', 'Walk']
  var transportation = traffic[Math.floor(Math.random()*traffic.length)]
  var schedule = {
    Day: Day,
    budget: budget,
    place: place,
    time: time,
    transportation: transportation
  }
  setTimeout(function(){
    chat('CS_Grad_Trip',user, message, time)
    addSchedule('CS_Grad_Trip', schedule)

    canvas('CS_Grad_Trip')
    //clickonMap()
  }, duration * 1000)

  // simulate this person login
  // simulate this person logout after 'duration' seconds
  setTimeout(function(){
    //clickonMap()
   }, duration * 1000)

  // simulate this person login
  // simulate this person logout after 'duration' seconds
   setTimeout(function(){
    logout(user)
  }, duration * 1000)

}
function login(user){
  console.log('login', user)
  ref_User.once('value', function(snapshot){
    var users = snapshot.val()
    users = Object.keys(users)
    if (user in users){
      ref_User.child(user.name).update({status:online})
    }
    else{
      ref_User.child(user.name).set({
        name: user.name,
        status: user.status
      })
    }
  })

}

function logout(user){
  console.log('logout', user)
  ref_User.child(user.name).update({status: 'offline'});
}

function joinGroup(user, group){
  ref_Group.child(group).child('member').child(user.name).set({
    name: user.name,
    status: user.status
  })
}

function chat(group,user, message, time){
{'fraction_non_alphanumeric': 0.15271885846509833, 'fraction_numerical': 0.008291554184342461, 'mean_word_length': 3.5821554770318023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '504868', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1690, 'n_words': 420}