<commit_before>'use strict';

/******************************************************************************
* Tests
******************************************************************************/
/// entry point for tests
function tests_ok(show) {
	show("Starting internal selftest…");
	return test_dummy(show) && test_local_storage(show); // add further test with logical and for short circuit evaluation
}

/// root of tests
function test_dummy(show) {
	show("Running test_dummy.");
	return true;
}

function test_local_storage(show) {
	// Save data to the current local store
	var reference = "John";
	localStorage.setItem("test_username", reference);

	// Access some stored data
	var result = localStorage.getItem("test_username");
	show( "test_username = " + result);

	if (result.length != reference.length) {
		show("String lengths don't match.");
		return false;
	}
	if (!result.endsWith(reference)) {
		show("String endings don't match.");
		return false;
	}
	return true;
}
/*****************************************************************************/

/// our entry point
function main() {
	console.log("HI and WELCOME");
	var text_block = document.querySelector('#text-block');
	var commit_button = document.querySelector('#commit-button');
	var next_button = document.querySelector('#next-button');
	var restart_button = document.querySelector('#restart-button');
	var image_part = document.querySelector('#image-part');
	console.log(text_block);

	var show = function(message) {
		if (text_block) {
			text_block.innerHTML = message;
		}
	}
	var show_and_log = function(msg) {show(msg); console.log(msg); };
	var logn = function(msg) { console.log(msg); };
	if (!tests_ok(show_and_log)) {
		show("Some Tests failed. Stopping. We think this platform is not appropriate to run this. Sorry.");
		return;
	}
	show("Starte Berechnung…");

	// username needed for indexing the final result
	var local_data = {
		"username" : "brs",
		"stage" : "start"
	}
	show_and_log(local_data);
	// TODO get some input from the user for the username
	var put_local_data = function(data) { localStorage.setItem("local_data", JSON.stringify(local_data)); };
	var get_local_data = function() { return JSON.parse(localStorage.getItem("local_data")) };
	put_local_data(local_data); // TODO check if we have privious data and ask(?) if we want to keep it

//	var tick = function() {
////		show("Fertig!");
//		var result = get_local_data(); // TODO just testing
//		show("username: " + result.username + "<br>stage: " + result.stage); // TODO just testing
//		setTimeout(tick, 1);
//	}

	var on_commit_click = function() {
		logn("commit");
	}

	var on_next_click = function() {
		logn("next");
		var stage = local_data.stage;
		var next = quiz_data[stage].next;
		if (0 == next.length) {
			return;
		}
		local_data.stage = next;
		put_local_data(local_data);
		redraw();
	}

	var on_restart_click = function() {<commit_msg>Versuch mit Bild aus Data-URL für spätere codierte Daten.<commit_after>'use strict';

/******************************************************************************
* Tests
******************************************************************************/
/// entry point for tests
function tests_ok(show) {
	show("Starting internal selftest…");
	return test_dummy(show) && test_local_storage(show); // add further test with logical and for short circuit evaluation
}

/// root of tests
function test_dummy(show) {
	show("Running test_dummy.");
	return true;
}

function test_local_storage(show) {
	// Save data to the current local store
	var reference = "John";
	localStorage.setItem("test_username", reference);

	// Access some stored data
	var result = localStorage.getItem("test_username");
	show( "test_username = " + result);

	if (result.length != reference.length) {
		show("String lengths don't match.");
		return false;
	}
	if (!result.endsWith(reference)) {
		show("String endings don't match.");
		return false;
	}
	return true;
}
/*****************************************************************************/

/// our entry point
function main() {
	console.log("HI and WELCOME");
	var text_block = document.querySelector('#text-block');
	var commit_button = document.querySelector('#commit-button');
	var next_button = document.querySelector('#next-button');
	var restart_button = document.querySelector('#restart-button');
	var image_part = document.querySelector('#image-part');
	console.log(text_block);

	var show = function(message) {
		if (text_block) {
			text_block.innerHTML = message;
		}
	}
	var show_and_log = function(msg) {show(msg); console.log(msg); };
	var logn = function(msg) { console.log(msg); };
	if (!tests_ok(show_and_log)) {
		show("Some Tests failed. Stopping. We think this platform is not appropriate to run this. Sorry.");
		return;
	}
	show("Starte Berechnung…");

	// username needed for indexing the final result
	var local_data = {
		"username" : "brs",
		"stage" : "start"
	}
	show_and_log(local_data);
	// TODO get some input from the user for the username
	var put_local_data = function(data) { localStorage.setItem("local_data", JSON.stringify(local_data)); };
	var get_local_data = function() { return JSON.parse(localStorage.getItem("local_data")) };
	put_local_data(local_data); // TODO check if we have privious data and ask(?) if we want to keep it

//	var tick = function() {
////		show("Fertig!");
//		var result = get_local_data(); // TODO just testing
//		show("username: " + result.username + "<br>stage: " + result.stage); // TODO just testing
//		setTimeout(tick, 1);
//	}

	var on_commit_click = function() {
		logn("commit");
		var image_data_url = "data:image/png;base64,\
iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP\
C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA\
AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J\
REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq\
ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0\
vr4MkhoXe0rZigAAAABJRU5ErkJggg=="; // from https://de.wikipedia.org/wiki/Data-URL
		show_image(image_data_url, 50, 50, "direkt Bilddaten"); // TODO just testing direkt data drawing
	}

	var on_next_click = function() {
		logn("next");
		var stage = local_data.stage;
		var next = quiz_data[stage].next;
		if (0 == next.length) {
			return;
		}
		local_data.stage = next;
		put_local_data(local_data);
		redraw();
	}

	var on_restart_click = function() {
{'fraction_non_alphanumeric': 0.2018377199813113, 'fraction_numerical': 0.007631210091885999, 'mean_word_length': 5.018744142455483, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, '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': '2023821', 'n_tokens_mistral': 2168, 'n_tokens_neox': 2073, 'n_words': 492}