From dcf791be4574961f33acfa170c0d25503f5dd882 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Tue, 3 Dec 2024 03:50:45 -0800 Subject: [PATCH] Add analysis code --- .../src/python/analysis.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 _topics/_08_reproducible_research_practices/src/python/analysis.py diff --git a/_topics/_08_reproducible_research_practices/src/python/analysis.py b/_topics/_08_reproducible_research_practices/src/python/analysis.py new file mode 100644 index 0000000..d3256b4 --- /dev/null +++ b/_topics/_08_reproducible_research_practices/src/python/analysis.py @@ -0,0 +1,18 @@ +from demo1 import Experiment, Trial +from pathlib import Path + +data_path = Path(r"src/data/demo1.json") +task_spec = Path(r"src/json/experiment-example.json") +with open(data_path, "r", encoding="utf-8") as f: + trials = [Trial.model_validate_json(x) for x in f.readlines()] + +# print all trials +[print(trial) for trial in trials] +# print total reward consumed +reward_consumed = sum([trial.reward_amount for trial in trials]) +print(f"Animal consumed a total of {reward_consumed} ml") + +# print the task settings that gave rise to the trials +with open(task_spec, "r", encoding="utf-8") as f: + task_settings = Experiment.model_validate_json(f.read()) +print(task_settings) \ No newline at end of file