Skip to content

Commit

Permalink
it works not
Browse files Browse the repository at this point in the history
  • Loading branch information
fodfodfod committed Oct 25, 2023
1 parent e4bc986 commit c978bf7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
1 change: 1 addition & 0 deletions fancybuild.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
./gradlew build

mv lib/build/libs/lib.jar ../2023Robot/libs/ShuffleboardLib.jar
#mv lib/build/libs/lib.jar ../SwerveDrive/libs/ShuffleboardLib.jar
24 changes: 19 additions & 5 deletions lib/src/main/java/shuffleboardlib/Question.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@
public class Question {
private final String question;
private final HashMap<String, Question> answersHashMap;
private final boolean isFinal;
private final String output;
// private final SendableChooser<Question> answers;
// private static ArrayList<Question> questions = new ArrayList<Question>();

public Question(String question, HashMap<String, Question> answersHashMap){
/**
* Create a question
* @param question a string for the question
* @param answersHashMap a hashmap of all of the answers
* @param isFinal is this the final question in the tree (might not actually do anything)
* @param output the string output, should always be used with isFinal
*/
public Question(String question, HashMap<String, Question> answersHashMap, boolean isFinal, String output){
this.question = question;
this.answersHashMap = answersHashMap;
this.isFinal = isFinal;
this.output = output;


// questions.add(this);
}
Expand All @@ -24,10 +36,12 @@ public HashMap<String, Question> getAnswersHashMap(){
return answersHashMap;
}





public boolean isFinal(){
return isFinal;
}

public String getOutput(){
return output;
}

}
36 changes: 25 additions & 11 deletions lib/src/main/java/shuffleboardlib/Questionnaire.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import edu.wpi.first.wpilibj2.command.SubsystemBase;

public class Questionnaire extends SubsystemBase {
/**does not include "Shuffleboard/" */
/** does not include "Shuffleboard/" */
private final Question rootQuestion;
private final NetworkTable networkTable;
// questions are switchable choosers which include the questions and the answers
private final ArrayList<SendableChooser<Question>> answerSendableChoosers = new ArrayList<SendableChooser<Question>>();
// just the question publisher, i don't know why I have this
private final ArrayList<StringPublisher> questionPublishers = new ArrayList<StringPublisher>();
// private final ArrayList<String> questionStringThings = new ArrayList<String>();
// private final ArrayList<String> questionStringThings = new
// ArrayList<String>();
private final int numQuestions;

// a desision tree
Expand Down Expand Up @@ -47,18 +48,16 @@ public Questionnaire(String shuffleboardPath, Question rootQuestion, int numQues
// create the question publishers
for (int i = 0; i < numQuestions; i++) {
questionPublishers.add(networkTable.getStringTopic("Question " + i).publish());
//this will be the actual question, it will be setup during configureQuestion
// this will be the actual question, it will be setup during configureQuestion
// questionStringThings.add("");
// tab.addString(shuffleboardPath, null)
// tab.addString("Question " + i, () -> questionStringThings.get(test)).withPosition(6, i);
tab.add("Question " + i, "you should not see this").withPosition(6, i);
// tab.addString("Question " + i, () ->
// questionStringThings.get(test)).withPosition(6, i);
tab.add("Question " + i, "No Question").withPosition(6, i);

}


// add the root question to the sendable choosers
// answerSendableChoosers.get(0).setDefaultOption(rootQuestion.getQuestion(), rootQuestion);

// configure the first question
configureQuestion(0, rootQuestion);
// configure all the questions in a loop
Expand All @@ -69,6 +68,7 @@ public Questionnaire(String shuffleboardPath, Question rootQuestion, int numQues
}

private void configureQuestion(int questionNumber, Question question) {
//question and answer may not exist
try {
// add the question to the network table
questionPublishers.get(questionNumber).set(question.getQuestion());
Expand All @@ -77,25 +77,39 @@ private void configureQuestion(int questionNumber, Question question) {
answerSendableChoosers.get(questionNumber).setDefaultOption("NA", null);

// add the answers to the sendable choosers
// try it because it might be the last question so there won't be more answers

for (String answer : question.getAnswersHashMap().keySet()) {
answerSendableChoosers.get(questionNumber).addOption(answer, question.getAnswersHashMap().get(answer));
}
} catch (NullPointerException e) {
// question does not exist
// do nothing
}

}

/**
*
* @return the output of the selected option, if none is selected it returns none
*/
public String getOutput() {
for (SendableChooser<Question> question : answerSendableChoosers) {
if (question.getSelected() != null && question.getSelected().getOutput() != null){
return question.getSelected().getOutput();
}
}
return null;

}

@Override
public void periodic() {
// configure the first question
configureQuestion(0, rootQuestion);
// configure all the questions in a loop
for (int i = 1; i < numQuestions; i++) {
configureQuestion(i, answerSendableChoosers.get(i-1).getSelected());
configureQuestion(i, answerSendableChoosers.get(i - 1).getSelected());
}

}

}
1 change: 0 additions & 1 deletion lib/src/test/java/shuffleboardlib/LibraryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import org.junit.Test;
import static org.junit.Assert.*;
import shuffleboardlib.Questionnaire;

public class LibraryTest {
@Test public void someLibraryMethodReturnsTrue() {
Expand Down

0 comments on commit c978bf7

Please sign in to comment.