Skip to content

Commit

Permalink
Fixed several things for the "bye" confirmation. Known issue: #71. Th…
Browse files Browse the repository at this point in the history
…ere may be other bugs.
  • Loading branch information
ojcchar committed Aug 3, 2021
1 parent d4f6773 commit 3bd59d7
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 60 deletions.
1 change: 0 additions & 1 deletion burt-gui/src/components/ScreenOptions/AppSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const AppSelector = (props) => {
const [screen, setScreen] = useState({});
const [disabled, setDisable] = useState(props.disabled);


const pickImageHandler = (image) => {
setScreen(image);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public enum StateVariable {
//general ones
NEXT_INTENTS, CURRENT_MESSAGE, SESSION_ID, PARTICIPANT_ID, PARTICIPANT_VALIDATED, PARTICIPANT_ASKED,
CONFIRM_END_CONVERSATION, LAST_ACTION, ACTION_NEGATIVE_END_CONVERSATION, LAST_MESSAGE,
MSG_NEGATIVE_END_CONVERSATION,
MSG_NEGATIVE_END_CONVERSATION,CONFIRM_END_CONVERSATION_NEGATIVE,

//app variables
APP_NAME, APP_VERSION, APP_PACKAGE, APP_ASKED,
Expand All @@ -28,7 +28,7 @@ public enum StateVariable {
REPORT_OB, REPORT_EB, REPORT_S2R, REPORT_GENERATED,

//reporting time
REPORTING_START_TIME, REPORTING_END_TIME
REPORTING_START_TIME, REPORTING_END_TIME



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import sealab.burt.nlparser.euler.actions.utils.AppNamesMappings;
import sealab.burt.server.actions.ChatBotAction;
import sealab.burt.server.conversation.entity.ChatBotMessage;
import sealab.burt.server.conversation.state.ConversationState;
import sealab.burt.server.conversation.entity.KeyValues;
import sealab.burt.server.conversation.entity.UserResponse;
import sealab.burt.server.conversation.state.ConversationState;

import java.text.MessageFormat;
import java.util.Arrays;
Expand Down Expand Up @@ -35,33 +35,40 @@ public List<ChatBotMessage> execute(ConversationState state) {
if (!msg.getMessages().isEmpty()) {
List<String> selectedValues = msg.getMessages().get(0).getSelectedValues();

//if not selected values, return an alert message
if (selectedValues == null || selectedValues.isEmpty())
return incorrectOptionMessages;

selectedApp = selectedValues.get(0);
}

//--------------------------------------

String finalSelectedApp = selectedApp;
Optional<KeyValues> appOption = SelectAppAction.ALL_APPS.stream()
.filter(app -> app.getKey().equals(finalSelectedApp))
.findFirst();

//invalid app selection
if (appOption.isEmpty()) {
return incorrectOptionMessages;
}

//-------------------------------------------

//at this point there is a valid app selection

this.nextExpectedIntents = Arrays.asList(AFFIRMATIVE_ANSWER, NEGATIVE_ANSWER);

//add app info to the state
String appNameVersion = appOption.get().getValue1();
String[] tokens = appNameVersion.split("v\\.");
String appName = tokens[0].trim();
state.put(APP_NAME, appName);
state.put(APP_VERSION, tokens[1].trim());

List<String> packageNames = AppNamesMappings.getPackageNames(appName);
if (packageNames==null || packageNames.isEmpty())
if (packageNames == null || packageNames.isEmpty())
throw new RuntimeException("Could not find packages for " + appName);
state.put(APP_PACKAGE, packageNames.get(0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import sealab.burt.server.conversation.entity.*;
import sealab.burt.server.conversation.state.ConversationState;
import sealab.burt.server.msgparsing.Intent;
import sealab.burt.server.conversation.state.QualityStateUpdater;

import java.util.Collections;
import java.util.List;
Expand All @@ -31,7 +30,6 @@ public List<ChatBotMessage> execute(ConversationState state) {
QualityResult result = (QualityResult) state.get(OB_QUALITY_RESULT);
List<GraphState> matchedStates = result.getMatchedStates();


//-------------------------------------
Integer currentObScreenPosition = (Integer) state.get(CURRENT_OB_SCREEN_POSITION);

Expand Down Expand Up @@ -79,41 +77,57 @@ public List<ChatBotMessage> execute(ConversationState state) {
.append("\"");

state.remove(StateVariable.CURRENT_OB_SCREEN_POSITION);
state.remove(CONFIRM_END_CONVERSATION_NEGATIVE);

return createChatBotMessages(response.toString(), "Shall we continue?");


} else if (NONE.equals(message.getMessage())) {

state.remove(OB_SCREEN_SELECTED);

boolean nextAttempt = state.checkNextAttemptAndResetObScreens();
//-----------------------------------
//manage attempts

log.debug("Current attempt (OB_SCREENS): " + state.getCurrentAttemptObScreens());
boolean negativeEndConversationConfirmation = state.containsKey(CONFIRM_END_CONVERSATION_NEGATIVE);

if (!nextAttempt) {
if (!negativeEndConversationConfirmation) {
boolean nextAttempt = state.checkNextAttemptAndResetObScreens();

startEBChecker(state);
this.setNextExpectedIntents(Collections.singletonList(Intent.EB_DESCRIPTION));
log.debug("Current attempt (OB_SCREENS): " + state.getCurrentAttemptObScreens());

QualityStateUpdater.updateOBState(state, null);
if (!nextAttempt) {

return createChatBotMessages("All right. Let's continue.",
"Can you please tell me how the app is supposed to work instead?"
);
}
startEBChecker(state);
this.setNextExpectedIntents(Collections.singletonList(Intent.EB_DESCRIPTION));

state.getStateUpdater().updateOBState(state, null);

state.increaseCurrentAttemptObScreens();
return createChatBotMessages("All right. Let's continue.",
"Can you please tell me how the app is supposed to work instead?"
);
}

state.increaseCurrentAttemptObScreens();
}

//---------------------------
//increase ob screen position

//increase the position of the next OB screen batch
currentObScreenPosition += SelectOBScreenAction.MAX_OB_SCREENS_TO_SHOW;
if (!negativeEndConversationConfirmation) {
currentObScreenPosition += SelectOBScreenAction.MAX_OB_SCREENS_TO_SHOW;
}
state.put(StateVariable.CURRENT_OB_SCREEN_POSITION, currentObScreenPosition);

//---------------------------
//prepare options

//get the options
List<KeyValues> options = SelectOBScreenAction.getObScreenOptions(matchedStates, state,
currentObScreenPosition);

state.remove(CONFIRM_END_CONVERSATION_NEGATIVE);

if (options.isEmpty()) {

Expand All @@ -135,13 +149,15 @@ public List<ChatBotMessage> execute(ConversationState state) {
//----------------------------------

MessageObj messageObj = new MessageObj(
" Please hit the \"<b>Done</b>\" button after you have selected it.", WidgetName.OBScreenSelector);
" Please hit the \"<b>Done</b>\" button after you have selected it.",
WidgetName.OBScreenSelector);

return createChatBotMessages(
"Okay then, which of the following screens is <b>having or triggering the problem</b>?",
new ChatBotMessage(messageObj, options, false));
}
} else {
state.remove(CONFIRM_END_CONVERSATION_NEGATIVE);
return getDefaultMessage(matchedStates, state, currentObScreenPosition);
}

Expand All @@ -155,7 +171,8 @@ private List<ChatBotMessage> getDefaultMessage(List<GraphState> matchedStates,
List<KeyValues> options = SelectOBScreenAction.getObScreenOptions(matchedStates, state, position);

MessageObj messageObj = new MessageObj(
"From the list below, can you please <b>select the screen that is having or triggering the problem</b>?",
"From the list below, can you please select the <b>screen that is having or triggering the " +
"problem</b>?",
WidgetName.OBScreenSelector);

return createChatBotMessages(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import sealab.burt.server.conversation.entity.*;
import sealab.burt.server.conversation.state.ConversationState;
import sealab.burt.server.msgparsing.Intent;
import sealab.burt.server.conversation.state.QualityStateUpdater;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -44,7 +43,6 @@ public List<ChatBotMessage> execute(ConversationState state) {
if (highQualityAssessment == null)
throw new RuntimeException("The high quality assessment is required");


UserResponse highQualityMessage = (UserResponse) state.get(S2R_MATCHED_MSG);
String highQualityStepMessage = highQualityMessage.getMessages().get(0).getMessage();

Expand All @@ -68,7 +66,6 @@ public List<ChatBotMessage> execute(ConversationState state) {
return getDefaultMessage(allMissingSteps, state);

state.getStateUpdater().addStepsToState(state, selectedSteps);

state.getStateUpdater().addStepAndUpdateGraphState(state, highQualityStepMessage, highQualityAssessment);

//---------------------
Expand All @@ -79,18 +76,25 @@ public List<ChatBotMessage> execute(ConversationState state) {
.append(" prior step(s).");

StringBuilder msg2 = new StringBuilder();
msg2.append("What step did <b>you perform after the step</b> \"")
msg2.append("What step did you perform <b>after the step</b> \"")
.append(highQualityStepMessage)
.append("\"?");


state.remove(CONFIRM_END_CONVERSATION_NEGATIVE);
return createChatBotMessages(msg1.toString(), msg2.toString());

} else if (NONE.equals(message.getMessage())) {

state.getStateUpdater().addStepAndUpdateGraphState(state, highQualityStepMessage, highQualityAssessment);
boolean negativeEndConversationConfirmation = state.containsKey(CONFIRM_END_CONVERSATION_NEGATIVE);
if (!negativeEndConversationConfirmation)
state.getStateUpdater().addStepAndUpdateGraphState(state, highQualityStepMessage,
highQualityAssessment);

state.remove(CONFIRM_END_CONVERSATION_NEGATIVE);
return createChatBotMessages("Got it, what is the next step?");
} else {
state.remove(CONFIRM_END_CONVERSATION_NEGATIVE);
return getDefaultMessage(allMissingSteps, state);
}

Expand All @@ -102,7 +106,7 @@ private List<ChatBotMessage> getDefaultMessage(List<AppStep> allMissingSteps,
List<KeyValues> stepOptions = SelectMissingS2RAction.getStepOptions(allMissingSteps, state);

MessageObj messageObj = new MessageObj(
"From the following options, <b>select the steps you performed before this step</b>",
"From the following options, please select the <b>steps that you performed before this step</b>",
WidgetName.S2RScreenSelector);

return createChatBotMessages(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,62 +72,65 @@ public List<ChatBotMessage> execute(ConversationState state) {
.filter(qa -> qa.getCategory().equals(S2RQualityCategory.MISSING))
.findFirst().get();

final List<AppStep> inferredSteps = assessment.getInferredSteps();
final List<AppStep> cleanedInferredSteps = cleanSteps(inferredSteps, state);
final List<AppStep> missingSteps = assessment.getInferredSteps();
final List<AppStep> cleanedMissingSteps = cleanSteps(missingSteps, state);

//---------------------------------------------------

List<AppStep> cleanedInferredSteps2 = removeLastReportSteps(state, cleanedInferredSteps);
List<AppStep> newCleanedMissingSteps = removeLastReportSteps(state, cleanedMissingSteps);

//---------------------------------------------------


UserResponse msg = (UserResponse) state.get(S2R_MATCHED_MSG);
String highQualityStepMessage = msg.getMessages().get(0).getMessage();

//---------------------------------------------------
boolean negativeEndConversationConfirmation = state.containsKey(CONFIRM_END_CONVERSATION_NEGATIVE);

if (cleanedInferredSteps2.isEmpty()) {

S2RQualityAssessment highQualityAssessment = feedback.getQualityAssessments().stream()
.filter(qa -> qa.getCategory().equals(S2RQualityCategory.HIGH_QUALITY))
.findFirst().orElse(null);
if (newCleanedMissingSteps.isEmpty()) {

if (highQualityAssessment == null)
throw new RuntimeException("The high quality assessment is required");
if (!negativeEndConversationConfirmation) {
S2RQualityAssessment highQualityAssessment = feedback.getQualityAssessments().stream()
.filter(qa -> qa.getCategory().equals(S2RQualityCategory.HIGH_QUALITY))
.findFirst().orElse(null);

this.nextExpectedIntents = Collections.singletonList(S2R_DESCRIPTION);
if (highQualityAssessment == null)
throw new RuntimeException("The high quality assessment is required");

state.getStateUpdater().addStepAndUpdateGraphState(state, highQualityStepMessage, highQualityAssessment);
state.getStateUpdater().addStepAndUpdateGraphState(state, highQualityStepMessage, highQualityAssessment);
}

this.nextExpectedIntents = Collections.singletonList(S2R_DESCRIPTION);
return createChatBotMessages("Got it, what is the next step?");
}

//---------------------------------------------------

List<KeyValues> stepOptions = getStepOptions(cleanedInferredSteps2, state);
List<KeyValues> stepOptions = getStepOptions(newCleanedMissingSteps, state);

state.put(S2R_ALL_MISSING, cleanedInferredSteps2);
state.put(S2R_ALL_MISSING, newCleanedMissingSteps);

//-----------------

state.remove(CONFIRM_END_CONVERSATION_NEGATIVE);

MessageObj messageObj = new MessageObj(
"Remember that the displayed screenshots are <b>for reference only</b>."
, WidgetName.S2RScreenSelector);
return createChatBotMessages(
"Got it! You reported the step \"" + highQualityStepMessage + "\"",
"It seems that <b>before that step you had to perform additional steps</b>. ",
"From the following options, please <b>select the steps that you performed before this step</b> and click " +
"It seems that before that step you had to perform <b>additional steps</b>. ",
"From the following options, please select the <b>steps that you performed before this step</b> and click " +
"the \"<b>done</b>\" button", new ChatBotMessage(messageObj, stepOptions, true));

}

private List<AppStep> removeLastReportSteps(ConversationState state, List<AppStep> cleanedInferredSteps) {
private List<AppStep> removeLastReportSteps(ConversationState state, List<AppStep> cleanedMissingSteps) {

//remove the last five "report" steps from the missing steps
List<BugReportElement> stepElements = (List<BugReportElement>) state.get(REPORT_S2R);

List<AppStep> cleanedInferredSteps2 = cleanedInferredSteps;
List<AppStep> newCleanedMissingSteps = cleanedMissingSteps;
if (stepElements !=null ) {
List<AppStep> lastSteps = stepElements
.subList(Math.max(stepElements.size() - 5, 0), stepElements.size())
Expand All @@ -136,13 +139,13 @@ private List<AppStep> removeLastReportSteps(ConversationState state, List<AppSte
.filter(Objects::nonNull)
.collect(Collectors.toList());

cleanedInferredSteps2 = cleanedInferredSteps.stream()
newCleanedMissingSteps = cleanedMissingSteps.stream()
.filter(step -> lastSteps.stream().noneMatch(
lasStep -> S2RPredictor.matchByTransitionId.test(step, lasStep)
))
.collect(Collectors.toList());
}
return cleanedInferredSteps2;
return newCleanedMissingSteps;
}

private List<AppStep> cleanSteps(List<AppStep> steps, ConversationState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void addStepsToState(ConversationState state,
state.put(REPORT_S2R, stepElements);
}

public static void updateOBState(ConversationState state, GraphState obState) {
public void updateOBState(ConversationState state, GraphState obState) {

log.debug("Updating OB state to: " + obState);

Expand All @@ -152,7 +152,7 @@ public static void updateOBState(ConversationState state, GraphState obState) {
}


public static void updateEBState(ConversationState state, GraphState ebState) {
public void updateEBState(ConversationState state, GraphState ebState) {

log.debug("Updating EB state to: " + ebState);

Expand Down
Loading

0 comments on commit 3bd59d7

Please sign in to comment.