Skip to content

medcat.utils.usage_monitoring

Classes:

Attributes:

DEFAULT_LOGS_LINUX module-attribute

DEFAULT_LOGS_LINUX = expanduser('~/.local/share/medcat/logs/')

DEFAULT_LOGS_MACOS module-attribute

DEFAULT_LOGS_MACOS = expanduser('~/Library/Application Support/medcat/logs/')

DEFAULT_LOGS_WINDOWS module-attribute

DEFAULT_LOGS_WINDOWS = join(get('APPDATA', 'NOT WINDOWS'), 'medcat', 'logs')

LOGS_ENV module-attribute

LOGS_ENV = 'MEDCAT_USAGE_LOGS'

LOGS_LOC_ENV module-attribute

LOGS_LOC_ENV = 'MEDCAT_USAGE_LOGS_LOCATION'

logger module-attribute

logger = getLogger(__name__)

UsageMonitor

UsageMonitor(model_hash: Union[Callable[[], str], str], config: UsageMonitor)

Methods:

Attributes:

Source code in medcat-v2/medcat/utils/usage_monitoring.py
26
27
28
29
30
31
32
def __init__(self, model_hash: Union[Callable[[], str], str],
             config: UsageMonitorConfig) -> None:
    self.config = config
    self.log_buffer: list[str] = []
    # NOTE: if the model hash changes (i.e model is trained)
    #       then this does not immediately take effect
    self._model_hash = model_hash

config instance-attribute

config = config

log_buffer instance-attribute

log_buffer: list[str] = []

log_file property

log_file

model_hash property

model_hash: str

should_monitor property

should_monitor: bool

log_inference

log_inference(input_text_len: int, nr_of_ents_found: int) -> None
Source code in medcat-v2/medcat/utils/usage_monitoring.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def log_inference(self,
                  input_text_len: int,
                  nr_of_ents_found: int) -> None:
    if not self._should_log():
        return
    timestamp = datetime.now().isoformat()
    log_entry = f"{timestamp},{input_text_len},{nr_of_ents_found}"
    self.log_buffer.append(log_entry)
    if len(self.log_buffer) >= self.config.batch_size:
        self._flush_logs()