diff --git a/api/predict.proto b/api/predict.proto index 3e52081..e1de3a2 100644 --- a/api/predict.proto +++ b/api/predict.proto @@ -1,4 +1,7 @@ -syntax = "proto3"; +syntax = "proto3"; + +package databoard; +option go_package = "learning/predict"; service Predict { rpc PayDay(RequestPay) returns (ReplyPay) {} diff --git a/data.py b/data.py index a7d4dcc..5771885 100644 --- a/data.py +++ b/data.py @@ -10,7 +10,7 @@ import os import numpy import time, datetime -def get_collect(): +def get_collect(region = "all"): collect = {} loadfile = "./collect.pickle" @@ -26,7 +26,7 @@ def get_collect(): today = time.strftime("%Y-%m-%d", time.localtime()) # 使用 execute() 方法执行 SQL 查询 - cursor.execute('''SELECT coin, extra_coins, pay_users, create_at from pay_items_hour pih where region = "all" and platform="all" and create_at <= %s''', today) + cursor.execute('''SELECT coin, extra_coins, pay_users, create_at from pay_items_hour pih where region = "%s" and platform="all" and create_at <= %s''',region , today) collect_pay = {} for row in cursor.fetchall(): # print(row) @@ -83,7 +83,7 @@ def get_collect(): -def load_pay_data(textNum = 80): +def load_pay_data(textNum = 80, region = "all"): collect = get_collect() diff --git a/grpc_server.py b/grpc_server.py index 0c9efdf..9823f2f 100644 --- a/grpc_server.py +++ b/grpc_server.py @@ -30,7 +30,7 @@ class Predict(predict_pb2_grpc.PredictServicer): def server(): grpc_server = grpc.server(futures.ThreadPoolExecutor(max_workers=2)) predict_pb2_grpc.add_PredictServicer_to_server(Predict(), grpc_server) - grpc_server.add_insecure_port('[::]:50051') + grpc_server.add_insecure_port('0.0.0.0:50051') grpc_server.start() grpc_server.wait_for_termination() diff --git a/predict_pb2.py b/predict_pb2.py index 304bb70..e9c2710 100644 --- a/predict_pb2.py +++ b/predict_pb2.py @@ -15,11 +15,11 @@ _sym_db = _symbol_database.Default() DESCRIPTOR = _descriptor.FileDescriptor( name='predict.proto', - package='', + package='databoard', syntax='proto3', - serialized_options=None, + serialized_options=b'Z\020learning/predict', create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\rpredict.proto\"?\n\nRequestPay\x12\x0c\n\x04Hour\x18\x01 \x01(\x05\x12\x0c\n\x04\x43oin\x18\x02 \x01(\x03\x12\x15\n\rYesterdayCoin\x18\x03 \x01(\x03\"@\n\x0bRequestGift\x12\x0c\n\x04Hour\x18\x01 \x01(\x05\x12\x0c\n\x04\x43oin\x18\x02 \x01(\x03\x12\x15\n\rYesterdayCoin\x18\x03 \x01(\x03\",\n\x0bReplyHeader\x12\x0c\n\x04\x43ode\x18\x01 \x01(\x05\x12\x0f\n\x07Message\x18\x02 \x01(\t\"8\n\x08ReplyPay\x12\x1c\n\x06Header\x18\x01 \x01(\x0b\x32\x0c.ReplyHeader\x12\x0e\n\x06Result\x18\x02 \x01(\x03\"9\n\tReplyGift\x12\x1c\n\x06Header\x18\x01 \x01(\x0b\x32\x0c.ReplyHeader\x12\x0e\n\x06Result\x18\x02 \x01(\x03\x32T\n\x07Predict\x12\"\n\x06PayDay\x12\x0b.RequestPay\x1a\t.ReplyPay\"\x00\x12%\n\x07GiftDay\x12\x0c.RequestGift\x1a\n.ReplyGift\"\x00\x62\x06proto3' + serialized_pb=b'\n\rpredict.proto\x12\tdataboard\"?\n\nRequestPay\x12\x0c\n\x04Hour\x18\x01 \x01(\x05\x12\x0c\n\x04\x43oin\x18\x02 \x01(\x03\x12\x15\n\rYesterdayCoin\x18\x03 \x01(\x03\"@\n\x0bRequestGift\x12\x0c\n\x04Hour\x18\x01 \x01(\x05\x12\x0c\n\x04\x43oin\x18\x02 \x01(\x03\x12\x15\n\rYesterdayCoin\x18\x03 \x01(\x03\",\n\x0bReplyHeader\x12\x0c\n\x04\x43ode\x18\x01 \x01(\x05\x12\x0f\n\x07Message\x18\x02 \x01(\t\"B\n\x08ReplyPay\x12&\n\x06Header\x18\x01 \x01(\x0b\x32\x16.databoard.ReplyHeader\x12\x0e\n\x06Result\x18\x02 \x01(\x03\"C\n\tReplyGift\x12&\n\x06Header\x18\x01 \x01(\x0b\x32\x16.databoard.ReplyHeader\x12\x0e\n\x06Result\x18\x02 \x01(\x03\x32|\n\x07Predict\x12\x36\n\x06PayDay\x12\x15.databoard.RequestPay\x1a\x13.databoard.ReplyPay\"\x00\x12\x39\n\x07GiftDay\x12\x16.databoard.RequestGift\x1a\x14.databoard.ReplyGift\"\x00\x42\x12Z\x10learning/predictb\x06proto3' ) @@ -27,28 +27,28 @@ DESCRIPTOR = _descriptor.FileDescriptor( _REQUESTPAY = _descriptor.Descriptor( name='RequestPay', - full_name='RequestPay', + full_name='databoard.RequestPay', filename=None, file=DESCRIPTOR, containing_type=None, create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( - name='Hour', full_name='RequestPay.Hour', index=0, + name='Hour', full_name='databoard.RequestPay.Hour', index=0, number=1, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( - name='Coin', full_name='RequestPay.Coin', index=1, + name='Coin', full_name='databoard.RequestPay.Coin', index=1, number=2, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( - name='YesterdayCoin', full_name='RequestPay.YesterdayCoin', index=2, + name='YesterdayCoin', full_name='databoard.RequestPay.YesterdayCoin', index=2, number=3, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, @@ -66,35 +66,35 @@ _REQUESTPAY = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=17, - serialized_end=80, + serialized_start=28, + serialized_end=91, ) _REQUESTGIFT = _descriptor.Descriptor( name='RequestGift', - full_name='RequestGift', + full_name='databoard.RequestGift', filename=None, file=DESCRIPTOR, containing_type=None, create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( - name='Hour', full_name='RequestGift.Hour', index=0, + name='Hour', full_name='databoard.RequestGift.Hour', index=0, number=1, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( - name='Coin', full_name='RequestGift.Coin', index=1, + name='Coin', full_name='databoard.RequestGift.Coin', index=1, number=2, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( - name='YesterdayCoin', full_name='RequestGift.YesterdayCoin', index=2, + name='YesterdayCoin', full_name='databoard.RequestGift.YesterdayCoin', index=2, number=3, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, @@ -112,28 +112,28 @@ _REQUESTGIFT = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=82, - serialized_end=146, + serialized_start=93, + serialized_end=157, ) _REPLYHEADER = _descriptor.Descriptor( name='ReplyHeader', - full_name='ReplyHeader', + full_name='databoard.ReplyHeader', filename=None, file=DESCRIPTOR, containing_type=None, create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( - name='Code', full_name='ReplyHeader.Code', index=0, + name='Code', full_name='databoard.ReplyHeader.Code', index=0, number=1, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( - name='Message', full_name='ReplyHeader.Message', index=1, + name='Message', full_name='databoard.ReplyHeader.Message', index=1, number=2, type=9, cpp_type=9, label=1, has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, @@ -151,28 +151,28 @@ _REPLYHEADER = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=148, - serialized_end=192, + serialized_start=159, + serialized_end=203, ) _REPLYPAY = _descriptor.Descriptor( name='ReplyPay', - full_name='ReplyPay', + full_name='databoard.ReplyPay', filename=None, file=DESCRIPTOR, containing_type=None, create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( - name='Header', full_name='ReplyPay.Header', index=0, + name='Header', full_name='databoard.ReplyPay.Header', index=0, number=1, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( - name='Result', full_name='ReplyPay.Result', index=1, + name='Result', full_name='databoard.ReplyPay.Result', index=1, number=2, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, @@ -190,28 +190,28 @@ _REPLYPAY = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=194, - serialized_end=250, + serialized_start=205, + serialized_end=271, ) _REPLYGIFT = _descriptor.Descriptor( name='ReplyGift', - full_name='ReplyGift', + full_name='databoard.ReplyGift', filename=None, file=DESCRIPTOR, containing_type=None, create_key=_descriptor._internal_create_key, fields=[ _descriptor.FieldDescriptor( - name='Header', full_name='ReplyGift.Header', index=0, + name='Header', full_name='databoard.ReplyGift.Header', index=0, number=1, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR, create_key=_descriptor._internal_create_key), _descriptor.FieldDescriptor( - name='Result', full_name='ReplyGift.Result', index=1, + name='Result', full_name='databoard.ReplyGift.Result', index=1, number=2, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, @@ -229,8 +229,8 @@ _REPLYGIFT = _descriptor.Descriptor( extension_ranges=[], oneofs=[ ], - serialized_start=252, - serialized_end=309, + serialized_start=273, + serialized_end=340, ) _REPLYPAY.fields_by_name['Header'].message_type = _REPLYHEADER @@ -245,53 +245,54 @@ _sym_db.RegisterFileDescriptor(DESCRIPTOR) RequestPay = _reflection.GeneratedProtocolMessageType('RequestPay', (_message.Message,), { 'DESCRIPTOR' : _REQUESTPAY, '__module__' : 'predict_pb2' - # @@protoc_insertion_point(class_scope:RequestPay) + # @@protoc_insertion_point(class_scope:databoard.RequestPay) }) _sym_db.RegisterMessage(RequestPay) RequestGift = _reflection.GeneratedProtocolMessageType('RequestGift', (_message.Message,), { 'DESCRIPTOR' : _REQUESTGIFT, '__module__' : 'predict_pb2' - # @@protoc_insertion_point(class_scope:RequestGift) + # @@protoc_insertion_point(class_scope:databoard.RequestGift) }) _sym_db.RegisterMessage(RequestGift) ReplyHeader = _reflection.GeneratedProtocolMessageType('ReplyHeader', (_message.Message,), { 'DESCRIPTOR' : _REPLYHEADER, '__module__' : 'predict_pb2' - # @@protoc_insertion_point(class_scope:ReplyHeader) + # @@protoc_insertion_point(class_scope:databoard.ReplyHeader) }) _sym_db.RegisterMessage(ReplyHeader) ReplyPay = _reflection.GeneratedProtocolMessageType('ReplyPay', (_message.Message,), { 'DESCRIPTOR' : _REPLYPAY, '__module__' : 'predict_pb2' - # @@protoc_insertion_point(class_scope:ReplyPay) + # @@protoc_insertion_point(class_scope:databoard.ReplyPay) }) _sym_db.RegisterMessage(ReplyPay) ReplyGift = _reflection.GeneratedProtocolMessageType('ReplyGift', (_message.Message,), { 'DESCRIPTOR' : _REPLYGIFT, '__module__' : 'predict_pb2' - # @@protoc_insertion_point(class_scope:ReplyGift) + # @@protoc_insertion_point(class_scope:databoard.ReplyGift) }) _sym_db.RegisterMessage(ReplyGift) +DESCRIPTOR._options = None _PREDICT = _descriptor.ServiceDescriptor( name='Predict', - full_name='Predict', + full_name='databoard.Predict', file=DESCRIPTOR, index=0, serialized_options=None, create_key=_descriptor._internal_create_key, - serialized_start=311, - serialized_end=395, + serialized_start=342, + serialized_end=466, methods=[ _descriptor.MethodDescriptor( name='PayDay', - full_name='Predict.PayDay', + full_name='databoard.Predict.PayDay', index=0, containing_service=None, input_type=_REQUESTPAY, @@ -301,7 +302,7 @@ _PREDICT = _descriptor.ServiceDescriptor( ), _descriptor.MethodDescriptor( name='GiftDay', - full_name='Predict.GiftDay', + full_name='databoard.Predict.GiftDay', index=1, containing_service=None, input_type=_REQUESTGIFT, diff --git a/predict_pb2_grpc.py b/predict_pb2_grpc.py index 78b837b..b7dcae7 100644 --- a/predict_pb2_grpc.py +++ b/predict_pb2_grpc.py @@ -15,12 +15,12 @@ class PredictStub(object): channel: A grpc.Channel. """ self.PayDay = channel.unary_unary( - '/Predict/PayDay', + '/databoard.Predict/PayDay', request_serializer=predict__pb2.RequestPay.SerializeToString, response_deserializer=predict__pb2.ReplyPay.FromString, ) self.GiftDay = channel.unary_unary( - '/Predict/GiftDay', + '/databoard.Predict/GiftDay', request_serializer=predict__pb2.RequestGift.SerializeToString, response_deserializer=predict__pb2.ReplyGift.FromString, ) @@ -56,7 +56,7 @@ def add_PredictServicer_to_server(servicer, server): ), } generic_handler = grpc.method_handlers_generic_handler( - 'Predict', rpc_method_handlers) + 'databoard.Predict', rpc_method_handlers) server.add_generic_rpc_handlers((generic_handler,)) @@ -75,7 +75,7 @@ class Predict(object): wait_for_ready=None, timeout=None, metadata=None): - return grpc.experimental.unary_unary(request, target, '/Predict/PayDay', + return grpc.experimental.unary_unary(request, target, '/databoard.Predict/PayDay', predict__pb2.RequestPay.SerializeToString, predict__pb2.ReplyPay.FromString, options, channel_credentials, @@ -92,7 +92,7 @@ class Predict(object): wait_for_ready=None, timeout=None, metadata=None): - return grpc.experimental.unary_unary(request, target, '/Predict/GiftDay', + return grpc.experimental.unary_unary(request, target, '/databoard.Predict/GiftDay', predict__pb2.RequestGift.SerializeToString, predict__pb2.ReplyGift.FromString, options, channel_credentials,