From 4cdd126e394a747a103fd6e6dc66f1fd89a0e5b7 Mon Sep 17 00:00:00 2001 From: Simon Tucker Date: Tue, 1 Jan 2019 23:15:00 -0800 Subject: [PATCH] Adds enum, stats of count --- proto/wantslist.pb.go | 85 +++++++++++++++++++++++++++++++------------ proto/wantslist.proto | 10 ++++- wantslist.go | 18 +++++++++ 3 files changed, 88 insertions(+), 25 deletions(-) diff --git a/proto/wantslist.pb.go b/proto/wantslist.pb.go index 1dcafbf..44a5034 100644 --- a/proto/wantslist.pb.go +++ b/proto/wantslist.pb.go @@ -22,6 +22,31 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package +type WantListEntry_Status int32 + +const ( + WantListEntry_UNPROCESSED WantListEntry_Status = 0 + WantListEntry_WANTED WantListEntry_Status = 1 +) + +var WantListEntry_Status_name = map[int32]string{ + 0: "UNPROCESSED", + 1: "WANTED", +} + +var WantListEntry_Status_value = map[string]int32{ + "UNPROCESSED": 0, + "WANTED": 1, +} + +func (x WantListEntry_Status) String() string { + return proto.EnumName(WantListEntry_Status_name, int32(x)) +} + +func (WantListEntry_Status) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_c74c703880358ab0, []int{1, 0} +} + type Config struct { Lists []*WantList `protobuf:"bytes,1,rep,name=lists,proto3" json:"lists,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -62,11 +87,12 @@ func (m *Config) GetLists() []*WantList { } type WantListEntry struct { - Want int32 `protobuf:"varint,1,opt,name=want,proto3" json:"want,omitempty"` - Index int32 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Want int32 `protobuf:"varint,1,opt,name=want,proto3" json:"want,omitempty"` + Index int32 `protobuf:"varint,2,opt,name=index,proto3" json:"index,omitempty"` + Status WantListEntry_Status `protobuf:"varint,3,opt,name=status,proto3,enum=wantslist.WantListEntry_Status" json:"status,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *WantListEntry) Reset() { *m = WantListEntry{} } @@ -108,6 +134,13 @@ func (m *WantListEntry) GetIndex() int32 { return 0 } +func (m *WantListEntry) GetStatus() WantListEntry_Status { + if m != nil { + return m.Status + } + return WantListEntry_UNPROCESSED +} + type WantList struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Wants []*WantListEntry `protobuf:"bytes,2,rep,name=wants,proto3" json:"wants,omitempty"` @@ -296,6 +329,7 @@ func (m *GetWantListResponse) GetLists() []*WantList { } func init() { + proto.RegisterEnum("wantslist.WantListEntry_Status", WantListEntry_Status_name, WantListEntry_Status_value) proto.RegisterType((*Config)(nil), "wantslist.Config") proto.RegisterType((*WantListEntry)(nil), "wantslist.WantListEntry") proto.RegisterType((*WantList)(nil), "wantslist.WantList") @@ -308,25 +342,28 @@ func init() { func init() { proto.RegisterFile("wantslist.proto", fileDescriptor_c74c703880358ab0) } var fileDescriptor_c74c703880358ab0 = []byte{ - // 276 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0x4d, 0x4b, 0xc3, 0x40, - 0x10, 0x6d, 0x5a, 0x53, 0xec, 0x04, 0x11, 0x26, 0x15, 0x16, 0x41, 0x29, 0x0b, 0x42, 0xbd, 0xe4, - 0xd0, 0x9e, 0xc4, 0x8b, 0x22, 0xe2, 0x45, 0x7a, 0x88, 0x07, 0xcf, 0xd1, 0x1d, 0x65, 0x41, 0x37, - 0x35, 0x3b, 0x7e, 0xfd, 0x28, 0xff, 0xa3, 0xec, 0xc4, 0xd6, 0xc4, 0xb6, 0x07, 0x6f, 0x93, 0x37, - 0xef, 0xbd, 0x79, 0x2f, 0x2c, 0xec, 0xbe, 0x17, 0x8e, 0xfd,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4c, - 0x77, 0xee, 0xfa, 0xf2, 0x5a, 0xa6, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x87, 0x08, 0x5e, 0x1f, - 0x40, 0x02, 0x00, 0x00, + // 330 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0x4d, 0x4f, 0xc2, 0x30, + 0x18, 0xa6, 0xe0, 0x16, 0x79, 0x17, 0x85, 0xbc, 0x60, 0xd2, 0x98, 0xa8, 0xa4, 0x09, 0x09, 0x5e, + 0x76, 0x80, 0x83, 0x07, 0x2f, 0x12, 0x58, 0xbc, 0x98, 0x69, 0x3a, 0x0d, 0xe7, 0xe9, 0xaa, 0x59, + 0xa2, 0x1d, 0xd2, 0xe2, 0xc7, 0x4f, 0xf1, 0x47, 0xf8, 0x1f, 0x4d, 0x3b, 0x40, 0x26, 0xec, 0xe0, + 0xad, 0x7b, 0xfa, 0xbc, 0xcf, 0xc7, 0xbb, 0x42, 0xe3, 0x3d, 0x96, 0x5a, 0x3d, 0xa7, 0x4a, 0xfb, + 0xd3, 0x59, 0xa6, 0x33, 0xac, 0xaf, 0x00, 0x36, 0x00, 0x77, 0x94, 0xc9, 0xc7, 0xf4, 0x09, 0x4f, + 0xc1, 0x31, 0x88, 0xa2, 0xa4, 0x53, 0xeb, 0x79, 0xfd, 0x96, 0xff, 0x3b, 0x35, 0x89, 0xa5, 0xbe, + 0x4a, 0x95, 0xe6, 0x39, 0x83, 0x7d, 0x11, 0xd8, 0x5b, 0x62, 0x81, 0xd4, 0xb3, 0x4f, 0x44, 0xd8, + 0x31, 0x74, 0x4a, 0x3a, 0xa4, 0xe7, 0x70, 0x7b, 0xc6, 0x36, 0x38, 0xa9, 0x4c, 0xc4, 0x07, 0xad, + 0x5a, 0x30, 0xff, 0xc0, 0x33, 0x70, 0x95, 0x8e, 0xf5, 0x5c, 0xd1, 0x5a, 0x87, 0xf4, 0xf6, 0xfb, + 0x27, 0x5b, 0x7c, 0xac, 0xa6, 0x1f, 0x59, 0x1a, 0x5f, 0xd0, 0x59, 0x17, 0xdc, 0x1c, 0xc1, 0x06, + 0x78, 0x77, 0xe1, 0x0d, 0xbf, 0x1e, 0x05, 0x51, 0x14, 0x8c, 0x9b, 0x15, 0x04, 0x70, 0x27, 0xc3, + 0xf0, 0x36, 0x18, 0x37, 0x09, 0x0b, 0x61, 0x77, 0x29, 0x63, 0x52, 0xc9, 0xf8, 0x45, 0xd8, 0x54, + 0x75, 0x6e, 0xcf, 0xe8, 0x83, 0x63, 0x0d, 0x69, 0xd5, 0xd6, 0xa4, 0x65, 0xf6, 0x3c, 0xa7, 0xb1, + 0x73, 0xc0, 0x61, 0x92, 0xac, 0x36, 0x20, 0x5e, 0xe7, 0x42, 0x69, 0xec, 0x42, 0x2d, 0x4e, 0x12, + 0x2b, 0x5c, 0xb2, 0x2a, 0x73, 0xcf, 0x0e, 0xa0, 0x55, 0x18, 0x56, 0xd3, 0x4c, 0x2a, 0xc1, 0xda, + 0x80, 0x97, 0x42, 0xff, 0xd1, 0x64, 0x17, 0xd0, 0x2a, 0xa0, 0x39, 0xf9, 0x1f, 0xff, 0xa5, 0xff, + 0x4d, 0xc0, 0x33, 0x58, 0x24, 0x66, 0x6f, 0xe9, 0x83, 0xc0, 0x10, 0xbc, 0x35, 0x7b, 0x3c, 0x5a, + 0x1b, 0xdd, 0xec, 0x74, 0x78, 0x5c, 0x76, 0xbd, 0x48, 0x5d, 0x31, 0x7a, 0x6b, 0x09, 0x0b, 0x7a, + 0x9b, 0x7d, 0x0a, 0x7a, 0x5b, 0x8a, 0xb1, 0xca, 0xbd, 0x6b, 0x9f, 0xe3, 0xe0, 0x27, 0x00, 0x00, + 0xff, 0xff, 0xb0, 0x0d, 0xe1, 0xd4, 0xa1, 0x02, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/proto/wantslist.proto b/proto/wantslist.proto index 7f5c6b4..c12ad27 100644 --- a/proto/wantslist.proto +++ b/proto/wantslist.proto @@ -8,7 +8,15 @@ message Config { message WantListEntry { int32 want = 1; - int32 index = 2; + int32 index = 2; + + enum Status { + UNPROCESSED = 0; + WANTED = 1; + IN_COLLECTION = 2; + } + + Status status = 3; } message WantList { diff --git a/wantslist.go b/wantslist.go index bb2eece..7639e8b 100644 --- a/wantslist.go +++ b/wantslist.go @@ -73,8 +73,26 @@ func (s *Server) Mote(ctx context.Context, master bool) error { // GetState gets the state of the server func (s *Server) GetState() []*pbg.State { + unprocCount := int64(0) + wantedCount := int64(0) + unknownCount := int64(0) + for _, list := range s.config.Lists { + for _, entry := range list.Wants { + switch entry.Status { + case pb.WantListEntry_UNPROCESSED: + unprocCount++ + case pb.WantListEntry_WANTED: + wantedCount++ + default: + unknownCount++ + } + } + } return []*pbg.State{ &pbg.State{Key: "lists", Value: int64(len(s.config.Lists))}, + &pbg.State{Key: "unproc", Value: unprocCount}, + &pbg.State{Key: "wanted", Value: wantedCount}, + &pbg.State{Key: "unknown", Value: unknownCount}, } }