<commit_before>arrayMinusArray = function(x, y) {
    return _.without.apply(_, [x].concat(y));
};

Router.map(function () {
    this.route('create', {path: '/'});
    this.route('view', {path: 'my-johari/:_privateGUID'});
    this.route('submitted', {path: '/submitted'});
    this.route('submit', {path: '/:_publicGUID'});
});

Session.set("adjectiveChoiceMonitor", 0);
Session.set("username", "");
Session.set("selectedAdjectives", []);

Template.adjectiveChooser.adjectives = function() {
    return allAdjectives;
}; 

Template.adjectiveChooser.events({
    'click li.adjective': function() {
        var selectedAdjectives = Session.get('selectedAdjectives');
        var newSelection = [];

        if (_.contains(selectedAdjectives, this.name)) {
            newSelection = _.without(selectedAdjectives, this.name);
        }
        else {
            newSelection = selectedAdjectives;
            newSelection.push(this.name);
        }

        Session.set('selectedAdjectives', newSelection);
    },
    'submit form': function(theEvent) {
        theEvent.preventDefault();
        Session.set("adjectiveChoiceMonitor", 1); // toggle choice-response
    }
});

Template.adjectiveChooser.isSelected = function() {
    var selectedAdjectives = Session.get('selectedAdjectives');
    var curAdjective = this.name;
    if (_.contains(selectedAdjectives, this.name)) {
        return 'selected';
    }
};

Template.adjectiveChooser.numSelected = function () {
    var selectedAdjectives = Session.get('selectedAdjectives');
    return selectedAdjectives.length;
};

Template.adjectiveChooser.validSelection = function () {
    var selectedAdjectives = Session.get('selectedAdjectives');
    return selectedAdjectives.length == 3;
};

Template.create.events({
    'blur .name': function(theEvent, theTemplate) {
        Session.set("username", theTemplate.find('.name').value);
    }
});

Template.create.respondToAdjectiveChoice = function () {
    if (Session.get("adjectiveChoiceMonitor") == 1) {
        Session.set("adjectiveChoiceMonitor", 0);
        var username = Session.get("username");
        var adjectives = Session.get('selectedAdjectives');
        Meteor.call("createUser", username, adjectives, function(error, result) {
            Router.go('view', {_privateGUID: result.privateGUID});
        });
    }
    return null;
};

Template.view.loadData = function() {
    Meteor.subscribe('userPrivateData', Router.current().params._privateGUID);
    Meteor.subscribe('userAdjectives', Router.current().params._privateGUID);
};

Template.view.name = function () {
    var nameRecord = Names.find().fetch()[0];
    return (nameRecord) ? nameRecord.name : null;
};

Template.view.publicLink = function () {
    var nameRecord = Names.find().fetch()[0];
    return Router.routes['submit'].url({_publicGUID: nameRecord.publicGUID});
};

Template.view.privateLink = function () {
    var nameRecord = Names.find().fetch()[0];
    return Router.routes['view'].url({_privateGUID: nameRecord.privateGUID});
};

Template.view.tallies = function () {
    var tallies = {
        arena: [],
        blindSpot: [],
        façade: [],
        unknown: []
    };

    var selfAdjectives = _.pluck(Adjectives.find({self: true}, {sort: ["adjective", "asc"]}).fetch(), "adjective");
    var friendData = Adjectives.find({self: false}, {sort: ["adjective", "asc"]}).fetch();
    var friendTallies = _.countBy(friendData, function(entry) {return entry.adjective; });
    var friendAdjectives = Object.keys(friendTallies);
    var allChosenAdjectives = selfAdjectives.concat(friendAdjectives);

    tallies.arena = _.intersection(selfAdjectives, friendAdjectives);
    tallies.blindSpot = arrayMinusArray(friendAdjectives, selfAdjectives);
    tallies.façade = arrayMinusArray(selfAdjectives, friendAdjectives);
    tallies.unknown = arrayMinusArray(_(allAdjectives).pluck("name").sort().value(), allChosenAdjectives);

    _.forEach(["arena", "blindSpot"], function(key) {
        tallies[key] = _.map(tallies[key], function(adjective) {
            return adjective + " (" + friendTallies[adjective] + ")";
        });
    });

    return tallies;
};<commit_msg>Don't grab a GUID from a nonexistent record.<commit_after>arrayMinusArray = function(x, y) {
    return _.without.apply(_, [x].concat(y));
};

