<commit_before>/**
*
*	STREAM: median
*
*
*
*	DESCRIPTION:
*		- 
*
*
*	API:
*		- 
*
*
*	NOTES:
*		[1] 
*
*
*	TODO:
*		[1] 
*
*
*	HISTORY:
*		- 2014/05/23: Created. [AReines].
*
*
*	DEPENDENCIES:
*		[1] 
*
*
*	LICENSE:
*		MIT
*
*	Copyright (c) 2014. <NAME>.
*
*
*	AUTHOR:
*		<NAME>. <EMAIL>. 2014.
*
*/

(function() {
	'use strict';

	// MODULES //

	var // Event stream module:
		eventStream = require( 'event-stream' ),

		// Stream transform:
		transformer = require( './../../transform' );


	// FUNCTIONS //

	/**
	* FUNCTIONS: median( vector )
	*	Computes the median value of a 1d dataset array.
	*
	* @private
	* @param {array} vector - 1d array
	* @returns {number} median value
	*/
	function median( vector ) {
		var id, vec;

		// Create a copy of the input vector:
		vec = vector.slice();

		// Sort the input vector:
		vec.sort( function ( a, b ) {
			return a - b;
		});

		// Get the middle index:
		id = Math.floor( vec.length / 2 );

		if ( vec.length % 2 ) {
			// The number of elements is not evenly divisible by two, hence we have a middle index:
			return vec[ id ];
		}

		// Even number of elements, so must take the mean of the two middle values:
		return ( vec[ id-1 ] + vec[ id ] ) / 2.0;
	} // end FUNCTION median()


	// STREAM //

	/**
	* FUNCTION: Stream()
	*	Stream constructor.
	*
	* @returns {object} Stream instance
	*/
	function Stream() {
		return this;
	} // end FUNCTION stream()

	/**
	* METHOD: _transform()
	*	Returns a data transformation function.
	*
	* @private
	* @returns {function} data transformation function
	*/
	Stream.prototype._transform = function() {
		/**
		* FUNCTION: transform( data )
		*	Defines the data transformation.
		*
		* @param {number} data - numeric stream data
		* @returns {number} transformed data
		*/
		return function transform( data ) {
			// Convert a comma delimited string into an array:
			data = JSON.parse( '[' + data + ']' );

			// Compute the median:
			return median( data );
		};
	}; // end METHOD _transform()

	/**
	* METHOD: stream()
	*	Returns a JSON data reduction stream for calculating the statistic.
	*/
	Stream.prototype.stream = function() {
		var jStream, sStream, mStream, pStream;

		// Create a stream to comma-deliminate all incoming data values:
		jStream = eventStream.join( ',' );

		// Create a sink stream to buffer all data values into memory:
		sStream = eventStream.wait();

		// Create a transform stream to calculate the median value:
		mStream = transformer( this._transform() );

		// Create a stream pipeline:
		pStream = eventStream.pipeline(
			jStream,
			sStream,
			mStream
		);

		// Return the pipeline:
		return pStream;
	}; // end METHOD stream()


	// EXPORTS //

	module.exports = function createStream() {
		return new Stream();
	};

})();<commit_msg>[UPDATE] median stream prototype.<commit_after>/**
*
*	STREAM: median
*
*
*
*	DESCRIPTION:
*		- 
*
*
*	API:
*		- 
*
*
*	NOTES:
*		[1] 
*
*
*	TODO:
*		[1] 
*
*
*	HISTORY:
*		- 2014/05/23: Created. [AReines].
*
*
*	DEPENDENCIES:
*		[1] 
*
*
*	LICENSE:
*		MIT
*
*	Copyright (c) 2014. <NAME>.
*
*
*	AUTHOR:
*		<NAME>. <EMAIL>. 2014.
*
*/

(function() {
	'use strict';

	// MODULES //

	var // Event stream module:
		eventStream = require( 'event-stream' ),

		// Stream transform:
		transformer = require( './../../transform' );


	// FUNCTIONS //

	/**
	* FUNCTIONS: median( vector )
	*	Computes the median value of a 1d dataset array.
	*
	* @private
	* @param {array} vector - 1d array
	* @returns {number} median value
	*/
	function median( vector ) {
		var id, vec;

		// Create a copy of the input vector:
		vec = vector.slice();

		// Sort the input vector:
		vec.sort( function ( a, b ) {
			return a - b;
		});

		// Get the middle index:
		id = Math.floor( vec.length / 2 );

		if ( vec.length % 2 ) {
			// The number of elements is not evenly divisible by two, hence we have a middle index:
			return vec[ id ];
		}

		// Even number of elements, so must take the mean of the two middle values:
		return ( vec[ id-1 ] + vec[ id ] ) / 2.0;
	} // end FUNCTION median()

	/**
	* FUNCTION: transform( data )
	*	Defines the data transformation.
	*
	* @private
	* @param {number} data - numeric stream data
	* @returns {number} transformed data
	*/
	function transform( data ) {
		// Convert a comma delimited string into an array:
		data = JSON.parse( '[' + data + ']' );

		// Compute the median:
		return median( data );
	} // end FUNCTION transform()


	// STREAM //

	/**
	* FUNCTION: Stream()
	*	Stream constructor.
	*
	* @returns {object} Stream instance
	*/
	function Stream() {
		return this;
	} // end FUNCTION stream()

	/**
	* METHOD: stream()
	*	Returns a JSON data reduction stream for calculating the statistic.
	*/
	Stream.prototype.stream = function() {
		var jStream, sStream, mStream, pStream;

		// Create a stream to comma-deliminate all incoming data values:
		jStream = eventStream.join( ',' );

		// Create a sink stream to buffer all data values into memory:
		sStream = eventStream.wait();

		// Create a transform stream to calculate the median value:
		mStream = transformer( transform );

		// Create a stream pipeline:
		pStream = eventStream.pipeline(
			jStream,
			sStream,
			mStream
		);

		// Return the pipeline:
		return pStream;
	}; // end METHOD stream()


	// EXPORTS //

	module.exports = function createStream() {
		return new Stream();
	};

})();
{'fraction_non_alphanumeric': 0.15030731979884523, 'fraction_numerical': 0.009685230024213076, 'mean_word_length': 2.6630286493860846, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '3594101', 'n_tokens_mistral': 2069, 'n_tokens_neox': 1842, 'n_words': 576}