info vizualization using a 2d ObjectArray
hi everybody,
i'm posting this question here because there is no "stupid questions" cathegory yet.
So here we go,
i have a so called "all.txt" file in which the results of a survey in offices are recorded. I'm trying to test some hypothesis due to visual methods.
The file is formated as follow:
1. row 4: climatic zone ("A" , "B", "C" or "D")
2. row 7: building operation mode ("nv" for natural ventilated and ""hvac" for heating or cooling)
3. row 8: user's vote in a 7 point numerical scala ("-3" means too cold, "-2" cold, "-1" slightly cold, "0" neutral, "1" slightly hot etc.)
4. row 9: indoor temperature
5. row 10: outdoor temperature
the tasks
i'm trying to create a grid to represent a determined number of intervals (the outdoor temperature in x-axis and indoor temperature in y-axis). The grid is
black and depending on the proportion of valid votes in it (valid votes are the neutral votes or 0 at the scala) it becomes brighter (if 100% than the cell will be white).
there 4 main tasks:
1. filter the information belonging in predetermined conditions (only nv mode) and temperature outdoor and indoor in the range (10-40°C)
2. separate votes in two cathegories valid and not valid (validVotes==0)
3. distribute votes in the grid
4. display the cells (controling alpha)
i used a two dimensional array of objects but it is not working, surely because i'm not passing the values correctly.
does anybody have some hints?
here is the code:
- // 2D Array of objects
Cell[][] grid;
// 1D Array raw data
String [] survey; - int cols = 3; //number of columns
int rows = 3; //number of rows
float w; //width of cells
float h; //height of cells - String validMode="nv"; //filter: nv mode
int validVote=0; //separate: votes in valid and not valid
float toutMin=10; //filter: lowest temperature indoor
float toutMax=40; //filter: highest temperature indoor
float tinMin=10; //filter: lowest temperature outdoor
float tinMax=40; //filter: highest temperature outdoor
int alpha; //determines opacity of cells - void setup() {
size(600, 600);
background (0);
w= width/cols;
h= height/rows;
survey= loadStrings("all.txt"); - grid = new Cell[cols][rows];
for (int i = 0; i < cols; i ++ ) {
for (int j = 0; j < rows; j ++ ) {
grid[i][j] = new Cell(i*w, j*h, w, h, alpha);
}
}
} - void draw() {
background(0);
for (int i = 0; i < cols; i ++ ) {
for (int j = 0; j < rows; j ++ ) {
grid[i][j].calculate(); //calculates each cell's opacity (alpha) tasks 1,2,3
grid[i][j].display(); //task 4
}
}
} - //the class
class Cell { - float x, y; // x,y location
float w, h; // width and height
int alpha; // alphaValue - // Cell Constructor
Cell(float _X, float _Y, float _W, float _H, int _A) {
x = _X;
y = _Y;
w = _W;
h = _H;
alpha = _A;
}
void calculate() {
//declare local variables
int countValidVote=0; //counter for valid votes
int countNotValidVote=0; //counter for not valid votes
String vote; - for (int k=0; k<survey.length; k++) {
String [] pieces= split (survey [k], ";");
String rawZones = pieces [3];
String rawModes = pieces [6];
int rawVotes = int(pieces [7]);
float tin = (float(pieces[8])/100);
float tout = (float(pieces[9])/100); - //filter
if (tout >= toutMin && tout <= toutMax && tin >= tinMin && tin <= tinMax && rawModes.equals(validMode)) {
float toutDiv= (toutMax-toutMin)/cols;
float tinDiv= (tinMax-tinMin)/cols;
x= (int) (tout/toutDiv) -1;
y=(int) (tin/tinDiv) -1;
//separate
if (rawVotes==0) {
vote= "voteValid";
}
else {
vote= "voteNotValid";
}
//distribute
for (x = 0; y < cols; x ++ ) {
for (y = 0; y < rows; y ++ ) {
if (rawVotes==validVote) {
countValidVote=countValidVote+1;
}
else {
countNotValidVote=countNotValidVote+1;
}
//calculate alpha
alpha=(int)(255*(countValidVote/ (countValidVote+countNotValidVote)));
}
}
}
}
}
void display() {
stroke(100);
fill (255, alpha);
rect (x, y, w, h);
}
}
the file first lines:
3;2;bangkok th;A;w;hot wet;hvac;1;2397;3150;
3;2;bangkok th;A;w;hot wet;hvac;1;2463;3150;
3;2;bangkok th;A;w;hot wet;hvac;1;2523;3150;
3;2;bangkok th;A;w;hot wet;hvac;1;2433;3150;
3;2;bangkok th;A;w;hot wet;hvac;2;2492;3150;
3;2;bangkok th;A;w;hot wet;hvac;1;2608;3150;
3;2;bangkok th;A;w;hot wet;hvac;1;2553;3150;
3;2;bangkok th;A;w;hot wet;hvac;-1;2502;3150;
3;2;bangkok th;A;w;hot wet;hvac;0;2452;3150;
3;2;bangkok th;A;w;hot wet;hvac;0;2448;3150;
3;2;bangkok th;A;w;hot wet;hvac;1;2467;3150;
thx!