<commit_before><?
include 'php/database.php';
include('php/wordcloud.class.php');
$database = connectToDB();
?>
<!DOCTYPE html>
<html>
<head>
<title><NAME> - Digital Collection</title>
<link rel="stylesheet" type="text/css" href="header.css" />
<link rel="stylesheet" type="text/css" href="footer.css" />
<link rel="stylesheet" type="text/css" href="results.css" />

<script src="jquery.js"></script>

<!-- Word Cloud -->
<link rel="stylesheet" type="text/css" href="jqcloud/jqcloud.css" />
<script type="text/javascript" src="jqcloud/jqcloud-1.0.0.js"></script>

<!-- Google Maps API -->
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCld462mkpAZrPllmHK8eJGXenW5Kus7g0&sensor=false">
</script>

<script type="text/javascript">

//This function handles a click on a particular city within the Google Map
//id must be a key in the NormalizedPlace table
function cityClicked(id)
{
    var getParams = '?query=';
    getParams += encodeURIComponent(document.getElementById('query').value);
    getParams += '&location=';
    getParams += encodeURIComponent(id);
    getParams += '&sort=';
    getParams += encodeURIComponent(sortKey);
    window.location = "results.php" + getParams;
}

//Given an r, g, b, returns a string representing a color in html
//Borrowed from the internet
function rgbToHtml(r, g, b)
{
    var decColor = r + 256 * g + 65536 * b;
    var str = decColor.toString(16);
    while (str.length < 6) {
        str = '0' + str;
    }
    return "#" + str;
}

// Draws a Bezier curve on a Google Map
//
//  First, the start and end points are converted to screen coordinates.
//  Then, the curvyness is used to generate a third point.  This point is
//  equidistant from the endpoints and, if you were travelling from start
//  to end, this point would be off to your left.  From these three points,
//  we generate a Bezier curve.  Then this curve is coverted back into
//  Lat/Long coordinates and plotted on the map.
//  Each segment of this curve will transition from Red to Blue.
//
//@param map The Google Map on which to draw.
//@param startLatLng The latitude/longitude of the curve's start point
//@param endLatLng The latitude/longitude of the curve's end point
//@param curvyness Determines how far the third point of the Bezier curve
//  is from the straight line between the endpoints.
//
//Reference http://en.wikipedia.org/wiki/B%C3%A9zier_curve
function drawCurve(map, startLatLng, endLatLng, curvyness) {
    var projection = map.getProjection();
    var p0 = projection.fromLatLngToPoint(startLatLng);
    var p2 = projection.fromLatLngToPoint(endLatLng);
    var xDiff = p2.x-p0.x;
    var yDiff = p2.y-p0.y;
    var dist = Math.sqrt(Math.pow(xDiff, 2) + Math.pow(yDiff, 2));
    dist *= curvyness;
    var angle = Math.atan2(yDiff, xDiff) + Math.PI/2;
    var mid = new google.maps.Point((p0.x+p2.x)/2, (p0.y+p2.y)/2);
    var p1 = new google.maps.Point(mid.x + dist * Math.cos(angle),
        mid.y + dist*Math.sin(angle));

    var SEGMENTS = 10;
    var prevLatLng;
    var currentLatLng;
    var first = true;
    for (var i = 0; i <= SEGMENTS; i += 1) {
        var t = i / SEGMENTS;
        var x = Math.pow(1 - t, 2) * p0.x + 2 * (1 - t) * t * p1.x
            + Math.pow(t, 2) * p2.x;
        var y = Math.pow(1 - t, 2) * p0.y + 2 * (1 - t) * t * p1.y
            + Math.pow(t, 2) * p2.y;
        currentLatLng = projection.fromPointToLatLng(new google.maps.Point(x, y));
        if (!first) {
            var r = Math.floor(255*t);
            var color = rgbToHtml(r, 0, 255 - r);
            var coords = [prevLatLng, currentLatLng];
            var line = new google.maps.Polyline({
              path: coords,
              strokeColor: color,
              strokeOpacity: 0.1 + 0.4 * Math.abs(t - 0.5),
              strokeWeight: 5
            });
            line.setMap(map);
        }
        prevLatLng = currentLatLng;
        first = false;
    }
}

