<commit_before>package main

import (
	"bufio"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"strconv"
	"strings"
)

// Chip size of the small bet.
const _SB = 10

const wxtErr = `Error when returning from gnuplot:
If you didn't see dashed lines, you lack support for the wxt terminal.
If you saw dashed lines, something else went wrong while running gnuplot.`

func graphData() error {
	var count int
	sums  := make(map[string]int)
	index := make([]string, 0)

	in, err := os.Open(os.Args[1])
	if err != nil {
		return err
	}
	defer in.Close()
	bufin := bufio.NewReader(in)

	tmp, err := ioutil.TempFile(".", "acpcLog")
	if err != nil {
		return err
	}
	defer os.Remove(tmp.Name())
	bufout := bufio.NewWriter(tmp)

	for {
		line, err := bufin.ReadString('\n')
		if err == io.EOF {
			break
		} else if err != nil {
			return err
		}
		line = strings.TrimRight(line, "\r\n")

		if line[:len("STATE")] == "STATE" {
			state := strings.Split(line, ":")
			scores := strings.Split(state[4], "|")
			players := strings.Split(state[5], "|")
			for i, p := range players {
				score, err := strconv.Atoi(scores[i])
				if err != nil {
					return err
				}
				sums[p] += score
			}
			if count == 0 {
				for _, p := range players {
					index = append(index, p)
				}
				fmt.Fprintln(bufout, "# Players:", index)
			}
			count++
			fmt.Fprintf(bufout, "%d ", count)
			for _, p := range index {
				fmt.Fprintf(bufout, "%f ", float64(sums[p])/_SB)
			}
			fmt.Fprintln(bufout)
		}
	}
	// Plotting Code.
	gp := exec.Command("gnuplot")
	gpipe, err := gp.StdinPipe()
	if err != nil {
		return err
	}
	defer gpipe.Close()

	err = gp.Start()
	if err != nil {
		return err
	}

	// Do stuff here!
	cmd := "set t wxt dash;"
	cmd += `set xl "Hand Number";`
	cmd += `set yl "Score [SB]";`
	cmd += fmt.Sprintf(`set title "%s";`, in.Name())
	cmd += "p "
	for i, p := range index[:len(index)-1] {<commit_msg>Flush the write buffer, use ReadFile.<commit_after>package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"strconv"
	"strings"
)

// Chip size of the small bet.
const _SB = 10

const wxtErr = `Error when returning from gnuplot:
If you didn't see dashed lines, you lack support for the wxt terminal.
If you saw dashed lines, something else went wrong while running gnuplot.`

func graphData() error {
	var count int
	sums  := make(map[string]int)
	index := make([]string, 0)

	log, err := ioutil.ReadFile(os.Args[1])
	if err != nil {
		return err
	}

	tmp, err := ioutil.TempFile(".", "acpcLog")
	if err != nil {
		return err
	}
	defer os.Remove(tmp.Name())
	bufout := bufio.NewWriter(tmp)

	lines := strings.Split(string(log), "\n")
	for _, line := range lines {
		if len(line) > 4 && line[:5] == "STATE" {
			state := strings.Split(line, ":")
			scores := strings.Split(state[4], "|")
			players := strings.Split(state[5], "|")
			for i, p := range players {
				score, err := strconv.Atoi(scores[i])
				if err != nil {
					return err
				}
				sums[p] += score
			}
			if count == 0 {
				for _, p := range players {
					index = append(index, p)
				}
				fmt.Fprintln(bufout, "# Players:", index)
			}
			count++
			fmt.Fprintf(bufout, "%d ", count)
			for _, p := range index {
				fmt.Fprintf(bufout, "%f ", float64(sums[p])/_SB)
			}
			fmt.Fprintln(bufout)
		}
	}
	bufout.Flush()
	tmp.Close()
	// Plotting Code.
	gp := exec.Command("gnuplot")
	gpipe, err := gp.StdinPipe()
	if err != nil {
		return err
	}
	defer gpipe.Close()

	err = gp.Start()
	if err != nil {
		return err
	}

	// Do stuff here!
	cmd := "set t wxt dash;"
	cmd += `set xl "Hand Number";`
	cmd += `set yl "Score [SB]";`
	cmd += fmt.Sprintf(`set title "%s";`, os.Args[1])
	cmd += "p "
	for i, p := range index[:len(index)-1] {
{'fraction_non_alphanumeric': 0.17475728155339806, 'fraction_numerical': 0.006202804746494067, 'mean_word_length': 2.966844919786096, 'pattern_counts': {'":': 2, '<': 3, '<?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': '3785984', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1432, 'n_words': 404}