Skip to content

Commit

Permalink
tweeks extension iris
Browse files Browse the repository at this point in the history
  • Loading branch information
beatthat committed Feb 27, 2020
1 parent 047423a commit 7548b68
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions client/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ function toXapiResultExt(mentorData: MentorData, state: State): XapiResultExt {
question: state.curQuestion,
questionSource: state.curQuestionSource,
questionIndex: currentQuestionIndex(state),
timestampAnswered: state.curQuestionUpdatedAt,
timestampAsked: mentorData.answerReceivedAt,
timestampAnswered: new Date(state.curQuestionUpdatedAt),
timestampAsked: new Date(mentorData.answerReceivedAt),
};
}

Expand Down Expand Up @@ -266,7 +266,7 @@ export function mentorAnswerPlaybackStarted(video: {
verb: "https://mentorpal.org/xapi/verb/answer-playback-started",
result: {
extensions: {
"https://mentorpal.org/xapi/activity/extensions/mentor-response": toXapiResultExt(
"https://mentorpal.org/xapi/activity/extensions/verb/answer-playback-started": toXapiResultExt(
mentorData,
curState
),
Expand Down Expand Up @@ -314,7 +314,7 @@ export const sendQuestion = (q: {
sendXapiStatement({
result: {
extensions: {
"https://mentorpal.org/xapi/activity/extensions/actor-question": {
"https://mentorpal.org/xapi/result/extensions/verb/asked": {
questionIndex: currentQuestionIndex(getState()) + 1,
text: q.question,
source: q.source,
Expand Down Expand Up @@ -351,11 +351,9 @@ export const sendQuestion = (q: {
sendXapiStatement({
result: {
extensions: {
"https://mentorpal.org/xapi/activity/extensions/mentor-response": {
"https://mentorpal.org/xapi/result/extensions/verb/answered": {
...response,
question: q.question,
questionIndex: currentQuestionIndex(getState()),
mentor,
},
},
},
Expand All @@ -371,17 +369,14 @@ export const sendQuestion = (q: {
});
});
});

// ...but still don't move forward till we have all the answers,
// because we will prefer the user's fav and then highest confidence
const responses = (
await Promise.all<QuestionResponse>(promises.map(p => p.catch(e => e)))
).filter(r => !(r instanceof Error));

if (responses.length === 0) {
return;
}

// Play favored mentor if an answer exists
if (state.mentorFaved) {
const fave_response = responses.find(response => {
Expand All @@ -392,7 +387,6 @@ export const sendQuestion = (q: {
return;
}
}

// Otherwise play mentor with highest confidence answer
responses.sort((a, b) => (a.answerConfidence > b.answerConfidence ? -1 : 1));
if (responses[0].answerIsOffTopic) {
Expand All @@ -418,7 +412,6 @@ export const answerFinished = () => (
getState: () => State
) => {
dispatch(onIdle());

// order mentors by highest answer confidence
const state = getState();
const mentors = state.mentorsById;
Expand All @@ -437,20 +430,17 @@ export const answerFinished = () => (
});
});
responses.sort((a, b) => (a.confidence > b.confidence ? -1 : 1));

// get the most confident answer that has not been given
const mentorNext = responses.find(response => {
return (
response.status === MentorQuestionStatus.READY && !response.is_off_topic
);
});

// set the next mentor to start playing, if there is one
if (!mentorNext) {
return;
}
dispatch(nextMentor(mentorNext.id));

// play the next mentor after the timeout
if (timer) {
clearTimeout(timer);
Expand Down

0 comments on commit 7548b68

Please sign in to comment.