<commit_before>package main

import (
	"encoding/csv"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

var credit float64
var expense float64

// Record represents a single line the the file
type Record struct {
	record []string
}

func parseValue(value string) float64 {
	parsedValue := strings.Replace(value, ".", "", -1)
	parsedValue = strings.Replace(parsedValue, ",", ".", -1)
	retValue, _ := strconv.ParseFloat(parsedValue, 64)

	return retValue
}

func parseRecord(record Record) (float64, string) {

	// Columns in the file are:
	// Date of the movement, --, description, expense, credit, --, balance

	for i := 0; i < len(record.record); i++ {
		// Expense
		if i == 3 && record.record[i] != "" {
			value := parseValue(record.record[i])
			expense += value
			return value, record.record[2]
		}

		// Credit
		if i == 4 && record.record[i] != "" {
			value := parseValue(record.record[i])
			credit += value
			return value, record.record[2]
		}
	}

	return 0, ""
}

// documentation for csv is at http://golang.org/pkg/encoding/csv/
func main() {

	file, error := os.Open("comprovativo.csv")
	if error != nil {
		fmt.Println("Error:", error)
		return
	}
	defer file.Close()

	reader := csv.NewReader(file)
	reader.Comma = ';'
	reader.FieldsPerRecord = -1 // If FieldsPerRecord is negative, no check is made and records may have a variable number of fields.
	lineCount := 0

	var report map[string]float64
	report = make(map[string]float64)

	for {
		r, error := reader.Read()
		record := Record{r}
		if error == io.EOF {
			break
		}
		if error != nil {
			fmt.Println("Error:", error)
			lineCount++
			continue
		}

		if lineCount < 4 {
			lineCount++
			continue
		}

		if len(record.record) != 8 {
			lineCount++
			continue
		}

		transactionValue, transactionDescription := parseRecord(record)
		report[transactionDescription] += transactionValue
		lineCount++
	}

	for transactionDescription, transactionValue := range report {
		fmt.Printf("%24s %8.2f \n", transactionDescription, transactionValue)
	}

	fmt.Println("Expense is ", expense)
	fmt.Println("Credit is ", credit)

	// TODO: Fetch data
	// Here, i want this data
	// Initial balance
	// Final Balance
	// Expense per 'description field'
	// Total expense
	// Total credit

}<commit_msg>Adds the concept of transactions<commit_after>package main

import (
	"encoding/csv"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

var credit float64
var expense float64

// Record represents a single line the the file
type Record struct {
	record []string
}

// Transaction is a money movement
type Transaction struct {
	field       string
	description string
}

func (t *Transaction) new(record Record) *Transaction {

	for i := 0; i < len(record.record); i++ {
		t.field = record.record[i]
		t.description = record.record[2]

		// Expense
		if i == 3 && record.record[i] != "" {
			value := t.value()
			expense += value
			return t
		}

		// Credit
		if i == 4 && record.record[i] != "" {
			value := t.value()
			credit += value
			return t
		}
	}

	return t
}

func (t *Transaction) value() float64 {
	parsedField := strings.Replace(t.field, ".", "", -1)
	parsedField = strings.Replace(parsedField, ",", ".", -1)
	retValue, _ := strconv.ParseFloat(parsedField, 64)

	return retValue
}

// documentation for csv is at http://golang.org/pkg/encoding/csv/
func main() {

	file, error := os.Open("comprovativo.csv")
	if error != nil {
		fmt.Println("Error:", error)
		return
	}
	defer file.Close()

	reader := csv.NewReader(file)
	reader.Comma = ';'
	reader.FieldsPerRecord = -1 // If FieldsPerRecord is negative, no check is made and records may have a variable number of fields.
	lineCount := 0

	var report map[string]float64
	report = make(map[string]float64)

	for {
		r, error := reader.Read()
		record := Record{r}
		if error == io.EOF {
			break
		}
		if error != nil {
			fmt.Println("Error:", error)
			lineCount++
			continue
		}

		if lineCount < 4 {
			lineCount++
			continue
		}

		if len(record.record) != 8 {
			lineCount++
			continue
		}

		t := Transaction{}
		transaction := t.new(record)
		report[transaction.description] += transaction.value()
		lineCount++
	}

	for transactionDescription, transactionValue := range report {
		fmt.Printf("%24s %8.2f \n", transactionDescription, transactionValue)
	}

	fmt.Println("Expense is ", expense)
	fmt.Println("Credit is ", credit)

	// TODO: Fetch data
	// Here, i want this data
	// Initial balance
	// Final Balance
	// Expense per 'description field'
	// Total expense
	// Total credit

}
{'fraction_non_alphanumeric': 0.1409915891987605, 'fraction_numerical': 0.01239486498450642, 'mean_word_length': 3.2834123222748817, 'pattern_counts': {'":': 0, '<': 7, '<?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': '687509', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1498, 'n_words': 428}