<commit_before>/*
** Module: node-aireas
**
**
**
**
*/

"use strict"; // This is for your code to comply with the ECMAScript 5 standard.

var main_module = 'node_aireas';
var moduleScapeAireasPath = require('path').resolve(__dirname, 'node_modules/scape-aireas/../..');
var apriConfig 	= require(moduleScapeAireasPath + '/apri-config');
apriConfig.init(main_module);

// **********************************************************************************

// add module specific requires
var request 		= require('request');
var express 		= require('express');
var cookieParser 	= require('cookie-parser');
var session 		= require('express-session');
var uid 			= require('uid-safe');
//var bodyParser 		= require('connect-busboy');
var fs 				= require('fs');
var _systemCode = apriConfig.getSystemCode();

var apriAireasGetPg 	= require('./node-aireas-get-pg');
apriAireasGetPg.init({
		systemFolderParent: apriConfig.getSystemFolderParent(),
		configParameter: apriConfig.getConfigParameter(),
		systemCode: apriConfig.getSystemCode()
	});
	

var app = express();


var sess = {
  	  secret: 'keyboscapelard cat'
  	, resave:true
	, saveUninitialized:true
  	, cookie: {
	// maxAge: 60000 
	}
}

if (app.get('env') === 'production') {
  	app.set('trust proxy', 1) // trust first proxy (app.enable('trust proxy');)
  	sess.cookie.secure = true // serve secure cookies
}

app.use(cookieParser());
app.use(session(sess));

app.use(function(req, res, next) {
//	console.log('Check for session info');
	if (req.session) {
  		var _sessionInfo = req.session;
		console.log('Session info found '+'req.cookies: ' + req.cookies['connect.sid'] + ' session.views ' + _sessionInfo.views);

  		if (_sessionInfo.views) {
			_sessionInfo.views++;
  		} else {
			_sessionInfo.views = 1;
			if(typeof req.cookies['connect.sid'] !== 'undefined'){
        		console.log('req.cookies: ' + req.cookies['connect.sid']);
    		}
			console.log('Session info init '+'req.session: ' + JSON.stringify(req.session) );
			console.log('Session info init '+'req.cookies: ' + JSON.stringify(req.cookies) +' ' + req.cookies['connect.sid'] + ' session.views ' + _sessionInfo.views);
  		}
		res.cookie('reqcount', _sessionInfo.views, { expires: new Date(Date.now() + 900000), httpOnly: true });
  	}

	next();
});


// **********************************************************************************


app.all('/*', function(req, res, next) {
  console.log("app.all/: " + req.url + " ; systemCode: " + _systemCode );
  next();
});



