<commit_before>package matches

import (
	"errors"
	"fmt"
	"net/url"
	"strconv"
	"time"

	"github.com/coltiebaby/glaw"
)

// Match Filter will help you sort through match history.
// To get a list of the IDs, you'll need to look at the [constants](*url)  supports
//
// url: https://developer.games.com/game-constants.html
type MatchFilter struct {
	Client glaw.ApiClient

	AccountID string
	Start     time.Time
	End       time.Time
	Champions []int
	Queues    []int
	Seasons   []int

	maxResults int
	page       int

	totalResults int
	begin        int
	end          int
}

func (filter *MatchFilter) Debug() {
	fmt.Printf("%+v\n", filter)
}

func getIndex(max, page int) (begin int, end int) {
	end = (page * max)
	begin = (end - max) + 1

	return begin, end
}

func NewMatchFilter(c glaw.ApiClient, start, end time.Time) (filter *MatchFilter) {
	filter = &MatchFilter{Client: c}

	filter.Start = start
	filter.End = end

	filter.SetMaxResults(20)

	return filter
}

// Confirm results are between 1 - 100
// TODO: log that we changes the result to something else
func (filter *MatchFilter) SetMaxResults(results int) {
	switch {
	case results <= 0:
		results = 1
	case results > 100:
		results = 100
	}

	filter.page = 0
	filter.maxResults = results
	filter.totalResults = results
}

func (filter *MatchFilter) Next() (matches MatchStorage, err error) {
	page := filter.page
	page++

	begin, end := getIndex(filter.maxResults, page)
	fmt.Println(begin, end)

	if begin > filter.totalResults {
		return matches, MaxResultsError
	} else {
		filter.page = page
	}

	filter.begin, filter.end = begin, end

	matches, err = GetMatchlists(filter.Client, filter.AccountID, filter.CreateValues())
	filter.totalResults = matches.TotalGames
	return matches, err
}

func (filter *MatchFilter) Prev() (matches MatchStorage, err error) {
	page := filter.page

	if page <= 1 {
		return matches, MinResultsError
	}

	page--
	filter.begin, filter.end = getIndex(filter.maxResults, page)
	filter.page = page

	matches, err = GetMatchlists(filter.Client, filter.AccountID, filter.CreateValues())
	filter.totalResults = matches.TotalGames
	return matches, err
}

func (filter *MatchFilter) GoTo(page int) (matches MatchStorage, err error) {
	wanted := (page-1)*filter.maxResults + 1
	if page < 1 || wanted > filter.totalResults {
		return matches, InvalidPageError
	}

	filter.begin, filter.end = getIndex(filter.maxResults, page)
	filter.page = page

	matches, err = GetMatchlists(filter.Client, filter.AccountID, filter.CreateValues())
	filter.totalResults = matches.TotalGames
	return matches, err
}

func (filter *MatchFilter) CreateValues() url.Values {
	params := url.Values{}

	add(&params, `champion`, filter.Champions)
	add(&params, `queue`, filter.Queues)
	add(&params, `season`, filter.Seasons)

	params.Add(`startIndex`, strconv.Itoa(filter.begin))
	params.Add(`endIndex`, strconv.Itoa(filter.end))

	// TODO: Not sure why these aren't working
	// from := timeToUnixMS(filter.Start)
	// to := timeToUnixMS(filter.End)

	// params.Add(`beginTime`, strconv.FormatInt(from, 10))
	// params.Add(`endTime`, strconv.FormatInt(to, 10))

	return params
}<commit_msg>filtering if nothing is added (#29)<commit_after>package matches

import (
	"errors"
	"fmt"
	"net/url"
	"strconv"
	"time"

	"github.com/coltiebaby/glaw"
)

// Match Filter will help you sort through match history.
// To get a list of the IDs, you'll need to look at the [constants](*url)  supports
//
// url: https://developer.games.com/game-constants.html
type MatchFilter struct {
	Client glaw.ApiClient

	AccountID string
	Start     time.Time
	End       time.Time
	Champions []int
	Queues    []int
	Seasons   []int

	maxResults int
	page       int

	totalResults int
	begin        int
	end          int
}

func (filter *MatchFilter) Debug() {
	fmt.Printf("%+v\n", filter)
}

func getIndex(max, page int) (begin int, end int) {
	end = (page * max)
	begin = (end - max) + 1

	return begin, end
}

func NewMatchFilter(c glaw.ApiClient, start, end time.Time) (filter *MatchFilter) {
	filter = &MatchFilter{Client: c}

	filter.Start = start
	filter.End = end

	filter.SetMaxResults(20)

	return filter
}

// Confirm results are between 1 - 100
// TODO: log that we changes the result to something else
func (filter *MatchFilter) SetMaxResults(results int) {
	switch {
	case results <= 0:
		results = 1
	case results > 100:
		results = 100
	}

	filter.page = 0
	filter.maxResults = results
	filter.totalResults = results
}

func (filter *MatchFilter) Next() (matches MatchStorage, err error) {
	page := filter.page
	page++

	begin, end := getIndex(filter.maxResults, page)
	fmt.Println(begin, end)

	if begin > filter.totalResults {
		return matches, MaxResultsError
	} else {
		filter.page = page
	}

	filter.begin, filter.end = begin, end

	matches, err = GetMatchlists(filter.Client, filter.AccountID, filter.CreateValues())
	filter.totalResults = matches.TotalGames
	return matches, err
}

func (filter *MatchFilter) Prev() (matches MatchStorage, err error) {
	page := filter.page

	if page <= 1 {
		return matches, MinResultsError
	}

	page--
	filter.begin, filter.end = getIndex(filter.maxResults, page)
	filter.page = page

	matches, err = GetMatchlists(filter.Client, filter.AccountID, filter.CreateValues())
	filter.totalResults = matches.TotalGames
	return matches, err
}

func (filter *MatchFilter) GoTo(page int) (matches MatchStorage, err error) {
	wanted := (page-1)*filter.maxResults + 1
	if page < 1 || wanted > filter.totalResults {
		return matches, InvalidPageError
	}

	filter.begin, filter.end = getIndex(filter.maxResults, page)
	filter.page = page

	matches, err = GetMatchlists(filter.Client, filter.AccountID, filter.CreateValues())
	filter.totalResults = matches.TotalGames
	return matches, err
}

func (filter *MatchFilter) CreateValues() url.Values {
	params := url.Values{}

	if len(filter.Champions) > 0 {
		add(&params, `champion`, filter.Champions)
	}

	if len(filter.Queues) > 0 {
		add(&params, `queue`, filter.Queues)
	}

	if len(filter.Seasons) > 0 {
		add(&params, `season`, filter.Seasons)
	}

	if filter.begin != 0 && filter.end != 0 {
		params.Add(`startIndex`, strconv.Itoa(filter.begin))
		params.Add(`endIndex`, strconv.Itoa(filter.end))
	}

	// TODO: Not sure why these aren't working
	// from := timeToUnixMS(filter.Start)
	// to := timeToUnixMS(filter.End)

	// params.Add(`beginTime`, strconv.FormatInt(from, 10))
	// params.Add(`endTime`, strconv.FormatInt(to, 10))

	return params
}
{'fraction_non_alphanumeric': 0.12575219873476315, 'fraction_numerical': 0.008486344699891991, 'mean_word_length': 3.933028919330289, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 2, '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': '6791144', 'n_tokens_mistral': 2273, 'n_tokens_neox': 2152, 'n_words': 599}