<commit_before>pjax_config_page_require_auth("account/knowledgetest", function(){
    return {
        onLoad: function() {
            KnowledgeTest.init();
        }
    };
});
<commit_msg>Integrate with backend for status checking<commit_after>pjax_config_page_require_auth("account/knowledgetest", function(){

    // TODO: show meaningful msg
    var cannotTakeKnowledgeTest = function() {
        window.location.href = page.url.url_for('user/my_accountws');
    };

    return {
        onLoad: function() {
            BinarySocket.init({
                onmessage: function(msg) {
                    var response = JSON.parse(msg.data);
                    var type = response.msg_type;

                    var passthrough = response.echo_req.passthrough;

                    if (type === 'get_account_status') {
                        var accountStatus = response.get_account_status;
                        if (accountStatus === 'jp_knowledge_test_pending' && passthrough === 'knowledgetest') {
                            KnowledgeTest.init();
                        } else if (accountStatus === 'jp_knowledge_test_fail') {
                            BinarySocket.send({get_settings: 1, passthrough: 'knowledgetest'});
                        } else {
                            cannotTakeKnowledgeTest();
                        }
                    } else if (type === 'get_settings') {
                        if (response.get_settings === 'knowledge_test_allowed' && passthrough === 'knowledgetest') {
                            KnowledgeTest.init();
                        } else {
                            cannotTakeKnowledgeTest();
                        }
                    } else {
                        cannotTakeKnowledgeTest();
                    }
                }
            });

            BinarySocket.send({get_account_status: 1, passthrough: 'knowledgetest'});
        }
    };
});

{'fraction_non_alphanumeric': 0.10341261633919338, 'fraction_numerical': 0.001034126163391934, 'mean_word_length': 1.4309045226130652, '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': '3391817', 'n_tokens_mistral': 503, 'n_tokens_neox': 465, 'n_words': 77}