<commit_before>/*jshint node: true, -W106 */
'use strict';

/*
* Name : mapChartFlowModel.js
* Module : Lib::DataTier::mapChartFlowModel
* Location : /lib/dataTier/flow
*
* History :
* 
* Version   Date         Programmer         Description
* =========================================================
* 0.0.2     2015-05-22   <NAME>      add updateMovie
* 0.0.1     2015-05-15   <NAME>    Initial code
* =========================================================
*/
var FlowModel = require('./flowModel.js');
var Helper = require('../../helpers/functionHelper.js');

function MapChartFlowModel(params) {
	if(params===undefined || params.ID===undefined || typeof params.ID !== 'string'|| params.ID.trim() === ''){ // ID field is required
		console.log('Error: 232');
		return;
	}

	params.type = 'MapChartFlow';
	this.parent.constructor.call(this, params);

	this._latitudeKey=null;
	this._longitudeKey=null;
	this._objectKey=null;
	this._latitudeFormat='coordinates';
	this._longitudeFormat='coordinates';
	this._marker={
		type: 'shape',//shape, icon, text
		shape: 'circle',//circle, triangle, square, diamond
		//icon: null,//path
		//text: null,//string
		//color: '#000'	//HEX
	};
	this._trace={
		type: 'none',//none, line, poly
		coordinates: []
		//strokeColor: '#FFF'	//HEX
		//fillColor: '#FFF'	//HEX
	};
	this._trailLength=3;//length of trail
	this._maxItemsSaved=500; //items saved

	this.updateProperties(params);
}

MapChartFlowModel.prototype = Object.create(FlowModel.prototype);
MapChartFlowModel.prototype.constructor = MapChartFlowModel;
MapChartFlowModel.prototype.parent = FlowModel.prototype;

MapChartFlowModel.prototype.updateProperties = function(params){
	if (params!==undefined){
		var prop=this.parent.updateProperties.call(this, params);
		if(params.longitudeKey!==undefined && typeof params.longitudeKey === 'string'){
			this._longitudeKey=prop.longitudeKey=params.longitudeKey;
		}
		if(params.latitudeKey!==undefined && typeof params.latitudeKey === 'string'){
			this._latitudeKey=prop.latitudeKey=params.latitudeKey;
		}
		if(params.objectKey!==undefined && typeof params.objectKey === 'string'){
			this._objectKey=prop.objectKey=params.objectKey;
		}
		if(params.longitudeFormat!==undefined && Helper.isValidMapFormat(params.longitudeFormat)){
			this._longitudeFormat=prop.longitudeFormat=params.longitudeFormat;
		}
		if(params.latitudeFormat!==undefined && Helper.isValidMapFormat(params.latitudeFormat)){
			this._latitudeFormat=prop.latitudeFormat=params.latitudeFormat;
		}
		if(params.marker!==undefined && Helper.isValidMapMarker(params.marker)){
			this._marker=prop.marker=params.marker;
		}
		if(params.trace!==undefined && Helper.isValidTrace(params.trace)){
			this._trace=prop.trace=params.trace;
		}
		if(params.trailLength!==undefined && typeof params.trailLength==='number' && params.trailLength>=1){
			this._trailLength=prop.trailLength=params.trailLength;
		}
		if(params.maxItemsSaved!==undefined && typeof params.maxItemsSaved==='number' && params.maxItemsSaved>=0){
			this._maxItemsSaved=prop.maxItemsSaved=params.maxItemsSaved;
		}
		return prop;
	}
	return 233;
};

MapChartFlowModel.prototype.addRecord = function(record){
	if(record!==undefined && record!==null && typeof record === 'object'){
		this._records.push(record);
		var index=this._records.length-1;
		var ID=this.generateNorrisRecordID(index);
		this._records[index].norrisRecordID=ID;
		this.validateRecord(index);
		return ID;
	}
	return 133;
};

