Skip to content

Commit

Permalink
Add analysis code
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-f-cruz committed Dec 3, 2024
1 parent 3c3397d commit dcf791b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions _topics/_08_reproducible_research_practices/src/python/analysis.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit dcf791b

Please sign in to comment.