<commit_before>console.log("START\t: loading firenodejs...");
var express = require('express');
var app = express();
var fs = require('fs');
var path = require('path');
var bodyParser = require('body-parser');
var parser = bodyParser.json();
var __appdir = path.join(__dirname, "../www");
var path_no_image = path.join(__appdir, 'img/no-image.jpg');

var fsd = require("./firestep-driver");
var firestep = new fsd.FireStepDriver();
var Camera = require("./camera").Camera;
var camera = new Camera();
var Images = require("./images").Images;
var images = new Images(firestep, camera, {pathNoImage:path_no_image});
var FireSight = require("./firesight").FireSight;
var firesight = new FireSight(images);
var Measure = require("./measure").Measure;
var measure = new Measure(images, firesight);
var firenodejsType = new require("./firenodejs").firenodejs;
var firenodejs = new firenodejsType(images, firesight, measure);

express.static.mime.define({
    'application/json': ['firestep']
});

app.use(parser);

app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    next();
});


///////////// REST /firenodejs
var dirs = ['bootstrap', 'html', 'img', 'css', 'js', 'lib', 'partials'];
for (var i = 0; i < dirs.length; i++) {
    var urlpath = '/firenodejs/' + dirs[i];
    var filepath = path.join(__appdir, dirs[i]);
    app.use(urlpath, express.static(filepath));
    console.log("HTTP\t: firenodejs mapping urlpath:" + urlpath + " to:" + filepath);
}

app.get('/firenodejs/index.html', function(req, res) {
    res.sendFile(path.join(__appdir, 'html/index.html'));
});
app.get('/', function(req, res) {
    res.redirect('/firenodejs/index.html');
});
app.get('/index.html', function(req, res) {
    res.redirect('/firenodejs/index.html');
});
app.get('/firenodejs/models', function(req, res) {
    var data = JSON.stringify(firenodejs.syncModels());
    console.log("HTTP:\t: GET " + req.url + " => " + data);
    res.send(data);
});
app.post('/firenodejs/models', function(req, res, next) {
    console.log("HTTP\t: POST " + req.url + " " + JSON.stringify(req.body));
    var msStart = millis();
    if (firenodejs.isAvailable()) {
        var models = firenodejs.syncModels(req.body);
        res.send(models);
        var msElapsed = millis() - msStart;
        console.log("HTTP\t: POST " + req.url + " " + Math.round(msElapsed) + 'ms => ' + JSON.stringify(models));
    } else {
        var msElapsed = millis() - msStart;
        console.log("HTTP\t: POST " + req.url + " " + Math.round(msElapsed) + 'ms => HTTP503');
        res.status(503).send({
            "error": "firenodejs unavailable"
        });
    }
});
app.post('/firestep/test', function(req, res, next) {
    console.log("HTTP\t: POST " + req.url + " " + JSON.stringify(req.body));
    firestep.test(res, req.body);
});

function millis() {
    var hrt = process.hrtime();
    var ms = hrt[0] * 1000 + hrt[1] / 1000000;
    return ms;
}

//////////// REST /camera
function restCapture(req, res, name) {
    var msStart = millis();
    camera.capture(name, function(path) {
        var msElapsed = millis() - msStart;
        console.log('HTTP\t: GET ' + req.url + ' => ' + path + ' ' +
            Math.round(msElapsed) + 'ms');
        res.sendFile(path);
    }, function(error) {
        console.log('HTTP\t: GET ' + req.url + ' => ' + error);
        res.status(404).sendFile(path_no_image);
    });
}
app.get('/camera/image.jpg', function(req, res) {
    restCapture(req, res);
});
app.get('/camera/*/image.jpg', function(req, res) {
    var tokens = req.url.split("/");
    restCapture(req, res, tokens[2]);
});
app.get('/camera/model', function(req, res) {
    res.send(camera.syncModel());
});
app.get('/camera/*/model', function(req, res) {
    var tokens = req.url.split("/");
    res.send(camera.syncModel(tokens[2]));
});

//////////// REST /firestep
app.get('/firestep/model', function(req, res) {
    var msStart = millis();
    var model = firestep.syncModel();
    var msElapsed = millis() - msStart;
    console.log('HTTP\t: GET ' + req.url +
        ' => ' + JSON.stringify(model) + ' ' +
        Math.round(msElapsed) + 'ms');
    res.send(model);
});
app.get('/firestep/location', function(req, res) {
    res.send(firestep.getLocation());
});
app.get('/firestep/history', function(req, res) {
    res.send(firestep.history());
});
post_firestep = function(req, res, next) {
    console.log("HTTP\t: POST " + req.url + " " + JSON.stringify(req.body));
    var msStart = millis();
    if (firestep.model.available) {
        firestep.send(req.body, function(data) {
            res.send(data);
            var msElapsed = millis() - msStart;
            console.log("HTTP\t: POST " + req.url + " " + Math.round(msElapsed) + 'ms => ' + data);
        });<commit_msg>moveLPP<commit_after>console.log("START\t: loading firenodejs...");
var express = require('express');
var app = express();
var fs = require('fs');
var path = require('path');
var bodyParser = require('body-parser');
var parser = bodyParser.json();
var __appdir = path.join(__dirname, "../www");
var path_no_image = path.join(__appdir, 'img/no-image.jpg');

var fsd = require("./firestep-driver");
var firestep = new fsd.FireStepDriver();
var Camera = require("./camera").Camera;
var camera = new Camera();
var Images = require("./images").Images;
var images = new Images(firestep, camera, {pathNoImage:path_no_image});
var FireSight = require("./firesight").FireSight;
var firesight = new FireSight(images);
var Measure = require("./measure").Measure;
var measure = new Measure(images, firesight);
var firenodejsType = new require("./firenodejs").firenodejs;
var firenodejs = new firenodejsType(images, firesight, measure);

express.static.mime.define({
    'application/json': ['firestep']
});

app.use(parser);

app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    next();
});


