<commit_before>// app.js

var sightings = [];
var sounds = [];
var chosen = 0;

function getLocation() {
	if (navigator.geolocation) {
		navigator.geolocation.getCurrentPosition(
			function success(position) {
				$('#location').append('<div>' + position.coords.latitude + ',' + position.coords.longitude + '</div>');
				getRecentNearbySightings(position.coords.latitude, position.coords.longitude);
			},
			function error() {
				console.log('error');
				getRecentNearbySightings(37, -122);
			},
			{
			});
	} else {
		$('#location').append('<div>37, -122</div>')
		getRecentNearbySightings(37, -122);
	}
}

function chooseRandomRecording(inID) {
	$('#audio').empty();

	if (sounds[inID] && sounds[inID].recordings) {
		var soundsData = sounds[inID];
		var randomRecordingID = Math.floor(Math.random() * soundsData.recordings.length);

		console.log(soundsData.recordings[randomRecordingID]);
		$('#audio').append('<audio src="' + soundsData.recordings[randomRecordingID].file + '" type="audio/mpeg" autoplay controls loop></audio>')
		$('#audio').append('<div>recorded at ' + soundsData.recordings[randomRecordingID].loc + '</div>');
	} else {
		console.log('no sounds for #' + inID);
		$('#audio').append('no recordings found');
	}
}

function getSounds(inID) {
	$('#audio').empty();
	$('#audio').append('loading sound data');
<commit_msg>use haversine to compute km's between two lat/long points. eventually, prefer nearby recordings<commit_after>// app.js

var myPosition;
var sightings = [];
var sounds = [];
var chosen = 0;

// http://www.movable-type.co.uk/scripts/latlong.html

function degreesToRadians(inDegrees) {
	return 2 * 3.14159 * inDegrees / 360.0;
}

function haversine(lat1, lon1, lat2, lon2) {
	var R = 6371; // km
	var φ1 = degreesToRadians(lat1);
	var φ2 = degreesToRadians(lat2);
	var Δφ = degreesToRadians(lat2-lat1);
	var Δλ = degreesToRadians(lon2-lon1);

	var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
	        Math.cos(φ1) * Math.cos(φ2) *
	        Math.sin(Δλ/2) * Math.sin(Δλ/2);
	var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

	var d = R * c;

	return d;
}

function getLocation() {
	if (navigator.geolocation) {
		navigator.geolocation.getCurrentPosition(
			function success(position) {
				myPosition = position;
				$('#location').append('<div>' + position.coords.latitude + ',' + position.coords.longitude + '</div>');
				getRecentNearbySightings(position.coords.latitude, position.coords.longitude);
			},
			function error() {
				console.log('error');
				getRecentNearbySightings(37, -122);
			},
			{
			});
	} else {
		$('#location').append('<div>37, -122</div>')
		getRecentNearbySightings(37, -122);
	}
}

function chooseRandomRecording(inID) {
	$('#audio').empty();

	if (sounds[inID] && sounds[inID].recordings) {
		var soundsData = sounds[inID];
		var randomRecordingID = Math.floor(Math.random() * soundsData.recordings.length);

		console.log(soundsData.recordings[randomRecordingID]);
		var kmDistance = haversine(myPosition.coords.latitude, myPosition.coords.longitude, soundsData.recordings[randomRecordingID].lat, soundsData.recordings[randomRecordingID].lng);
		$('#audio').append('<audio src="' + soundsData.recordings[randomRecordingID].file + '" type="audio/mpeg" autoplay controls loop></audio>')
		$('#audio').append('<div>recorded ' + Math.round(kmDistance) + ' kilometers away</div>');
	} else {
		console.log('no sounds for #' + inID);
		$('#audio').append('no recordings found');
	}
}

function getSounds(inID) {
	$('#audio').empty();
	$('#audio').append('loading sound data');

{'fraction_non_alphanumeric': 0.18435125246270756, 'fraction_numerical': 0.019138755980861243, 'mean_word_length': 4.6682615629984054, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '160319', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1234, 'n_words': 212}