var map;
var basicData;
var cloudData;
var cityData;
var sortKey='date';
function redrawAllCurves()
{
    for (i in basicData) {
        doc = basicData[i];
        if (doc['srcLat'] != null && doc['dstLat'] != null) {
            var curvyness = 0.1 + Math.random() * 0.2;
            drawCurve(map,
                new google.maps.LatLng(doc['srcLat'], doc['srcLng']), 
                new google.maps.LatLng(doc['dstLat'], doc['dstLng']),
                curvyness);
        }
    }
}

var markers = [];
function redrawMarkers()
{
    //Clear all existing markers.
    var i;
    for (i in markers) {
        markers[i].setMap(null);
    }
    markers = [];

    //Determine how many markers we want to draw at this zoom level
    var maxMarkers;
    if (map.getZoom() > 7) {
        //If we are zoomed in really close, show them all
        maxMarkers = cityData.length
    }
    else {
        //Otherwise just show the first few (which are the ones with
        //the most traffic)
        maxMarkers = Math.min(cityData.length,
            Math.ceil(Math.pow(map.getZoom(), 1.2)));
    }

    //Add the markers
    for (i = 0; i < maxMarkers; i++) {
        var city = cityData[i];
        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(city['lat'], city['lng']),
            map: map,
            title: city['name']
        });
        google.maps.event.addListener(marker, 'click', function() {
            cityClicked(city['id'])});
        markers.push(marker);
    }
}

function changeSort() {
    sortKey = $('input:radio[name=sort]:checked').val();
    queryChanged();
}

//If the user has selected the basic view, this function will generate
//the content.  In this case, the content is simply a list of the matching
//documents in the order they are returned from the server.
//
//A 'hidden' parameter to this function is the global basicData, which
//is the most recent data received from the server.
function basicContent() {
    var doc;
    var i;
    var newContent = "";
    newContent += "\
    <form id='sortForm' >\
    <input type='radio' name='sort' id='sort_similarity' \
        onclick='changeSort()'\
        value='similarity'>Relevance</input>\
    <input type='radio' name='sort' id='sort_date'\
        onclick='changeSort()'\
        value='date'>Date</input>\
    </form>";
    newContent += "<p>Showing " + basicData.length + " results</p>";
    for (i in basicData) {
        doc = basicData[i];
        newContent += "<p>" + (parseInt(i) + 1)
        + ". <a href='document.php?id="
        + doc['id'] + ".xml'>" + doc['title'] + "</a>:<p>"
        + doc['summary'] + "</p></p><br>";
    }
    document.getElementById('content').innerHTML = newContent;
    $('#sort_' + sortKey).prop('checked',true);
}

