07. Analyse Trial Results
Retrieve Output IDs
To access trial results, first retrieve the available output IDs.
import json
import jinko_helpers as jinko
# Retrieving the output IDs
response = jinko.make_request(
f"/core/v2/trial_manager/trial/{trial_core_item_id}/snapshots/{trial_snapshot_id}/output_ids",
method="GET",
)
responseSummary = json.loads(response.content.decode("utf-8"))
print("Available time series:", responseSummary)
The response provides a list of available time series data points.
Retrieve Time Series Data
Once you have identified the output IDs, you can request time series data.
import jinko_helpers as jinko
import zipfile
import io
TIME_SERIES_IDS = ["x"]
try:
print("Retrieving time series data...")
response = jinko.make_request(
"/core/v2/result_manager/timeseries_summary",
method="POST",
json={
"select": TIME_SERIES_IDS,
"trialId": {
"coreItemId": trial_core_item_id,
"snapshotId": trial_snapshot_id,
},
},
)
if response.status_code == 200:
print("Time series data retrieved successfully.")
archive = zipfile.ZipFile(io.BytesIO(response.content))
filename = archive.namelist()[0]
print(f"Extracted time series file: {filename}")
csvTimeSeries = archive.read(filename).decode("utf-8")
else:
print(f"Failed to retrieve time series data: {response.status_code} - {response.reason}")
response.raise_for_status()
except Exception as e:
print(f"Error during time series retrieval or processing: {e}")
raise
This request returns a compressed CSV file containing the time series data.
Visualizing Time Series Data
Once extracted, the data can be loaded into a Pandas DataFrame for analysis and visualization.
import pandas as pd
import matplotlib.pyplot as plt
# Convert CSV content to DataFrame
dfTimeSeries = pd.read_csv(io.StringIO(csvTimeSeries))
# Filter data for a single patient
unique_patient_ids = dfTimeSeries["Patient Id"].unique()
patient_data = dfTimeSeries[dfTimeSeries["Patient Id"] == unique_patient_ids[0]]
# Plot each arm separately
for arm, group in patient_data.groupby("Arm"):
plt.plot(group["Time"], group["Value"], marker="o", linestyle="-", label=arm)
# Customize the plot
plt.title("Time Series of Selected Output")
plt.xlabel("Time (seconds)")
plt.ylabel("Value")
plt.legend(title="Arm")
plt.show()
Summary
In this module, you:
- Retrieved the available output IDs for a trial.
- Requested and extracted time series data.
- Processed and visualized the results using Python and Matplotlib.
Next, you can explore more advanced analyses, such as aggregating results across patients or applying statistical models to the data.