<commit_before>'use strict';

var path = require('path'), fs = require('fs');

module.exports = function (grunt) {
	grunt.registerMultiTask('beaker', 'Measure your file size', function () {
		var src = this.data.src;
		var options = this.options();
		var sizes_store = options.version;
		var collect_data = options.collectData;
		var sma = options.sma;
		var sma_key = options.key;
		
		var sizes_data = null;
		
		// was sizes file passed?
		if(!sizes_store){
			grunt.fail.fatal("sizes file was not passed, please specify it.");
		}
		else{
			sizes_data = parseSizesFile(sizes_store);
		}
		
		if(collect_data){
			// recursively find files to process
			grunt.file.recurse(src, function(abspath) {
				statFile(abspath, sizes_data, sizes_store);
			});
		}
		else if(sma){
			calcSMA(sma, sizes_data, sma_key);
		}
	});
	
	function parseSizesFile (sizes_store){
		// check if version file exists
		if(!grunt.file.exists(sizes_store)){
			grunt.fail.fatal("sizes file does not exist, please create an empty file.");
		}
		
		var data = fs.readFileSync(sizes_store, 'utf8');
		if(data === ''){
			data = '{}'; // default, in case its a 0b file 
		}
		
		try{
			return JSON.parse(data);
		} catch (e) {
			grunt.fail.fatal("Problem parsing the sizes file: ", e);
		}
	}
	
	// return the mtime and sizefor file
	function statFile(path, sizes_data, sizes_file_path){
		writeFileData(path, new Date(fs.statSync(path).mtime).getTime(), fs.statSync(path).size, sizes_data, sizes_file_path);
	}
	
	// create the correct data structure and write it to the file
	function writeFileData(file_path, time, size, sizes_data, sizes_file_path){
		
		// create file type object if it doesnt exist
		if(sizes_data[path.extname(file_path).replace('.','')] === undefined){
			sizes_data[path.extname(file_path).replace('.','')] = {};<commit_msg>unnecessary date cast<commit_after>'use strict';

var path = require('path'), fs = require('fs');

module.exports = function (grunt) {
	grunt.registerMultiTask('beaker', 'Measure your file size', function () {
		var src = this.data.src;
		var options = this.options();
		var sizes_store = options.version;
		var collect_data = options.collectData;
		var sma = options.sma;
		var sma_key = options.key;
		
		var sizes_data = null;
		
		// was sizes file passed?
		if(!sizes_store){
			grunt.fail.fatal("sizes file was not passed, please specify it.");
		}
		else{
			sizes_data = parseSizesFile(sizes_store);
		}
		
		if(collect_data){
			// recursively find files to process
			grunt.file.recurse(src, function(abspath) {
				statFile(abspath, sizes_data, sizes_store);
			});
		}
		else if(sma){
			calcSMA(sma, sizes_data, sma_key);
		}
	});
	
	function parseSizesFile (sizes_store){
		// check if version file exists
		if(!grunt.file.exists(sizes_store)){
			grunt.fail.fatal("sizes file does not exist, please create an empty file.");
		}
		
		var data = fs.readFileSync(sizes_store, 'utf8');
		if(data === ''){
			data = '{}'; // default, in case its a 0b file 
		}
		
		try{
			return JSON.parse(data);
		} catch (e) {
			grunt.fail.fatal("Problem parsing the sizes file: ", e);
		}
	}
	
	// return the mtime and sizefor file
	function statFile(path, sizes_data, sizes_file_path){
		writeFileData(path, fs.statSync(path).mtime.getTime(), fs.statSync(path).size, sizes_data, sizes_file_path);
	}
	
	// create the correct data structure and write it to the file
	function writeFileData(file_path, time, size, sizes_data, sizes_file_path){
		
		// create file type object if it doesnt exist
		if(sizes_data[path.extname(file_path).replace('.','')] === undefined){
			sizes_data[path.extname(file_path).replace('.','')] = {};
{'fraction_non_alphanumeric': 0.14113785557986872, 'fraction_numerical': 0.0010940919037199124, 'mean_word_length': 3.850132625994695, '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': '180056', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1242, 'n_words': 313}