<commit_before>var httpDownloadPrefix = 'data:text/plain;base64,';

define(["SimpleClient", "underscore", "clientCode/dropzone"], function(SimpleClient, _, Dropzone) {
    return function(questionTemplate, submissionTemplate) {
        var simpleClient = new SimpleClient.SimpleClient({questionTemplate: questionTemplate, submissionTemplate: submissionTemplate, skipRivets: true});

        // Returns the raw (base-64 encoded) file contents
        function getSubmittedFileContents(name) {
            var files = simpleClient.submittedAnswer.get('files') || [];
            console.log(files)
            var contents = null;
            _.each(files, function(file) {
                if (file.name === name) {
                    contents = file.contents;
                }
            });
            return contents;
        }

        // contents should be base-64 encoded
        function saveSubmittedFile(name, contents) {
            var files = simpleClient.submittedAnswer.get('files') || [];
            files = JSON.parse(JSON.stringify(files)); // deep clone needed to avoid changing backbone object
            var idx = _.findIndex(files, function(file) {
                if (file.name === name) {
                    return true;
                }
            });
            if (idx === -1) {
                files.push({
                    name: name,
                    contents: contents
                });
            } else {
                files[idx].contents = contents;
            }
            simpleClient.submittedAnswer.set('files', files);
        }

        // Uses the same method as Git to check if a file is binary or text:
        // If the first 8000 bytes contain a NUL character ('\0'), we consider
        // the file to be binary.
        // http://stackoverflow.com/questions/6119956/how-to-determine-if-git-handles-a-file-as-binary-or-as-text
        function isBinary(decodedFileContents) {
            var nulIdx = decodedFileContents.indexOf('\0');
            var fileLength = decodedFileContents.length;
            return nulIdx != -1 && nulIdx <= (fileLength <= 8000 ? fileLength : 8000);
        }

        function uploadStatus() {
            var $uploadStatusPanel = $('<div class="panel panel-default"></div>');
            var $uploadStatusPanelHeading = $('<div class="panel-heading">Files</div>');
            $uploadStatusPanel.append($uploadStatusPanelHeading);
            var $uploadStatus = $('<ul class="list-group"></ul>');
            var requiredFiles = simpleClient.params.get('requiredFiles');

            _.each(requiredFiles, function(file) {
                console.log(file)
                var $item = $('<li class="list-group-item"></li>');
                $uploadStatus.append($item);
                $item.append('<code>' + encodeURIComponent(file) + '</code> - ');
                var fileData = getSubmittedFileContents(file);
                if (!fileData) {
                    $item.append('not uploaded');
                } else {
                    var $preview = $('<pre><code></code></pre>');
                    try {
                        var fileContents = atob(fileData);
                        if (!isBinary(fileContents)) {
                            $preview.find('code').text(fileContents);
                        } else {
                            $preview.find('code').text('Binary file not previewed.');
                        }
                    } catch (e) {
                        console.log(e);
                        $preview.find('code').text('Unable to decode file.');
                    }
                    $preview.hide();
                    var $toggler = $('<a href="#">view</a>');
                    $toggler.on('click', function(e) {
                        $preview.toggle();
                        e.preventDefault();
                        return false;
                    });
                    $item.append($toggler);
                    $item.append($preview);
                }
            });

            $uploadStatusPanel.append($uploadStatus);

            return $uploadStatusPanel;
        }

        function initializeTemplate() {
            var $fileUpload = $('#fileUpload');
            $fileUpload.html('');

            var $dropTarget = $('<div class="dropzone"><div class="dz-message">Drop files here or click to upload.<br/><small>Only the files listed below will be accepted&mdash;others will be silently ignored.</small></div></div>');
            var $style = $('<style scoped>' +
                    '.dropzone { position: relative; min-height: 15ex; border-radius: 4px; background-color: #FAFDFF; border: 1px solid #D9EDF7; }' +
                    '.dropzone.dz-clickable { cursor: pointer; }' +
                    '.dropzone.dz-drag-hover { background-color: #D9EDF7; border-color: #AED3E5; }' +
                    '.dz-message { position: absolute; top: 50%; transform: translateY(-50%); text-align: center; width: 100%; }' +
                    '</style>'
                    );

            var requiredFiles = simpleClient.params.get('requiredFiles');

            var dropzone = $dropTarget.dropzone({
                url: '/none',
                autoProcessQueue: false,
                accept: function(file, done) {
                    if (_.contains(requiredFiles, file.name)) {
                        done();
                        return;
                    }
                    done('invalid file');
                },
                addedfile: function(file) {
                    console.log("adding file...")
                    if (!_.contains(requiredFiles, file.name)) {
                        return;
                    }
                    console.log("reading!")<commit_msg>remove console.log() from MultiFileClient<commit_after>var httpDownloadPrefix = 'data:text/plain;base64,';

define(["SimpleClient", "underscore", "clientCode/dropzone"], function(SimpleClient, _, Dropzone) {
    return function(questionTemplate, submissionTemplate) {
        var simpleClient = new SimpleClient.SimpleClient({questionTemplate: questionTemplate, submissionTemplate: submissionTemplate, skipRivets: true});

        // Returns the raw (base-64 encoded) file contents
        function getSubmittedFileContents(name) {
            var files = simpleClient.submittedAnswer.get('files') || [];
            var contents = null;
            _.each(files, function(file) {
                if (file.name === name) {
                    contents = file.contents;
                }
            });
            return contents;
        }

        // contents should be base-64 encoded
        function saveSubmittedFile(name, contents) {
            var files = simpleClient.submittedAnswer.get('files') || [];
            files = JSON.parse(JSON.stringify(files)); // deep clone needed to avoid changing backbone object
            var idx = _.findIndex(files, function(file) {
                if (file.name === name) {
                    return true;
                }
            });
            if (idx === -1) {
                files.push({
                    name: name,
                    contents: contents
                });
            } else {
                files[idx].contents = contents;
            }
            simpleClient.submittedAnswer.set('files', files);
        }

        // Uses the same method as Git to check if a file is binary or text:
        // If the first 8000 bytes contain a NUL character ('\0'), we consider
        // the file to be binary.
        // http://stackoverflow.com/questions/6119956/how-to-determine-if-git-handles-a-file-as-binary-or-as-text
        function isBinary(decodedFileContents) {
            var nulIdx = decodedFileContents.indexOf('\0');
            var fileLength = decodedFileContents.length;
            return nulIdx != -1 && nulIdx <= (fileLength <= 8000 ? fileLength : 8000);
        }

        function uploadStatus() {
            var $uploadStatusPanel = $('<div class="panel panel-default"></div>');
            var $uploadStatusPanelHeading = $('<div class="panel-heading">Files</div>');
            $uploadStatusPanel.append($uploadStatusPanelHeading);
            var $uploadStatus = $('<ul class="list-group"></ul>');
            var requiredFiles = simpleClient.params.get('requiredFiles');

            _.each(requiredFiles, function(file) {
                var $item = $('<li class="list-group-item"></li>');
                $uploadStatus.append($item);
                $item.append('<code>' + encodeURIComponent(file) + '</code> - ');
                var fileData = getSubmittedFileContents(file);
                if (!fileData) {
                    $item.append('not uploaded');
                } else {
                    var $preview = $('<pre><code></code></pre>');
                    try {
                        var fileContents = atob(fileData);
                        if (!isBinary(fileContents)) {
                            $preview.find('code').text(fileContents);
                        } else {
                            $preview.find('code').text('Binary file not previewed.');
                        }
                    } catch (e) {
                        console.log(e);
                        $preview.find('code').text('Unable to decode file.');
                    }
                    $preview.hide();
                    var $toggler = $('<a href="#">view</a>');
                    $toggler.on('click', function(e) {
                        $preview.toggle();
                        e.preventDefault();
                        return false;
                    });
                    $item.append($toggler);
                    $item.append($preview);
                }
            });

            $uploadStatusPanel.append($uploadStatus);

            return $uploadStatusPanel;
        }

        function initializeTemplate() {
            var $fileUpload = $('#fileUpload');
            $fileUpload.html('');

            var $dropTarget = $('<div class="dropzone"><div class="dz-message">Drop files here or click to upload.<br/><small>Only the files listed below will be accepted&mdash;others will be silently ignored.</small></div></div>');
            var $style = $('<style scoped>' +
                    '.dropzone { position: relative; min-height: 15ex; border-radius: 4px; background-color: #FAFDFF; border: 1px solid #D9EDF7; }' +
                    '.dropzone.dz-clickable { cursor: pointer; }' +
                    '.dropzone.dz-drag-hover { background-color: #D9EDF7; border-color: #AED3E5; }' +
                    '.dz-message { position: absolute; top: 50%; transform: translateY(-50%); text-align: center; width: 100%; }' +
                    '</style>'
                    );

            var requiredFiles = simpleClient.params.get('requiredFiles');

            var dropzone = $dropTarget.dropzone({
                url: '/none',
                autoProcessQueue: false,
                accept: function(file, done) {
                    if (_.contains(requiredFiles, file.name)) {
                        done();
                        return;
                    }
                    done('invalid file');
                },
                addedfile: function(file) {
                    if (!_.contains(requiredFiles, file.name)) {
                        return;
                    }
{'fraction_non_alphanumeric': 0.12768005600770105, 'fraction_numerical': 0.008051107027216241, 'mean_word_length': 1.5188450517963412, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1210314', 'n_tokens_mistral': 2912, 'n_tokens_neox': 2698, 'n_words': 611}