<commit_before>import async     from 'async';
import scitran   from './scitran';
import crn       from './crn';
import userStore from '../user/user.store';

/**
 * BIDS
 *
 * A library for interactions with the
 * scitran service through BIDS concepts.
 */
export default  {

// Read -----------------------------------------------------------------------------------

    /**
     * Filter Sessions
     *
     * Takes a list of scitran sessions and a subjectID
     * and calls back with a list of BIDS sessions in
     * that subject.
     */
    filterSessions (scitranSessions, subjectId, callback) {
        let sessions = [];
        async.each(scitranSessions, (session, cb) => {
            if (session.subject.code === subjectId) {
                session.children = session.files;
                session.name = session.label;
                sessions.push(session);
                cb();
            } else {
                cb();
            }
        }, () => {
            sessions.sort((a, b) => {
                let aLabel = a.label.toLowerCase();
                let bLabel = b.label.toLowerCase();
                if (aLabel < bLabel) {return -1;}
                else if (aLabel > bLabel) {return 1;}
                else {return 0;}
            });
            callback(sessions);
        });
    },

    /**
     * Get Modalities
     *
     * Get all BIDS modalidalities for a session.
     */
    getModalities: scitran.getAcquisitions,

    /**
     * Get Datasets
     *
     * Returns a list of datasets including any
     * derived statuses and notes on each. Only returns
     * the top level 'project' container. Takes an optional
     * boolean as second argument to specifiy if request
     * is made with authentication. Defaults to true.<commit_msg>Added sorting to modality level<commit_after>import async     from 'async';
import scitran   from './scitran';
import crn       from './crn';
import userStore from '../user/user.store';

/**
 * BIDS
 *
 * A library for interactions with the
 * scitran service through BIDS concepts.
 */
export default  {

// Read -----------------------------------------------------------------------------------

    /**
     * Filter Sessions
     *
     * Takes a list of scitran sessions and a subjectID
     * and calls back with a list of BIDS sessions in
     * that subject.
     */
    filterSessions (scitranSessions, subjectId, callback) {
        let sessions = [];
        async.each(scitranSessions, (session, cb) => {
            if (session.subject.code === subjectId) {
                session.children = session.files;
                session.name = session.label;
                sessions.push(session);
                cb();
            } else {
                cb();
            }
        }, () => {
            sessions.sort((a, b) => {
                let aLabel = a.label.toLowerCase();
                let bLabel = b.label.toLowerCase();
                if (aLabel < bLabel) {return -1;}
                else if (aLabel > bLabel) {return 1;}
                else {return 0;}
            });
            callback(sessions);
        });
    },

    /**
     * Get Modalities
     *
     * Get all BIDS modalities for a session.
     */
    getModalities(sessionId, callback) {
        scitran.getAcquisitions(sessionId, (modalities) => {
            modalities.sort((a, b) => {
                let aLabel = a.label.toLowerCase();
                let bLabel = b.label.toLowerCase();
                if (aLabel < bLabel) {return -1;}
                else if (aLabel > bLabel) {return 1;}
                else {return 0;}
            });
            callback(modalities);
        });
    },

    /**
     * Get Datasets
     *
     * Returns a list of datasets including any
     * derived statuses and notes on each. Only returns
     * the top level 'project' container. Takes an optional
     * boolean as second argument to specifiy if request
     * is made with authentication. Defaults to true.
{'fraction_non_alphanumeric': 0.1443609022556391, 'fraction_numerical': 0.002255639097744361, 'mean_word_length': 1.457512315270936, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 14, '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': '1650834', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1036, 'n_words': 324}