Skip to content

Instantly share code, notes, and snippets.

@BorisKourt
Last active December 26, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BorisKourt/7199224 to your computer and use it in GitHub Desktop.
Save BorisKourt/7199224 to your computer and use it in GitHub Desktop.
Jess's visualization code.
String[] textFile;
int[] data;
IntList timeArray;
IntList pressArray;
ArrayList<IntList> pressPerIncr = new ArrayList(); //arraylist of an intlist of presses per a time period
//count of total presses
int lArm;
int rArm;
int lNeck;
int rNeck;
int lSides;
int rSides;
//count of presses per time
IntList lArmPresses;
IntList rArmPresses;
IntList lNeckPresses;
IntList rNeckPresses;
IntList lSidesPresses;
IntList rSidesPresses;
String[] theTitles = {
"L-Arm", "L-Side", "L-Neck", "R-Side", "R-Neck", "R-Arm"
};
int[] theTotals = new int[6];
color[] theColors = {
color(239, 100, 120), color(246, 185, 83), color(170, 166, 48), color(57, 137, 107), color(47, 70, 91), color(248, 52, 40)
};
int theMin;
int theMax;
int minTime;
int maxTime;
int maxPress;
PImage img;
void setup() {
size(1000, 700);
img = loadImage("Person.jpg");
textFile = loadStrings("LOG00097.TXT");
data = int(split(textFile[0], ','));
//get total presses of each location
lArm = getTotals(0);
rArm = getTotals(5);
lNeck = getTotals(2);
rNeck = getTotals(4);
lSides = getTotals(1);
rSides = getTotals(3);
//ended up needing separate arrays for time and presses in order to split presses per time periods
timeArray = new IntList();
splitArrayTime(data, timeArray);
pressArray = new IntList();
splitArrayPress(data, pressArray);
theTotals[0] = lArm;
theTotals[5] = rArm;
theTotals[2] = lNeck;
theTotals[4] = rNeck;
theTotals[1] = lSides;
theTotals[3] = rSides;
theMin = min(theTotals);
theMax = max(theTotals);
maxTime = timeArray.max();
minTime = timeArray.min();
//divide presses into which are done at specific line intervals
pressPerTime();
//this is for individual presses per time period
lArmPresses = new IntList();
rArmPresses = new IntList();
lNeckPresses = new IntList();
rNeckPresses = new IntList();
lSidesPresses = new IntList();
rSidesPresses = new IntList();
pressVarPerTime(lArmPresses, 0);
pressVarPerTime(rArmPresses, 5);
pressVarPerTime(lNeckPresses, 2);
pressVarPerTime(rNeckPresses, 4);
pressVarPerTime(lSidesPresses, 1);
pressVarPerTime(rSidesPresses, 3);
}
void draw() {
background(255);
image(img, 75, 60, 96*2, 296*2);
drawBars();
drawLines();
drawDots(lArm, 120, 225, 0);
drawDots(rArm, 235, 225, 5);
drawDots(lNeck, 150, 165, 2);
drawDots(rNeck, 200, 170, 4);
drawDots(lSides, 130, 325, 1);
drawDots(rSides, 215, 325, 3);
fill(0);
text("Location of Presses", 175, 25);
}
void drawBars() {
int barLength = 300;
int startBarX = 550;
int startBarY = 575;
for (int i = 0; i < theTotals.length; i++) {
noStroke();
fill(theColors[i]);
rect(startBarX, startBarY - 35*i, map(theTotals[i], 0, theMax, 0, barLength), 30);
}
stroke(1);
line(startBarX - 25, startBarY + 50, startBarX + barLength + 25, startBarY + 50);
line(startBarX - 25, startBarY + 50, startBarX - 25, startBarY - 25 - (35*(theTotals.length-1)));
fill(0);
stroke(1);
for (int i = 0; i < theTotals.length; i++) {
fill(theColors[i]);
text(theTitles[i], startBarX - 110, startBarY - (35*i) + 20);
}
for (int i = 0; i < 6; i++) {
fill(0);
text(theMax/6 * i, startBarX + i*(barLength/6), startBarY + 75);
}
}
void drawLines() {
int startLineX = 525;
int startLineY = 250;
int lineLength = 350;
int theHeight = 200;
int numIncr = 10;
strokeWeight(2);
beginShape();
for (int i = 0; i < lArmPresses.size(); i++) {
noFill();
stroke(theColors[0]);
float x = (i * (lineLength/10) + startLineX);
float y = map(lArmPresses.get(i), 0, theMax, startLineY, startLineY-theHeight);
vertex(x, y);
}
endShape();
beginShape();
for (int i = 0; i < lArmPresses.size(); i++) {
noFill();
stroke(theColors[5]);
float x = (i * (lineLength/10) + startLineX);
float y = map(rArmPresses.get(i), 0, theMax, startLineY, startLineY-theHeight);
vertex(x, y);
}
endShape();
beginShape();
for (int i = 0; i < lArmPresses.size(); i++) {
noFill();
stroke(theColors[2]);
float x = (i * (lineLength/10) + startLineX);
float y = map(lNeckPresses.get(i), 0, theMax, startLineY, startLineY-theHeight);
vertex(x, y);
}
endShape();
beginShape();
for (int i = 0; i < lArmPresses.size(); i++) {
noFill();
stroke(theColors[4]);
float x = (i * (lineLength/10) + startLineX);
float y = map(rNeckPresses.get(i), 0, theMax, startLineY, startLineY-theHeight);
vertex(x, y);
}
endShape();
beginShape();
for (int i = 0; i < lArmPresses.size(); i++) {
noFill();
stroke(theColors[1]);
float x = (i * (lineLength/10) + startLineX);
float y = map(lSidesPresses.get(i), 0, theMax, startLineY, startLineY-theHeight);
vertex(x, y);
}
endShape();
beginShape();
for (int i = 0; i < lArmPresses.size(); i++) {
noFill();
stroke(theColors[3]);
float x = (i * (lineLength/10) + startLineX);
float y = map(rSidesPresses.get(i), 0, theMax, startLineY, startLineY-theHeight);
vertex(x, y);
}
endShape();
stroke(1);
line(startLineX, startLineY, startLineX + lineLength, startLineY);
line(startLineX, startLineY, startLineX, startLineY - (35*(theTotals.length-1)));
for (int i = 0; i < 6; i++) {
fill(0);
text(String.format("%.2f", float(maxTime/1000/60)/10 * i), startLineX + i*(lineLength/6), startLineY + 30);
}
for (int i = 0; i < 6; i++) {
fill(0);
//println(maxPress);
text(theMax/6 * i, startLineX-25, startLineY - (i * 35) + 5);
}
textAlign(CENTER);
text("Minutes", startLineX + lineLength/2, startLineY + 75);
pushMatrix();
translate(width/2-25, height/2-175);
rotate(3 * PI/2);
text("Presses", 0, 0);
popMatrix();
}
int getTotals(int toCount) {
int theTotal = 0;
for (int i = 0; i < data.length; i+=2) {
if (data[i] == toCount) {
theTotal++;
}
}
return theTotal;
}
void splitArrayTime(int[] theInitArray, IntList outputArray) {
for (int i=1; i< theInitArray.length; i+=2) {
outputArray.append(theInitArray[i]);
}
}
void splitArrayPress(int[] theInitArray, IntList outputArray) {
for (int i=0; i< theInitArray.length; i+=2) {
outputArray.append(theInitArray[i]);
}
}
void pressPerTime() {
int timeRange = (maxTime - minTime)/10;
for (int j = 0; j < 10; j++) {
IntList matchingNums = new IntList();
for (int i = 0; i < pressArray.size()-1; i++) {
if (timeArray.get(i) > (j * timeRange) && timeArray.get(i) < (j+1) * timeRange) {
matchingNums.append(pressArray.get(i));
}
else {
matchingNums.append(0);
}
}
pressPerIncr.add(matchingNums);
}
}
void pressVarPerTime(IntList indvPressPerTime, int theNum) {
for (int i = 0; i < pressPerIncr.size(); i++) {
int theCount = 0;
for (int j = 0; j < pressPerIncr.get(i).size(); j++) {
if (int(pressPerIncr.get(i).get(j)) == theNum) {
theCount++;
}
}
indvPressPerTime.append(theCount);
}
}
void drawDots(int numPresses, int theX, int theY, int theI) {
float dotSize = map(numPresses, 0, theMax, 15, 40);
textSize(13);
noStroke();
fill(theColors[theI]);
ellipse(theX, theY, dotSize, dotSize);
textAlign(CENTER, CENTER);
fill(255);
text(numPresses, theX, theY-2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment