-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve reproducibility reporting and small fixes.
- Reproducibility reporting improvements - Docker compose improvements - Attempt at log collectiony
- Loading branch information
Showing
20 changed files
with
234 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from abc import abstractmethod | ||
from enum import Enum | ||
import logging | ||
|
||
from bci.evaluations.collectors.base import BaseCollector | ||
|
||
from .collectors.requests import RequestCollector | ||
from .collectors.logs import LogCollector | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Type(Enum): | ||
REQUESTS = 1 | ||
LOGS = 2 | ||
|
||
|
||
class Collector: | ||
|
||
def __init__(self, types: list[Type]) -> None: | ||
self.collectors: list[BaseCollector] = [] | ||
if Type.REQUESTS in types: | ||
collector = RequestCollector() | ||
self.collectors.append(collector) | ||
if Type.LOGS in types: | ||
collector = LogCollector() | ||
self.collectors.append(collector) | ||
logger.debug(f'Using {len(self.collectors)} result collectors') | ||
|
||
def start(self): | ||
for collector in self.collectors: | ||
collector.start() | ||
|
||
def stop(self): | ||
for collector in self.collectors: | ||
collector.stop() | ||
|
||
@abstractmethod | ||
def collect_results(self) -> dict: | ||
all_data = {} | ||
for collector in self.collectors: | ||
all_data.update(collector.data) | ||
logger.debug(f'Collected data: {all_data}') | ||
return all_data | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import re | ||
from abc import abstractmethod | ||
|
||
|
||
class BaseCollector: | ||
|
||
def __init__(self) -> None: | ||
self.data = {} | ||
|
||
@abstractmethod | ||
def start(): | ||
pass | ||
|
||
@abstractmethod | ||
def stop(): | ||
pass | ||
|
||
@staticmethod | ||
def _parse_bughog_variables(raw_log_lines: list[str], regex) -> list[tuple[str, str]]: | ||
''' | ||
Parses the given `raw_log_lines` for matches against the given `regex`. | ||
''' | ||
data = [] | ||
regex_match_lists = [re.findall(regex, line) for line in raw_log_lines if re.search(regex, line)] | ||
# Flatten list | ||
regex_matches = [regex_match for regex_match_list in regex_match_lists for regex_match in regex_match_list] | ||
for match in regex_matches: | ||
var = match[0] | ||
val = match[1] | ||
BaseCollector._add_val_var_pair(var, val, data) | ||
return data | ||
|
||
|
||
@staticmethod | ||
def _add_val_var_pair(var: str, val: str, data: list) -> list: | ||
for entry in data: | ||
if entry['var'] == var and entry['val'] == val: | ||
return data | ||
data.append({ | ||
'var': var, | ||
'val': val | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from .base import BaseCollector | ||
|
||
|
||
class LogCollector(BaseCollector): | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
self.data['log_vars'] = [] | ||
|
||
def start(self): | ||
with open('/tmp/browser.log', 'w') as file: | ||
file.write('') | ||
|
||
def stop(self): | ||
data = [] | ||
regex = r'\+\+\+bughog_(.+)=(.+)\+\+\+' | ||
with open('/tmp/browser.log', 'r+') as log_file: | ||
log_lines = [line for line in log_file.readlines()] | ||
log_file.write('') | ||
data = self._parse_bughog_variables(log_lines, regex) | ||
self.data['log_vars'] = data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.