We are about to switch to a new forum software. Until then we have removed the registration on this forum.
My prof. example/tutorial code of how to use data sets:
// Reading Data sets
//varible that starts with a captial letter is an object. ex: Table
// 12:38
// 012345
Table data;
int rowCount; // for calculating the # of rows in a data file
int callTimeHours, callTimeMinutes;
String callTime, callType;
void setup() {
size (1000, 100);
data = loadTable("chrissy_project1a.csv" , "header");
rowCount = data.getRowCount();
println(rowCount);
textAlign(CENTER);
}
void draw() {
background (0);
for(int row = 0; row < rowCount; row ++) {
callTime = data.getString(row, "callTime");
callType = data.getString(row, "callType");
String callTimeCheck = callTime.substring(1,2);
if (callTimeCheck.equals (":") == true) {
callTimeHours = int(callTime.substring(0,1));
callTimeMinutes= int(callTime.substring(2));
}
else {
callTimeHours = int(callTime.substring(0,2));
callTimeMinutes= int(callTime.substring(3));
}
//println(callTimeMinutes);
int calculatedTime = (callTimeHours * 60) + callTimeMinutes;
float mappedCalculatedTime = map(calculatedTime, 0, 1440, 0, 1000); // makes things smaller
//println(mappedCalculatedTime);
if (callType.equals("MYO") == true) {
stroke(0, 255, 0, 120);
} else {
stroke (255, 0, 0, 120);
//println(callType);
}
stroke(255, 0, 0, 120);
line(calculatedTime, 30, calculatedTime, 70);
//draws a vertical line where the mouse is
stroke(180);
line (mouseX, 0, mouseX, height);
float callOut = dist(mouseX, mouseY, mappedCalculatedTime, mouseY);
if (callOut < 1) {
text(callTime, mouseX + 20, mouseY - 20);
}
}
}
MY CURRENT CODE - just started, but not sure how to proceed. I'm not sure how to put in the text that I need the data to follow and how to actually make each line their own data
PFont f; // STEP 1 Declare PFont variable
Table data;
int rowCount; // for calculating the # of rows in a data file
int callTimeHours, callTimeMinutes;
String callTime, callType, month, weekday, callFrom, locationCalled, duration;
void setup() {
size(1300,1000);
data = loadTable("chrissy_data.csv" , "header");
rowCount = data.getRowCount();
println(rowCount);
textAlign(CENTER);
f = createFont("Poppins",16,true); // STEP 2 Create Font
}
void draw() {
translate (100, 200);
textFont(f,16); // STEP 3 Specify font to be used
fill(0); // STEP 4 Specify font color
text("month",10,100); // STEP 5 Display Text
text("weekday",210,100); // STEP 5 Display Text
text("day",410,100); // STEP 5 Display Text
text("callTime",600,100); // STEP 5 Display Text
text("callType",800,100); // STEP 5 Display Text
text("duration",1000,100); // STEP 5 Display Text
for(int row = 0; row < rowCount; row ++) {
callTime = data.getString(row, "callTime");
callType = data.getString(row, "callType");
month = data.getString(row, "month");
weekday = data.getString(row, "weekday");
callFrom = data.getString(row, "callFrom");
locationCalled = data.getString(row, "locationCalled");
duration = data.getString(row, "duration");
String callTimeCheck = callTime.substring(1,2);
if (callTimeCheck.equals (":") == true) {
callTimeHours = int(callTime.substring(0,1));
callTimeMinutes= int(callTime.substring(2));
}
else {
callTimeHours = int(callTime.substring(0,2));
callTimeMinutes= int(callTime.substring(3));
}
//println(callTimeMinutes);
}
int calculatedTime = (callTimeHours * 60) + callTimeMinutes;
float mappedCalculatedTime = map(calculatedTime, 0, 1440, 0, 1000); // makes things smaller
//println(mappedCalculatedTime);
}
Answers
Can you post the data?
Are you allowed to use the code of your teacher?
Do you want to create exactly the same graphic or something of your own?
You need to for loop over your data and for each line draw a line for each column
For each line: the x value is related to the column of the table (you can make an array of x values and use the table column as a index for it)
The y value is related to the value of the cell (row column position of the table) so that each month or weekday has a y value. Depending from your data you could use a HashMap to store the y value of the months.
But please post your data formatted as text
The same as the graphic i created above (it just an illustrator file, my prof told me to plot out the design and see how the information would be plotted/looked). I am allowed to use his code.
I am not sure if this is formatted properly or not, tell me if it is not! Thanks!
weekday month day callTime callFrom locationCalled callType duration
Sat Jun 15 12:32 TORONTO TORONTO MYO 1
Sat Jun 15 12:33 TORONTO TORONTO MYO 2
Sat Jun 15 17:23 TORONTO TORONTO OUT 1
Sat Jun 15 17:23 TORONTO TORONTO OUT 1
Sun Jun 16 10:57 TORONTO STREETSVL OUT 2
Sun Jun 16 10:58 TORONTO STREETSVL OUT 1
Sun Jun 16 10:59 TORONTO STREETSVL OUT 2
Sun Jun 16 11:02 TORONTO TORONTO OUT 2
Sun Jun 16 11:03 TORONTO TORONTO OUT 2
Sun Jun 16 11:05 TORONTO TORONTO OUT 2
Sun Jun 16 11:06 TORONTO TORONTO OUT 3
Sun Jun 16 11:08 TORONTO TORONTO OUT 2
Sun Jun 16 11:13 TORONTO TORONTO OUT 1
Sun Jun 16 11:18 TORONTO TORONTO OUT 1
Sun Jun 16 11:19 TORONTO TORONTO OUT 2
Sun Jun 16 11:21 TORONTO TORONTO OUT 1
Sun Jun 16 11:26 TORONTO TORONTO OUT 4
Sun Jun 16 11:29 TORONTO TORONTO OUT 2
Sun Jun 16 11:31 TORONTO TORONTO OUT 1
Sun Jun 16 11:31 TORONTO TORONTO OUT 2
Sun Jun 16 11:37 TORONTO TORONTO OUT 2
Sun Jun 16 11:39 TORONTO UNIONVILLE OUT 1
Sun Jun 16 11:40 TORONTO TORONTO OUT 3
Sun Jun 16 12:03 TORONTO TORONTO OUT 1
Sun Jun 16 15:23 TORONTO TORONTO MYO 2
Sun Jun 16 15:24 TORONTO TORONTO MYO 2
Sun Jun 16 15:26 TORONTO TORONTO MYO 2
Sun Jun 16 21:58 TORONTO TORONTO OUT 13
Mon Jun 17 12:44 TORONTO TORONTO MYO 4
Mon Jun 17 14:07 TORONTO TORONTO OUT 2
Mon Jun 17 14:54 TORONTO TORONTO OUT 8
Mon Jun 17 15:09 INCOMING TORONTO INC 1
Mon Jun 17 21:02 TORONTO TORONTO OUT 1
Tue Jun 18 10:31 TORONTO TORONTO MYO 1
Tue Jun 18 10:59 TORONTO TORONTO MYO 1
Tue Jun 18 11:10 TORONTO TORONTO MYO 1
Tue Jun 18 11:28 TORONTO TORONTO MYO 1
Tue Jun 18 12:08 INCOMING TORONTO MYI 10
Wed Jun 19 14:08 TORONTO TORONTO OUT 21
Wed Jun 19 20:06 TORONTO TORONTO OUT 1
Wed Jun 19 20:46 INCOMING TORONTO MYI 61
Wed Jun 19 22:56 TORONTO TORONTO MYO 1
Thu Jun 20 08:56 TORONTO TORONTO MYO 2
Thu Jun 20 11:14 TORONTO TORONTO MYO 2
Thu Jun 20 11:16 TORONTO TORONTO MYO 14
Fri Jun 21 10:29 TORONTO TORONTO MYO 1
Fri Jun 21 19:40 TORONTO TORONTO MYO 1
Fri Jun 21 19:49 TORONTO TORONTO MYO 3
Fri Jun 21 21:36 TORONTO TORONTO MYO 5
Sat Jun 22 13:07 TORONTO TORONTO MYO 1
Sat Jun 22 13:40 INCOMING TORONTO MYI 34
Sat Jun 22 14:18 TORONTO TORONTO MYO 2
Sat Jun 22 14:25 INCOMING TORONTO INC 10
Sat Jun 22 20:02 TORONTO TORONTO OUT 1
Sun Jun 23 18:05 TORONTO TORONTO MYO 1
Mon Jun 24 14:54 INCOMING TORONTO INC 1
Mon Jun 24 14:56 TORONTO TORONTO MYO 1
Mon Jun 24 14:56 TORONTO TORONTO MYO 1
Mon Jun 24 19:31 TORONTO TORONTO OUT 4
Mon Jun 24 20:31 TORONTO TORONTO OUT 1
Mon Jun 24 21:42 TORONTO TORONTO OUT 18
Tue Jun 25 22:07 TORONTO TORONTO OUT 8
Wed Jun 26 17:04 TORONTO TORONTO OUT 2
Wed Jun 26 20:18 TORONTO TORONTO OUT 2
Thu Jun 27 09:06 TORONTO TORONTO OUT 48
Thu Jun 27 10:56 TORONTO TORONTO MYO 5
Thu Jun 27 11:04 TORONTO 1-877 CALL OUT 5
Thu Jun 27 11:11 TORONTO 1-877 CALL OUT 18
Thu Jun 27 11:28 TORONTO 1-800 CALL OUT 39
Thu Jun 27 12:07 TORONTO 1-877 CALL OUT 11
Thu Jun 27 12:26 TORONTO TORONTO MYO 1
Thu Jun 27 19:00 TORONTO TORONTO OUT 1
Fri Jun 28 11:01 TORONTO TORONTO OUT 14
Fri Jun 28 11:07 INCOMING TORONTO INC 1
Fri Jun 28 11:14 INCOMING TORONTO INC 11
Fri Jun 28 21:49 TORONTO TORONTO MYO 2
Sat Jun 29 10:15 TORONTO TORONTO MYO 1
Sat Jun 29 14:28 TORONTO TORONTO MYO 1
Sat Jun 29 14:29 TORONTO TORONTO MYO 11
Sat Jun 29 14:43 TORONTO TORONTO MYO 1
Sat Jun 29 14:43 TORONTO TORONTO MYO 1
Sat Jun 29 14:44 TORONTO TORONTO MYO 1
Sat Jun 29 14:44 TORONTO TORONTO MYO 3
Sat Jun 29 17:48 TORONTO TORONTO MYO 1
Sun Jun 30 13:04 TORONTO TORONTO MYO 2
Sun Jun 30 13:07 INCOMING TORONTO INC 22
Sun Jun 30 15:12 TORONTO TORONTO MYO 1
Sun Jun 30 20:14 INCOMING TORONTO MYI 2
Sun Jun 30 20:41 TORONTO TORONTO MYO 2
Mon Jul 1 12:24 TORONTO TORONTO MYO 1
Mon Jul 1 17:04 INCOMING TORONTO MYI 4
Tue Jul 2 17:54 TORONTO TORONTO MYO 2
Thu Jul 4 13:07 TORONTO TORONTO MYO 3
Sat Jul 6 10:59 INCOMING TORONTO MYI 37
Sat Jul 6 11:36 TORONTO TORONTO OUT 1
Sat Jul 6 13:08 INCOMING TORONTO INC 1
Sat Jul 6 14:47 TORONTO TORONTO MYO 8
Sat Jul 6 15:19 INCOMING TORONTO INC 4
Sat Jul 6 15:24 TORONTO TORONTO MYO 1
Sat Jul 6 15:26 INCOMING TORONTO MYI 4
Sat Jul 6 15:45 TORONTO TORONTO OUT 2
Sat Jul 6 22:27 TORONTO TORONTO MYO 1
Sun Jul 7 14:56 TORONTO TORONTO MYO 1
Sun Jul 7 14:57 INCOMING TORONTO MYI 2
Mon Jul 8 13:14 TORONTO TORONTO MYO 2
Mon Jul 8 13:15 TORONTO TORONTO MYO 2
Mon Jul 8 13:41 TORONTO TORONTO MYO 1
Mon Jul 8 13:44 TORONTO TORONTO MYO 1
Mon Jul 8 15:36 TORONTO TORONTO MYO 1
Mon Jul 8 15:37 TORONTO TORONTO MYO 5
Mon Jul 8 21:44 TORONTO TORONTO MYO 2
Tue Jul 9 08:55 TORONTO TORONTO OUT 2
Tue Jul 9 12:28 TORONTO TORONTO MYO 1
Tue Jul 9 12:28 INCOMING TORONTO MYI 1
Tue Jul 9 12:35 TORONTO TORONTO MYO 2
Tue Jul 9 12:57 TORONTO TORONTO MYO 1
Tue Jul 9 13:05 INCOMING TORONTO MYI 1
Tue Jul 9 16:10 TORONTO TORONTO MYO 2
Tue Jul 9 19:50 TORONTO TORONTO MYO 4
Wed Jul 10 16:05 TORONTO TORONTO OUT 2
Thu Jul 11 19:51 TORONTO TORONTO MYO 5
Sat Jul 13 11:41 TORONTO TORONTO MYO 53
Sat Jul 13 14:26 TORONTO TORONTO MYO 1
Sat Jul 13 14:27 TORONTO TORONTO MYO 2
Sat Jul 13 14:29 TORONTO TORONTO MYO 1
Sat Jul 13 19:53 TORONTO TORONTO MYO 2
Sun Jul 14 09:57 TORONTO TORONTO OUT 3
Sun Jul 14 11:45 TORONTO TORONTO OUT 1
Sun Jul 14 13:29 TORONTO TORONTO MYO 10
Sun Jul 14 13:38 TORONTO TORONTO MYO 1
Sun Jul 14 13:39 TORONTO TORONTO MYO 9
Mon Jul 15 14:32 INCOMING HALIFAX RBM 4
Tue Jul 16 21:56 INCOMING HALIFAX RBM 1
Tue Jul 16 22:20 INCOMING HALIFAX RBM 6
Wed Jul 17 14:20 INCOMING HALIFAX IRM 1
Thu Jul 18 23:54 INCOMING HALIFAX RBM 15
Fri Jul 19 12:49 INCOMING HALIFAX RBM 1
Fri Jul 19 22:28 TORONTO TORONTO MYO 1
Fri Jul 19 22:39 TORONTO TORONTO MYO 1
Sat Jul 20 13:05 INCOMING TORONTO INC 1
Sat Jul 20 13:31 TORONTO TORONTO MYO 1
Sat Jul 20 13:33 TORONTO 1-800 CALL OUT 2
Sat Jul 20 13:39 INCOMING TORONTO INC 9
I did not post all my data since there are like 300+, the numbers are minutes. And each header has to follow the naming conventions above.
https://drive.google.com/file/d/1ZA-ytwBj_wHCaL8mtxcBzhN0k1HMKcGN/view?usp=sharing
Here is the csv file.
I had to use a comma separated data set
sketch below
sketch
Thank you!
I added the third row, how can I make them all connect though.
@Chrisir For some reason when i try to add callTime, it get rid of the numbers? Did I do something wrong with the code?
I‘d think callTime is 12:33 eg
But in the HashMap you only have the hours
So he doesn’t find a match
What you need is callTimeHours and use that value for the HashMap
Your teacher uses callTimeHours - look at his code to see it
Did you see the red lines your teacher draws? They don’t follow our principle with the columns we have.
You could make the lines of each call of one unique color so that you can distinguish the calls
@Chrisir
How can I make just the calltype coloured and the rest in black and white?
here I show how the callType is red and the others are white
by the way, in my version the if-clauses are not good because they can block each other. You need to monitor if you forgot one data in one of your
put
lines:Here is a good monitoring because
println
gives out a warning when a data can not be found in callType1. You should do this for all HashMaps.Chrisir
@Chrisir This is the new code, I had to take away the months since it confused my prof. My prof wants me to just have the call type and its lines be different colours and the rest is just white lines. When I try to code the calltime it just does not seem to work out, I wonder what am i doing wrong
Table data; int rowCount; // for calculating the # of rows in a data file int callTimeHours, callTimeMinutes; //String callTime, callType;
??
First you are not filling callTimeHours1 with data in setup
2nd as I said before in line 112 you are testing the hashMap against callTime which is 12:20 or so. when you look up in the HashMap where you only have 0,1,2....11,12,13 you won't find it.
so split callTime up into hours as your teacher did, then use callTimeHours with callTimeHours1 :
3rd : I've shown you how to make callType red.
stroke(255,0,0); // red
before it, and after itstroke(255); // white
things like that should be written with a for loop by the way:
which is
you got a few of call types missing. Please add them to the HashMap
calltype1
in setup().(I made a new version and integrated a check for these issues. In this new version also the color red is used for call types, the other lines are white. The
calltime
works now.)Thanks!
How would I make specific call types (like MYI =red, MYO = blue) a different colour? I tried doing something down below but it does not work
And for the callTime, it does not seem to work.
Thanks for answering my questions!
First
when you use those lines, are the values as expected?
Did you fill
callTimeHours1
in setup() by usingput
?I guess callTimeHours is 08 with a leading zero, so the content of
callTimeHours1
in setup() must also have a leading zero.Second
These stroke commands
must be before line to have effect with line, not after line.
Remark
== true
is not necessarythis would work too
Please post your entire code
Chrisir
this is not enough description -
does it run or is there a compiler error? OR a runtime error?
When it runs: what happens falsely, what do you want to happen instead?
Thanks got the colours figured out!
you have items in callTimeHours1, but not a leading zero for 1,2,3,....
you could use this instead:
I don't think you need
callTimeMinutes1
Please hit ctrl-t in processing to get a better auto-format (indents)
I changed it, but the lines still does not show up?
always post your entire code
compare these values
to the values you have put into callTimeHours1 in setup() please
ah, the data type is wrong, you have int, but you want String
before setup() :
and these lines have to be changed accordingly (without
int(
) :Is this correct?
Why do you ask me?
Does it work?
Does it do what you want?
You decide.
My Remarks
You made a table. But it has a long distance to the upper left corner. There is a lot of space wasted and you should move your table in the upper left corner.
You haven't used ctrl-t recently. Bad indents.
setup and draw are far too long. Make sub functions. Especially in setup make a sub function initHashMaps. Same for draw: function showData with the for loop and showHeadlines with the headlines
more comments
The names callTimeHours1 etc. for all the HashMaps are not good because wa can't tell from the name its a hashMap. Try callTimeHoursHM instead. For all of them.
You have a lot of multiple empty lines you should remove; one empty line between sections are very good. Two or more are bad.
You have a lot of dead lines you should remove:
Chrisir
This can be a nw function
determineStrokeColorFromCallType()
:If a if clause like this
if (calltype1.get(callType) !=null) {
fails, you don't receive any message.Instead consider to make the end of your for-loop in draw() like this:
In this comment:
// We can also access values by their key
the word also doesn't make senseI made a version where you can browse through the calls (keys + and - ) additionally
one call is highlighted (in the lines) and shown on a separate sheet in the lower right corner as longer text
Can you do this ?
I chose not to add the calls, since my prof said it would be hard for me to do this since i do not know coding at all.
Final code:
Very nice!
Congratulations!
just for completeness sake:
the before mentioned version:
one call is highlighted in green (in the lines) and shown on a separate sheet in the lower right corner as longer text (yellow box)
Chrisir ;-)