MapChartFlowModel.prototype.updateRecord = function(ID, record){
	if (record === undefined || record === null || Array.isArray(record)){
		return 131;
	}
	if (typeof ID==='string' && ID.indexOf(this._ID) !== -1) {
		var records=this._records.length;
		var i=0;
		var found=false;
		while (i<records && (!found)){
			if (this._records[i].norrisRecordID===ID){
				found=true;
			}
			else{
				i++;
			}
		}//while
		if (found){//in records[i] there is the ID	
			record.norrisRecordID=this._records[i].norrisRecordID;
			this._records[i]=record;
			this.validateRecord(i);
			return true;
		}
		//no ID in records
	}
	//invalid ID
	return 132;
};


MapChartFlowModel.prototype.updateMovie = function(params){
	if (params === undefined || params === null || !Array.isArray(params)){
		return 131;
	}
	var found=false;
	var recordsID=[];
	var i=0;
	for (var keyParam in params) {
		if(params[keyParam][this._latitudeKey] === undefined ||
			params[keyParam][this._longitudeKey] === undefined ||
			params[keyParam][this._objectKey] === undefined){
			//console.log('Invalid record : ');
			//console.dir(params[keyParam]);
		}else{
			found=false;
			for (var keyRecord in this._records) {
				console.log(params[keyParam][this._objectKey]+' '+this._records[keyRecord][this._objectKey]);
				if(params[keyParam][this._objectKey]===this._records[keyRecord][this._objectKey]){
					found=true;
					params[keyParam].norrisRecordID=this._records[keyRecord].norrisRecordID;
					recordsID.push(this._records[keyRecord].norrisRecordID);
					break;
				}
			}
			if(!found){
				params[keyParam].norrisRecordID=this.generateNorrisRecordID(i);
				recordsID.push(params[keyParam].norrisRecordID);
				//console.log('Nuovo record '+params[keyParam].norrisRecordID);
			}
		}
		i++;
	}
	this._records=params;<commit_msg>try to delete logs<commit_after>/*jshint node: true, -W106 */
'use strict';

/*
* Name : mapChartFlowModel.js
* Module : Lib::DataTier::mapChartFlowModel
* Location : /lib/dataTier/flow
*
* History :
* 
* Version   Date         Programmer         Description
* =========================================================
* 0.0.2     2015-05-22   <NAME>      add updateMovie
* 0.0.1     2015-05-15   <NAME>    Initial code
* =========================================================
*/
var FlowModel = require('./flowModel.js');
var Helper = require('../../helpers/functionHelper.js');

function MapChartFlowModel(params) {
	if(params===undefined || params.ID===undefined || typeof params.ID !== 'string'|| params.ID.trim() === ''){ // ID field is required
		console.log('Error: 232');
		return;
	}

	params.type = 'MapChartFlow';
	this.parent.constructor.call(this, params);

	this._latitudeKey=null;
	this._longitudeKey=null;
	this._objectKey=null;
	this._latitudeFormat='coordinates';
	this._longitudeFormat='coordinates';
	this._marker={
		type: 'shape',//shape, icon, text
		shape: 'circle',//circle, triangle, square, diamond
		//icon: null,//path
		//text: null,//string
		//color: '#000'	//HEX
	};
	this._trace={
		type: 'none',//none, line, poly
		coordinates: []
		//strokeColor: '#FFF'	//HEX
		//fillColor: '#FFF'	//HEX
	};
	this._trailLength=3;//length of trail
	this._maxItemsSaved=500; //items saved

	this.updateProperties(params);
}

MapChartFlowModel.prototype = Object.create(FlowModel.prototype);
MapChartFlowModel.prototype.constructor = MapChartFlowModel;
MapChartFlowModel.prototype.parent = FlowModel.prototype;

MapChartFlowModel.prototype.updateProperties = function(params){
	if (params!==undefined){
		var prop=this.parent.updateProperties.call(this, params);
		if(params.longitudeKey!==undefined && typeof params.longitudeKey === 'string'){
			this._longitudeKey=prop.longitudeKey=params.longitudeKey;
		}
		if(params.latitudeKey!==undefined && typeof params.latitudeKey === 'string'){
			this._latitudeKey=prop.latitudeKey=params.latitudeKey;
		}
		if(params.objectKey!==undefined && typeof params.objectKey === 'string'){
			this._objectKey=prop.objectKey=params.objectKey;
		}
		if(params.longitudeFormat!==undefined && Helper.isValidMapFormat(params.longitudeFormat)){
			this._longitudeFormat=prop.longitudeFormat=params.longitudeFormat;
		}
		if(params.latitudeFormat!==undefined && Helper.isValidMapFormat(params.latitudeFormat)){
			this._latitudeFormat=prop.latitudeFormat=params.latitudeFormat;
		}
		if(params.marker!==undefined && Helper.isValidMapMarker(params.marker)){
			this._marker=prop.marker=params.marker;
		}
		if(params.trace!==undefined && Helper.isValidTrace(params.trace)){
			this._trace=prop.trace=params.trace;
		}
		if(params.trailLength!==undefined && typeof params.trailLength==='number' && params.trailLength>=1){
			this._trailLength=prop.trailLength=params.trailLength;
		}
		if(params.maxItemsSaved!==undefined && typeof params.maxItemsSaved==='number' && params.maxItemsSaved>=0){
			this._maxItemsSaved=prop.maxItemsSaved=params.maxItemsSaved;
		}
		return prop;
	}
	return 233;
};

MapChartFlowModel.prototype.addRecord = function(record){
	if(record!==undefined && record!==null && typeof record === 'object'){
		this._records.push(record);
		var index=this._records.length-1;
		var ID=this.generateNorrisRecordID(index);
		this._records[index].norrisRecordID=ID;
		this.validateRecord(index);
		return ID;
	}
	return 133;
};

MapChartFlowModel.prototype.updateRecord = function(ID, record){
	if (record === undefined || record === null || Array.isArray(record)){
		return 131;
	}
	if (typeof ID==='string' && ID.indexOf(this._ID) !== -1) {
		var records=this._records.length;
		var i=0;
		var found=false;
		while (i<records && (!found)){
			if (this._records[i].norrisRecordID===ID){
				found=true;
			}
			else{
				i++;
			}
		}//while
		if (found){//in records[i] there is the ID	
			record.norrisRecordID=this._records[i].norrisRecordID;
			this._records[i]=record;
			this.validateRecord(i);
			return true;
		}
		//no ID in records
	}
	//invalid ID
	return 132;
};


MapChartFlowModel.prototype.updateMovie = function(params){
	if (params === undefined || params === null || !Array.isArray(params)){
		return 131;
	}
	var found=false;
	var recordsID=[];
	var i=0;
	for (var keyParam in params) {
		if(params[keyParam][this._latitudeKey] === undefined ||
			params[keyParam][this._longitudeKey] === undefined ||
			params[keyParam][this._objectKey] === undefined){
			//console.log('Invalid record : ');
			//console.dir(params[keyParam]);
			console.log();
		}else{
			found=false;
			for (var keyRecord in this._records) {
				//console.log(params[keyParam][this._objectKey]+' '+this._records[keyRecord][this._objectKey]);
				if(params[keyParam][this._objectKey]===this._records[keyRecord][this._objectKey]){
					found=true;
					params[keyParam].norrisRecordID=this._records[keyRecord].norrisRecordID;
					recordsID.push(this._records[keyRecord].norrisRecordID);
					break;
				}
			}
			if(!found){
				params[keyParam].norrisRecordID=this.generateNorrisRecordID(i);
				recordsID.push(params[keyParam].norrisRecordID);
				//console.log('Nuovo record '+params[keyParam].norrisRecordID);
			}
		}
		i++;
	}
	this._records=params;
{'fraction_non_alphanumeric': 0.1804624823029731, 'fraction_numerical': 0.010571024067956583, 'mean_word_length': 4.831590533847001, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '510581', 'n_tokens_mistral': 3843, 'n_tokens_neox': 3461, 'n_words': 539}