<commit_before>$ -> 
	editor = CodeMirror.fromTextArea document.getElementById("code"), 
		mode:
			name: "python"
			version: 3
			singleLineStringErrors: false
		lineNumbers: true
		indentUnit: 4
		matchBrackets: true
		lineWrapping: true

	editor.setValue '# Paste your final_strategy into this box, along with any helper functions you need.\n\ndef final_strategy(score, opponent_score):\n    """*** YOUR CODE HERE ***"""\n    return 5 # Replace this statement\n\n\n'
	editor.setOption "extraKeys",
		"Ctrl-Enter": (cm) ->
			getWinrate()
		"Cmd-Enter": (cm) ->
			getWinrate()
	editor.focus()

	running = false
	getWinrate = ->
		return if running

		running = true
		NProgress.start()

		$('#winrate').text '...'
		$('#unhelpfulMessage').text 'calculating...'

		params = JSON.stringify
			strategy: editor.getValue()

		$.ajax
			type: 'POST'
			contentType: "application/json"
			url: "/winrate"
			dataType: "json"
			data: params
			success: (res) ->
				if res.status == 'success'
					winrate = res.winrate * 100

					counter = new countUp 'winrate', 0, winrate, 2, 4, 
						useEasing: true
						decimal: '.'
						suffix: '%'

					counter.start () ->
						$('#unhelpfulMessage').text res.message
				else
					setOutput ';___;', res.error.type + '!'

			complete: (res) ->
				NProgress.done()
				running = false
				
			error: (res) ->
				setOutput ';___;', 'you broke it :('

	setOutput = (winrate, msg) ->
		$('#winrate').text winrate
		$('#unhelpfulMessage').text msg

	$('#getWinrate').click (e) ->
		getWinrate()

	$("#getWinrate").mouseup ->
		$(this).blur()
<commit_msg>Make error messages more descriptive<commit_after>$ -> 
	editor = CodeMirror.fromTextArea document.getElementById("code"), 
		mode:
			name: "python"
			version: 3
			singleLineStringErrors: false
		lineNumbers: true
		indentUnit: 4
		matchBrackets: true
		lineWrapping: true

	editor.setValue '# Paste your final_strategy into this box, along with any helper functions you need.\n\ndef final_strategy(score, opponent_score):\n    """*** YOUR CODE HERE ***"""\n    return 5 # Replace this statement\n\n\n'
	editor.setOption "extraKeys",
		"Ctrl-Enter": (cm) ->
			getWinrate()
		"Cmd-Enter": (cm) ->
			getWinrate()
	editor.focus()

	running = false
	getWinrate = ->
		return if running

		running = true
		NProgress.start()

		$('#winrate').text '...'
		$('#unhelpfulMessage').text 'calculating...'

		params = JSON.stringify
			strategy: editor.getValue()

		$.ajax
			type: 'POST'
			contentType: "application/json"
			url: "/winrate"
			dataType: "json"
			data: params
			success: (res) ->
				if res.status == 'success'
					winrate = res.winrate * 100

					counter = new countUp 'winrate', 0, winrate, 2, 4, 
						useEasing: true
						decimal: '.'
						suffix: '%'

					counter.start () ->
						$('#unhelpfulMessage').text res.message
				else
					setOutput ';___;', 'oops! your code has a ' + res.error.type

			complete: (res) ->
				NProgress.done()
				running = false
				
			error: (res) ->
				setOutput ';___;', 'rip server'

	setOutput = (winrate, msg) ->
		$('#winrate').text winrate
		$('#unhelpfulMessage').text msg

	$('#getWinrate').click (e) ->
		getWinrate()

	$("#getWinrate").mouseup ->
		$(this).blur()

{'fraction_non_alphanumeric': 0.16084132384781935, 'fraction_numerical': 0.005567584287039901, 'mean_word_length': 3.062814070351759, 'pattern_counts': {'":': 4, '<': 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': '4119992', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1065, 'n_words': 266}