Skip to content

Commit

Permalink
Merge pull request #22 from vagechirkov/minor-updates-before-pilot-2
Browse files Browse the repository at this point in the history
Pilot 2A and 2B
  • Loading branch information
vagechirkov authored Feb 9, 2023
2 parents 08f7eda + 375b6d7 commit a55787d
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 28 deletions.
15 changes: 14 additions & 1 deletion backend/app/routes/session_utils/save_trial.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ async def save_social_learning_selection(trials: List[Trial],
sl_selection = trials[0]
sl_trials = trials[1:]

# TODO: remove this after pilot 2B !!!
# ----------------- Relevant for pilot 2B -----------------
# sl_selection.id == 4 is the first social learning selection trial
if sl_selection.id == 4:
comment = "To be able to get to the arrows with 400 points you first need to take three arrows with -50 points."
else:
comment = "Follow three red arrows, then follow the highest points possible."
# ---------------------------------------------------------

# remove instruction trial if it is in the list of social learning trials
sl_trials = [t for t in sl_trials if t.trial_type != 'instruction']

Expand Down Expand Up @@ -119,7 +128,11 @@ async def save_social_learning_selection(trials: List[Trial],
sl_trials[n * 3 + i].advisor = Advisor(
advisor_id=body.advisor_id,
solution=t.solution,
written_strategy=wr_s.strategy
# written_strategy=wr_s.strategy
# TODO: remove this after pilot 2B !!!
# ----------------- Relevant for pilot 2B -----------------
written_strategy=comment
# ---------------------------------------------------------
)
# assign advisor's network to the trial
sl_trials[n * 3 + i].network = t.network
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Trials/Observation/Observation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Observation: FC<IObservation> = (props) => {
<Typography variant="h3" align='center'>
Watch player {teacherId} solves the task
</Typography>
<NetworkTrial showComment={true} teacherId={teacherId} isTimerPaused={!playAnimation}/>
<NetworkTrial showComment={true} teacherId={teacherId} isTimerPaused={true}/>
</>
);
}
Expand Down
121 changes: 95 additions & 26 deletions frontend/src/components/Trials/Trials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {StaticNetworkEdgeInterface} from "../Network/StaticNetwork/StaticNetwork
import WaitForNextTrialScreen from "./WaitForNextTrialScreen";

const TIME_BETWEEN_TRIALS = 1000;
const TIME_AFTER_LAST_STEP = 2000;


interface ITrial {
Expand Down Expand Up @@ -71,7 +72,8 @@ export const PracticeTrial: FC<ITrial> = (props) => {

return (
<>
<Header title={'Practice'} showTutorial={showTotalScoreTutorial} onTutorialClose={endTrial} showTip={false}/>
<Header title={'Practice'} showTutorial={showTotalScoreTutorial} onTutorialClose={endTrial}
showTip={false}/>
<NetworkTrial isPractice={true}/>
</>
);
Expand Down Expand Up @@ -102,18 +104,34 @@ export const SelectionTrial: FC<ITrial> = (props) => {
}

export const ObservationTrial: FC<ITrial> = (props) => {
const {sessionState} = useSessionContext();
const [isTimeoutAfterLastMoveDone, setIsTimeoutAfterLastMoveDone] = useState(false);
const {networkState} = useNetworkContext();
const {sessionState} = useSessionContext();

useEffect(() => {
if (networkState.isNetworkFinished) {
const timer1 = setTimeout(() => {
setIsTimeoutAfterLastMoveDone(true);
}, TIME_AFTER_LAST_STEP);
return () => clearTimeout(timer1);
} else {
setIsTimeoutAfterLastMoveDone(false);
}
}, [networkState.isNetworkFinished]);

useEffect(() => {
if (networkState.isNetworkFinished)
setTimeout(() => {
if (networkState.isNetworkFinished && isTimeoutAfterLastMoveDone) {
const timer2 = setTimeout(() => {
props.endTrial({moves: networkState.moves})
}, TIME_BETWEEN_TRIALS);
}, [networkState.isNetworkFinished]);
return () => clearTimeout(timer2);
}
}, [networkState.isNetworkFinished, isTimeoutAfterLastMoveDone]);

if (!networkState.network || !props.data.advisor || !props.data.advisor.solution || networkState.isNetworkFinished)
return <WaitForNextTrialScreen />
if (!networkState.network || !props.data.advisor || !props.data.advisor.solution)
return <WaitForNextTrialScreen/>
else if (networkState.isNetworkFinished && isTimeoutAfterLastMoveDone)
return <WaitForNextTrialScreen/>
else
return (
<>
Expand All @@ -128,18 +146,34 @@ export const ObservationTrial: FC<ITrial> = (props) => {
}

export const RepeatTrial: FC<ITrial> = (props) => {
const {sessionState} = useSessionContext();
const [isTimeoutAfterLastMoveDone, setIsTimeoutAfterLastMoveDone] = useState(false);
const {networkState} = useNetworkContext();
const {sessionState} = useSessionContext();

useEffect(() => {
if (networkState.isNetworkFinished) {
const timer1 = setTimeout(() => {
setIsTimeoutAfterLastMoveDone(true);
}, TIME_AFTER_LAST_STEP);
return () => clearTimeout(timer1);
} else {
setIsTimeoutAfterLastMoveDone(false);
}
}, [networkState.isNetworkFinished]);

useEffect(() => {
if (networkState.isNetworkFinished)
setTimeout(() => {
if (networkState.isNetworkFinished && isTimeoutAfterLastMoveDone) {
const timer2 = setTimeout(() => {
props.endTrial({moves: networkState.moves})
}, TIME_BETWEEN_TRIALS);
}, [networkState.isNetworkFinished]);
return () => clearTimeout(timer2);
}
}, [networkState.isNetworkFinished, isTimeoutAfterLastMoveDone]);

if (!networkState.network || !props.data.advisor || !props.data.advisor.solution || networkState.isNetworkFinished)
return <WaitForNextTrialScreen />
if (!networkState.network || !props.data.advisor || !props.data.advisor.solution)
return <WaitForNextTrialScreen/>
else if (networkState.isNetworkFinished && isTimeoutAfterLastMoveDone)
return <WaitForNextTrialScreen/>
else
return (
<>
Expand All @@ -156,11 +190,14 @@ export const TryYourselfTrial: FC<ITrial> = (props) => {
const {networkState} = useNetworkContext();

useEffect(() => {
if (networkState.isNetworkFinished)
if (networkState.isNetworkFinished) {
// wait for 4 seconds before submitting the results to give participant time to compare the solutions
setTimeout(() => {
const timer1 = setTimeout(() => {
props.endTrial({moves: networkState.moves})
}, 4000);

return () => clearTimeout(timer1);
}
}, [networkState.isNetworkFinished]);

const calculateScore = useCallback((moves: number[], edges: StaticNetworkEdgeInterface[]) => {
Expand All @@ -175,7 +212,7 @@ export const TryYourselfTrial: FC<ITrial> = (props) => {
}, []);

if (!networkState.network || !props.data.advisor || !props.data.advisor.solution)
return <WaitForNextTrialScreen />
return <WaitForNextTrialScreen/>
else
return (
<>
Expand All @@ -190,18 +227,34 @@ export const TryYourselfTrial: FC<ITrial> = (props) => {
}

export const IndividualTrial: FC<ITrial> = (props) => {
const [isTimeoutAfterLastMoveDone, setIsTimeoutAfterLastMoveDone] = useState(false);
const {networkState} = useNetworkContext();
const {sessionState} = useSessionContext();

useEffect(() => {
if (networkState.isNetworkFinished)
setTimeout(() => {
if (networkState.isNetworkFinished) {
const timer1 = setTimeout(() => {
setIsTimeoutAfterLastMoveDone(true);
}, TIME_AFTER_LAST_STEP);
return () => clearTimeout(timer1);
} else {
setIsTimeoutAfterLastMoveDone(false);
}
}, [networkState.isNetworkFinished]);

useEffect(() => {
if (networkState.isNetworkFinished && isTimeoutAfterLastMoveDone) {
const timer2 = setTimeout(() => {
props.endTrial({moves: networkState.moves})
}, TIME_BETWEEN_TRIALS);
}, [networkState.isNetworkFinished]);
return () => clearTimeout(timer2);
}
}, [networkState.isNetworkFinished, isTimeoutAfterLastMoveDone]);

if (!networkState.network || networkState.isNetworkFinished)
return <WaitForNextTrialScreen />
if (!networkState.network)
return <WaitForNextTrialScreen/>
else if (networkState.isNetworkFinished && isTimeoutAfterLastMoveDone)
return <WaitForNextTrialScreen/>
else
return (
<>
Expand All @@ -212,18 +265,34 @@ export const IndividualTrial: FC<ITrial> = (props) => {
}

export const DemonstrationTrial: FC<ITrial> = (props) => {
const [isTimeoutAfterLastMoveDone, setIsTimeoutAfterLastMoveDone] = useState(false);
const {networkState} = useNetworkContext();
const {sessionState} = useSessionContext();

useEffect(() => {
if (networkState.isNetworkFinished)
setTimeout(() => {
if (networkState.isNetworkFinished) {
const timer1 = setTimeout(() => {
setIsTimeoutAfterLastMoveDone(true);
}, TIME_AFTER_LAST_STEP);
return () => clearTimeout(timer1);
} else {
setIsTimeoutAfterLastMoveDone(false);
}
}, [networkState.isNetworkFinished]);

useEffect(() => {
if (networkState.isNetworkFinished && isTimeoutAfterLastMoveDone) {
const timer2 = setTimeout(() => {
props.endTrial({moves: networkState.moves})
}, TIME_BETWEEN_TRIALS);
}, [networkState.isNetworkFinished]);
return () => clearTimeout(timer2);
}
}, [networkState.isNetworkFinished, isTimeoutAfterLastMoveDone]);

if (!networkState.network || networkState.isNetworkFinished)
return <WaitForNextTrialScreen />
if (!networkState.network)
return <WaitForNextTrialScreen/>
else if (networkState.isNetworkFinished && isTimeoutAfterLastMoveDone)
return <WaitForNextTrialScreen/>
else
return (
<>
Expand Down

0 comments on commit a55787d

Please sign in to comment.