From e4d5b30cbf44e9621cf8cb255a87a7c174137a31 Mon Sep 17 00:00:00 2001 From: Ohad Adi Date: Fri, 26 Jan 2024 23:40:48 +0200 Subject: [PATCH] [ApiServerDB] fix comment - use defintions for separators --- src_py/apiServer/decoderHttpMainServer.py | 22 +++++++++---------- src_py/apiServer/decoderHttpMainServerDefs.py | 7 ++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src_py/apiServer/decoderHttpMainServer.py b/src_py/apiServer/decoderHttpMainServer.py index e46d8134..e96c7a37 100644 --- a/src_py/apiServer/decoderHttpMainServer.py +++ b/src_py/apiServer/decoderHttpMainServer.py @@ -14,18 +14,18 @@ def decode_main_server_ets_str(string_to_convert: str): result_dict = {} # {entity_name: ets_dict,...} - entity_with_stats_list = string_to_convert.split("|")[:-1] # Example: [c2&bytes_sent:0:int#messages_sent:8015:int#bad_messages:0:int#batches_sent:0:int#messages_received:8015:int#batches_received:0:int#bytes_received:40022:int#batches_dropped:0:int#messages_dropped:0:int#, w4^bytes_sent$0$int@empty_batches$0$int@bad_messages$0$int@batches_dropped_predict$0$int@batches_sent_predict$0$int@nan_loss_count$0$int@batches_received_predict$1001$int@batches_dropped_train$0$int@acc_time_training$0$int@bytes_received$0$int@average_time_prediction$0$int@batches_received_train$1000$int@average_time_training$0$int@acc_time_prediction$0$int@batches_sent_train$0$int@, s1&bytes_sent:0:int#messages_sent:4:int#bad_messages:0:int#batches_sent:8004:int#messages_received:7:int#batches_received:0:int#bytes_received:0:int#batches_dropped:0:int#messages_dropped:0:int#, c1&bytes_sent:54036:int#messages_sent:8016:int#bad_messages:0:int#batches_sent:0:int#messages_received:8016:int#batches_received:0:int#bytes_received:40022:int#batches_dropped:0:int#messages_dropped:0:int#, w2^bytes_sent$0$int@empty_batches$0$int@bad_messages$0$int@batches_dropped_predict$0$int@batches_sent_predict$0$int@nan_loss_count$0$int@batches_received_predict$1001$int@batches_dropped_train$0$int@acc_time_training$0$int@bytes_received$0$int@average_time_prediction$0$int@batches_received_train$1000$int@average_time_training$0$int@acc_time_prediction$0$int@batches_sent_train$0$int@, w1^bytes_sent$0$int@empty_batches$0$int@bad_messages$0$int@batches_dropped_predict$0$int@batches_sent_predict$0$int@nan_loss..] + entity_with_stats_list = string_to_convert.split(SEP_ENTITY_OR_STATS)[:-1] for entity_with_stats in entity_with_stats_list: # Example: entity_with_stats = c2&bytes_sent:0:int#messages_sent:8015:int#bad_messages:0:int#batches_sent:0:int... - if "&" in entity_with_stats: + if SEP_ENTITY_AND_STATS in entity_with_stats: # Example: entity_with_stats = c2&bytes_sent:0:int#messages_sent:8015:int#bad_messages:0:int#batches_sent:0:int... - entity_name = entity_with_stats.split('&')[0] # Example: c2 - entity_stats = entity_with_stats.split('&')[1] # Example: bytes_sent:0:int#messages_sent:8015:int#bad_messages:0:int#batches_sent:0:int... - triplets = entity_stats.split("#")[:-1] # Example: [bytes_sent:0:int, messages_sent:8015:int, bad_messages:0:int, batches_sent:0:int, ...] + entity_name = entity_with_stats.split(SEP_ENTITY_AND_STATS)[0] # Example: c2 + entity_stats = entity_with_stats.split(SEP_ENTITY_AND_STATS)[1] # Example: bytes_sent:0:int#messages_sent:8015:int#bad_messages:0:int#batches_sent:0:int... + triplets = entity_stats.split(SEP_ENTITY_HASH_STATS)[:-1] # Example: [bytes_sent:0:int, messages_sent:8015:int, bad_messages:0:int, batches_sent:0:int, ...] entity_dict = {} for triplet in triplets: - key, value, value_type = triplet.split(':') # Example: [bytes_sent,0,int] + key, value, value_type = triplet.split(SEP_ENTITY_COLON_STATS) # Example: [bytes_sent,0,int] if value_type == 'string': value = value else: @@ -34,15 +34,15 @@ def decode_main_server_ets_str(string_to_convert: str): result_dict[entity_name] = entity_dict - if "^" in entity_with_stats: # Belongs only to workers + if SEP_ENTITY_XOR_STATS in entity_with_stats: # Belongs only to workers # Example: entity_with_stats = w4^bytes_sent$0$int@empty_batches$0$int@... - worker_name = entity_with_stats.split('^')[0] - worker_stats = entity_with_stats.split('^')[1] - worker_triplets = worker_stats.split('@')[:-1] # Example: [bytes_sent$0$int, empty_batches$0$int, ...] + worker_name = entity_with_stats.split(SEP_ENTITY_XOR_STATS)[0] + worker_stats = entity_with_stats.split(SEP_ENTITY_XOR_STATS)[1] + worker_triplets = worker_stats.split(SEP_ENTITY_AT_STATS)[:-1] # Example: [bytes_sent$0$int, empty_batches$0$int, ...] worker_dict = {} for worker_triplet in worker_triplets: - key, value, value_type = worker_triplet.split('$') # Example: [bytes_sent,0,int] + key, value, value_type = worker_triplet.split(SEP_ENTITY_DOLLAR_STATS) # Example: [bytes_sent,0,int] if value_type == 'string': value = value else: diff --git a/src_py/apiServer/decoderHttpMainServerDefs.py b/src_py/apiServer/decoderHttpMainServerDefs.py index e69de29b..c66fb44e 100644 --- a/src_py/apiServer/decoderHttpMainServerDefs.py +++ b/src_py/apiServer/decoderHttpMainServerDefs.py @@ -0,0 +1,7 @@ +SEP_ENTITY_AND_STATS = '&' +SEP_ENTITY_OR_STATS = '|' +SEP_ENTITY_HASH_STATS = '#' +SEP_ENTITY_AT_STATS = '@' +SEP_ENTITY_COLON_STATS = ':' +SEP_ENTITY_XOR_STATS = '^' +SEP_ENTITY_DOLLAR_STATS = '$' \ No newline at end of file