<commit_before>package main

import (
	"log"
	"net/http"
	"sort"
	"strconv"
	"time"
)

type numFreq struct {
	num  int
	freq int
}

type sortByFreq []numFreq

func (b sortByFreq) Len() int           { return len(b) }
func (b sortByFreq) Swap(i, j int)      { b[i], b[j] = b[j], b[i] }
func (b sortByFreq) Less(i, j int) bool { return b[i].freq < b[j].freq }

func params(r *http.Request) queryParams {
	var (
		p        = r.URL.Query()
		set, _   = strconv.Atoi(p["set"][0])
		start, _ = time.Parse(time.RFC3339, p["start"][0])
		end, _   = time.Parse(time.RFC3339, p["end"][0])
	)
	return queryParams{
		Start:   start,
		End:     end,
		Set:     set,
		Machine: p["machine"][0],
	}
}

func createMainTableData(p queryParams) []TableRow {
	var (
		sBalls, sBonus = getSortedResultsByFreq(p)
		most, least    = getMostAndleast(sBalls, sBonus)
	)

	last, err := db.getLastDraw()
	if err != nil {
		log.Println(err)
	}

	return []TableRow{
		TableRow{
			Label: "Last Draw",
			Num:   last,
		},
		TableRow{
			Label: "Most Frequent",
			Num:   most,
		},
		TableRow{
			Label: "Least Frequent",
			Num:   least,
		},
		TableRow{
			Label: "Random Set",
			Num:   drawRandomSet(),
		},
	}
}

func getMostAndleast(sBalls, sBonus sortByFreq) (most, least []int) {
	// most = first 6 and least = last non-zero 6
	for i, j := 0, len(sBalls)-1; i < j; i, j = i+1, j-1 {
		if sBalls[i].num != 0 && len(most) < 6 {
			most = append(most, sBalls[i].num)
		}
		if sBalls[j].num != 0 && len(least) < 6 {
			least = append(least, sBalls[j].num)
		}
		if len(most) == 6 && len(least) == 6 {
			break
		}
	}
<commit_msg>label change<commit_after>package main

import (
	"log"
	"net/http"
	"sort"
	"strconv"
	"time"
)

type numFreq struct {
	num  int
	freq int
}

type sortByFreq []numFreq

func (b sortByFreq) Len() int           { return len(b) }
func (b sortByFreq) Swap(i, j int)      { b[i], b[j] = b[j], b[i] }
func (b sortByFreq) Less(i, j int) bool { return b[i].freq < b[j].freq }

func params(r *http.Request) queryParams {
	var (
		p        = r.URL.Query()
		set, _   = strconv.Atoi(p["set"][0])
		start, _ = time.Parse(time.RFC3339, p["start"][0])
		end, _   = time.Parse(time.RFC3339, p["end"][0])
	)
	return queryParams{
		Start:   start,
		End:     end,
		Set:     set,
		Machine: p["machine"][0],
	}
}

func createMainTableData(p queryParams) []TableRow {
	var (
		sBalls, sBonus = getSortedResultsByFreq(p)
		most, least    = getMostAndleast(sBalls, sBonus)
	)

	last, err := db.getLastDraw()
	if err != nil {
		log.Println(err)
	}

	return []TableRow{
		TableRow{
			Label: "Most Recent",
			Num:   last,
		},
		TableRow{
			Label: "Most Frequent",
			Num:   most,
		},
		TableRow{
			Label: "Least Frequent",
			Num:   least,
		},
		TableRow{
			Label: "Random Set",
			Num:   drawRandomSet(),
		},
	}
}

func getMostAndleast(sBalls, sBonus sortByFreq) (most, least []int) {
	// most = first 6 and least = last non-zero 6
	for i, j := 0, len(sBalls)-1; i < j; i, j = i+1, j-1 {
		if sBalls[i].num != 0 && len(most) < 6 {
			most = append(most, sBalls[i].num)
		}
		if sBalls[j].num != 0 && len(least) < 6 {
			least = append(least, sBalls[j].num)
		}
		if len(most) == 6 && len(least) == 6 {
			break
		}
	}

{'fraction_non_alphanumeric': 0.1737776393646839, 'fraction_numerical': 0.01494861413889754, 'mean_word_length': 2.8980582524271843, 'pattern_counts': {'":': 0, '<': 11, '<?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': '757640', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1385, 'n_words': 327}