Commit 7d702331 authored by Xiaoying Pu's avatar Xiaoying Pu

put the logic together

parent c275b0d9
......@@ -8,7 +8,7 @@ import java.util.List;
import javax.swing.UIManager;
import util.EventListener;
import util.EventType;
import util.State;
import util.WLState;
/**
* In the spirit of modularity, an interface for controlling the digit task.
......@@ -95,7 +95,7 @@ public class DigitTaskFacade {
* @param workload
*
*/
public void showDigit(State workload) {
public void showDigit(WLState workload) {
java.awt.EventQueue.invokeLater(() -> {
theController.startStressor(workload);
});
......
......@@ -8,7 +8,7 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import util.EventListener;
import util.EventType;
import util.State;
import util.WLState;
/**
*
......@@ -98,7 +98,7 @@ public class SecondaryTaskController implements ActionListener {
*
* @param workload
*/
public void startStressor(State workload) {
public void startStressor(WLState workload) {
final String stressor = theModel.generateStressor(workload);
java.awt.EventQueue.invokeLater(() -> {
......
......@@ -2,7 +2,7 @@ package digit.model;
import java.util.Random;
import util.Configurator;
import util.State;
import util.WLState;
/**
*
......@@ -37,23 +37,23 @@ public class SecondaryTaskModel {
* @param workload
* @return
*/
public String generateStressor(State workload) {
public String generateStressor(WLState workload) {
// TODO change the constructor to take Configurator data
Random randomGenerator = new Random();
double seed = randomGenerator.nextDouble();
if (workload == State.HIGH_WORKLOAD) {
if (workload == WLState.HIGH_WORKLOAD) {
curDigit = (int) (seed * 10000000); // TODO: prevent hardcoding
} else if (workload == State.LOW_WORKLOAD) {
} else if (workload == WLState.LOW_WORKLOAD) {
curDigit = (int) (seed * 10);
}
String strCurDigit = Integer.toString(curDigit);
// Guarantees 6 digits
if (workload == State.HIGH_WORKLOAD) {
if (workload == WLState.HIGH_WORKLOAD) {
while (strCurDigit.length() < 6) {
strCurDigit = "0" + strCurDigit;
}
......
......@@ -18,11 +18,10 @@ public class TestUDPController {
UDPController cntrl = new UDPController();
cntrl.setUp();
for (int i = 0; i < util.UDPConstants.TrialSet.length; i++) {
// not useable any more because of the interface change
//for (int i = 0; i < util.UDPConstants.TrialSet.length; i++) {
// not useable any more because of the interface change
// cntrl.sendTrialAndRecvResponse(i);
}
cntrl.endExperiment();
}
//cntrl.endExperiment();
}
......@@ -6,6 +6,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import util.EventListener;
import util.EventType;
import util.WLState;
/**
* This visage, no mere veneer of vanity, is a vestige of vox populi, now
......@@ -23,6 +24,7 @@ public class MouseTrackerFacade {
this.theModel = new PrimaryTaskModel();
this.theController = new PrimaryTaskController(theModel);
this.eventList = new ArrayList<>();
this.theController.addListener(new ControllerEndDecisionListener());
}
public void theFirstContact() {
......@@ -31,20 +33,22 @@ public class MouseTrackerFacade {
/**
*
* @param state
*/
public void startAndWait() {
public void startAndWait(WLState state) {
// TODO: impl: send signals and stuff, right?
System.out.println("Make a choice: ");
System.out.println("Waiting response... ");
// TODO: REMOVE THIS AFTER IMPLENMENTING THE UDP STUFF
endDecision();
this.theController.startDecision(state);
}
/**
* TODO: Either user make a decision, or time is up
*/
private void endDecision() {
public void endDecision() {
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
......@@ -64,4 +68,12 @@ public class MouseTrackerFacade {
listener.run(type);
});
}
class ControllerEndDecisionListener extends EventListener {
@Override
public void run(EventType type) {
}
}
}
......@@ -7,6 +7,7 @@ import java.util.logging.Logger;
import util.DecisionType;
import util.EventListener;
import util.EventType;
import util.WLState;
/**
*
......@@ -54,9 +55,10 @@ public class PrimaryTaskController {
return this.theModel.getCurTaskID();
}
public void startDecision() {
public void startDecision(WLState state) {
//TODO need to fix this
this.udpHandle.sendTrialAndRecvResponse(this.theModel.getDecision(DecisionType.GETMIXATYPICAL, "HWL"));
String msg = this.theModel.getDecision(DecisionType.GETMIXATYPICAL, state.toString());
this.udpHandle.sendTrialAndRecvResponse(msg);
System.out.println("Decision started, waiting for response.. ");
}
......
......@@ -81,6 +81,7 @@ public class Trial extends Thread {
case DIGITINPUT_FINISHED:
actionQueue.add(new QuitAction(ActionType.QUIT_TRIAL));
break;
default:
System.err.println(type.toString());
System.err.println("Was ist los?");
......@@ -128,10 +129,21 @@ public class Trial extends Thread {
@Override
public void run() {
ActionType type = this.getType();
if (type == ActionType.START_HWL_DIGIT) {
sFacade.showDigit(util.State.HIGH_WORKLOAD);
} else if (type == ActionType.START_LWL_DIGIT) {
sFacade.showDigit(util.State.LOW_WORKLOAD);
// how ugly is this
if (type == ActionType.START_HWL_DIGIT
|| type == ActionType.START_LWL_DIGIT) {
WLState curState;
if (type == ActionType.START_HWL_DIGIT) {
curState = WLState.HIGH_WORKLOAD;
sFacade.showDigit(util.WLState.HIGH_WORKLOAD);
} else {
curState = WLState.LOW_WORKLOAD;
sFacade.showDigit(util.WLState.LOW_WORKLOAD);
}
// start UDP to MouseTracker
pFacade.startAndWait(curState);
}
int tTask = Configurator.gettSTask();
......@@ -152,9 +164,6 @@ public class Trial extends Thread {
Logger.getLogger(Dm_task.class.getName()).log(Level.SEVERE, null, ex);
}
pFacade.startAndWait();
/* TODO: how to handle the deicion making task returned?
Wait for an event;
if timed out, event should be fired regardless, but where should the timer be???
......
......@@ -27,18 +27,18 @@ public class UDPConstants {
public static int UDP_TIMEOUT = 20 * 1000; // in millisecond
public static int PACKET_LENGTH = 512;
public static String[] TrialSet = {
"2,Microsoft,technology,,1,2,",
"2,Gucci,fashion,,2,1,",
"2,Apple,technology,,1,2,",
"2,Sony,technology,,1,2,",
"2,Prada,fashion,,2,1,",
"2,MarcJacobs,fashion,,2,1,", // The system doesn't like the space between Marc and Jacobs...
"2,IBM,technology,,1,2,",
"2,Versace,fashion,,2,1,",
"2,Toshiba,technology,,1,2,",
"2,Valentino,fashion,,2,1,"}; // got rid of an extra comma
//type,stim,cond,rand,correct,default-compare,resp_1,resp_2
// public static String[] TrialSet = {
// "2,Microsoft,technology,,1,2,",
// "2,Gucci,fashion,,2,1,",
// "2,Apple,technology,,1,2,",
// "2,Sony,technology,,1,2,",
// "2,Prada,fashion,,2,1,",
// "2,MarcJacobs,fashion,,2,1,", // The system doesn't like the space between Marc and Jacobs...
// "2,IBM,technology,,1,2,",
// "2,Versace,fashion,,2,1,",
// "2,Toshiba,technology,,1,2,",
// "2,Valentino,fashion,,2,1,"}; // got rid of an extra comma
// //type,stim,cond,rand,correct,default-compare,resp_1,resp_2
// public static String[] TrialSet = {
// "2,Female,HWL,1,1,2,Female,Male",
// "2,Male,HWL,1,1,1,Male,Female",
......@@ -50,7 +50,6 @@ public class UDPConstants {
// "2,Man,LWL,1,2,1,Female,Male",
// "2,Wife,LWL,1,1,2,Female,Male"
// };
public static int success = 0;
......
......@@ -5,7 +5,7 @@ package util;
*
* @author Xiaoying Pu <xp002@bucknell.edu>
*/
public enum State {
public enum WLState {
HIGH_WORKLOAD(7),
LOW_WORKLOAD(1);
......@@ -15,7 +15,7 @@ public enum State {
*/
private int digitLen;
State(int howManyBack) {
WLState(int howManyBack) {
this.digitLen = howManyBack;
}
......
......@@ -6,7 +6,7 @@
package digit;
import org.junit.Test;
import util.State;
import util.WLState;
/**
*
......@@ -23,7 +23,7 @@ public class DigitTaskFacadeTest {
@Test
public void testShowDigit() {
System.out.println("showDigit");
State workload = null;
WLState workload = null;
DigitTaskFacade instance = new DigitTaskFacade();
instance.showDigit(workload);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment