Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions src/Extensions/OperationControl.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@
<Expression xsi:type="rx:BehaviorSubject" TypeArguments="sys:Boolean">
<rx:Name>GiveRewardRight</rx:Name>
</Expression>
<Expression xsi:type="rx:BehaviorSubject" TypeArguments="sys:Boolean">
<rx:Name>GiveManualWaterRight</rx:Name>
</Expression>
<Expression xsi:type="rx:Defer">
<Name>SetRewardAmount</Name>
<Workflow>
Expand Down Expand Up @@ -458,6 +461,18 @@
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:SubscribeWhen" />
</Expression>
<Expression xsi:type="Annotation">
<Text><![CDATA[Triggered from visualizer when user manually gives water]]></Text>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>GiveManualWaterRight</Name>
</Expression>
<Expression xsi:type="IncludeWorkflow" Path="Extensions\InlineSoftwareEvent.bonsai">
<EventName>GiveManualWaterRight</EventName>
</Expression>
<Expression xsi:type="MulticastSubject">
<Name>GiveRewardRight</Name>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>GiveRewardRight</Name>
</Expression>
Expand Down Expand Up @@ -607,27 +622,30 @@
</Expression>
</Nodes>
<Edges>
<Edge From="1" To="3" Label="Source1" />
<Edge From="2" To="3" Label="Source2" />
<Edge From="4" To="5" Label="Source1" />
<Edge From="4" To="7" Label="Source1" />
<Edge From="2" To="4" Label="Source1" />
<Edge From="3" To="4" Label="Source2" />
<Edge From="5" To="6" Label="Source1" />
<Edge From="6" To="10" Label="Source1" />
<Edge From="6" To="7" Label="Source1" />
<Edge From="7" To="8" Label="Source1" />
<Edge From="8" To="9" Label="Source1" />
<Edge From="9" To="10" Label="Source2" />
<Edge From="9" To="10" Label="Source1" />
<Edge From="9" To="12" Label="Source1" />
<Edge From="10" To="11" Label="Source1" />
<Edge From="11" To="15" Label="Source1" />
<Edge From="12" To="13" Label="Source1" />
<Edge From="12" To="17" Label="Source1" />
<Edge From="13" To="14" Label="Source1" />
<Edge From="14" To="15" Label="Source1" />
<Edge From="14" To="15" Label="Source2" />
<Edge From="15" To="16" Label="Source1" />
<Edge From="16" To="21" Label="Source1" />
<Edge From="17" To="18" Label="Source1" />
<Edge From="17" To="22" Label="Source1" />
<Edge From="18" To="19" Label="Source1" />
<Edge From="19" To="20" Label="Source1" />
<Edge From="20" To="21" Label="Source2" />
<Edge From="21" To="22" Label="Source1" />
<Edge From="20" To="21" Label="Source1" />
<Edge From="21" To="26" Label="Source1" />
<Edge From="22" To="23" Label="Source1" />
<Edge From="23" To="24" Label="Source1" />
<Edge From="24" To="25" Label="Source1" />
<Edge From="25" To="26" Label="Source2" />
<Edge From="26" To="27" Label="Source1" />
</Edges>
</Workflow>
</Expression>
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/Visualizers.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@
</Combinator>
</Expression>
<Expression xsi:type="MulticastSubject">
<Name>GiveRewardRight</Name>
<Name>GiveManualWaterRight</Name>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
Expand Down Expand Up @@ -447,7 +447,7 @@
</Combinator>
</Expression>
<Expression xsi:type="MulticastSubject">
<Name>GiveRewardRight</Name>
<Name>GiveManualWaterRight</Name>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
Expand Down
7 changes: 7 additions & 0 deletions src/aind_behavior_dynamic_foraging/data_contract/_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,13 @@ def make_dataset(
name="SoftwareEvents",
description="Software events generated by the workflow. The timestamps of these events are low precision and should not be used to align to physiology data.",
data_streams=[
SoftwareEvents(
name="GiveManualWaterRight",
description="An event emitted when manual water is given through visualizer.",
reader_params=SoftwareEvents.make_params(
root_path / "behavior/SoftwareEvents/GiveManualWaterRigt.json"
),
),
SoftwareEvents(
name="TrialGeneratorSpec",
description="An event emitted with the specification for the trial generator.",
Expand Down
45 changes: 45 additions & 0 deletions src/aind_behavior_dynamic_foraging/data_contract/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
from typing import Optional

from aind_behavior_dynamic_foraging.data_contract import dataset
from aind_behavior_dynamic_foraging.task_logic import AindDynamicForagingTaskLogic


def calculate_consumed_water(session_path: os.PathLike) -> Optional[float]:
"""Calculate the total volume of water consumed during a session.

Args:
session_path (os.PathLike): Path to the session directory.

Returns:
Optional[float]: Total volume of water consumed in milliliters, or None if unavailable.
"""

trial_outcomes = dataset(session_path)["Behavior"]["SoftwareEvents"]["TrialOutcome"].load().data["data"]
is_right_choice = [to["is_right_choice"] for to in trial_outcomes]
is_rewarded = [to["is_rewarded"] for to in trial_outcomes]

is_right_manual_water = (
dataset(session_path)["Behavior"]["SoftwareEvents"]["GiveManualWaterRight"].load().data["data"]
)

task_logic_data = dataset(session_path)["Behavior"]["InputSchemas"]["TaskLogic"].load().data
task_logic = AindDynamicForagingTaskLogic.model_validate(task_logic_data)
right_reward_size = task_logic.task_parameters.reward_size.right_value_volume
left_reward_size = task_logic.task_parameters.reward_size.left_value_volume

total = 0
for choice, rewarded in zip(is_right_choice, is_rewarded):
if rewarded:
if choice is True:
total += right_reward_size * 1e-3
if choice is False:
total += left_reward_size * 1e-3

for is_right in is_right_manual_water:
if is_right:
total += right_reward_size * 1e-3
else:
total += left_reward_size * 1e-3

return total
Loading