<commit_before>let window = self;
onmessage = function(request) {
	importScripts(request.data.url+"assets/js/Dexie.min.js");
	importScripts(request.data.url+"library/modules/Database.js");
	KC3Database.init( request.data.playerId );
	fetchData(request.data);
};

function fetchData(options){
	let startHour = Math.floor((new Date(options.start))/( 1*60*60*1000));
	let endHour = Math.floor((new Date(options.end))/( 1*60*60*1000))+24;
	KC3Database.con[options.tableName]
		.where("hour").between(startHour, endHour, true, true)
		.toArray(function(result){
			formatData(startHour, endHour, options, result);
		});
}

function formatData(startHour, endHour, options, result){
	let graphPoints = [];
	let labels = [];
	let datasets = {};
	let maxPoints = Math.ceil((endHour - startHour) / options.interval);
	
	// Create datasets based on graphable items
	options.graphableItems.name.forEach(function(name, gii){
		datasets[options.graphableItems.dbkey[gii]] = {
			label: options.graphableItems.full[gii],
			fillColor: "rgba(225,225,225,0)",
			strokeColor: "rgba("+options.graphableItems.colorbyte[gii]+",1)",
			pointColor: "rgba("+options.graphableItems.colorbyte[gii]+",1)",
			pointStrokeColor: "#"+options.graphableItems.colorhex[gii],
			pointHighlightFill: "#"+options.graphableItems.colorhex[gii],
			pointHighlightStroke: "rgba("+options.graphableItems.colorbyte[gii]+",1)",
			data: Array.from('0'.repeat(maxPoints)).map((e)=>{ return parseInt(e); })
		};
	});
	
	// Categorize records into points in the graph (based on interval)
	result.forEach(function(rsc){
		// rsc.date = new Date(rsc.hour * 60 * 60 * 1000);
		let offset = rsc.hour - startHour;
		let graphIndex = Math.floor(offset / options.interval);
		graphPoints[String(graphIndex)] = graphPoints[String(graphIndex)] || [];
		graphPoints[String(graphIndex)].push(rsc);
	});
	
	// Get averages for each point in the graph
	graphPoints.forEach(function(graphPoint, pointIndex){
		options.graphableItems.dbkey.forEach(function(dbkey){
			let valuesInPoint = graphPoint.map((e) => {return e[dbkey]; });
			datasets[dbkey].data[pointIndex] = avg(valuesInPoint);
		});
	});<commit_msg>graphs/ Fix long decimal values<commit_after>let window = self;
onmessage = function(request) {
	importScripts(request.data.url+"assets/js/Dexie.min.js");
	importScripts(request.data.url+"library/modules/Database.js");
	KC3Database.init( request.data.playerId );
	fetchData(request.data);
};

function fetchData(options){
	let startHour = Math.floor((new Date(options.start))/( 1*60*60*1000));
	let endHour = Math.floor((new Date(options.end))/( 1*60*60*1000))+24;
	KC3Database.con[options.tableName]
		.where("hour").between(startHour, endHour, true, true)
		.toArray(function(result){
			formatData(startHour, endHour, options, result);
		});
}

function formatData(startHour, endHour, options, result){
	let graphPoints = [];
	let labels = [];
	let datasets = {};
	let maxPoints = Math.ceil((endHour - startHour) / options.interval);
	
	// Create datasets based on graphable items
	options.graphableItems.name.forEach(function(name, gii){
		datasets[options.graphableItems.dbkey[gii]] = {
			label: options.graphableItems.full[gii],
			fillColor: "rgba(225,225,225,0)",
			strokeColor: "rgba("+options.graphableItems.colorbyte[gii]+",1)",
			pointColor: "rgba("+options.graphableItems.colorbyte[gii]+",1)",
			pointStrokeColor: "#"+options.graphableItems.colorhex[gii],
			pointHighlightFill: "#"+options.graphableItems.colorhex[gii],
			pointHighlightStroke: "rgba("+options.graphableItems.colorbyte[gii]+",1)",
			data: Array.from('0'.repeat(maxPoints)).map((e)=>{ return parseInt(e); })
		};
	});
	
	// Categorize records into points in the graph (based on interval)
	result.forEach(function(rsc){
		// rsc.date = new Date(rsc.hour * 60 * 60 * 1000);
		let offset = rsc.hour - startHour;
		let graphIndex = Math.floor(offset / options.interval);
		graphPoints[String(graphIndex)] = graphPoints[String(graphIndex)] || [];
		graphPoints[String(graphIndex)].push(rsc);
	});
	
	// Get averages for each point in the graph
	graphPoints.forEach(function(graphPoint, pointIndex){
		options.graphableItems.dbkey.forEach(function(dbkey){
			let valuesInPoint = graphPoint.map((e) => {return e[dbkey]; });
			datasets[dbkey].data[pointIndex] = Math.round(avg(valuesInPoint));
		});
	});
{'fraction_non_alphanumeric': 0.16797415782187355, 'fraction_numerical': 0.02030456852791878, 'mean_word_length': 5.638591117917305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5811208', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1460, 'n_words': 246}