Router.map(function () {
    this.route('create', {path: '/'});
    this.route('view', {path: 'my-johari/:_privateGUID'});
    this.route('submitted', {path: '/submitted'});
    this.route('submit', {path: '/:_publicGUID'});
});

Session.set("adjectiveChoiceMonitor", 0);
Session.set("username", "");
Session.set("selectedAdjectives", []);

Template.adjectiveChooser.adjectives = function() {
    return allAdjectives;
}; 

Template.adjectiveChooser.events({
    'click li.adjective': function() {
        var selectedAdjectives = Session.get('selectedAdjectives');
        var newSelection = [];

        if (_.contains(selectedAdjectives, this.name)) {
            newSelection = _.without(selectedAdjectives, this.name);
        }
        else {
            newSelection = selectedAdjectives;
            newSelection.push(this.name);
        }

        Session.set('selectedAdjectives', newSelection);
    },
    'submit form': function(theEvent) {
        theEvent.preventDefault();
        Session.set("adjectiveChoiceMonitor", 1); // toggle choice-response
    }
});

Template.adjectiveChooser.isSelected = function() {
    var selectedAdjectives = Session.get('selectedAdjectives');
    var curAdjective = this.name;
    if (_.contains(selectedAdjectives, this.name)) {
        return 'selected';
    }
};

Template.adjectiveChooser.numSelected = function () {
    var selectedAdjectives = Session.get('selectedAdjectives');
    return selectedAdjectives.length;
};

Template.adjectiveChooser.validSelection = function () {
    var selectedAdjectives = Session.get('selectedAdjectives');
    return selectedAdjectives.length == 3;
};

Template.create.events({
    'blur .name': function(theEvent, theTemplate) {
        Session.set("username", theTemplate.find('.name').value);
    }
});

Template.create.respondToAdjectiveChoice = function () {
    if (Session.get("adjectiveChoiceMonitor") == 1) {
        Session.set("adjectiveChoiceMonitor", 0);
        var username = Session.get("username");
        var adjectives = Session.get('selectedAdjectives');
        Meteor.call("createUser", username, adjectives, function(error, result) {
            Router.go('view', {_privateGUID: result.privateGUID});
        });
    }
    return null;
};

Template.view.loadData = function() {
    Meteor.subscribe('userPrivateData', Router.current().params._privateGUID);
    Meteor.subscribe('userAdjectives', Router.current().params._privateGUID);
};

Template.view.name = function () {
    var nameRecord = Names.find().fetch()[0];
    return (nameRecord) ? nameRecord.name : null;
};

Template.view.publicLink = function () {
    var nameRecord = Names.find().fetch()[0];
    return nameRecord ? Router.routes['submit'].url({_publicGUID: nameRecord.publicGUID}) : "";
};

Template.view.privateLink = function () {
    var nameRecord = Names.find().fetch()[0];
    return nameRecord ? Router.routes['view'].url({_privateGUID: nameRecord.privateGUID}) : "";
};

Template.view.tallies = function () {
    var tallies = {
        arena: [],
        blindSpot: [],
        façade: [],
        unknown: []
    };

    var selfAdjectives = _.pluck(Adjectives.find({self: true}, {sort: ["adjective", "asc"]}).fetch(), "adjective");
    var friendData = Adjectives.find({self: false}, {sort: ["adjective", "asc"]}).fetch();
    var friendTallies = _.countBy(friendData, function(entry) {return entry.adjective; });
    var friendAdjectives = Object.keys(friendTallies);
    var allChosenAdjectives = selfAdjectives.concat(friendAdjectives);

    tallies.arena = _.intersection(selfAdjectives, friendAdjectives);
    tallies.blindSpot = arrayMinusArray(friendAdjectives, selfAdjectives);
    tallies.façade = arrayMinusArray(selfAdjectives, friendAdjectives);
    tallies.unknown = arrayMinusArray(_(allAdjectives).pluck("name").sort().value(), allChosenAdjectives);

    _.forEach(["arena", "blindSpot"], function(key) {
        tallies[key] = _.map(tallies[key], function(adjective) {
            return adjective + " (" + friendTallies[adjective] + ")";
        });
    });

    return tallies;
};
{'fraction_non_alphanumeric': 0.15776323616894705, 'fraction_numerical': 0.0019036287923854848, 'mean_word_length': 3.8227194492254735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3660005', 'n_tokens_mistral': 2593, 'n_tokens_neox': 2542, 'n_words': 413}