<commit_before><!DOCTYPE html>
    <style>
        /* Custom CSS for the custom homepage... */
        .lite-header {font-weight: 300;}

        div.hmpg-action-block {padding-top:2em;}
        div.search-widget {padding-bottom: 2em;}
        div.browse-subjects a {color: #C55B28;}
        div.browse-subjects a:focus, div.browse-subjects a:hover {color: #9F3502;}
        div.hmpg-recent-col div.hmpg-recent-thumb img {max-height:48px;max-width:48px;}
        div.hmpg-recent-col div.hmpg-recent-thumb span {font-size:38px;}
        div.hmpg-activity-block .row .lite-header {margin-left:1em;}

        .btn-harvard { 
          color: #A51C30;
          background: #FFFFFF;
          font-weight: bold;
        }
        .btn-harvard:hover, 
        .btn-harvard:focus, 
        .btn-harvard:active, 
        .btn-harvard.active, 
        .open .dropdown-toggle.btn-harvard { 
          color: #7F000A;
          background: #FFFFFF;
          font-weight: bold;
        } 
    </style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
    var baseUrl = "http://localhost:8080";
    //var baseUrl = "https://dataverse.harvard.edu"
    
    //This get slow and eventually the resulting pile of substrings is too long if there are actually 1000 results
    //For this search to be valid the results returned will need to be higher than 1000 even
    var firstSearch = baseUrl + "/api/search?q=*&type=dataverse&per_page=1000";
    var secondSearch = baseUrl + "/api/search?q=*&type=dataset&sort=date&order=desc&per_page=";
    var thumbBaseURL = baseUrl + "/api/datasets/:persistentId/thumbnail" + "?persistentId=";
    var metricBaseUrl = baseUrl + "/api/info/metrics/";
    
    /**
    * Runs two search queries, the first to get dataverses based on a certain filter, and the second to get recent datasets for those dataverses.
    * The initial intent of the query is to get recent datasets based on dataverse subjects
    * @param {string} fqString - the filter for the first query, which returns which dataverses to get recent datasets from. For example: "&fq=dvCategory:(Journal%20OR%20Laboratory)" To get dataverses that are a Journal or Laboratory.
    * @param {number} resultCount - the number of results to write
    * @param {string} elm - The id of the html element to write the result to
    */
    function writeRecentDatasetsInDataverses(fqString, resultCount, elm) {
        var tempSecondSearch = secondSearch + resultCount;
        
        $.get(firstSearch + fqString, function(jData) {
            jData.data.items.forEach(function(item){
                tempSecondSearch += "&subtree=" + item.identifier;
            });

            $.get(tempSecondSearch, function(jData2) {
                var resultHtml = "";
                jData2.data.items.forEach(function(item){
                    resultHtml += "<div class=\"col-xs-2 text-center hmpg-recent-thumb\"><a href=\"/dataset.xhtml?persistentId=" + item.global_id + "\" title=\"" + item.name + "\"><img src=\"" + thumbBaseURL + item.global_id + "\" alt=\"Dataset thumbnail\"></a></div>";
                    resultHtml += "<div class=\"col-xs-10\"><p><a href=\"/dataset.xhtml?persistentId=" + item.global_id + "\" title=\"" + item.name + "\">" + item.name + "</a></p></div>";
                    resultHtml += "<hr class=\"col-xs-11 no-margin-top\"/>"
                });
                document.getElementById(elm).innerHTML = resultHtml;
            });
        });
    }
    
    function queryMetricSimple(metricRelPath, month, elm) {
        // $.get(metricBaseUrl + metricRelPath + month, function(jData) {
        //     document.getElementById(elm).innerHTML = JSON.stringify(jData);
        // });

        $.get(metricBaseUrl + metricRelPath + month, function(jData) {

            var resultCount = jData.data.count; //"6"

            document.getElementById(elm).innerHTML = resultCount;
        });
    }

    function querySubject(elm) {
        $.get(metricBaseUrl + "dataverses/bySubject", function(jData) {
            var resultHtml = "";
            jData.data.forEach(function(item) {
                //TODO: NEED DYNAMIC 'ROOT' DV NAME
                resultHtml += "<p><a href=\"/dataverse/root?q=&fq0=subject_ss%3A%22" + item.subject + "%22&types=datasets&sort=dateSort&order=desc\" title=\"" + item.subject + "\">" + item.subject + "</a> (" + item.count + ")</p>";
            });
            document.getElementById(elm).innerHTML = resultHtml;
        });
    }

    //These are the correct searches, but commented out as I don't have enough results
    //writeRecentDatasetsInDataverses("&fq=dvCategory:(Journal%20OR%20Laboratory)",3, "journals");
    //writeRecentDatasetsInDataverses("&fq=dvCategory:(\"Research+Project\"%20OR%20Researcher)",6, "researchers");
    
    writeRecentDatasetsInDataverses("" , 3, "journals");
    writeRecentDatasetsInDataverses("" , 6, "researchers");
    
    queryMetricSimple("datasets/toMonth", "", "activityAllTimeDatasetsValue");
    queryMetricSimple("files/toMonth", "", "activityAllTimeFilesValue");
    
    //These don't actually return the past 30 days, just the value up until September. Will need discussion
    queryMetricSimple("datasets/toMonth", "/2018-09", "activity30DaysDatasetsValue");
    queryMetricSimple("files/toMonth", "/2018-09", "activity30DaysFilesValue");
    
    querySubject("dataversesBySubject");
</script>

<html>
    <body>

        <div id="dataversesBySubjectHead"><b>Dataverses By Subject</b></div>
        <div id="dataversesBySubject"></div>
        <hr>

    <!-- SEARCH + BROWSE + RECENT -->
    <div class="row hmpg-browse-block">


        <div class="col-xs-12">
            <div class="row">
                <div class="col-xs-4">
                    <div class="h4 lite-header margin-bottom">Datasets from journal articles</div>
                </div>
                <div class="col-xs-8">
                    <div class="h4 lite-header margin-bottom">Datasets from research projects, groups and researchers</div>
                </div>
            </div>
            

            <div class="row">
                <div class="col-xs-4 hmpg-recent-col">
                    <hr class="col-xs-11 no-margin-top"/>

                    <!-- JOURNAL RESULTS -->
                    <div id="journals">Should not see this</div>

                    <!-- VIEW ALL -->
                    <div class="col-xs-11 text-center">
                        <p class="small text-muted"><a href="#" title="{TITLE}">TODO ALL RECENT JOURNAL ACTIVITY</a> <span class="glyphicon glyphicon-chevron-right"></span></p>
                    </div>
                </div>

                <div class="col-xs-4 hmpg-recent-col">
                    <hr class="col-xs-11 no-margin-top"/>

                    <!-- RESEARCHERS RESULTS -->
                    <div id="researchers">Should not see this</div>

                    <!-- VIEW ALL -->
                    <div class="col-xs-11 text-center">
                        <p class="small text-muted"><a href="#" title="{TITLE}">TODO ALL RECENT RESEARCHERS ACTIVITY</a> <span class="glyphicon glyphicon-chevron-right"></span></p>
                    </div>
                </div>

                <div class="col-xs-4 hmpg-recent-col">
                    <hr class="col-xs-11 no-margin-top"/>

                    <!-- RESULT 1 -->
                    <div class="col-xs-2 text-center hmpg-recent-thumb">
                        <a href="/dataset.xhtml?persistentId=doi:10.7910/DVN/P0OMNM" title="{TITLE}"><img src="data:image/png;base64,iVBORw0K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+zdFIniAUtj4/m2Aj3GEpN4AczH4DT/YuP6DNXX7/wrrZpiFshIWORIcanIQoinge6pLK8x1MjmlBQOjPAlj5PDhhTkKSPJCwf6nK13wGDbf++DqGyj6l1eNMDnarYlLd1HtbL0pt1zrLkxLnQb3W7L8cnndG6kQv29efZiuQYIfz6nh9G1LM3xqVlDSFT1Qf7DEXo+JzAYNl2jxjQqOoxeMNx/sQh7lFVOvVGVjhehewlQ+234dpKQGH2rxDntfUj9emlibN2S+Y+z1OA811Msom1NiDIlVYrSjB5EkOhpi4GdpT7M0G9pp0nR4Hb2nxbSNjkzMYoNHYthT4uieU+QMqBso2SbyEoESf9oZOzJEdkKkjVVxdqCDMBJ1mghFQJF0zx58XzhQJzMLbRHFOo3uJqAWXt2qn4AAAAASUVORK5CYII=" alt="Dataset thumbnail"></a>
                    </div>
                    <div class="col-xs-10">
                        <p><a href="#" title="{TITLE}">TODO Short Title</a><br/><span class="text-muted small"><a href="#" title="" class="highlightBold">Dataverse Name</a> - Publish Date</span></p>
                    </div>
                    <hr class="col-xs-11 no-margin-top"/>

                    <!-- RESULT 2 -->
                    <div class="col-xs-2 text-center hmpg-recent-thumb">
                        <a href="/dataset.xhtml?persistentId=doi:10.7910/DVN/P0OMNM" title="{TITLE}"><span class="icon-dataset"></span></a>
                    </div>
                    <div class="col-xs-10">
                        <p><a href="#" title="{TITLE}">TODO Replication Data For: Long Dataset Title, Whatever the Median Dataset Title Length Is Currently in Production, I Should Probably Look That Up</a><br/><span class="text-muted small"><a href="#" title="" class="highlightBold">Dataverse Name</a> - Publish Date</span></p>
                    </div>
                    <hr class="col-xs-11 no-margin-top"/>

                    <!-- RESULT 3 -->
                    <div class="col-xs-2 text-center hmpg-recent-thumb">
                        <a href="/dataset.xhtml?persistentId=doi:10.7910/DVN/P0OMNM" title="{TITLE}"><span class="icon-dataset"></span></a>
                    </div>
                    <div class="col-xs-10">
                        <p><a href="#" title="{TITLE}">TODO Replication Data For: Long Dataset Title, Whatever the Median Dataset Title Length Is Currently in Production, I Should Probably Look That Up</a><br/><span class="text-muted small"><a href="#" title="" class="highlightBold">Dataverse Name</a> - Publish Date</span></p>
                    </div>
                    <hr class="col-xs-11 no-margin-top"/>
                </div>
            </div>
        </div>
    </div>

    <hr/>

    <!-- ACTIVITY -->
    <div class="row hmpg-activity-block">
        <div class="col-xs-12">
            <div class="h4 lite-header margin-bottom">Activity</div>
        </div><commit_msg>Revised column layout of recent datasets in custom hmpg template [ref #5053]<commit_after><!DOCTYPE html>
    <style>
        /* Custom CSS for the custom homepage... */
        .lite-header {font-weight: 300;}

        div.hmpg-action-block {padding-top:2em;}
        div.search-widget {padding-bottom: 2em;}
        div.browse-subjects a {color: #C55B28;}
        div.browse-subjects a:focus, div.browse-subjects a:hover {color: #9F3502;}
        div.hmpg-recent-col div.hmpg-recent-thumb img {max-height:48px;max-width:48px;}
        div.hmpg-recent-col div.hmpg-recent-thumb span {font-size:38px;}
        div.hmpg-activity-block .row .lite-header {margin-left:1em;}

        .btn-harvard { 
          color: #A51C30;
          background: #FFFFFF;
          font-weight: bold;
        }
        .btn-harvard:hover, 
        .btn-harvard:focus, 
        .btn-harvard:active, 
        .btn-harvard.active, 
        .open .dropdown-toggle.btn-harvard { 
          color: #7F000A;
          background: #FFFFFF;
          font-weight: bold;
        } 
    </style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>
    var baseUrl = "http://localhost:8080";
    //var baseUrl = "https://dataverse.harvard.edu"
    
    //This get slow and eventually the resulting pile of substrings is too long if there are actually 1000 results
    //For this search to be valid the results returned will need to be higher than 1000 even
    var firstSearch = baseUrl + "/api/search?q=*&type=dataverse&per_page=1000";
    var secondSearch = baseUrl + "/api/search?q=*&type=dataset&sort=date&order=desc&per_page=";
    var thumbBaseURL = baseUrl + "/api/datasets/:persistentId/thumbnail" + "?persistentId=";
    var metricBaseUrl = baseUrl + "/api/info/metrics/";
    
    /**
    * Runs two search queries, the first to get dataverses based on a certain filter, and the second to get recent datasets for those dataverses.
    * The initial intent of the query is to get recent datasets based on dataverse subjects
    * @param {string} fqString - the filter for the first query, which returns which dataverses to get recent datasets from. For example: "&fq=dvCategory:(Journal%20OR%20Laboratory)" To get dataverses that are a Journal or Laboratory.
    * @param {number} resultCount - the number of results to write
    * @param {string} elm - The id of the html element to write the result to
    */
    function writeRecentDatasetsInDataverses(fqString, resultCount, elm, colSize) {
        var tempSecondSearch = secondSearch + resultCount;
        
        $.get(firstSearch + fqString, function(jData) {
            jData.data.items.forEach(function(item){
                tempSecondSearch += "&subtree=" + item.identifier;
            });

            $.get(tempSecondSearch, function(jData2) {
                var resultHtml = "";
                jData2.data.items.forEach(function(item){
                    resultHtml += "<div class=\"col-xs-" + colSize + "\">"
                    resultHtml += "<div class=\"col-xs-2 text-center hmpg-recent-thumb\"><a href=\"/dataset.xhtml?persistentId=" + item.global_id + "\" title=\"" + item.name + "\"><span class=\"icon-dataset\"></span></a></div>";
                    resultHtml += "<div class=\"col-xs-10\"><p><a href=\"/dataset.xhtml?persistentId=" + item.global_id + "\" title=\"" + item.name + "\">" + item.name + "</a></p><p class=\"small text-muted\">" + item.parentDataverse + " - " + item.publicationDate + "</p></div>";
                    resultHtml += "<hr class=\"col-xs-11 no-margin-top\"/></div>"
                });
                document.getElementById(elm).innerHTML = resultHtml;


                // BROKEN THUMBNAIL IMAGES
                // <img src=\"" + thumbBaseURL + item.global_id + "\" alt=\"Dataset thumbnail\">


            });
        });
    }
    
    function queryMetricSimple(metricRelPath, month, elm) {
        // $.get(metricBaseUrl + metricRelPath + month, function(jData) {
        //     document.getElementById(elm).innerHTML = JSON.stringify(jData);
        // });

        $.get(metricBaseUrl + metricRelPath + month, function(jData) {

            var resultCount = jData.data.count;

            document.getElementById(elm).innerHTML = resultCount;
        });
    }

    function querySubject(elm) {
        $.get(metricBaseUrl + "dataverses/bySubject", function(jData) {
            var resultHtml = "";
            jData.data.forEach(function(item) {
                //TODO: NEED DYNAMIC 'ROOT' DV NAME
                resultHtml += "<div class=\"col-xs-4 browse-subjects\"><p><a href=\"/dataverse/root?q=&fq0=subject_ss%3A%22" + item.subject + "%22&types=datasets&sort=dateSort&order=desc\" title=\"" + item.subject + "\">" + item.subject + "</a> <span class=\"text-muted\">" + item.count + "</span></p></div>";
            });
            document.getElementById(elm).innerHTML = resultHtml;
        });
    }

    //These are the correct searches, but commented out as I don't have enough results
    //writeRecentDatasetsInDataverses("&fq=dvCategory:(Journal%20OR%20Laboratory)",3, "journals");
    //writeRecentDatasetsInDataverses("&fq=dvCategory:(\"Research+Project\"%20OR%20Researcher)",6, "researchers");
    
    writeRecentDatasetsInDataverses("" , 3, "journals", 12);
    writeRecentDatasetsInDataverses("" , 6, "researchers", 6);
    
    queryMetricSimple("datasets/toMonth", "", "activityAllTimeDatasetsValue");
    queryMetricSimple("files/toMonth", "", "activityAllTimeFilesValue");
    
    //These don't actually return the past 30 days, just the value up until September. Will need discussion
    queryMetricSimple("datasets/toMonth", "/2018-09", "activity30DaysDatasetsValue");
    queryMetricSimple("files/toMonth", "/2018-09", "activity30DaysFilesValue");
    
    querySubject("dataversesBySubject");
</script>

<html>
    <body>


    <!-- SEARCH + BROWSE + RECENT -->
    <div class="row hmpg-browse-block">
        
        <!-- SEARCH -->
        <div class="col-xs-12">
            <div class="h4 lite-header margin-bottom">Find data across research fields, preview metadata, and download files.</div>

            <div class="row">
                <div class="col-xs-4">
                    <div class="search-widget input-group">
                        <input id="inputDataverseSearch" class="form-control" type="text" placeholder="Search over 75,000 datasets..." onkeydown="if (event.keyCode == 13) document.getElementById('btnDataverseSearch').click();">
                        <span class="input-group-btn">
                            <button id="btnDataverseSearch" class="btn btn-default" type="button" onclick="window.location = '/dataverse/root?q=' + document.getElementById('inputDataverseSearch').value;return false;"><span class="glyphicon glyphicon-search"></span> Find</button>
                        </span>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- BROWSE -->
        <div class="col-xs-12">
            <p class="text-muted small">Browse dataverses in this repository by subject.</p>
            <div id="dataversesBySubject" class="row margin-bottom">

            </div>
        </div>

        <!-- RECENT -->
        <div class="col-xs-12">
            <div class="row">
                <div class="col-xs-4 hmpg-recent-col">
                    <div class="h4 lite-header margin-bottom">Datasets from journal articles</div>

                    <hr class="col-xs-11 no-margin-top"/>

                    <!-- JOURNAL RESULTS -->
                    <div id="journals" class="row col-xs-12">Loading...</div>

                    <!-- VIEW ALL -->
                    <div class="col-xs-12 text-center">
                        <p class="small text-muted"><a href="/dataverse/root?q=&fq0=subject_ss%3A%22Chemistry%22&types=dataverses%3Adatasets&sort=dateSort&order=desc" title="{TITLE}">TODO ALL RECENT JOURNAL ACTIVITY</a> <span class="glyphicon glyphicon-chevron-right"></span></p>
                    </div>
                </div>

                <div class="col-xs-8 hmpg-recent-col">
                    <div class="h4 lite-header margin-bottom">Datasets from research projects, groups and researchers</div>

                    <hr class="col-xs-11 no-margin-top"/>

                    <!-- RESEARCHERS RESULTS -->
                    <div id="researchers" class="row col-xs-12">Loading...</div>

                    <!-- VIEW ALL -->
                    <div class="col-xs-12 text-center">
                        <p class="small text-muted"><a href="/dataverse/root?q=&fq0=subject_ss%3A%22Chemistry%22&types=dataverses%3Adatasets&sort=dateSort&order=desc" title="{TITLE}">TODO ALL RECENT RESEARCHERS ACTIVITY</a> <span class="glyphicon glyphicon-chevron-right"></span></p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <hr/>

    <!-- ACTIVITY -->
    <div class="row hmpg-activity-block">
        <div class="col-xs-12">
            <div class="h4 lite-header margin-bottom">Activity</div>
        </div>
{'fraction_non_alphanumeric': 0.14241546842027777, 'fraction_numerical': 0.02620601658732885, 'mean_word_length': 2.44863767134879, 'pattern_counts': {'":': 0, '<': 257, '<?xml version=': 0, '>': 257, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2740892', 'n_tokens_mistral': 7166, 'n_tokens_neox': 6611, 'n_words': 1198}