Exemple #1
0
 def get_data_by_uid(self, uid, date):
     shard_idx = self.uid_shard(uid)
     if shard_idx == -1:
         return -1
     data = data_server_pb2.Data()
     data.uid = uid
     data.date = date
     call_future = self.stub_list[shard_idx].GetUserData.future(data)
     user_data_list = []
     for item in call_future.result().line_str:
         user_data_list.append(item)
     return user_data_list
Exemple #2
0
 def get_param_by_uid(self, uid):
     shard_idx = self.uid_shard(uid)
     if shard_idx == -1:
         return -1
     data = data_server_pb2.Data()
     data.uid = uid
     call_future = self.stub_list[shard_idx].GetUserParams.future(data)
     user_params = call_future.result()
     param_dict = {}
     for param in user_params.user_params:
         param_dict[param.name] = np.array(list(param.weight),
                                           dtype=np.float32)
         param_dict[param.name].shape = list(param.shape)
     return param_dict
Exemple #3
0
 def send_one_patch(self, patch, date):
     for line in patch:
         group = line.strip().split("\t")
         if len(group) != 3:
             continue
         data = data_server_pb2.Data()
         data.uid = group[0]
         data.date = date
         data.line = line.strip()
         stub_idx = self.uid_shard(data.uid)
         if stub_idx == -1:
             logging.info("send_one_patch continue for uid: %s" % data.uid)
             continue
         call_future = self.stub_list[stub_idx].SendData.future(data)
         u_num = call_future.result()
Exemple #4
0
 def clear():
     for stub in self.stub_list:
         data = data_server_pb2.Data()
         data.date = date
         call_future = stub.ClearUserData.future(data)
         res = call_future.result()