Commit d39bd399 authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

Added logging and readme file

parent 1dd7a309
......@@ -15,6 +15,8 @@ import org.jnativehook.keyboard.NativeKeyEvent;
import com.sun.jna.platform.win32.WinUser.WINDOWINFO;
private static final int WS_ICONIC = 0x20000000; //for check minimized
import java.util.ArrayList;
import java.util.Scanner;
import shiffman.box2d.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.joints.*;
......@@ -24,10 +26,14 @@ import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;
import org.jbox2d.dynamics.contacts.*;
import java.io.*;
import java.util.Date;
Box2DProcessing box2d;
boolean question;
int afterAttentionTime;
String user = "gaa721";
float afterAttentionTime;
String participationID;
Capture video;
OpenCV opencv;
......@@ -61,46 +67,115 @@ int drawdelay;
boolean eof=false;
float rx, ry;
float rx1, ry1, m, c;
FileInputStream fileIn, fileInE;
FileInputStream fileIn, fileInE, fileInQ;
String currShape;
float cx, cy;
FileOutputStream fileOut, fileOutE;
FileOutputStream fileOut, fileOutE, fileOutQ;
float cradius;
ObjectOutputStream out, outE;
ObjectInputStream in, inE;
ObjectOutputStream out, outE, outQ;
ObjectInputStream in, inE, inQ;
OutputStream os;
int t;
boolean complete;
int Stime, timer;
boolean questionMouse;
float questionBoxX, questionBoxY;
boolean changingFile = false;
Date date = new Date();
//File logfile ;// new File("c:/Users/gaa721/Desktop/" + date.toString() + "-" + participationID );
PrintWriter writer;
FileWriter fw ;
BufferedWriter bw;
String folderName ;
// D)
//String[] Questions = {
// "Select the most recent portion","was line drawn first or circle was moved first? Select that ", "Select the most recent portion", "Select the new portion drawn after the black screen "
//};
// C)
//String[] Questions = {
// "Select the portion drwan immediately after the black screen","where was the deleted circle? ", "What was the initial position of the smaller circle", "In which circle something was drawn? ","was anything deleted, select that"
//};
// B)
//String[] Questions = {
// "What is starting point of the botommost line","What was the position of the circle before moving? ", "Select the most recent line drawn?", "Where was the deleted object before deletion? "
//};
// A)
//String[] Questions = {
// "What is most recent drawing","Which portion has stayed for least amount of time? ", "Which circle travlelled more distance", "What was drawn immediately after the black screen? "
//};
// "E")
String[] Questions = {
"Select the portion which was drawn after the black screen", "Select The portion which was drawn recently", "Select the portion which had stayed longest after the black Screen", "Select the portion which was drawn after the black screen", "Select The portion which was drawn recently", "Select The portion which was drawn recently", "Select the objects which were moved", "Select The portion which was drawn recently", "Thnaks"
"Select the portion which was drawn after the black screen", "Select the portion which was drawn IMMEDIATELY after the black screen", "Select the portion which had stayed longest after the black Screen", "Select the portion which was drawn RECENTLY", "Select The portion which was drawn recently ", "Select The starting position of new line created"
}
;
int QuestionCounter;
int frameCounter;
boolean startMenu ;
Rectangle[] r = {
new Rectangle(111.0, 65.0, 347.0, 258.0), new Rectangle(1467.0, 265.0, 1570.0, 382.0), new Rectangle(447.0, 209.0, 529.0, 343.0), new Rectangle(1103.0, 185.0, 1202.0, 291.0), new Rectangle(915.0, 208.0, 958.0, 258.0), new Rectangle(1231.0, 660.0, 1385.0, 803.0), new Rectangle(1340.0, 839.0, 1434.0, 911.0)
};
float totalShapesandTrailCount = 0;
boolean questionSaving;
ArrayList<Question> questions ;
char tempFiler = 'E';
void setup()
{
QuestionCounter = 0;
createGUI();
startMenu = true;
setupInside();
}
void setupInside()
{
QuestionCounter = 0;
button1.setVisible(false);
// createGUI1();
frameCounter = 0;
afterAttentionTime=2;
afterAttentionTime=1.2;
complete= true;
frameCounter = 0;
startMenu = true;
Stime = millis();
Stime = 0;//millis();
question = false;
timer=0;
saveornot = false;
t=0;
mover=10;
questionSaving = false;
questions = new ArrayList<Question>();
changingFile = false;
if (questionSaving)
{
try {
fileOutQ = new FileOutputStream("c:/Users/"+user+"/Desktop/" +"DrawingData/"+ tempFiler + "Quest.ser");
}
catch (FileNotFoundException ex) {
// Do something with mistake or ignore
print( ex.toString());
}
try {
outQ = new ObjectOutputStream(fileOutQ);
}
catch (IOException e) {
System.err.println(e);
}
}
if (saveornot)
{
try {
fileOut = new FileOutputStream("c:/Users/gaa721/Desktop/shapes.ser");
fileOutE = new FileOutputStream("c:/Users/gaa721/Desktop/Events.ser");
fileOut = new FileOutputStream("c:/Users/"+user+"/Desktop/" +"DrawingData/"+ tempFiler + "shapes.ser");
fileOutE = new FileOutputStream("c:/Users/"+user+"/Desktop/" +"DrawingData/"+ tempFiler + "Events.ser");
}
catch (FileNotFoundException ex) {
// Do something with mistake or ignore
......@@ -109,6 +184,7 @@ void setup()
try {
out = new ObjectOutputStream(fileOut);
outE = new ObjectOutputStream(fileOutE);
outQ = new ObjectOutputStream(fileOutQ);
}
catch (IOException e) {
System.err.println(e);
......@@ -116,7 +192,6 @@ void setup()
}
k=0;
eof=false;
drawdelay=10;
size(displayWidth-100, displayHeight-100);
attentHere=false;
......@@ -126,6 +201,7 @@ void setup()
aboveWindows = new ArrayList<RECT>();
rectOfInterest = new RECT();
windowOfInterest = User32.INSTANCE.GetForegroundWindow();
totalShapesandTrailCount = 0;
// prepareExitHandler();
//remove this when webcam is on
......@@ -151,11 +227,10 @@ void setup()
// Turn on collision listening!
box2d.listenForCollisions();
//
rx=random(10, 490);
ry=random(10, 490);
rx1=random(10, 490);
ry1=random(10, 490);
rx = random(10, 490);
ry = random(10, 490);
rx1= random(10, 490);
ry1= random(10, 490);
//rx=20;
//ry=20;
//rx1=60;
......@@ -168,10 +243,12 @@ void setup()
currShape = "b";
try {
fileIn = new FileInputStream("c:/Users/gaa721/Desktop/shapes.ser");
fileInE = new FileInputStream("c:/Users/gaa721/Desktop/Events.ser");
fileIn = new FileInputStream("c:/Users/"+user+"/Desktop/" + "DrawingData/"+tempFiler + "shapes.ser");
fileInE = new FileInputStream("c:/Users/"+user+"/Desktop/" + "DrawingData/"+tempFiler + "Events.ser");
fileInQ = new FileInputStream("c:/Users/"+user+"/Desktop/" + "DrawingData/"+tempFiler + "Quest.ser");
in = new ObjectInputStream(fileIn);
inE = new ObjectInputStream(fileInE);
inQ = new ObjectInputStream(fileInQ);
}
catch(FileNotFoundException o)
{
......@@ -209,75 +286,117 @@ void setup()
return;
}
}
//print(p.shapes.size());
for (Shape s: p.shapes)
eof = false;
if (!questionSaving)
{
//print(s.data.shape);
try {
while (!eof)
{
Question tempQuest = (Question) inQ.readObject();
questions.add(tempQuest);
}
}
catch(ClassNotFoundException i) {
}
catch(java.io.EOFException ex1)
{
eof=true;
}
catch(IOException i)
{
i.printStackTrace();
return;
}
}
//print(p.shapes.size());
// for (Shape s: p.shapes)
// {
// //print(s.data.shape);
// }
}
void draw()
{
if (!saveornot)
if (!changingFile)
{
if (!startMenu)
if (!saveornot)
{
// attention = true;
timer = millis() - Stime;
// print(timer + " ") ;
if (!question )
if (!startMenu)
{
if (timer<=10000 )
// attention = true;
timer = (int)totalShapesandTrailCount - Stime;
// print(timer + " ") ;
if (!question )
{
attention = true;
drawing();
}
else
{
attention = false;
drawing();
background(0, 0, 0);
if (timer>=15000 )
if (timer<=100 )
{
timer = 0;
Stime = millis();
question = true;
attention = true;
drawing();
fill(0, 0, 0);
text(Questions[QuestionCounter], 600, 600);
}
else
{
attention = false;
drawing();
background(0, 0, 0);
if (p.Ecounter>=p.e.e.size()-3 )
timer= 200;
if (timer>=200 )
{
timer = 0;
Stime = (int)totalShapesandTrailCount;
question = true;
drawing();
textSize(20);
fill(0, 0, 0);
if (!questionSaving)
text(questions.get(QuestionCounter).getQuestion(), 600, 600);
else
text(Questions[QuestionCounter], 600, 600);
}
}
}
}
if (question)
{
if (question)
{
if (!questionMouse)
{
if (mousePressed)
if (!questionMouse)
{
pushMatrix();
background(255);
p.drawAll();
text(Questions[QuestionCounter], 600, 600);
rectMode(CORNERS);
fill(0, 0, 0, 80);
rect(questionBoxX, questionBoxY, mouseX, mouseY);
popMatrix();
if (mousePressed)
{
pushMatrix();
background(255);
p.drawAll();
pushMatrix();
rectMode(CORNERS);
textSize(20);
// if(!questionSaving)
// rect((float)questions.get(QuestionCounter).answer.p1.x, (float)questions.get(QuestionCounter).answer.p1.y, (float)questions.get(QuestionCounter).answer.p2.x, (float)questions.get(QuestionCounter).answer.p2.y);
popMatrix();
if (!questionSaving)
text(questions.get(QuestionCounter).getQuestion(), 600, 600);
else
text(Questions[QuestionCounter], 600, 600);
rectMode(CORNERS);
fill(0, 0, 0, 80);
// rect(questionBoxX, questionBoxY, sqrt(sq(mouseX-questionBoxX) + sq(mouseY - questionBoxY)), sqrt(sq(mouseX-questionBoxX) + sq(mouseY - questionBoxY)));
rect(questionBoxX, questionBoxY, mouseX, mouseY);
popMatrix();
}
}
}
}
} //drawing();
} //drawing();
}
else
drawing();
}
else
drawing();
}
......@@ -306,10 +425,13 @@ void mousePressed()
// }
if (question && questionMouse)
{
text("Select the portion which was drawn first after the black screen", 600, 600);
if (!questionSaving)
text(questions.get(QuestionCounter).getQuestion(), 600, 600);
else
text(Questions[QuestionCounter], 600, 600);
questionBoxX=mouseX;
questionBoxY=mouseY;
ellipse(questionBoxX, questionBoxY, 10, 10);
// ellipse(questionBoxX, questionBoxY, 10, 10);
questionMouse = false;
}
}
......@@ -321,6 +443,7 @@ void mouseReleased()
mp=false;
p.e.addEvent('d', p.shapes.size());
print(totalShapesandTrailCount++ + " ");
p.addShape(currShape, cx, cy, cradius);
}
if (question)
......@@ -331,17 +454,73 @@ void mouseReleased()
// rect(questionBoxX,questionBoxX,mouseX,mouseY);
questionMouse = true;
question = false;
QuestionCounter++;
if (QuestionCounter>=Questions.length)
noLoop();
Rectangle r1 = new Rectangle(questionBoxX, questionBoxY, mouseX, mouseY);
// print(questionBoxX + " " +questionBoxY + " " +mouseX + " " +mouseY);
r1.show();
if (!questionSaving)
{
questions.get(QuestionCounter).answer.show();
double intersection = r1.getIntersectionPercent(questions.get(QuestionCounter).answer, r1);
double bigRecRatio = (r1.getArea()/questions.get(QuestionCounter).answer.getArea());
print(intersection);
String rightorwronng = "";
if ( intersection > 70.0 && bigRecRatio <2.00)
{
rightorwronng = "Correct";
}
else if ( intersection > 40.0 && bigRecRatio <2.00)
{
rightorwronng = "Maybe";
}
else if (intersection > 70.0)
rightorwronng = "overFlow Correct";
else if ( intersection > 40.0)
rightorwronng = "overFlow maybe";
else rightorwronng = "Incorrect";
writer.println("Date " + date.toString() + " Timestamp: " + millis() + " Partipation ID: " + participationID +" Trial number: " + tempFiler + (QuestionCounter+1) + " Correct Answer: " + RectoString(questions.get(QuestionCounter).answer) + " Answer Given: " + RectoString(r1) +" Intersection Percentage: " + intersection + " Answer Given/ Answer Ratio: "+ bigRecRatio +" Comment: " + rightorwronng );
pushMatrix();
textSize(20);
fill(0, 0, 0);
text( "participationID: " + participationID, 200, 200);
popMatrix();
save(folderName + "/" + day()+"-"+month()+"-"+year()+"-"+ hour()+"-"+minute() +"-"+second()+ "-" +millis() +"-"+ participationID +"-" + tempFiler + (QuestionCounter+1)+ ".png");
QuestionCounter++;
if (QuestionCounter>=questions.size())
{
background(255, 255, 255);
textSize(20);
text("Thanks", 200, 200);
// createGUI1();
button1.setVisible(true);
changingFile = true;
// noLoop();
}
}
else
{
try {
outQ.writeObject(new Question(Questions[QuestionCounter++], r1));
}
catch(IOException i) {
}
}
timer = 0;
Stime = millis();
save("/"+participationID+ "/" + ++frameCounter + ".png");
Stime = (int)totalShapesandTrailCount;
}
moving=false;
for ( Shape s : p.shapes)
s.data.mving=false;
//p.nshapes.clear();
}
void keyPressed()
{
......@@ -422,6 +601,30 @@ void drawing()
box2d.step();
background(255, 255, 255);
if (saveornot)
{
timer = (int)totalShapesandTrailCount - Stime;
// print(timer + " ") ;
if (timer<=100 )
{
}
else if (timer>=200 )
{
timer = 0;
Stime = (int)totalShapesandTrailCount;
}
else
background(0, 0, 0);
}
/*
opencv.loadImage(video);
faces = opencv.detect();
......@@ -457,7 +660,10 @@ void drawing()
cy=mouseY;
// print(p.e);
if (saveornot)
{
p.e.addEvent('d', p.shapes.size());
print(totalShapesandTrailCount++ + " ");
}
p.addShape("b", cx, cy, 10);
}
......@@ -473,7 +679,7 @@ void drawing()
{
k=1;
}
if (!attention )
if (!attention )
{
k++;
......@@ -494,7 +700,7 @@ void drawing()
drawdelay--;
if (drawdelay<=0)
{
drawdelay=(int)random(0, 10);
drawdelay=3;
if (temp.ind<p.Eshapes.size())
p.shapes.add(p.Eshapes.get(temp.ind));
if (!attention)
......@@ -504,6 +710,7 @@ void drawing()
p.nshapes.get(p.nshapes.size()-1).seen = attention;
}
p.Ecounter++;
totalShapesandTrailCount++;
}
}
......@@ -511,7 +718,7 @@ void drawing()
if (temp.s=='m')
{
Shape s = p.Eshapes.get(temp.ind);
print(s.data.xs.size());
// print(s.data.xs.size());
if (!attention && !p.nshapes.contains(s))
{
......@@ -528,10 +735,13 @@ void drawing()
}
s.body.setTransform(box2d.coordPixelsToWorld(new Vec2(s.data.xs.get(s.t), s.data.ys.get(s.t) )), s.body.getAngle());
s.t++;
if (s.t%5==0)
totalShapesandTrailCount++;
}
else
{
p.Ecounter++;
totalShapesandTrailCount++;
}
}
if (temp.s == 'e')
......@@ -552,6 +762,7 @@ void drawing()
}
p.Eshapes.get(temp.ind).deleted = true;
p.Ecounter++;
totalShapesandTrailCount++;
}
}
}
......@@ -559,4 +770,19 @@ void drawing()
p.drawAll();
}
public String PointtoString(Rectangle.Point p)
{
return "X: " + p.x + " Y: " + p.y;
}
public String RectoString(Rectangle r)
{
return "Point 1: " + PointtoString(r.p1) + " Point 2: " + PointtoString(r.p2) ;
}
// The Nature of Code
// <http://www.shiffman.net/teaching/nature>
// Spring 2010
// Box2DProcessing example
// A rectangular box
class Box {
// We need to keep track of a Body and a width and height
Body body;
float w;
float h;