From 8fb0c6be35efb105cab176ff63ca91d8c3235e49 Mon Sep 17 00:00:00 2001 From: tginsbu1 Date: Mon, 9 Sep 2024 15:23:23 -0500 Subject: [PATCH 1/2] adding data info --- src/wei/experiment_client.py | 12 +++++++++++- src/wei/routers/experiment_routes.py | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/wei/experiment_client.py b/src/wei/experiment_client.py index 4e55fda0..50dcd7ad 100644 --- a/src/wei/experiment_client.py +++ b/src/wei/experiment_client.py @@ -9,6 +9,7 @@ from wei.types import Workflow, WorkflowRun, WorkflowStatus from wei.types.base_types import PathLike +from wei.types.datapoint_types import DataPoint from wei.types.event_types import ( CommentEvent, DecisionEvent, @@ -472,7 +473,7 @@ def save_datapoint_value( ------- response: Dict - figuring it out""" + writes the funct""" url = f"{self.url}/runs/data/" + datapoint_id response = requests.get(url) if response.ok: @@ -486,6 +487,15 @@ def save_datapoint_value( f.write(response.content) response.raise_for_status() + def get_experiment_datapoints(self) -> Dict[str, DataPoint]: + """ + returns a dictionary of the datapoints for this experiment. + """ + url = f"{self.url}/{self.experiment_id}/data" + response = requests.get(url) + if response.ok: + return response.json() + def log_experiment_end(self) -> Event: """Logs the end of the experiment in the experiment log diff --git a/src/wei/routers/experiment_routes.py b/src/wei/routers/experiment_routes.py index 1f48d8bf..82671907 100644 --- a/src/wei/routers/experiment_routes.py +++ b/src/wei/routers/experiment_routes.py @@ -11,6 +11,7 @@ from wei.core.experiment import get_experiment, register_new_experiment from wei.core.state_manager import state_manager from wei.core.storage import get_experiment_log_file +from wei.types.datapoint_types import DataPoint from wei.types.event_types import Event from wei.types.experiment_types import Campaign, Experiment, ExperimentDesign @@ -27,6 +28,16 @@ async def event_return(experiment_id: str) -> Dict[str, Event]: return events +@router.get("/{experiment_id}/data") +async def data_return(experiment_id: str) -> Dict[str, DataPoint]: + """Returns all of the data points related to an experiment""" + datapoints = {} + for datapoint_id, datapoint in state_manager.get_all_datapoints().items(): + if datapoint.experiment_id == experiment_id: + datapoints[datapoint_id] = datapoint + return datapoints + + @router.get("/{experiment_id}/log") async def log_return(experiment_id: str) -> str: """Returns the log for a given experiment""" From 25f9d277c4da4c7b95d4d1fd942ce9260b8c8a9c Mon Sep 17 00:00:00 2001 From: Ryan Lewis Date: Tue, 10 Sep 2024 10:27:08 -0500 Subject: [PATCH 2/2] Fix doc string --- src/wei/experiment_client.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/wei/experiment_client.py b/src/wei/experiment_client.py index 50dcd7ad..46f11229 100644 --- a/src/wei/experiment_client.py +++ b/src/wei/experiment_client.py @@ -459,21 +459,8 @@ def get_datapoint_value(self, datapoint_id: str) -> Dict[Any, Any]: return response.content response.raise_for_status() - def save_datapoint_value( - self, datapoint_id: str, output_filepath: str - ) -> Dict[Any, Any]: - """Returns the datapoint for the given id - - Parameters - ---------- - - None - - Returns - ------- - - response: Dict - writes the funct""" + def save_datapoint_value(self, datapoint_id: str, output_filepath: str): + """Saves the value of the given datapoint to the specified filepath""" url = f"{self.url}/runs/data/" + datapoint_id response = requests.get(url) if response.ok: