Skip to content

Commit

Permalink
Service refactor, decision.py supports lists as outputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
bronevet-abc committed Nov 4, 2024
1 parent 21f69bc commit c33c50d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions py/sight/widgets/decision/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,12 @@ def get_decision_outcome_proto(outcome_label: str,
double_value=val,
)
else:
if (isinstance(val, dict)):
if (isinstance(val, dict) or isinstance(val, list)):
json_value = json.dumps(val)
elif (isinstance(val, pd.Series)):
json_value = json.dumps(val.to_dict())
else:
raise TypeError("value needs to be dict type")
raise TypeError(f'Value of {key} needs to be dict, list or pd.Series type. Actual type is {type(val)}, val={val}.')

value = sight_pb2.Value(sub_type=sight_pb2.Value.ST_JSON,
json_value=json_value)
Expand Down
11 changes: 9 additions & 2 deletions sight_service/service_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def warn(*args, **kwargs):
import functools
import grpc
import logging
import math

load_dotenv()

Expand Down Expand Up @@ -73,6 +74,7 @@ def generate_unique_number() -> int:
import logging

func_to_elapsed_time = defaultdict(float)
func_to_elapsed_time_sq = defaultdict(float)
func_call_count = defaultdict(float)

def rpc_call(func):
Expand All @@ -89,13 +91,18 @@ def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
elapsed_time = time.time() - start_time
func_to_elapsed_time[func.__name__] += elapsed_time
func_to_elapsed_time_sq[func.__name__] += elapsed_time*elapsed_time
func_call_count[func.__name__] += 1

logging.info('>>>>>> %s, file %s, elapsed: (this=%f, avg=%f, count=%d)',
mean = func_to_elapsed_time[func.__name__]/func_call_count[func.__name__]
mean_sq = func_to_elapsed_time_sq[func.__name__]/func_call_count[func.__name__]

logging.info('>>>>>> %s, file %s, elapsed: (this=%f, avg=%f, rel_sd=%f, count=%d)',
func.__name__,
os.path.basename(__file__),
elapsed_time,
func_to_elapsed_time[func.__name__]/func_call_count[func.__name__],
mean,
math.sqrt(mean_sq - mean*mean)/mean if mean != 0 else 0,
func_call_count[func.__name__],
)
return result
Expand Down

0 comments on commit c33c50d

Please sign in to comment.