<commit_before>const ERR = require('async-stacktrace');
const AWS = require('aws-sdk');
const fs = require('fs-extra');

const config = require('./config');
const logger = require('./logger');
const sqldb = require('./sqldb');
const sqlLoader = require('./sql-loader');
const externalGradingSocket = require('./external-grading-socket');
const ExternalGraderEC2 = require('./externalGraderEC2');
const ExternalGraderBatch = require('./externalGraderBatch');
const ExternalGraderLocal = require('./externalGraderLocal');

const sql = sqlLoader.loadSqlEquiv(__filename);

module.exports.init = function(assessment, callback) {
    module.exports.assessment = assessment;
    if (config.externalGradingUseAws) {
        // So, this is terrible, but AWS will look relative to the Node working
        // directory, not the current directory. So aws-config.json should be
        // in the project root.
        if (fs.existsSync('./aws-config.json')) {
            logger.info('Loading AWS credentials for external grading.');
            AWS.config.loadFromPath('./aws-config.json');
        } else {
            logger.info('Missing \'aws-config.json\' in project root; this should only matter for local development.');
            AWS.config.update({region: 'us-east-2'});
        }
        if (config.externalGradingUseBatch) {
            module.exports.grader = new ExternalGraderBatch();
        } else {
            module.exports.grader = new ExternalGraderEC2();
        }
        callback(null);
    } else {
        // local dev mode
        logger.info('Not loading AWS credentials; external grader running locally.');
        module.exports.grader = new ExternalGraderLocal();
        callback(null);
    }
};

module.exports.sendToGradingQueue = function(grading_job, submission, variant, question, course) {
    if (!question.external_grading_enabled) {
        logger.info('External grading disabled for job id: ' + grading_job.id);

        // Make the grade 0
        let ret = {
            gradingId: grading_job.id,
            grading: {
                score: 0,
                feedback: {<commit_msg>Use us-east-1 when running external grading with batch<commit_after>const ERR = require('async-stacktrace');
const AWS = require('aws-sdk');
const fs = require('fs-extra');

const config = require('./config');
const logger = require('./logger');
const sqldb = require('./sqldb');
const sqlLoader = require('./sql-loader');
const externalGradingSocket = require('./external-grading-socket');
const ExternalGraderEC2 = require('./externalGraderEC2');
const ExternalGraderBatch = require('./externalGraderBatch');
const ExternalGraderLocal = require('./externalGraderLocal');

const sql = sqlLoader.loadSqlEquiv(__filename);

module.exports.init = function(assessment, callback) {
    module.exports.assessment = assessment;
    if (config.externalGradingUseAws) {
        // So, this is terrible, but AWS will look relative to the Node working
        // directory, not the current directory. So aws-config.json should be
        // in the project root.
        if (fs.existsSync('./aws-config.json')) {
            logger.info('Loading AWS credentials for external grading.');
            AWS.config.loadFromPath('./aws-config.json');
        } else {
            logger.info('Missing \'aws-config.json\' in project root; this should only matter for local development.');
        }
        if (config.externalGradingUseBatch) {
            AWS.config.update({region: 'us-east-1'});
            module.exports.grader = new ExternalGraderBatch();
        } else {
            AWS.config.update({region: 'us-east-2'});
            module.exports.grader = new ExternalGraderEC2();
        }
        callback(null);
    } else {
        // local dev mode
        logger.info('Not loading AWS credentials; external grader running locally.');
        module.exports.grader = new ExternalGraderLocal();
        callback(null);
    }
};

module.exports.sendToGradingQueue = function(grading_job, submission, variant, question, course) {
    if (!question.external_grading_enabled) {
        logger.info('External grading disabled for job id: ' + grading_job.id);

        // Make the grade 0
        let ret = {
            gradingId: grading_job.id,
            grading: {
                score: 0,
                feedback: {
{'fraction_non_alphanumeric': 0.12583544595528923, 'fraction_numerical': 0.0032265498962894676, 'mean_word_length': 2.7870855148342057, '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': '6679550', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1146, 'n_words': 301}