<commit_before># Sketches: sketch id + boolean if the sketch has loaded yet
sketches = {
	"words": 0, 
	"average": 0, 
	"distinct": 0, 
	"oxford": 0,
	"fancy": 0,
	"awl": 0,
	"awl-details": 0
}

totalWordsLevels = [50, 100, 200, 300, 500, 1000, 2000, 3000, 5000];
totalWordsIdentifier = "num_words";

distinctLevels = [10, 50, 100, 150, 200, 300, 400, 800, 1000];
distinctIdentifier = "different_words";


@updateSketches = (id) ->
	$.ajax id.toString(),
		type: 'GET'
		dataType: 'json'
		error: (jqXHR, textStatus, errorThrown) ->
			console.log "WARNING: Couldn't get current stats"
		success: (data, textStatus, jqXHR) ->
			console.log "SUCCESS: Got current stats, updating sketches..."

			for sketch of sketches
				updateSketch(sketch, data)


@updateSketch = (sketch, data) ->
	# Sketches aren't loaded when document is ready
	# --> wait for them to load, since Processing.js provides no callback
	timer = 0
	timeout = 2000
	clearInterval(mem)
	mem = setInterval ->
		instance = Processing.getInstanceById(sketch);
		if instance
			if not sketches[sketch]
				# Load this sketch for the first time 
				initSketch(sketch, instance)
			instance.update($.parseJSON(data["stats"]));
			clearInterval(mem);
		else
			timer += 10
			if timer > timeout
				console.log("WARNING: Failed to load sketch");
				clearInterval(mem);
	, 10


@initSketch = (sketch, instance) ->
	switch sketch
		when "words"
			instance.setIdentifier(totalWordsIdentifier);
			instance.setLevels(totalWordsLevels);
		when "distinct"
			instance.setIdentifier(distinctIdentifier);
			instance.setLevels(distinctLevels);
		else # Do nothing

	sketches[sketch] = 1


$ ->
	if $('.visualization').length > 0 # See if we're on a paper_show page
		paper_id = $('#paper_id').html()
		updateSketches(paper_id)

		setInterval ->
			updateSketches(paper_id)
		, 5000<commit_msg>Increase level cap for distinct words<commit_after># Sketches: sketch id + boolean if the sketch has loaded yet
sketches = {
	"words": 0, 
	"average": 0, 
	"distinct": 0, 
	"oxford": 0,
	"fancy": 0,
	"awl": 0,
	"awl-details": 0,
	"word-cloud": 0
}

update_interval = 5000;

totalWordsLevels = [50, 100, 200, 300, 500, 1000, 2000, 3000, 5000];
totalWordsIdentifier = "num_words";

distinctLevels = [50, 100, 200, 300, 500, 800, 1000, 1250, 1500];
distinctIdentifier = "different_words";

@updateSketches = (id) ->
	$.ajax id.toString(),
		type: 'GET'
		dataType: 'json'
		error: (jqXHR, textStatus, errorThrown) ->
			console.log "WARNING: Couldn't get current stats"
		success: (data, textStatus, jqXHR) ->
			console.log "SUCCESS: Got current stats, updating sketches..."

			for sketch of sketches
				updateSketch(sketch, data)


@updateSketch = (sketch, data) ->
	# Sketches aren't loaded when document is ready
	# --> wait for them to load, since Processing.js provides no callback
	timer = 0
	timeout = 2000
	clearInterval(mem)
	mem = setInterval ->
		instance = Processing.getInstanceById(sketch);
		if instance
			if not sketches[sketch]
				# Load this sketch for the first time 
				initSketch(sketch, instance)
			instance.update($.parseJSON(data["stats"]));
			clearInterval(mem);
		else
			timer += 10
			if timer > timeout
				console.log("WARNING: Failed to load sketch");
				clearInterval(mem);
	, 10


@initSketch = (sketch, instance) ->
	switch sketch
		when "words"
			instance.setIdentifier(totalWordsIdentifier);
			instance.setLevels(totalWordsLevels);
		when "distinct"
			instance.setIdentifier(distinctIdentifier);
			instance.setLevels(distinctLevels);
		else # Do nothing

	sketches[sketch] = 1


$ ->
	if $('.visualization').length > 0 # See if we're on a paper_show page
		paper_id = $('#paper_id').html()
		updateSketches(paper_id)

		setInterval ->
			updateSketches(paper_id)
		, update_interval 
{'fraction_non_alphanumeric': 0.12893831082870003, 'fraction_numerical': 0.04236166269526079, 'mean_word_length': 4.077956989247312, 'pattern_counts': {'":': 15, '<': 3, '<?xml version=': 0, '>': 25, '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': '2874507', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1251, 'n_words': 362}