///////////// REST /firenodejs
var dirs = ['bootstrap', 'html', 'img', 'css', 'js', 'lib', 'partials'];
for (var i = 0; i < dirs.length; i++) {
    var urlpath = '/firenodejs/' + dirs[i];
    var filepath = path.join(__appdir, dirs[i]);
    app.use(urlpath, express.static(filepath));
    console.log("HTTP\t: firenodejs mapping urlpath:" + urlpath + " to:" + filepath);
}

app.get('/firenodejs/index.html', function(req, res) {
    res.sendFile(path.join(__appdir, 'html/index.html'));
});
app.get('/', function(req, res) {
    res.redirect('/firenodejs/index.html');
});
app.get('/index.html', function(req, res) {
    res.redirect('/firenodejs/index.html');
});
app.get('/firenodejs/models', function(req, res) {
    var data = JSON.stringify(firenodejs.syncModels());
    console.log("HTTP:\t: GET " + req.url + " => " + data);
    res.send(data);
});
app.post('/firenodejs/models', function(req, res, next) {
    console.log("HTTP\t: POST " + req.url + " " + JSON.stringify(req.body));
    var msStart = millis();
    if (firenodejs.isAvailable()) {
        var models = firenodejs.syncModels(req.body);
        res.send(models);
        var msElapsed = millis() - msStart;
        console.log("HTTP\t: POST " + req.url + " " + Math.round(msElapsed) + 'ms => ' + JSON.stringify(models));
    } else {
        var msElapsed = millis() - msStart;
        console.log("HTTP\t: POST " + req.url + " " + Math.round(msElapsed) + 'ms => HTTP503');
        res.status(503).send({
            "error": "firenodejs unavailable"
        });
    }
});
app.post('/firestep/test', function(req, res, next) {
    console.log("HTTP\t: POST " + req.url + " " + JSON.stringify(req.body));
    firestep.test(res, req.body);
});

function millis() {
    var hrt = process.hrtime();
    var ms = hrt[0] * 1000 + hrt[1] / 1000000;
    return ms;
}

//////////// REST /camera
function restCapture(req, res, name) {
    var msStart = millis();
    camera.capture(name, function(path) {
        var msElapsed = millis() - msStart;
        console.log('HTTP\t: GET ' + req.url + ' => ' + path + ' ' +
            Math.round(msElapsed) + 'ms');
        res.sendFile(path);
    }, function(error) {
        console.log('HTTP\t: GET ' + req.url + ' => ' + error);
        res.status(404).sendFile(path_no_image);
    });
}
app.get('/camera/image.jpg', function(req, res) {
    restCapture(req, res);
});
app.get('/camera/*/image.jpg', function(req, res) {
    var tokens = req.url.split("/");
    restCapture(req, res, tokens[2]);
});
app.get('/camera/model', function(req, res) {
    res.send(camera.syncModel());
});
app.get('/camera/*/model', function(req, res) {
    var tokens = req.url.split("/");
    res.send(camera.syncModel(tokens[2]));
});

//////////// REST /firestep
app.get('/firestep/model', function(req, res) {
    var msStart = millis();
    var model = firestep.syncModel();
    var msElapsed = millis() - msStart;
    console.log('HTTP\t: GET ' + req.url +
        ' => ' + JSON.stringify(model) + ' ' +
        Math.round(msElapsed) + 'ms');
    res.send(model);
});
app.get('/firestep/location', function(req, res) {
    res.send(firestep.getLocation());
});
app.get('/firestep/history', function(req, res) {
    res.send(firestep.history());
});
post_firestep = function(req, res, next) {
    console.log("HTTP\t: POST " + req.url + " " + JSON.stringify(req.body));
    var msStart = millis();
    if (firestep.model.available) {
        firestep.send(req.body, function(data) {
            res.send(data);
            var msElapsed = millis() - msStart;
            console.log("HTTP\t: POST " + req.url + " " + 
                Math.round(msElapsed) + 'ms => ' + JSON.stringify(data));
        });
{'fraction_non_alphanumeric': 0.2061929662667897, 'fraction_numerical': 0.005126627704296114, 'mean_word_length': 3.2687089715536106, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7076104', 'n_tokens_mistral': 3353, 'n_tokens_neox': 3322, 'n_words': 644}