app.get('/'+_systemCode+'/data/aireas/:getFunction/:airbox', function(req, res) {
  console.log("data request: " + req.url );
  if (	req.params.getFunction == 'getAllMeasures' 		|| 
  		req.params.getFunction == 'getLastWeekMeasures') {
		apriAireasGetPg.getMeasures({airbox: req.params.airbox, getFunction: req.params.getFunction }, function(err, result) {
			res.contentType('application/json');
 			res.send(result.rows);
		});
		return;
  }
  
  if (	req.params.getFunction == 'getMeasureStatisticsStddev' || 
  		req.params.getFunction == 'getMeasureStatisticsAvg' ) {
		apriAireasGetPg.getMeasureStatistics({ getFunction: req.params.getFunction }, function(err, result) {
			var _outRecords = [];
			var _result = result.rows; 
			for (var i=0;i<_result.length;i++) {
				var outRecord = {};
				outRecord.geometry = JSON.parse(_result[i].geom);
				outRecord.type = 'Feature';

				outRecord.properties = {};

				outRecord.properties.pm_all_statistic 		= parseFloat(_result[i].pm_all_statistic);

				_outRecords.push(outRecord);<commit_msg>update allow<commit_after>/*
** Module: node-aireas
**
**
**
**
*/

"use strict"; // This is for your code to comply with the ECMAScript 5 standard.

var main_module = 'node_aireas';
var moduleScapeAireasPath = require('path').resolve(__dirname, 'node_modules/scape-aireas/../..');
var apriConfig 	= require(moduleScapeAireasPath + '/apri-config');
apriConfig.init(main_module);

// **********************************************************************************

// add module specific requires
var request 		= require('request');
var express 		= require('express');
var cookieParser 	= require('cookie-parser');
var session 		= require('express-session');
var uid 			= require('uid-safe');
//var bodyParser 		= require('connect-busboy');
var fs 				= require('fs');
var _systemCode = apriConfig.getSystemCode();

var apriAireasGetPg 	= require('./node-aireas-get-pg');
apriAireasGetPg.init({
		systemFolderParent: apriConfig.getSystemFolderParent(),
		configParameter: apriConfig.getConfigParameter(),
		systemCode: apriConfig.getSystemCode()
	});
	

var app = express();


var sess = {
  	  secret: 'keyboscapelard cat'
  	, resave:true
	, saveUninitialized:true
  	, cookie: {
	// maxAge: 60000 
	}
}

if (app.get('env') === 'production') {
  	app.set('trust proxy', 1) // trust first proxy (app.enable('trust proxy');)
  	sess.cookie.secure = true // serve secure cookies
}

app.use(cookieParser());
app.use(session(sess));

app.use(function(req, res, next) {
//	console.log('Check for session info');
	if (req.session) {
  		var _sessionInfo = req.session;
		console.log('Session info found '+'req.cookies: ' + req.cookies['connect.sid'] + ' session.views ' + _sessionInfo.views);

  		if (_sessionInfo.views) {
			_sessionInfo.views++;
  		} else {
			_sessionInfo.views = 1;
			if(typeof req.cookies['connect.sid'] !== 'undefined'){
        		console.log('req.cookies: ' + req.cookies['connect.sid']);
    		}
			console.log('Session info init '+'req.session: ' + JSON.stringify(req.session) );
			console.log('Session info init '+'req.cookies: ' + JSON.stringify(req.cookies) +' ' + req.cookies['connect.sid'] + ' session.views ' + _sessionInfo.views);
  		}
		res.cookie('reqcount', _sessionInfo.views, { expires: new Date(Date.now() + 900000), httpOnly: true });
  	}

	next();
});


// **********************************************************************************


app.all('/*', function(req, res, next) {
  	console.log("app.all/: " + req.url + " ; systemCode: " + _systemCode );
	res.header("Access-Control-Allow-Origin", "*");
	res.header("Access-Control-Allow-Headers", "X-Requested-With");
	next();
});



app.get('/'+_systemCode+'/data/aireas/:getFunction/:airbox', function(req, res) {
  console.log("data request: " + req.url );
  if (	req.params.getFunction == 'getAllMeasures' 		|| 
  		req.params.getFunction == 'getLastWeekMeasures') {
		apriAireasGetPg.getMeasures({airbox: req.params.airbox, getFunction: req.params.getFunction }, function(err, result) {
			res.contentType('application/json');
 			res.send(result.rows);
		});
		return;
  }
  
  if (	req.params.getFunction == 'getMeasureStatisticsStddev' || 
  		req.params.getFunction == 'getMeasureStatisticsAvg' ) {
		apriAireasGetPg.getMeasureStatistics({ getFunction: req.params.getFunction }, function(err, result) {
			var _outRecords = [];
			var _result = result.rows; 
			for (var i=0;i<_result.length;i++) {
				var outRecord = {};
				outRecord.geometry = JSON.parse(_result[i].geom);
				outRecord.type = 'Feature';

				outRecord.properties = {};

				outRecord.properties.pm_all_statistic 		= parseFloat(_result[i].pm_all_statistic);

				_outRecords.push(outRecord);
{'fraction_non_alphanumeric': 0.20996539792387542, 'fraction_numerical': 0.004152249134948097, 'mean_word_length': 4.36053412462908, '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': '6561401', 'n_tokens_mistral': 2579, 'n_tokens_neox': 2394, 'n_words': 417}