Time codes
in
Programming Questions
•
2 years ago
Hi,
I'm new to Processing and trying to work on a program to view some data. There are 2 separate data sources (.txt files), one is a series of data points taken every 8th second, with a start time. The other is a series of events marked separately at certain times. I have the data at 8th seconds working fine, but want either to make each data point know what time it is or make each of the data points with time codes know which 8th second they belong to. Can anyone suggest a smart way to merge the data so it can be aligned on the same x axis?
Thanks!
Here's my code with the first set of data.
float[] t,e;
float average;
int total_points;
float total;
PFont font;
void setup(){
String[] lines;
int index = 0;
size(1200, 300);
background(200);
stroke(255);
smooth();
font= loadFont("Gotham-Light-12.vlw");
textFont(font);
//reads the data from the file
lines = loadStrings("q2.txt");
//println(lines.length);
println(lines[5]);
int total_points=lines.length-8;
println(total_points);
//total_points=1000; //allows me to use fewer points to troubleshoot
//moves (0,0) to (0, 300)
t= new float[total_points];
e= new float[total_points];
for (int i=0;i<(total_points);i++){
String[] firstline=lines[8+i].split(",");
float edaRaw = float(firstline[5]);
//print there to see what values are in array
//print(((i+1.0)/8.0));print(',');
//println(edaRaw);
//figure out how many entries in a day, alway use same #, this is 6 hours
int maxFrames;
maxFrames= 172800/8;
float time= map((i+1.0)/8.0, 0, maxFrames, 0, 1200);
float eda= map(edaRaw, 0, 20, 0, -300);
//print(time);
//print(",");
//println(eda);
t[i]=time;
e[i]=eda;
//vertex(time,eda);
}
//trying to calculate average
//float average= -100;
float previous = 0;
float value;
float total;
//adds up all the eda values
for (int i=2;i<t.length;i++){
previous = (previous - e[i]);
}
//println(previous);
average = -1*(previous/(total_points));
println(average);
}
void draw(){
//draw x coordinate grid
background(200);
for (int m=0; m<20; m++){
stroke(255);
line(0, 15*m, 1200, 15*m);
//textSize(12);
//text(20-m, 1200, 15*m);
}
//shifts y axis so 0,0 is bottom left corner of window
translate(0,300);
//shade everything over "average" red
for (int i=0;i<t.length;i++){
if (e[i] < average) {
stroke(243,111,93);
line(t[i], average, t[i], e[i]);
}
}
//shade everything below "average" blue
for (int i=0;i<t.length;i++){
if (e[i] > average) {
stroke(130,175,203);
line(t[i], average, t[i], e[i]);
}
}
//draws line
noFill();
beginShape();
for (int i=0;i<t.length;i++){
stroke(0);
vertex(t[i],e[i]);
}
endShape();
//drawing line at average eda value
line(0, average, 1200, average);
//recognize x value of mouse and print eda associated with it
for (int i=0;i<t.length;i++){
if (mouseX == t[i]){
float edaPrint= map(e[i], 0, -300, 0, 20);
//println(edaPrint);
textSize(12);
//text("eda at time " + t[i] +"=" + edaPrint, mouseX, mouseY-300);
text("eda at time " + t[i] +"=" + edaPrint, 20, -274);
}
}
}
1