Esempio n. 1
0
func Daj(in *os.File) Wyniki {
	defer in.Close()
	gocsv.SetCSVReader(func(in io.Reader) *csv.Reader {
		read := gocsv.DefaultCSVReader(in)
		read.TrimLeadingSpace = true
		return read
	})
	lista := make(wynikiCSV, 0, 50)
	if err := gocsv.UnmarshalFile(in, &lista); err != nil {
		panic(err)
	}
	return lista.Wyniki()
}
Esempio n. 2
0
func openDB() map[string]int {
	if _, err := os.Stat(dbFilePath); err != nil {
		return make(map[string]int)
	}

	list := CmdList{}
	file, _ := os.Open(dbFilePath)
	if err := gocsv.UnmarshalFile(file, &list); err != nil {
		panic(err)
	}

	itemSet := make(map[string]int)
	for _, item := range list {
		itemSet[item.Cmd] = item.Count
	}
	return itemSet
}
Esempio n. 3
0
func main() {
	flag.Parse()
	if ok := checkFlags(); !ok {
		fmt.Println("One or more required flags were missing...")
		flag.PrintDefaults()
		return
	}

	if *team1 != "" && *team2 != "" {
		//Print markup for team names
		teamRank1 := matcher.TeamRank{Name: *team1}
		teamRank2 := matcher.TeamRank{Name: *team2}
		//match group with one empty match
		fakeMatch := []matcher.MatchGroup{{}}
		fakeMatch[0].Teams[0] = teamRank1
		fakeMatch[0].Teams[1] = teamRank2
		fakeMatch[0].N = 2

		fmt.Println("<----------REDDIT FORMAT---------->\n")
		PrintMatchesReddit(fakeMatch)
		fmt.Println("<----------ORSA FORMAT---------->\n")
		PrintMatchesORSA(fakeMatch)
		fmt.Println("\n\n<----------PLAIN GROUPS FORMAT---------->\n")
		PrintMatchesFlat(fakeMatch)

		return
	}

	rankFile, err := os.Open(*rankFileName)
	if err != nil {
		panic(err)
	}
	defer rankFile.Close()

	ranks := &matcher.RankedList{}
	heap.Init(ranks)

	unsortedRanks := []*matcher.TeamRank{}
	if err := gocsv.UnmarshalFile(rankFile, &unsortedRanks); err != nil {
		panic(err)
	}

	for _, r := range unsortedRanks {
		heap.Push(ranks, *r)
	}

	groups := readGroups(groupsFileName)
	matches := []matcher.MatchGroup{}

	maxAttempts := 11
	attemptNum := 1
	leftoverTeams := []matcher.TeamRank{}
	matches = MakeMatches(matches, []matcher.TeamRank{}, ranks, groups)
	for ranks.Len() > 1 && attemptNum < maxAttempts {
		//move leftover teams into an interleave group
		for ranks.Len() > 0 {
			leftoverTeams = append(leftoverTeams, heap.Pop(ranks).(matcher.TeamRank))
		}

		//disband a number of teams
		for i := 0; i < attemptNum; i++ {
			if len(matches) > 0 {
				DisbandMatch(matches[len(matches)-1], ranks)
				matches = matches[:len(matches)-1]
			}
		}
		fmt.Printf("%d leftover, %d pool\n", len(leftoverTeams), ranks.Len())
		matches = MakeMatches(matches, leftoverTeams, ranks, groups)

		leftoverTeams = []matcher.TeamRank{}
		attemptNum++
	}

	if ranks.Len() == 1 {
		//Add the odd man out to the first available match
		PlaceExtraTeam(&matches, ranks, groups)
	} else if ranks.Len() > 1 {
		fmt.Println("Attempts ran out, and we weren't able to group everyone :(")
	}

	fmt.Println("<----------REDDIT FORMAT---------->\n")
	PrintMatchesReddit(matches)
	fmt.Println("<----------ORSA FORMAT---------->\n")
	PrintMatchesORSA(matches)
	fmt.Println("\n\n<----------PLAIN GROUPS FORMAT---------->\n")
	PrintMatchesFlat(matches)
	fmt.Println("\n\n<----------RESULTS---------->\n")
	fmt.Printf("%d matches, %d teams left over\n\n", len(matches), ranks.Len())
}