Select Git revision
steel.go
-
Gomez Goiri, Aitor authored
Redefining asset-archive operation functionality.
Gomez Goiri, Aitor authoredRedefining asset-archive operation functionality.
steel.go 1.84 KiB
/**
* steel.go
*
* COPYRIGHT: FUNDACIÓN TECNALIA RESEARCH & INNOVATION, 2022.
*/
package stats
// Refined stats which will be returned
type SteelStats struct {
TotalSlag float64 `json:"total"` // in tons
Reused PercentageMetric `json:"reused"`
Discarded PercentageMetric `json:"discarded"`
SoldBatch float64 `json:"sold"` // in t/sold batch
Price SummaryMetric `json:"price"` // in t/€
}
// Raw stored stats (per steel company)
type RawSteelOrgStats struct {
RawStats
SlagReused float64 `json:"reused"` // in tons
SlagDiscarded float64 `json:"discarded"` // in tons
}
func (raw *RawSteelOrgStats) RegisterSlag(quantity uint32, units string) {
raw.TotalSlag += toTons(quantity, units)
}
func (raw *RawSteelOrgStats) RegisterDiscard(quantity uint32, units string) {
raw.SlagDiscarded += toTons(quantity, units)
}
func (raw *RawSteelOrgStats) UpgradeSale(quantity uint32, price float32, units string) {
soldBatch := toTons(quantity, units)
raw.SlagReused += soldBatch
raw.TotalPrice += float64(price)
raw.SoldBatches += 1
convertedPrice := float64(price) / soldBatch
if convertedPrice < raw.MinPrice {
raw.MinPrice = convertedPrice
}
if raw.MaxPrice < convertedPrice {
raw.MaxPrice = convertedPrice
}
}
func (raw *RawSteelOrgStats) RefineStats() (*SteelStats) {
ret := new(SteelStats)
ret.TotalSlag = raw.TotalSlag
ret.Reused.Total = raw.SlagReused
if ret.TotalSlag > 0 && ret.Reused.Total > 0 {
ret.Reused.Percentage = ret.Reused.Total / ret.TotalSlag
}
ret.Discarded.Total = raw.SlagDiscarded
if ret.TotalSlag > 0 && ret.Discarded.Total > 0 {
ret.Discarded.Percentage = ret.Discarded.Total / ret.TotalSlag
}
ret.SoldBatch = ret.TotalSlag / float64(raw.SoldBatches)
ret.Price.Minimum = raw.MinPrice
ret.Price.Maximum = raw.MaxPrice
if raw.TotalSlag > 0 {
ret.Price.Average = raw.TotalPrice / raw.TotalSlag
}
return ret
}