<commit_before>package evepraisal

import (
	"fmt"
	"log"
	"strings"
	"time"

	"github.com/evepraisal/go-evepraisal/parsers"
)

type Appraisal struct {
	ID         string `json:"id"`
	Created    int64  `json:"created"`
	Kind       string `json:"kind"`
	MarketID   int    `json:"market_id"`
	MarketName string `json:"market_name"`
	Totals     struct {
		Buy    float64 `json:"buy"`
		Sell   float64 `json:"sell"`
		Volume int64   `json:"volume"`
	} `json:"totals"`
	Items    []AppraisalItem `json:"items"`
	Raw      string          `json:"raw"`
	Unparsed map[int]string  `json:"unparsed"`
}

func StringToAppraisal(s string) (*Appraisal, error) {
	appraisal := &Appraisal{
		Created: time.Now().Unix(),
		Raw:     s,
	}

	result, unparsed := parsers.AllParser(parsers.StringToInput(s))
	appraisal.Unparsed = map[int]string(unparsed)

	kind, err := findKind(result)
	if err != nil {
		return appraisal, err
	}
	appraisal.Kind = kind

	items := parserResultToAppraisalItems(result)
	for i := 0; i < len(items); i++ {
		t, ok := TypeMap[strings.ToLower(items[i].Name)]
		if !ok {
			log.Println("WARN: parsed out name that isn't a type", items[i].Name)
			continue
		}
		items[i].TypeID = t.Type.ID
		items[i].TypeName = t.Type.Name

		prices, ok := PriceMap[t.Type.ID]
		if !ok {
			log.Println("WARN: No market data for type (%d %s)", items[i].TypeID, items[i].TypeName)
			continue
		}
		items[i].Prices = prices

		appraisal.Totals.Buy += prices.Buy.Max * float64(items[i].Quantity)
		appraisal.Totals.Sell += prices.Sell.Min * float64(items[i].Quantity)
		appraisal.Totals.Volume += prices.All.Volume * items[i].Quantity
	}
	appraisal.Items = items

	return appraisal, nil
}

type AppraisalItem struct {
	Name     string                 `json:"name"`
	TypeID   int64                  `json:"typeID"`
	TypeName string                 `json:"typeName"`
	Quantity int64                  `json:"quantity"`
	Meta     map[string]interface{} `json:"meta"`
	Prices   Prices                 `json:"prices"`
}

func (i AppraisalItem) SellTotal() float64 {
	return float64(i.Quantity) * i.Prices.Sell.Min
}<commit_msg>Fix go vet issue<commit_after>package evepraisal

import (
	"fmt"
	"log"
	"strings"
	"time"

	"github.com/evepraisal/go-evepraisal/parsers"
)

type Appraisal struct {
	ID         string `json:"id"`
	Created    int64  `json:"created"`
	Kind       string `json:"kind"`
	MarketID   int    `json:"market_id"`
	MarketName string `json:"market_name"`
	Totals     struct {
		Buy    float64 `json:"buy"`
		Sell   float64 `json:"sell"`
		Volume int64   `json:"volume"`
	} `json:"totals"`
	Items    []AppraisalItem `json:"items"`
	Raw      string          `json:"raw"`
	Unparsed map[int]string  `json:"unparsed"`
}

func StringToAppraisal(s string) (*Appraisal, error) {
	appraisal := &Appraisal{
		Created: time.Now().Unix(),
		Raw:     s,
	}

	result, unparsed := parsers.AllParser(parsers.StringToInput(s))
	appraisal.Unparsed = map[int]string(unparsed)

	kind, err := findKind(result)
	if err != nil {
		return appraisal, err
	}
	appraisal.Kind = kind

	items := parserResultToAppraisalItems(result)
	for i := 0; i < len(items); i++ {
		t, ok := TypeMap[strings.ToLower(items[i].Name)]
		if !ok {
			log.Printf("WARN: parsed out name that isn't a type: %s", items[i].Name)
			continue
		}
		items[i].TypeID = t.Type.ID
		items[i].TypeName = t.Type.Name

		prices, ok := PriceMap[t.Type.ID]
		if !ok {
			log.Printf("WARN: No market data for type (%d %s)", items[i].TypeID, items[i].TypeName)
			continue
		}
		items[i].Prices = prices

		appraisal.Totals.Buy += prices.Buy.Max * float64(items[i].Quantity)
		appraisal.Totals.Sell += prices.Sell.Min * float64(items[i].Quantity)
		appraisal.Totals.Volume += prices.All.Volume * items[i].Quantity
	}
	appraisal.Items = items

	return appraisal, nil
}

type AppraisalItem struct {
	Name     string                 `json:"name"`
	TypeID   int64                  `json:"typeID"`
	TypeName string                 `json:"typeName"`
	Quantity int64                  `json:"quantity"`
	Meta     map[string]interface{} `json:"meta"`
	Prices   Prices                 `json:"prices"`
}

func (i AppraisalItem) SellTotal() float64 {
	return float64(i.Quantity) * i.Prices.Sell.Min
}
{'fraction_non_alphanumeric': 0.14641080312722105, 'fraction_numerical': 0.009950248756218905, 'mean_word_length': 3.234704112337011, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1913218', 'n_tokens_mistral': 1657, 'n_tokens_neox': 1491, 'n_words': 328}