<commit_before>
// Persistent datastore with automatic loading
var Datastore = require('nedb');
var uuid = require('uuid');

var db = new Datastore({
        filename: 'path/to/datafile',
        autoload: true,
        timestampData: true});

exports.getStudyList = function (onList) {
    db.find({}, function (err, docs) {
        
        var studyArray = [];
        
        for (var index = 0; index < docs.length; index++) {
            var doc = docs[index];
            studyArray.push(doc.study);
        }
        
        var studyList = {'studies': studyArray};
        
        onList(studyList);
    });
};

exports.createStudy = function (onCreate) {
    var doc = {
        study: uuid.v4(),
        today: new Date(),
        directory: 'dir'};

    db.insert(doc, function (err, newDoc) {
        
        //create studydir
        //init studydir
        
        var newStudy = {};
        newStudy.name = newDoc.study;
        onCreate(newStudy);
    });
};

exports.deleteStudy = function (id, onDelete) {
    
    db.remove({ study: id }, {}, function (err, numRemoved) {
        if (numRemoved == 1)
            onDelete("Delete study ( " + id + " )")
        else
            onDelete(err)
    });
};
<commit_msg>Create and remove study directories<commit_after>
// Persistent datastore with automatic loading
var Datastore = require('nedb');
var uuid = require('uuid');
var fs = require('fs');

function getUserHome() {
    return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
}

function getDataHome() {
    var dataHome = getUserHome() + '/HstWebApp';
    try {
        fs.mkdirSync(dataHome);
    } finally {
        return dataHome;
    }
}

var db = new Datastore({
        filename: getDataHome() + '/data.db',
        autoload: true,
        timestampData: true});

exports.getStudyList = function (onList) {
    db.find({}, function (err, docs) {
        
        var studyArray = [];
        
        for (var index = 0; index < docs.length; index++) {
            var doc = docs[index];
            studyArray.push(doc.study);
        }
        
        var studyList = {'studies': studyArray};
        
        onList(studyList);
    });
};

exports.createStudy = function (onCreate) {
    var id = uuid.v4();
    var studyDir = getDataHome() + '/' + id;
    fs.mkdirSync(studyDir)
    
    var doc = {
        study: id,
        today: new Date(),
        directory: studyDir};

    db.insert(doc, function (err, newDoc) {
        
        //init studydir
        
        var newStudy = {};
        newStudy.name = newDoc.study;
        onCreate(newStudy);
    });
};

exports.deleteStudy = function (id, onDelete) {
    
    db.find({ study: id }, function (err, docs) {
        var studyData = docs[0]; 
        var studyDir = studyData.directory;
        
        db.remove({ study: id }, {}, function (err, numRemoved) {
            
            fs.rmdirSync(studyDir);
            if (numRemoved == 1)
                onDelete("Delete study ( " + id + " )")
            else
                onDelete(err)
        });
    });
};

{'fraction_non_alphanumeric': 0.13916693574426864, 'fraction_numerical': 0.0029060381013884403, 'mean_word_length': 1.8738404452690167, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5590772', 'n_tokens_mistral': 968, 'n_tokens_neox': 930, 'n_words': 225}