<commit_before>

function Item(dict, itemView) {

    // [<audience>, <engagement type>, <display level>]
    var metricInfo = {
        "citeulike:bookmarks": ["scholars", "saved", "badges", 3],
        "delicious:bookmarks": ["public", "saved", "badges", 3],
        "dryad:most_downloaded_file": ["scholars", "viewed", "badges", 100],
        "dryad:package_views": ["scholars", "viewed", "badges", 100],
        "dryad:total_downloads": ["scholars", "viewed", "badges", 100],
        "facebook:shares":["public", "discussed", "badges", 3],
        "facebook:comments":["public", "discussed", "badges", 3],
        "facebook:likes":["public", "discussed", "badges", 3],
        "facebook:clicks":["public", "discussed", "badges", 3],
        "github:forks":["public", "cited", "badges", 3],
        "github:watchers":["public", "saved", "badges", 3],
        "mendeley:career_stage":["", "", 0, 0],
        "mendeley:country":["", "", 0, 0],
        "mendeley:discipline":["", "", 0, 0],
        "mendeley:student_readers":["scholars", "saved", 0, 0],
        "mendeley:developing_countries":["scholars", "saved", 0, 0],
        "mendeley:groups":["", "", 0, 0],
        "mendeley:readers":["scholars", "saved", "badges", 3],
        "plos:crossref": [],                    // figure it out
        "plos:html_views": [],                  // figure it out
        "plos:pdf_views": [],                   // figure it out
        "plos:pmc_abstract": ["", "", 0],
        "plos:pmc_figure": ["", "", 0],
        "plos:pmc_full-text": ["", "", 0],
        "plos:pmc_pdf": ["", "", 0],
        "plos:pmc_supp-data": ["", "", 0],
        "plos:pmc_unique-ip": ["", "", 0],
        "plos:pubmed_central": ["", "", 0],
        "plos:scopus": [],                      // figure it out
        "pubmed:f1000": ["scholars", "recommended", "badges", 1],
        "pubmed:pmc_citations": ["scholars", "cited", "badges", 3],
        "pubmed:pmc_citations_editorials": ["scholars", "recommended", "zoom", 0],
        "pubmed:pmc_citations_reviews": ["scholars", "cited", "zoom", 0],
        "scienceseeker:blog_posts": ["scholars", "discussed", "zoom", 0],
        "slideshare:comments": ["public", "discussed", "badges", 3],
        "slideshare:downloads": ["public", "viewed", "badges", 3],
        "slideshare:favorites": ["public", "saved", "badges", 3],
        "slideshare:views": ["public", "viewed", "badges", 3],
        "topsy:influential_tweets": ["public", "discussed", "zoom", 0],
        "topsy:tweets": ["public", "discussed", "badges", 3],
        "wikipedia:mentions": ["public", "cited", "badges", 1]
    }


    // developing countries as per IMF 2012, plus Cuba and North Korea (not IMF members)
    // see http://www.imf.org/external/pubs/ft/weo/2012/01/pdf/text.pdf
    this.developing_countries = "Afghanistan|Albania|Algeria|Angola|Antigua and Barbuda|Argentina|Armenia|Azerbaijan|Bahamas|Bahrain|Bangladesh|Barbados|Belarus|Belize|Benin|Bhutan|Bolivia|Bosnia and Herzegovina|Botswana|Brazil|Brunei|Bulgaria|Burkina Faso|Burma|Burundi|Cambodia|Cameroon|Cape Verde|Central African Republic|Chad|Chile|China|Colombia|Comoros|Cuba|Democratic Republic of the Congo|Republic of the Congo|Costa Rica|Côte d Ivoire|Croatia|Djibouti|Dominica|Dominican Republic|Ecuador|Egypt|El Salvador|Equatorial Guinea|Eritrea|Ethiopia|Fiji|Gabon|The Gambia|Georgia|Ghana|Grenada|Guatemala|Guinea|Guinea-Bissau|Guyana|Haiti|Honduras|Hungary|India|Indonesia|Iran|Iraq|Jamaica|Jordan|Kazakhstan|Kenya|Kiribati|Kuwait|Kyrgyzstan|Laos|Latvia|Lebanon|Lesotho|Liberia|Libya|Lithuania|Macedonia|Madagascar|Malawi|Malaysia|Maldives|Mali|Marshall Islands|Mauritania|Mauritius|Mexico|Federated States of Micronesia|Moldova|Mongolia|Montenegro|Morocco|Mozambique|Namibia|Nauru|Nepal|Nicaragua|Niger|Nigeria|North Korea|Oman|Pakistan|Palau|Panama|Papua New Guinea|Paraguay|Peru|Philippines|Poland|Qatar|Romania|Russia|Rwanda|Saint Kitts and Nevis|Saint Lucia|Saint Vincent and the Grenadines|Samoa|São Tomé and Príncipe|Saudi Arabia|Senegal|Serbia|Seychelles|Sierra Leone|Solomon Islands|Somalia|South Africa|South Sudan|Sri Lanka|Sudan|Suriname|Swaziland|Syria|Tajikistan|Tanzania|Thailand|Timor-Leste|Togo|Tonga|Trinidad and Tobago|Tunisia|Turkey|Turkmenistan|Tuvalu|Uganda|Ukraine|United Arab Emirates|Uruguay|Uzbekistan|Vanuatu|Venezuela|Vietnam|Yemen|Zambia|Zimbabwe"

    this.render = function() {
        return this.itemView.render(this.dict)
    }


    this.makeEngagementTable = function(dict, metricInfo){

        var engagementTable = {
            "scholars": {"viewed": [], "discussed": [], "saved": [], "cited": [], "recommended": []},
            "public": {"viewed": [], "discussed": [], "saved": [], "cited": [], "recommended": []}
        }

        // make the table
        for (var metricName in dict.metrics) {
            var display = metricInfo[metricName][2]
            if (!display) {
                continue // don't bother putting in table, we don't show it anyway
            }
            var audience = metricInfo[metricName][0]
            var engagementType = metricInfo[metricName][1]

            var metric = this.dict.metrics[metricName]
            metric.display = display
            metric.minNumForAward = metricInfo[metricName][3]

            engagementTable[audience][engagementType].push(metric)
        }

        // convert the engagement table from a nested hashes to nested arrays
        // mostly because mustache.js needs it this way. should probably break this
        // but out as a method.
        ret = []
        for (var rowName in engagementTable) {
            var row = {audience: rowName, cells: [] }
            for (colName in engagementTable[rowName]) {
                var cell = engagementTable[rowName][colName]

                if (!cell.length) continue // we don't do anything with empty cells

                cellContents = {
                    metrics: cell,
                    engagementType: colName,
                    audience: rowName // because mustache can't access parent context
                }
                row.cells.push(cellContents)
            }
            ret.push(row)
        }
        return {"audiences": ret}
    }

    this.objToArr = function(obj){
        var arr = []
        for (k in obj) {
            arr.push(obj[k])
        }
        return arr
    }

    // returns a copy of obj1, minus the keys it shares with obj2
    this.subractKeys = function(obj1, obj2) {
        var newObj1 = {}
        for (k in obj1) {
            if (!(k in obj2)) {
                newObj1[k] = obj1[k]
            }
        }
        return newObj1
    }

    this.makeAwards = function(engagementTable) {
        var any = {}
        var over50perc = {}
        for (var i=0; i < engagementTable.audiences.length; i++) {
            var row = engagementTable.audiences[i]

            for (var j=0; j < row.cells.length; j++) {
                var cell = row.cells[j]

                for (var k=0; k < cell.metrics.length; k++) {
                    var metric = cell.metrics[k]
                    var cellName = row.audience+"."+cell.engagementType

                    if (metric.values.raw >= metric.minNumForAward) {

                        // add a big badge if we can
                        if (metric.percentiles !== undefined) {
                            if (metric.percentiles.CI95_lower >= 75) {
                                over50perc[cellName] = {
                                    audience: row.audience,
                                    engagementType:cell.engagementType,
                                    metric: metric
                                }
                            }
                        }<commit_msg>fix bugs in badge displays<commit_after>

function Item(dict, itemView) {

    // [<audience>, <engagement type>, <display level>]
    var metricInfo = {
        "citeulike:bookmarks": ["scholars", "saved", "badge", 3],
        "delicious:bookmarks": ["public", "saved", "badge", 3],
        "dryad:most_downloaded_file": ["scholars", "viewed", "badge", 100],
        "dryad:package_views": ["scholars", "viewed", "badge", 100],
        "dryad:total_downloads": ["scholars", "viewed", "badge", 100],
        "facebook:shares":["public", "discussed", "badge", 3],
        "facebook:comments":["public", "discussed", "badge", 3],
        "facebook:likes":["public", "discussed", "badge", 3],
        "facebook:clicks":["public", "discussed", "badge", 3],
        "github:forks":["public", "cited", "badge", 3],
        "github:watchers":["public", "saved", "badge", 3],
        "mendeley:career_stage":["", "", 0, 0],
        "mendeley:country":["", "", 0, 0],
        "mendeley:discipline":["", "", 0, 0],
        "mendeley:student_readers":["scholars", "saved", 0, 0],
        "mendeley:developing_countries":["scholars", "saved", 0, 0],
        "mendeley:groups":["", "", 0, 0],
        "mendeley:readers":["scholars", "saved", "badge", 3],
        "plos:crossref": [],                    // figure it out
        "plos:html_views": [],                  // figure it out
        "plos:pdf_views": [],                   // figure it out
        "plos:pmc_abstract": ["", "", 0],
        "plos:pmc_figure": ["", "", 0],
        "plos:pmc_full-text": ["", "", 0],
        "plos:pmc_pdf": ["", "", 0],
        "plos:pmc_supp-data": ["", "", 0],
        "plos:pmc_unique-ip": ["", "", 0],
        "plos:pubmed_central": ["", "", 0],
        "plos:scopus": [],                      // figure it out
        "pubmed:f1000": ["scholars", "recommended", "badge", 1],
        "pubmed:pmc_citations": ["scholars", "cited", "badge", 3],
        "pubmed:pmc_citations_editorials": ["scholars", "recommended", "zoom", 0],
        "pubmed:pmc_citations_reviews": ["scholars", "cited", "zoom", 0],
        "scienceseeker:blog_posts": ["scholars", "discussed", "zoom", 0],
        "slideshare:comments": ["public", "discussed", "badge", 3],
        "slideshare:downloads": ["public", "viewed", "badge", 3],
        "slideshare:favorites": ["public", "saved", "badge", 3],
        "slideshare:views": ["public", "viewed", "badge", 3],
        "topsy:influential_tweets": ["public", "discussed", "zoom", 0],
        "topsy:tweets": ["public", "discussed", "badge", 3],
        "wikipedia:mentions": ["public", "cited", "badge", 1]
    }


    // developing countries as per IMF 2012, plus Cuba and North Korea (not IMF members)
    // see http://www.imf.org/external/pubs/ft/weo/2012/01/pdf/text.pdf
    this.developing_countries = "Afghanistan|Albania|Algeria|Angola|Antigua and Barbuda|Argentina|Armenia|Azerbaijan|Bahamas|Bahrain|Bangladesh|Barbados|Belarus|Belize|Benin|Bhutan|Bolivia|Bosnia and Herzegovina|Botswana|Brazil|Brunei|Bulgaria|Burkina Faso|Burma|Burundi|Cambodia|Cameroon|Cape Verde|Central African Republic|Chad|Chile|China|Colombia|Comoros|Cuba|Democratic Republic of the Congo|Republic of the Congo|Costa Rica|Côte d Ivoire|Croatia|Djibouti|Dominica|Dominican Republic|Ecuador|Egypt|El Salvador|Equatorial Guinea|Eritrea|Ethiopia|Fiji|Gabon|The Gambia|Georgia|Ghana|Grenada|Guatemala|Guinea|Guinea-Bissau|Guyana|Haiti|Honduras|Hungary|India|Indonesia|Iran|Iraq|Jamaica|Jordan|Kazakhstan|Kenya|Kiribati|Kuwait|Kyrgyzstan|Laos|Latvia|Lebanon|Lesotho|Liberia|Libya|Lithuania|Macedonia|Madagascar|Malawi|Malaysia|Maldives|Mali|Marshall Islands|Mauritania|Mauritius|Mexico|Federated States of Micronesia|Moldova|Mongolia|Montenegro|Morocco|Mozambique|Namibia|Nauru|Nepal|Nicaragua|Niger|Nigeria|North Korea|Oman|Pakistan|Palau|Panama|Papua New Guinea|Paraguay|Peru|Philippines|Poland|Qatar|Romania|Russia|Rwanda|Saint Kitts and Nevis|Saint Lucia|Saint Vincent and the Grenadines|Samoa|São Tomé and Príncipe|Saudi Arabia|Senegal|Serbia|Seychelles|Sierra Leone|Solomon Islands|Somalia|South Africa|South Sudan|Sri Lanka|Sudan|Suriname|Swaziland|Syria|Tajikistan|Tanzania|Thailand|Timor-Leste|Togo|Tonga|Trinidad and Tobago|Tunisia|Turkey|Turkmenistan|Tuvalu|Uganda|Ukraine|United Arab Emirates|Uruguay|Uzbekistan|Vanuatu|Venezuela|Vietnam|Yemen|Zambia|Zimbabwe"

    this.render = function() {
        return this.itemView.render(this.dict)
    }


    this.makeEngagementTable = function(dict, metricInfo){

        var engagementTable = {
            "scholars": {"viewed": [], "discussed": [], "saved": [], "cited": [], "recommended": []},
            "public": {"viewed": [], "discussed": [], "saved": [], "cited": [], "recommended": []}
        }

        // make the table
        for (var metricName in dict.metrics) {
            var display = metricInfo[metricName][2]
            if (!display) {
                continue // don't bother putting in table, we don't show it anyway
            }
            var audience = metricInfo[metricName][0]
            var engagementType = metricInfo[metricName][1]

            var metric = this.dict.metrics[metricName]
            metric.display = display
            metric.minNumForAward = metricInfo[metricName][3]

            engagementTable[audience][engagementType].push(metric)
        }

        // convert the engagement table from a nested hashes to nested arrays
        // mostly because mustache.js needs it this way. should probably break this
        // but out as a method.
        ret = []
        for (var rowName in engagementTable) {
            var row = {audience: rowName, cells: [] }
            for (colName in engagementTable[rowName]) {
                var cell = engagementTable[rowName][colName]

                if (!cell.length) continue // we don't do anything with empty cells

                cellContents = {
                    metrics: cell,
                    engagementType: colName,
                    audience: rowName // because mustache can't access parent context
                }
                row.cells.push(cellContents)
            }
            ret.push(row)
        }
        return {"audiences": ret}
    }

    this.objToArr = function(obj){
        var arr = []
        for (k in obj) {
            arr.push(obj[k])
        }
        return arr
    }

    // returns a copy of obj1, minus the keys it shares with obj2
    this.subractKeys = function(obj1, obj2) {
        var newObj1 = {}
        for (k in obj1) {
            if (!(k in obj2)) {
                newObj1[k] = obj1[k]
            }
        }
        return newObj1
    }

    this.makeAwards = function(engagementTable) {
        var any = {}
        var over50perc = {}
        for (var i=0; i < engagementTable.audiences.length; i++) {
            var row = engagementTable.audiences[i]

            for (var j=0; j < row.cells.length; j++) {
                var cell = row.cells[j]

                for (var k=0; k < cell.metrics.length; k++) {
                    var metric = cell.metrics[k]
                    var cellName = row.audience+"."+cell.engagementType

                    if (metric.values.raw && metric.display=="badge") {

                        // add a big badge if we can
                        if (metric.percentiles !== undefined) {
                            if (metric.percentiles.CI95_lower >= 75 &&
                                metric.values.raw >= metric.minNumForAward) {
                                over50perc[cellName] = {
                                    audience: row.audience,
                                    engagementType:cell.engagementType,
                                    metric: metric
                                }
                            }
                        }
{'fraction_non_alphanumeric': 0.1496751784910272, 'fraction_numerical': 0.01132051199588345, 'mean_word_length': 2.5384615384615383, 'pattern_counts': {'":': 108, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4654706', 'n_tokens_mistral': 5374, 'n_tokens_neox': 4880, 'n_words': 950}