<commit_before>#!/usr/bin/env node
var io = require('socket.io-client');
var yaml = require('yamljs');
var parseArgs = require('minimist');


var args = parseArgs(process.argv, {
                    default: {
                        'trace': 'trace.yaml',
                        'host': 'http://localhost:8080'
                    }});

var players = {};
players['moderator'] = io(args['host'], {multiplex: false});

function processEvent(event, cb) {
    var uuid = event.player;
    var name = event.name;
    if (event.type === 'join') {
        console.info(name + ' joined (' + uuid + ')');
        var socket = io(args['host'], {multiplex: false});
        players[uuid] = socket;
        socket.emit('new player', name);
        cb();
        return;
    }
    var socket = players[uuid];
    if (event.type === 'word') {
        var word = event.word;
        console.info(uuid + ' submitted ' + word);
        socket.emit('new word', word, function() {});
        cb();
        return;
    }
    if (event.type === 'start') {
      socket.emit('start game');
      cb();
      return;
    }
    if (event.type === 'stop') {
      socket.emit('stop game');
      cb();
      return;
    }
    console.warn('unknown event type: ' + event.type);
    cb();
}

var trace = yaml.load(args['trace']);
var timeMultiplier = trace.config.timeUnitsMillis || 1;
if (timeMultiplier != 1) {
  console.log('scaling times by ' + timeMultiplier);
}

var startTime = Date.now();

// TODO(tchajed): sort events by offset

function scheduleEvent(num) {
    if (num >= trace.events.length) {
        // we're done
        console.log("finished trace");
        setTimeout(function() {
          process.exit(0);
        }, 1000);
        return;
    }
    var event = trace.events[num];
    var time = startTime + event.time * timeMultiplier;
    var now = Date.now();
    setTimeout(function() {
        processEvent(event, function() {
            scheduleEvent(num + 1);
        });<commit_msg>Sory replay events by time<commit_after>#!/usr/bin/env node
var io = require('socket.io-client');
var yaml = require('yamljs');
var parseArgs = require('minimist');


var args = parseArgs(process.argv, {
                    default: {
                        'trace': 'trace.yaml',
                        'host': 'http://localhost:8080'
                    }});

var players = {};
players['moderator'] = io(args['host'], {multiplex: false});

function processEvent(event, cb) {
    var uuid = event.player;
    var name = event.name;
    if (event.type === 'join') {
        console.info(name + ' joined (' + uuid + ')');
        var socket = io(args['host'], {multiplex: false});
        players[uuid] = socket;
        socket.emit('new player', name);
        cb();
        return;
    }
    var socket = players[uuid];
    if (event.type === 'word') {
        var word = event.word;
        console.info(uuid + ' submitted ' + word);
        socket.emit('new word', word, function() {});
        cb();
        return;
    }
    if (event.type === 'start') {
      socket.emit('start game');
      console.log('starting game');
      cb();
      return;
    }
    if (event.type === 'stop') {
      socket.emit('stop game');
      console.log('stopping game');
      cb();
      return;
    }
    console.warn('unknown event type: ' + event.type);
    cb();
}

var trace = yaml.load(args['trace']);
var timeMultiplier = trace.config.timeUnitsMillis || 1;
if (timeMultiplier != 1) {
  console.log('scaling times by ' + timeMultiplier);
}

var startTime = Date.now();

trace.events.sort(function(e1, e2) {
  return e1.time - e2.time;
});

function scheduleEvent(num) {
    if (num >= trace.events.length) {
        // we're done
        console.log("finished trace");
        setTimeout(function() {
          process.exit(0);
        }, 1000);
        return;
    }
    var event = trace.events[num];
    var time = startTime + event.time * timeMultiplier;
    var now = Date.now();
    setTimeout(function() {
        processEvent(event, function() {
            scheduleEvent(num + 1);
        });
{'fraction_non_alphanumeric': 0.1670743639921722, 'fraction_numerical': 0.00684931506849315, 'mean_word_length': 2.199530516431925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4567624', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1242, 'n_words': 288}