<commit_before>package handlers

import (
	"fmt"
	"log"
	"net/http"
	"text/template"

	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)

func add(x, y int) int {
	return x + y
}

func formatScore(x float64) string {
	return fmt.Sprintf("%.2f", x*100)
}

// HighScoresHandler handles the stats page
func HighScoresHandler(w http.ResponseWriter, r *http.Request) {
	session, err := mgo.Dial(mongoURL)
	if err != nil {
		log.Println("ERROR: could not get collection:", err)
		http.Error(w, err.Error(), 500)
		return
	}
	defer session.Close()
	coll := session.DB(mongoDatabase).C(mongoCollection)

	var highScores []struct {
		Repo    string
		Files   int
		Average float64
	}
	err = coll.Find(bson.M{"files": bson.M{"$gt": 100}}).Sort("-average").All(&highScores)
	if err != nil {
		log.Println("ERROR: could not get high scores: ", err)
		http.Error(w, err.Error(), 500)
		return
	}

	count, err := coll.Count()
	if err != nil {
		log.Println("ERROR: could not get count of high scores: ", err)
		http.Error(w, err.Error(), 500)
		return
	}

	funcs := template.FuncMap{"add": add, "formatScore": formatScore}
	t := template.Must(template.New("high_scores.html").Funcs(funcs).ParseFiles("templates/high_scores.html"))

	t.Execute(w, map[string]interface{}{"HighScores": highScores, "Count": count})
}
<commit_msg>limit high scores to 50<commit_after>package handlers

import (
	"fmt"
	"log"
	"net/http"
	"text/template"

	"gopkg.in/mgo.v2"
	"gopkg.in/mgo.v2/bson"
)

func add(x, y int) int {
	return x + y
}

func formatScore(x float64) string {
	return fmt.Sprintf("%.2f", x*100)
}

// HighScoresHandler handles the stats page
func HighScoresHandler(w http.ResponseWriter, r *http.Request) {
	session, err := mgo.Dial(mongoURL)
	if err != nil {
		log.Println("ERROR: could not get collection:", err)
		http.Error(w, err.Error(), 500)
		return
	}
	defer session.Close()
	coll := session.DB(mongoDatabase).C(mongoCollection)

	var highScores []struct {
		Repo    string
		Files   int
		Average float64
	}
	err = coll.Find(bson.M{"files": bson.M{"$gt": 100}}).Sort("-average").Limit(50).All(&highScores)
	if err != nil {
		log.Println("ERROR: could not get high scores: ", err)
		http.Error(w, err.Error(), 500)
		return
	}

	count, err := coll.Count()
	if err != nil {
		log.Println("ERROR: could not get count of high scores: ", err)
		http.Error(w, err.Error(), 500)
		return
	}

	funcs := template.FuncMap{"add": add, "formatScore": formatScore}
	t := template.Must(template.New("high_scores.html").Funcs(funcs).ParseFiles("templates/high_scores.html"))

	t.Execute(w, map[string]interface{}{"HighScores": highScores, "Count": count})
}

{'fraction_non_alphanumeric': 0.1675531914893617, 'fraction_numerical': 0.0182370820668693, 'mean_word_length': 4.266, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, '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': '3913678', 'n_tokens_mistral': 1078, 'n_tokens_neox': 990, 'n_words': 228}