mirror of
https://github.com/vacp2p/10ksim.git
synced 2026-01-09 22:27:57 -05:00
Connection & Time to reach healthy distribution (#48)
* Create class decorator for check if path exists. * Create plot function to use for analysis of reach Nº of connections
This commit is contained in:
@@ -18,9 +18,10 @@ from src.mesh_analysis.readers.victoria_reader import VictoriaReader
|
||||
from src.mesh_analysis.tracers.waku_tracer import WakuTracer
|
||||
from src.plotting.utils import add_boxplot_stat_labels
|
||||
from src.utils import file_utils, log_utils, path_utils, list_utils
|
||||
from src.utils.path_utils import check_path_exists
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
sns.set_theme()
|
||||
|
||||
class WakuMessageLogAnalyzer:
|
||||
def __init__(self, stateful_sets: List[str], timestamp_to_analyze: str = None,
|
||||
@@ -381,3 +382,25 @@ class WakuMessageLogAnalyzer:
|
||||
plt.show()
|
||||
|
||||
return Ok(None)
|
||||
|
||||
|
||||
@check_path_exists
|
||||
def check_time_to_reach_value_plot(self, file_data_path: Path, threshold_value: int, value_name: str,
|
||||
dump_path: Path) -> Result[None, str]:
|
||||
df = pd.read_csv(file_data_path)
|
||||
df['Time'] = pd.to_datetime(df['Time'])
|
||||
df.set_index('Time', inplace=True)
|
||||
|
||||
mask = df >= threshold_value
|
||||
first_reach = mask.idxmax()
|
||||
first_reach[~mask.any()] = pd.NaT # Set to NaT if the target is never reached
|
||||
time_to_target = (first_reach - df.index[0]).dt.total_seconds() / 60
|
||||
|
||||
plt.figure(figsize=(10, 6))
|
||||
plt.boxplot(time_to_target.dropna(), vert=False)
|
||||
plt.title(f'Time to Reach {value_name} - {time_to_target.dropna().shape[0]}/{df.shape[1]}')
|
||||
plt.xlabel('Time to Reach Target (minutes)')
|
||||
plt.savefig(dump_path)
|
||||
plt.show()
|
||||
|
||||
return Ok(None)
|
||||
|
||||
@@ -36,3 +36,15 @@ def prepare_path_for_folder(folder_location: Union[str, Path]) -> Result[Path, s
|
||||
return Err(f'Error creating {folder_location.parent}. {e}')
|
||||
|
||||
return Ok(folder_location)
|
||||
|
||||
|
||||
def check_path_exists(func):
|
||||
def wrapper(self, path: Path, *args, **kwargs):
|
||||
if not path.exists():
|
||||
error = f'Path {args[0]} does not exist'
|
||||
logger.error(error)
|
||||
return Err(error)
|
||||
return func(self, path, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
Reference in New Issue
Block a user