//Generates the content of the geographic view, which is a Google Map
//
//A 'hidden' parameter to this function is the global basicData, which
//is the most recent data received from the server.
function geographicContent() {
    $('#content').height(500);
    var myOptions = {
        center: new google.maps.LatLng(34, -94),
        zoom: 4,
        mapTypeId: google.maps.MapTypeId.TERRAIN
    };
    map = new google.maps.Map(document.getElementById("content"), myOptions);
    if (map.getProjection() != null) {
        redrawAllCurves();
    }
    else {
        google.maps.event.addListener(map, 'projection_changed', redrawAllCurves);<commit_msg>Added year range to basic view<commit_after><?
include 'php/database.php';
include('php/wordcloud.class.php');
$database = connectToDB();
?>
<!DOCTYPE html>
<html>
<head>
<title><NAME> - Digital Collection</title>
<link rel="stylesheet" type="text/css" href="header.css" />
<link rel="stylesheet" type="text/css" href="footer.css" />
<link rel="stylesheet" type="text/css" href="results.css" />

<script src="jquery.js"></script>

<!-- Word Cloud -->
<link rel="stylesheet" type="text/css" href="jqcloud/jqcloud.css" />
<script type="text/javascript" src="jqcloud/jqcloud-1.0.0.js"></script>

<!-- Google Maps API -->
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCld462mkpAZrPllmHK8eJGXenW5Kus7g0&sensor=false">
</script>

<script type="text/javascript">

//This function handles a click on a particular city within the Google Map
//id must be a key in the NormalizedPlace table
function cityClicked(id)
{
    var getParams = '?query=';
    getParams += encodeURIComponent(document.getElementById('query').value);
    getParams += '&location=';
    getParams += encodeURIComponent(id);
    getParams += '&sort=';
    getParams += encodeURIComponent(sortKey);
    window.location = "results.php" + getParams;
}

//Given an r, g, b, returns a string representing a color in html
//Borrowed from the internet
function rgbToHtml(r, g, b)
{
    var decColor = r + 256 * g + 65536 * b;
    var str = decColor.toString(16);
    while (str.length < 6) {
        str = '0' + str;
    }
    return "#" + str;
}

// Draws a Bezier curve on a Google Map
//
//  First, the start and end points are converted to screen coordinates.
//  Then, the curvyness is used to generate a third point.  This point is
//  equidistant from the endpoints and, if you were travelling from start
//  to end, this point would be off to your left.  From these three points,
//  we generate a Bezier curve.  Then this curve is coverted back into
//  Lat/Long coordinates and plotted on the map.
//  Each segment of this curve will transition from Red to Blue.
//
//@param map The Google Map on which to draw.
//@param startLatLng The latitude/longitude of the curve's start point
//@param endLatLng The latitude/longitude of the curve's end point
//@param curvyness Determines how far the third point of the Bezier curve
//  is from the straight line between the endpoints.
//
//Reference http://en.wikipedia.org/wiki/B%C3%A9zier_curve
function drawCurve(map, startLatLng, endLatLng, curvyness) {
    var projection = map.getProjection();
    var p0 = projection.fromLatLngToPoint(startLatLng);
    var p2 = projection.fromLatLngToPoint(endLatLng);
    var xDiff = p2.x-p0.x;
    var yDiff = p2.y-p0.y;
    var dist = Math.sqrt(Math.pow(xDiff, 2) + Math.pow(yDiff, 2));
    dist *= curvyness;
    var angle = Math.atan2(yDiff, xDiff) + Math.PI/2;
    var mid = new google.maps.Point((p0.x+p2.x)/2, (p0.y+p2.y)/2);
    var p1 = new google.maps.Point(mid.x + dist * Math.cos(angle),
        mid.y + dist*Math.sin(angle));

    var SEGMENTS = 10;
    var prevLatLng;
    var currentLatLng;
    var first = true;
    for (var i = 0; i <= SEGMENTS; i += 1) {
        var t = i / SEGMENTS;
        var x = Math.pow(1 - t, 2) * p0.x + 2 * (1 - t) * t * p1.x
            + Math.pow(t, 2) * p2.x;
        var y = Math.pow(1 - t, 2) * p0.y + 2 * (1 - t) * t * p1.y
            + Math.pow(t, 2) * p2.y;
        currentLatLng = projection.fromPointToLatLng(new google.maps.Point(x, y));
        if (!first) {
            var r = Math.floor(255*t);
            var color = rgbToHtml(r, 0, 255 - r);
            var coords = [prevLatLng, currentLatLng];
            var line = new google.maps.Polyline({
              path: coords,
              strokeColor: color,
              strokeOpacity: 0.1 + 0.4 * Math.abs(t - 0.5),
              strokeWeight: 5
            });
            line.setMap(map);
        }
        prevLatLng = currentLatLng;
        first = false;
    }
}

var map;
var basicData;
var cloudData;
var cityData;
var sortKey='date';
function redrawAllCurves()
{
    for (i in basicData) {
        doc = basicData[i];
        if (doc['srcLat'] != null && doc['dstLat'] != null) {
            var curvyness = 0.1 + Math.random() * 0.2;
            drawCurve(map,
                new google.maps.LatLng(doc['srcLat'], doc['srcLng']), 
                new google.maps.LatLng(doc['dstLat'], doc['dstLng']),
                curvyness);
        }
    }
}

var markers = [];
function redrawMarkers()
{
    //Clear all existing markers.
    var i;
    for (i in markers) {
        markers[i].setMap(null);
    }
    markers = [];

    //Determine how many markers we want to draw at this zoom level
    var maxMarkers;
    if (map.getZoom() > 7) {
        //If we are zoomed in really close, show them all
        maxMarkers = cityData.length
    }
    else {
        //Otherwise just show the first few (which are the ones with
        //the most traffic)
        maxMarkers = Math.min(cityData.length,
            Math.ceil(Math.pow(map.getZoom(), 1.2)));
    }

    //Add the markers
    for (i = 0; i < maxMarkers; i++) {
        var city = cityData[i];
        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(city['lat'], city['lng']),
            map: map,
            title: city['name']
        });
        google.maps.event.addListener(marker, 'click', function() {
            cityClicked(city['id'])});
        markers.push(marker);
    }
}

function changeSort() {
    sortKey = $('input:radio[name=sort]:checked').val();
    queryChanged();
}

//If the user has selected the basic view, this function will generate
//the content.  In this case, the content is simply a list of the matching
//documents in the order they are returned from the server.
//
//A 'hidden' parameter to this function is the global basicData, which
//is the most recent data received from the server.
function basicContent() {
    var doc;
    var i;
    var newContent = "";
    newContent += "\
    <form id='sortForm' >\
    <input type='radio' name='sort' id='sort_similarity' \
        onclick='changeSort()'\
        value='similarity'>Relevance</input>\
    <input type='radio' name='sort' id='sort_date'\
        onclick='changeSort()'\
        value='date'>Date</input>\
    </form>";

    var minYear = 9999, maxYear = -9999, year;
    for (i in basicData) {
        doc = basicData[i];
        var year = parseInt(new Date(doc['date']).getFullYear());
        if (year < minYear) {
            minYear = year;
        }
        if (year > maxYear) {
            maxYear = year;
        }
    }

    newContent += "<p>Showing " + basicData.length + " results";
    if (basicData.length > 0) {
        newContent += " between " + minYear + " and " + maxYear;
    }
    newContent += "</p>";
    for (i in basicData) {
        doc = basicData[i];
        newContent += "<p>" + (parseInt(i) + 1)
        + ". <a href='document.php?id="
        + doc['id'] + ".xml'>" + doc['title'] + "</a>:<p>"
        + doc['summary'] + "</p></p><br>";
    }
    document.getElementById('content').innerHTML = newContent;
    $('#sort_' + sortKey).prop('checked',true);
}

//Generates the content of the geographic view, which is a Google Map
//
//A 'hidden' parameter to this function is the global basicData, which
//is the most recent data received from the server.
function geographicContent() {
    $('#content').height(500);
    var myOptions = {
        center: new google.maps.LatLng(34, -94),
        zoom: 4,
        mapTypeId: google.maps.MapTypeId.TERRAIN
    };
    map = new google.maps.Map(document.getElementById("content"), myOptions);
    if (map.getProjection() != null) {
        redrawAllCurves();
    }
    else {
        google.maps.event.addListener(map, 'projection_changed', redrawAllCurves);
{'fraction_non_alphanumeric': 0.1464653039968754, 'fraction_numerical': 0.012823851061059759, 'mean_word_length': 2.619081272084806, 'pattern_counts': {'":': 0, '<': 82, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4457048', 'n_tokens_mistral': 5143, 'n_tokens_neox': 4978, 'n_words': 1432}