<commit_before>package hostdb

import (
	"math/big"

	"github.com/NebulousLabs/Sia/types"
)

var (
	// Because most weights would otherwise be fractional, we set the base
	// weight to 10^80 to give ourselves lots of precision when determing the
	// weight of a host
	baseWeight = types.NewCurrency(new(big.Int).Exp(big.NewInt(10), big.NewInt(150), nil))
)

// calculateHostWeight returns the weight of a host according to the settings of
// the host database entry. Currently, only the price is considered.
func calculateHostWeight(entry hostEntry) (weight types.Currency) {
	// If the price is 0, just return the base weight to avoid divide by zero.
	price := entry.StoragePrice
	if price.IsZero() {
		return baseWeight
	}

	// Divide the base weight by the price to the fifth power.
	return baseWeight.Div(price).Div(price).Div(price).Div(price).Div(price)
}<commit_msg>include contract & bandwidth price in calculateHostWeight<commit_after>package hostdb

import (
	"math/big"

	"github.com/NebulousLabs/Sia/types"
)

var (
	// Because most weights would otherwise be fractional, we set the base
	// weight to 10^150 to give ourselves lots of precision when determing the
	// weight of a host
	baseWeight = types.NewCurrency(new(big.Int).Exp(big.NewInt(10), big.NewInt(150), nil))
)

// calculateHostWeight returns the weight of a host according to the settings of
// the host database entry. Currently, only the price is considered.
func calculateHostWeight(entry hostEntry) (weight types.Currency) {
	// In the weighted price, the download bandwidth price is multiplied by
	// numDownloads, which is our guess at the median number of downloads per
	// file (some files may go untouched, but others may be requested
	// many times).
	const numDownloads = uint64(50)
	price := entry.StoragePrice.Add(entry.ContractPrice).Add(entry.UploadBandwidthPrice).Add(entry.DownloadBandwidthPrice.Mul64(numDownloads))

	// If the price is 0, just return the base weight to avoid divide by zero.
	if price.IsZero() {
		return baseWeight
	}

	// Divide the base weight by the price to the fifth power.
	return baseWeight.Div(price).Div(price).Div(price).Div(price).Div(price)
}
{'fraction_non_alphanumeric': 0.09455719557195572, 'fraction_numerical': 0.012453874538745387, 'mean_word_length': 4.2773722627737225, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3205340', 'n_tokens_mistral': 664, 'n_tokens_neox': 632, 'n_words': 240}