2018-10-22 23:55:29 +02:00
|
|
|
package hetzner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Offers struct {
|
|
|
|
Server []Server `json:"server"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Server struct {
|
|
|
|
Key int `json:"key"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Freetext string `json:"freetext"`
|
|
|
|
Description []string `json:"description"`
|
|
|
|
Dist []string `json:"dist"`
|
|
|
|
Datacenter []string `json:"datacenter"`
|
|
|
|
Specials []string `json:"specials"`
|
|
|
|
Traffic string `json:"traffic"`
|
2018-10-25 21:18:45 +02:00
|
|
|
Bandwidth int `json:"bandwith"`
|
2018-10-22 23:55:29 +02:00
|
|
|
|
2018-10-25 21:18:45 +02:00
|
|
|
Price string `json:"price"`
|
|
|
|
PriceV string `json:"price_v"`
|
|
|
|
SetupPrice string `json:"setup_price"`
|
2018-10-22 23:55:29 +02:00
|
|
|
|
2018-10-25 21:18:45 +02:00
|
|
|
Cpu string `json:"cpu"`
|
|
|
|
CpuBenchmark int `json:"cpu_benchmark"`
|
|
|
|
CpuCount int `json:"cpu_count"`
|
|
|
|
Ram int `json:"ram"`
|
|
|
|
RamHr string `json:"ram_hr"`
|
|
|
|
HddSize int `json:"hdd_size"`
|
|
|
|
HddHr string `json:"hdd_hr"`
|
|
|
|
HddCount int `json:"hdd_count"`
|
|
|
|
SpecialHdd string `json:"specialHdd"`
|
2018-10-22 23:55:29 +02:00
|
|
|
|
2018-10-25 21:18:45 +02:00
|
|
|
NextReduce int `json:"next_reduce"`
|
|
|
|
NextReduceHr string `json:"next_reduce_hr"`
|
2018-10-22 23:55:29 +02:00
|
|
|
|
2018-10-25 21:18:45 +02:00
|
|
|
FixedPrice bool `json:"fixed_price"`
|
|
|
|
IsHighio bool `json:"is_highio"`
|
|
|
|
IsEcc bool `json:"is_ecc"`
|
2018-10-22 23:55:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) TotalHdd() int {
|
2018-10-25 21:18:45 +02:00
|
|
|
return s.HddCount * s.HddSize
|
2018-10-22 23:55:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) Score() float64 {
|
2018-10-25 21:18:45 +02:00
|
|
|
return (float64(s.TotalHdd())*0.2 + float64(s.Ram)*0.4 + float64(s.CpuBenchmark)*0.4) / s.ParsePrice()
|
2018-10-22 23:55:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) ParsePrice() float64 {
|
|
|
|
priceParsed, err := strconv.ParseFloat(s.Price, 32)
|
|
|
|
if err != nil {
|
2018-10-25 21:18:45 +02:00
|
|
|
fmt.Printf("Could not parse price %s for server %d: %s", s.Price, s.Key, err)
|
2018-10-22 23:55:29 +02:00
|
|
|
return -1
|
|
|
|
}
|
2018-10-25 21:18:45 +02:00
|
|
|
return priceParsed * 1.19
|
2018-10-22 23:55:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) Header() string {
|
|
|
|
return fmt.Sprint("ID\tRam\tHDD\tCPU\tPrice\tScore\tReduce time\tSpecials")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) ToString() string {
|
|
|
|
fixedPriceSymbol := "*"
|
2018-10-25 21:18:45 +02:00
|
|
|
if !s.FixedPrice {
|
2018-10-22 23:55:29 +02:00
|
|
|
fixedPriceSymbol = ""
|
|
|
|
}
|
|
|
|
specials := strings.Join(s.Specials, ", ")
|
2018-10-25 21:18:45 +02:00
|
|
|
return fmt.Sprintf("%s-%d\t%s\t%s (%d)\t%s (%d)\t%.2f €%s\t%.2f\t%s\t%s", s.Name, s.Key, s.RamHr, s.HddHr, s.TotalHdd(), s.Cpu, s.CpuBenchmark, s.ParsePrice(), fixedPriceSymbol, s.Score(), s.NextReduceHr, specials)
|
2018-10-22 23:55:29 +02:00
|
|
|
}
|