csv files
in
Programming Questions
•
10 months ago
I want to include multiple csv files in my program and am adding them in the 'loadStrings' line.
The reason for the multiple files is I want to see the csv files through a timeline in the visual graph output.
My Questions:
1.) I don't know what my syntax error is with the 'loadStrings' line.
2.) I need to add some codes at 'if(millis()...' to create a counter to bring in the multiple csv files and am not sure how to do this. I think this includes loadStrings ("bike" + counter + ".cvs") but not sure how to do this?
any help?
Thank you!
//The row you're looking for
int row = 0;
//The column you're looking for
int col = 1;
int val;
String week; // add from locations graph
float t2 = 0;
PFont myFont; //add from locations graph
long premillis = 0; // define time function
int counter = 0;
String[] feedFile;
String[] feedFile2;
ArrayList<String[]> finalArray = new ArrayList<String[]>();
ArrayList<String[]> finalArray2 = new ArrayList<String[]>();
float finalValue;
void setup()
{
size(900,600);
feedFile2 = loadStrings ("bike1.csv"+"bike0.csv"+"bike.csv"); //from the bike search data
feedFile = loadStrings("report1.csv"); // from the heart disease data 12/9/12
for (int i = 10; i < 475; i++) //copy this for loop into the if loop inside void draw for the time function
{
finalArray.add(split(feedFile[i],","));
}//end for i
for (int i = 10; i < 475; i++) //copy this for loop into the if loop inside void draw for the time function
{
finalArray2.add(split(feedFile2[i],","));
}//end for i
//This is where you can get back a specific feild from the array with row and column
finalValue = float(finalArray.get(row)[col]);
println(finalValue);
myFont = createFont("FFScala", 10);//timegraph font
textFont(myFont);
}//end for setup
void draw()
{
background (255);
//if(millis() - premillis > 30000) { //loop defines the live load every 30 seconds
// feedFile = loadStrings("report.csv"); //do I need this line?
//feedFile2 = loadStrings("bike.csv"); //from the bike search data
//finalArray.clear();
//finalArray2.clear();
//for (int i = 5; i < 469; i++) //copy this for loop into the if loop inside void draw for the time function
// {
// finalArray.add(split(feedFile[i],","));
// }
// for (int i = 5; i < 469; i++) //copy this for loop into the if loop inside voide draw for the time function
// {
// finalArray2.add(split(feedFile2[i],","));
// }
// premillis = millis();
// }
stroke(0,0,0);
strokeWeight(1); // timeline verticle line width
for (int t = 0; t < finalArray.size(); t +=8) {
week = finalArray.get(t)[0];
t2 = map(t, 0, finalArray.size() -1, 0, width);
line (t2,height, t2, height - 300); // timeline verticle line height
fill(0);
textAlign(CENTER);
if(mouseX > int(t2) -2 && mouseX < int(t2) +2) {
text(week, t2, height - 300); // date placement on verticle lines
}//end for mouse
}//end for t
stroke(225,50,0,100); // the heart disease data color and opacity
noFill();
//println(finalArray.size());
strokeWeight(4); // the heart disease data line width
strokeCap(ROUND);
beginShape();
for (int t = 0; t < finalArray.size(); t++) {
val = int(finalArray.get(t)[1]);
//println(val);
t2 = map(t, 0, finalArray.size() - 1,0, width);
vertex(t2,height - val);
}//end for t
endShape();
stroke(50,225,0,100); // the bike data color and opacity
strokeWeight(4); // the bike data line width
strokeCap(ROUND); // smooth graph line
beginShape();
for (int t = 0; t < finalArray2.size(); t++) {
val = int(finalArray2.get(t)[1]);
t2 = map(t,0, finalArray2.size() - 1,0, width);
vertex(t2,height - val);
}//end for t
endShape();
//You can put all the code under setup() function here to have a live reading
}//end for draw
The reason for the multiple files is I want to see the csv files through a timeline in the visual graph output.
My Questions:
1.) I don't know what my syntax error is with the 'loadStrings' line.
2.) I need to add some codes at 'if(millis()...' to create a counter to bring in the multiple csv files and am not sure how to do this. I think this includes loadStrings ("bike" + counter + ".cvs") but not sure how to do this?
any help?
Thank you!
//The row you're looking for
int row = 0;
//The column you're looking for
int col = 1;
int val;
String week; // add from locations graph
float t2 = 0;
PFont myFont; //add from locations graph
long premillis = 0; // define time function
int counter = 0;
String[] feedFile;
String[] feedFile2;
ArrayList<String[]> finalArray = new ArrayList<String[]>();
ArrayList<String[]> finalArray2 = new ArrayList<String[]>();
float finalValue;
void setup()
{
size(900,600);
feedFile2 = loadStrings ("bike1.csv"+"bike0.csv"+"bike.csv"); //from the bike search data
feedFile = loadStrings("report1.csv"); // from the heart disease data 12/9/12
for (int i = 10; i < 475; i++) //copy this for loop into the if loop inside void draw for the time function
{
finalArray.add(split(feedFile[i],","));
}//end for i
for (int i = 10; i < 475; i++) //copy this for loop into the if loop inside void draw for the time function
{
finalArray2.add(split(feedFile2[i],","));
}//end for i
//This is where you can get back a specific feild from the array with row and column
finalValue = float(finalArray.get(row)[col]);
println(finalValue);
myFont = createFont("FFScala", 10);//timegraph font
textFont(myFont);
}//end for setup
void draw()
{
background (255);
//if(millis() - premillis > 30000) { //loop defines the live load every 30 seconds
// feedFile = loadStrings("report.csv"); //do I need this line?
//feedFile2 = loadStrings("bike.csv"); //from the bike search data
//finalArray.clear();
//finalArray2.clear();
//for (int i = 5; i < 469; i++) //copy this for loop into the if loop inside void draw for the time function
// {
// finalArray.add(split(feedFile[i],","));
// }
// for (int i = 5; i < 469; i++) //copy this for loop into the if loop inside voide draw for the time function
// {
// finalArray2.add(split(feedFile2[i],","));
// }
// premillis = millis();
// }
stroke(0,0,0);
strokeWeight(1); // timeline verticle line width
for (int t = 0; t < finalArray.size(); t +=8) {
week = finalArray.get(t)[0];
t2 = map(t, 0, finalArray.size() -1, 0, width);
line (t2,height, t2, height - 300); // timeline verticle line height
fill(0);
textAlign(CENTER);
if(mouseX > int(t2) -2 && mouseX < int(t2) +2) {
text(week, t2, height - 300); // date placement on verticle lines
}//end for mouse
}//end for t
stroke(225,50,0,100); // the heart disease data color and opacity
noFill();
//println(finalArray.size());
strokeWeight(4); // the heart disease data line width
strokeCap(ROUND);
beginShape();
for (int t = 0; t < finalArray.size(); t++) {
val = int(finalArray.get(t)[1]);
//println(val);
t2 = map(t, 0, finalArray.size() - 1,0, width);
vertex(t2,height - val);
}//end for t
endShape();
stroke(50,225,0,100); // the bike data color and opacity
strokeWeight(4); // the bike data line width
strokeCap(ROUND); // smooth graph line
beginShape();
for (int t = 0; t < finalArray2.size(); t++) {
val = int(finalArray2.get(t)[1]);
t2 = map(t,0, finalArray2.size() - 1,0, width);
vertex(t2,height - val);
}//end for t
endShape();
//You can put all the code under setup() function here to have a live reading
}//end for draw
1