Skip to content

Commit

Permalink
total_time_spent estimate
Browse files Browse the repository at this point in the history
  • Loading branch information
sreekaroo committed Feb 5, 2024
1 parent e91f1ff commit ee7bb01
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 19 deletions.
37 changes: 23 additions & 14 deletions bcipy/simulator/helpers/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np

from bcipy.helpers.acquisition import max_inquiry_duration
from bcipy.simulator.helpers.state_manager import SimState
from bcipy.simulator.helpers.types import InquiryResult
from bcipy.simulator.simulator_base import Simulator
Expand All @@ -31,22 +32,31 @@ class SimMetrics1Handler(RefereeHandler):
def handle(self, sim: Simulator) -> Dict[str, Any]:
state: SimState = getattr(sim, ("state_manager")).get_state()

info: Dict = SimMetrics1().__dict__
info['total_inquiries'] = state.total_inquiry_count()
info['total_series'] = state.series_n

# calculating total decisions made
flattened_inquiries: List[InquiryResult] = reduce(lambda l1, l2: l1 + l2,
state.series_results, [])
info['total_decisions'] = len(
list(filter(lambda inq: bool(inq.decision), flattened_inquiries)))
total_decisions = len(list(filter(lambda inq: bool(inq.decision), flattened_inquiries)))

# average number of inqs before a decision
inq_counts = []
for series in state.series_results:
if [inq for inq in series if inq.decision]:
inq_counts.append(len(series))
info['inquiries_per_selection'] = round(np.array(inq_counts).mean(), 3)
inquiries_per_selection = round(np.array(inq_counts).mean(), 3)

# inq and series counts
total_inquiries = state.total_inquiry_count()
total_series = state.series_n

# total time spent estimate seconds = (max_inq_time_estimate * total_inquiries)
parameters = sim.get_parameters()
max_inq_time = max_inquiry_duration(parameters)

This comment has been minimized.

Copy link
@lawhead

lawhead Feb 6, 2024

Collaborator

I think this will overestimate the time for most tasks, but is probably a good place to start.

total_time_spent = total_inquiries * max_inq_time

return info
ret = SimMetrics1(total_series=total_series, total_inquiries=total_inquiries,
total_decisions=total_decisions, total_time_spent=total_time_spent,
inquiries_per_selection=inquiries_per_selection)
return ret.__dict__


class MetricReferee(ABC):
Expand All @@ -62,19 +72,18 @@ def visualize(self, sim: Simulator):
""" Generate registered visualizations for sim """

@abstractmethod
def set_metric_handler(self, name: str, handler: RefereeHandler):
def add_metric_handler(self, name: str, handler: RefereeHandler):
""" Add a metric calculation that will be executed upon self.score() """

@abstractmethod
def set_viz_handler(self, name: str, handler: RefereeHandler):
def add_viz_handler(self, name: str, handler: RefereeHandler):
""" Register a visualization that will be executed upon self.visualize() """


class RefereeImpl(MetricReferee):

def __init__(self, metric_handlers=None, viz_handlers=None):
self.metric_handlers: Dict[
str, RefereeHandler] = metric_handlers if metric_handlers else {}
self.metric_handlers: Dict[str, RefereeHandler] = metric_handlers if metric_handlers else {}
self.viz_handlers: Dict[str, RefereeHandler] = viz_handlers if viz_handlers else {}

self.inquiry_time: float = 1 # 1 inq -> 1 second
Expand All @@ -96,8 +105,8 @@ def visualize(self, sim: Simulator):
for handler_name, viz_handler in self.viz_handlers.items():
viz_handler.handle(sim)

def set_metric_handler(self, name: str, handler: RefereeHandler):
def add_metric_handler(self, name: str, handler: RefereeHandler):
self.metric_handlers[name] = handler

def set_viz_handler(self, name: str, handler: RefereeHandler):
def add_viz_handler(self, name: str, handler: RefereeHandler):
self.viz_handlers[name] = handler
4 changes: 2 additions & 2 deletions bcipy/simulator/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ def load_parameters(self, params: Optional[Parameters]):
else:
return self.data_engine.get_parameters()

def get_param(self, name):
pass
def get_parameters(self):
return self.parameters.copy()
2 changes: 1 addition & 1 deletion bcipy/simulator/sim_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"type": "float"
},
"sim_lm_active": {
"value": "1",
"value": "0",
"section": "sim_config",
"readableName": "is lm active or off",
"helpTip": "",
Expand Down
6 changes: 4 additions & 2 deletions bcipy/simulator/simulator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from abc import ABC, abstractmethod

from bcipy.helpers.parameters import Parameters


class Simulator(ABC):
"""Simulator.
Expand All @@ -17,5 +19,5 @@ def run(self):
""" Run loop for simulation"""

@abstractmethod
def get_param(self, name):
""" retrieving parameter """
def get_parameters(self) -> Parameters:
""" retrieving parameters copy"""

0 comments on commit ee7bb01

Please sign in to comment.