<commit_before>package server

import (
	"encoding/json"
	"fmt"
	"log"
	"math"
	"net/http"
	"strconv"

	"warcluster/entities"
	"warcluster/leaderboard"
)

type searchResult struct {
	Username string
	Page     int
}

func leaderboardPlayersHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	pageQuery, ok := r.URL.Query()["page"]
	if !ok {
		http.Error(w, "Bad Request", 400)
		return
	}

	page, intErr := strconv.ParseInt(pageQuery[0], 10, 0)
	if intErr != nil {
		http.Error(w, "Page Not Found", 404)
		return
	}

	boardPage, err := leaderBoard.Page(page)
	if err != nil {
		http.Error(w, "Page Not Found", 404)
		return
	}

	result, _ := json.Marshal(boardPage)
	fmt.Fprintf(w, string(result))
}

func leaderboardTeamsHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")

	teams, err := json.Marshal(leaderBoard.Teams())
	if err != nil {
		http.Error(w, "Internal Server Error", 500)
		return
	}
	fmt.Fprintf(w, string(teams))
}

func searchHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	username, ok := r.URL.Query()["player"]
	if !ok || len(username[0]) < 3 {
		http.Error(w, "Bad Request", 400)
		return
	}

	players, err := entities.GetList(fmt.Sprintf("player.%s*", username[0]))
	if err != nil {
		http.Error(w, "Internal Server Error", 500)
		return
	}
	result := make([]searchResult, 0)

	for _, player := range players {
		username := player[7:len(player)]
		page := math.Ceil(float64(leaderBoard.Place(username)) / 10)<commit_msg>Fix the page attribute of each player in the search<commit_after>package server

import (
	"encoding/json"
	"fmt"
	"log"
	"math"
	"net/http"
	"strconv"

	"warcluster/entities"
	"warcluster/leaderboard"
)

type searchResult struct {
	Username string
	Page     int
}

func leaderboardPlayersHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	pageQuery, ok := r.URL.Query()["page"]
	if !ok {
		http.Error(w, "Bad Request", 400)
		return
	}

	page, intErr := strconv.ParseInt(pageQuery[0], 10, 0)
	if intErr != nil {
		http.Error(w, "Page Not Found", 404)
		return
	}

	boardPage, err := leaderBoard.Page(page)
	if err != nil {
		http.Error(w, "Page Not Found", 404)
		return
	}

	result, _ := json.Marshal(boardPage)
	fmt.Fprintf(w, string(result))
}

func leaderboardTeamsHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")

	teams, err := json.Marshal(leaderBoard.Teams())
	if err != nil {
		http.Error(w, "Internal Server Error", 500)
		return
	}
	fmt.Fprintf(w, string(teams))
}

func searchHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	username, ok := r.URL.Query()["player"]
	if !ok || len(username[0]) < 3 {
		http.Error(w, "Bad Request", 400)
		return
	}

	players, err := entities.GetList(fmt.Sprintf("player.%s*", username[0]))
	if err != nil {
		http.Error(w, "Internal Server Error", 500)
		return
	}
	result := make([]searchResult, 0)

	for _, player := range players {
		username := player[7:len(player)]
		page := math.Ceil(float64(leaderBoard.Place(username)+1) / 10)
{'fraction_non_alphanumeric': 0.1714021000617665, 'fraction_numerical': 0.01945645460160593, 'mean_word_length': 4.327302631578948, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4473350', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1178, 'n_words': 262}