<commit_before>package leaderboard

import (
	"superstellar/backend/pb"
	"superstellar/backend/state"
	"sort"
)

const LeaderboardLength = 10

type Leaderboard struct {
	ranks []Rank
}

func LeaderboardFromSpace(space *state.Space) *Leaderboard{
	size := len(space.Spaceships)
	ranks := make([]Rank, 0, size)
	for _, stateship := range space.Spaceships {
		// TODO: change to MaxHP?
		ranks = append(ranks, Rank{stateship.ID, stateship.HP})
	}
	sort.Stable(sort.Reverse(SortableByScore(ranks)))
	return &Leaderboard{ranks: ranks}
}

// ToProto returns protobuf representation
func (leaderboard *Leaderboard) ToProto() *pb.Leaderboard {
	ranks := make([]*pb.Rank, 0, len(leaderboard.ranks))
	for _, rank := range leaderboard.ranks {
		ranks = append(ranks, rank.ToProto())<commit_msg>Use MaxHP as Score<commit_after>package leaderboard

import (
	"superstellar/backend/pb"
	"superstellar/backend/state"
	"sort"
)

const LeaderboardLength = 10

type Leaderboard struct {
	ranks []Rank
}

func LeaderboardFromSpace(space *state.Space) *Leaderboard{
	size := len(space.Spaceships)
	ranks := make([]Rank, 0, size)
	for _, stateship := range space.Spaceships {
		ranks = append(ranks, Rank{stateship.ID, stateship.MaxHP})
	}
	sort.Stable(sort.Reverse(SortableByScore(ranks)))
	return &Leaderboard{ranks: ranks}
}

// ToProto returns protobuf representation
func (leaderboard *Leaderboard) ToProto() *pb.Leaderboard {
	ranks := make([]*pb.Rank, 0, len(leaderboard.ranks))
	for _, rank := range leaderboard.ranks {
		ranks = append(ranks, rank.ToProto())
{'fraction_non_alphanumeric': 0.13454075032341525, 'fraction_numerical': 0.00517464424320828, 'mean_word_length': 5.419087136929461, 'pattern_counts': {'":': 0, '<': 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': '6119951', 'n_tokens_mistral': 567, 'n_tokens_neox': 539, 'n_words': 118}