<commit_before>var express = require('express');
var path = require('path');
var dotenv = require('dotenv');
var fs = require('fs');
var turf = require('turf');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var expressValidator = require('express-validator');
var HttpStatus = require('http-status-codes');
var lineReader = require('line-reader');
var uuid = require('node-uuid');
var nosql = require('nosql');

var imageTypes = {
    'Landsat': 2,
    'Sentinel': 4
};

var expressLogFile = fs.createWriteStream(__dirname + '/express.log', {
    flags: 'a'
});

var app = express();
app.use(morgan('combined', {
    stream: expressLogFile
}));
var jsonParser = bodyParser.json();
app.use(expressValidator());
app.disable('x-powered-by');
dotenv.load();

var port = process.env.PORT || 3000;
var host = process.env.LOCALHOST || 'localhost';
console.log('host: ' + process.env.localhost);

var dbObservations=nosql.load('./db/ew_observations.nosql');
dbObservations.description('Earthwatchers observations.');

var router = express.Router();

router.get('/', function (req, res) {
    // todo: return root document
    res.json({
        message: 'Earthwatchers serverside'
    });
});

router.get('/version', function (req, res) {
    res.json({
        message: 'Version 0.2'
    });
});

function nocache(req, res, next) {
  res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
  res.header('Expires', '-1');
  res.header('Pragma', 'no-cache');
  next();
}

router.get('/observations/:project/:geohexcode/:username', nocache, function (req, res) {
    // sampleurl : observations/Borneo/PO2632/bert
    var project = req.params.project;
    var geohexcode = req.params.geohexcode;
    var username = req.params.username;
    console.log('request observations for project: ' + project + ', geohexcode:' + geohexcode + ', username: ' + username );

    // read observations from file
    // dbObservations
    res.status(HttpStatus.OK).send();
    // get stats for the given hexagon
});

// spatial select the stalliteimages that intersect with client envelope
// example request:
// /satelliteimages?bbox=111.68,0.14,111.69,0.15&imagetype=Landsat
router.get('/satelliteimages', function (req, res) {
    var bboxPar = req.query.bbox;
    var imageType = req.query.imagetype;
    if (bboxPar !== null || imageType !== null) {
        var imageTypeNr = imageTypes[imageType];

        var bbox = bboxPar.split(',');<commit_msg>added service for retrieving observations per project/hexagon/user<commit_after>var express = require('express');
var path = require('path');
var dotenv = require('dotenv');
var fs = require('fs');
var turf = require('turf');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var expressValidator = require('express-validator');
var HttpStatus = require('http-status-codes');
var lineReader = require('line-reader');
var uuid = require('node-uuid');
var nosql = require('nosql');

var imageTypes = {
    'Landsat': 2,
    'Sentinel': 4
};

var expressLogFile = fs.createWriteStream(__dirname + '/express.log', {
    flags: 'a'
});

var app = express();
app.use(morgan('combined', {
    stream: expressLogFile
}));
var jsonParser = bodyParser.json();
app.use(expressValidator());
app.disable('x-powered-by');
dotenv.load();

var port = process.env.PORT || 3000;
var host = process.env.LOCALHOST || 'localhost';
console.log('host: ' + process.env.localhost);

var dbObservations=nosql.load('./db/ew_observations.nosql');
dbObservations.description('Earthwatchers observations.');

var router = express.Router();

router.get('/', function (req, res) {
    // todo: return root document
    res.json({
        message: 'Earthwatchers serverside'
    });
});

router.get('/version', function (req, res) {
    res.json({
        message: 'Version 0.2'
    });
});

function nocache(req, res, next) {
  res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
  res.header('Expires', '-1');
  res.header('Pragma', 'no-cache');
  next();
}

router.get('/observations/:project/:geohexcode/:username', nocache, function (req, res) {
    // sampleurl : observations/Borneo/PO2632/bert
    var project = req.params.project;
    var geohexcode = req.params.geohexcode;
    var username = req.params.username;
    console.log('request observations for project: ' + project + ', geohexcode:' + geohexcode + ', username: ' + username );

    dbObservations.all(function(doc) {
        return (doc.project === project && doc.geohex === geohexcode && doc.user === username);
    }, function(error,selected){
        res.status(HttpStatus.OK).send(selected);
    });
});

// spatial select the stalliteimages that intersect with client envelope
// example request:
// /satelliteimages?bbox=111.68,0.14,111.69,0.15&imagetype=Landsat
router.get('/satelliteimages', function (req, res) {
    var bboxPar = req.query.bbox;
    var imageType = req.query.imagetype;
    if (bboxPar !== null || imageType !== null) {
        var imageTypeNr = imageTypes[imageType];

        var bbox = bboxPar.split(',');
{'fraction_non_alphanumeric': 0.17003333987056285, 'fraction_numerical': 0.011374779368503628, 'mean_word_length': 4.182926829268292, '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': '2678060', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1588, 'n_words': 365}