This repository has been archived on 2021-09-02. You can view files and clone it, but cannot push or open issues or pull requests.
my-bloody-hetzner-sb-notifier/hetzner/types.go
Mahmoud Rahbar Azad 66001f861f
Initial commit.
Example output:
Got 580 offers. Filtered offers: 3
           ID|     Ram|             HDD|                           CPU|    Price|   Score|  Reduce time|Specials
  SB57-931121|  128 GB|  2x 2 TB (4096)|  Intel Xeon E5-1650V2 (12518)|  57.00 €|  103.12|      53h 53m|ECC, Ent. HDD, iNIC
  SB69-927780|  128 GB|  2x 2 TB (4096)|  Intel Xeon E5-1650V3 (13335)|  69.00 €|   89.92|      49h 39m|ECC, Ent. HDD, iNIC
  SB76-910394|  128 GB|  3x 2 TB (6144)|  Intel Xeon E5-1650V2 (12518)|  76.00 €|   82.73|      01h 21m|ECC, Ent. HDD, iNIC
2018-10-22 23:55:29 +02:00

75 lines
2.1 KiB
Go

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"`
Bandwith int `json:"bandwith"`
Price string `json:"price"`
Price_v string `json:"price_v"`
Setup_price string `json:"setup_price"`
Cpu string `json:"cpu"`
Cpu_benchmark int `json:"cpu_benchmark"`
Cpu_count int `json:"cpu_count"`
Ram int `json:"ram"`
Ram_hr string `json:"ram_hr"`
Hdd_size int `json:"hdd_size"`
Hdd_hr string `json:"hdd_hr"`
Hdd_count int `json:"hdd_count"`
SpecialHdd string `json:"specialHdd"`
Next_reduce int `json:"next_reduce"`
Next_reduce_hr string `json:"next_reduce_hr"`
Fixed_price bool `json:"fixed_price"`
Is_highio bool `json:"is_highio"`
Is_ecc bool `json:"is_ecc"`
}
func (s *Server) TotalHdd() int {
return s.Hdd_count*s.Hdd_size
}
func (s *Server) Score() float64 {
return (float64(s.TotalHdd())*0.2 + float64(s.Ram)*0.4 + float64(s.Cpu_benchmark)*0.4)/s.ParsePrice()
}
func (s *Server) ParsePrice() float64 {
priceParsed, err := strconv.ParseFloat(s.Price, 32)
if err != nil {
fmt.Printf("Could not parse price %s for server %s: %s", s.Price, s.Key, err)
return -1
}
return priceParsed*1.19
}
func (s *Server) Header() string {
return fmt.Sprint("ID\tRam\tHDD\tCPU\tPrice\tScore\tReduce time\tSpecials")
}
func (s *Server) ToString() string {
fixedPriceSymbol := "*"
if !s.Fixed_price {
fixedPriceSymbol = ""
}
specials := strings.Join(s.Specials, ", ")
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.Ram_hr, s.Hdd_hr, s.TotalHdd(), s.Cpu, s.Cpu_benchmark, s.ParsePrice(), fixedPriceSymbol, s.Score(), s.Next_reduce_hr, specials)
}