diff --git a/main.go b/main.go index 753ae22..5758f63 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "sort" "time" "golang.org/x/net/context" @@ -264,6 +265,33 @@ func printCharacterInformation(swaggerclient *ESI.App, m *Character) { } +type byPIPinType []*ESIPlanetaryInteraction.PinsItems0 + +func (s byPIPinType) Len() int { + return len(s) +} +func (s byPIPinType) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} +func (s byPIPinType) Less(i, j int) bool { + a := s[i] + b := s[j] + + if *a.TypeID != *b.TypeID { + return *a.TypeID < *b.TypeID + } + + if a.ExtractorDetails != nil { + return *a.ExtractorDetails.ProductTypeID < *a.ExtractorDetails.ProductTypeID + } + + if a.SchematicID > 0 { + return a.SchematicID < b.SchematicID + } + + return *a.PinID < *b.PinID +} + func printCharacterPlanets(swaggerclient *ESI.App, m *Character) { callParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsParams() @@ -307,7 +335,18 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) { continue } - for _, pin := range pesiresponse.Payload.Pins { + pins := pesiresponse.Payload.Pins + sort.Sort(byPIPinType(pins)) + + ptIds := make([]int32, 0, len(pins)) + for _, pin := range pins { + if pin.ExtractorDetails != nil { + ptIds = append(ptIds, *pin.ExtractorDetails.ProductTypeID) + } + } + pinNames := getUniverseNames(swaggerclient, &ptIds) + + for _, pin := range pins { if pin.ExtractorDetails != nil { status := fmt.Sprint(aurora.Red("✘").Bold()) statuscomment := fmt.Sprint(aurora.Red("expired").Bold()) @@ -318,9 +357,10 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) { duration = time.Time(pin.ExpiryTime).Sub(now) } - fmt.Printf(" %s Extractor % 5ds cycle, % 6d per cycle, %s %s (%02dd%02d:%02d)\n", + fmt.Printf(" %s Extractor % 5ds cycle, %s, % 6d per cycle, %s %s (%02dd%02d:%02d)\n", status, *pin.ExtractorDetails.CycleTime, + pinNames[*pin.ExtractorDetails.ProductTypeID], *pin.ExtractorDetails.QtyPerCycle, statuscomment, time.Time(pin.ExpiryTime).Format("_2 Jan 2006, 15:04"),