<commit_before>package main

import (
	"compress/gzip"
	"github.com/dustin/go-humanize"
	"html/template"
	"log"
	"math"
	"net/http"
	"strconv"
	"strings"
	"time"
)

type playerArg struct {
	ChampionImage string
	ChampionName  string
	Summoner      string
}

type recordingArg struct {
	IsComplete       bool
	NoMetadata       bool
	Players          []playerArg
	Recording        bool
	Ago              string
	Queue            string
	CapitalizedQueue string
	Region           string
	AQueue           string
	Code             string
	LegendsGG        string
}

type renderArg struct {
	Recordings   []recordingArg
	CurrentPage  int
	Pages        []int
	NextPage     int
	PreviousPage int
	LoadTime     string
}

var pageTemplate *template.Template

func serveView(w http.ResponseWriter, r *http.Request) {
	var currentPage int
	if r.URL.Path == "/" {
		currentPage = 1
	} else {
		num, err := strconv.Atoi(r.URL.Path[1:])
		if err != nil {
			w.Header().Set("Content-Type", "text/plain")
			w.WriteHeader(http.StatusNotFound)
			w.Write([]byte("404 page not found"))
			return
		}

		currentPage = num
	}

	templateRenderArg := getRenderArg(r, currentPage)

	w.Header().Set("Content-Type", "text/html; charset=utf-8")

	if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
		w.Header().Set("Content-Encoding", "gzip")
		w.WriteHeader(http.StatusOK)

		writer := gzip.NewWriter(w)
		if err := pageTemplate.Execute(writer, templateRenderArg); err != nil {
			writer.Write([]byte("template render error"))
			log.Println("render: template error:", err)
		}
		writer.Close()
	} else {
		w.WriteHeader(http.StatusOK)
		if err := pageTemplate.Execute(w, templateRenderArg); err != nil {<commit_msg>Add redirect for out of bounds pages<commit_after>package main

import (
	"compress/gzip"
	"github.com/dustin/go-humanize"
	"html/template"
	"log"
	"math"
	"net/http"
	"strconv"
	"strings"
	"time"
)

type playerArg struct {
	ChampionImage string
	ChampionName  string
	Summoner      string
}

type recordingArg struct {
	IsComplete       bool
	NoMetadata       bool
	Players          []playerArg
	Recording        bool
	Ago              string
	Queue            string
	CapitalizedQueue string
	Region           string
	AQueue           string
	Code             string
	LegendsGG        string
}

type renderArg struct {
	Recordings   []recordingArg
	CurrentPage  int
	Pages        []int
	NextPage     int
	PreviousPage int
	LoadTime     string
}

var pageTemplate *template.Template

func serveView(w http.ResponseWriter, r *http.Request) {
	var currentPage int
	if r.URL.Path == "/" {
		currentPage = 1
	} else {
		num, err := strconv.Atoi(r.URL.Path[1:])
		if err != nil {
			w.Header().Set("Content-Type", "text/plain")
			w.WriteHeader(http.StatusNotFound)
			w.Write([]byte("404 page not found"))
			return
		}

		currentPage = num
	}

	recordingsMutex.RLock()
	numRecordings := len(sortedRecordings)
	recordingsMutex.RUnlock()

	if (currentPage > int(math.Ceil(float64(numRecordings)/
		float64(config.ShowPerPage))) && currentPage != 1) ||
		currentPage < 1 {
		http.Redirect(w, r, "/", http.StatusFound)
		return
	}

	templateRenderArg := getRenderArg(r, currentPage)

	w.Header().Set("Content-Type", "text/html; charset=utf-8")

	if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") {
		w.Header().Set("Content-Encoding", "gzip")
		w.WriteHeader(http.StatusOK)

		writer := gzip.NewWriter(w)
		if err := pageTemplate.Execute(writer, templateRenderArg); err != nil {
			writer.Write([]byte("template render error"))
			log.Println("render: template error:", err)
		}
		writer.Close()
	} else {
		w.WriteHeader(http.StatusOK)
		if err := pageTemplate.Execute(w, templateRenderArg); err != nil {
{'fraction_non_alphanumeric': 0.12361971451656342, 'fraction_numerical': 0.004847831941826017, 'mean_word_length': 3.2156640181611804, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '863084', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1242, 'n_words': 280}