How to create this out of data? (parallel design data visualization)

Data Visualization Design1

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

  • edited February 2018

    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.

  • edited February 2018

    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.

  • Answer ✓

    I had to use a comma separated data set

    sketch below

    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,CALLOUT,5
    Thu,Jun,27,11:11,TORONTO,1-877,CALLOUT,18
    Thu,Jun,27,11:28,TORONTO,1-800,CALLOUT,39
    Thu,Jun,27,12:07,TORONTO,1-877,CALLOUT,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,CALLOUT,2
    Sat,Jul,20,13:39,INCOMING,TORONTO,INC,9
    

    sketch

    // 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;
    
    String callTime, callType, month, weekday, callFrom, locationCalled, duration;  
    
    HashMap  <String, Integer> weekdays1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> month1 = new HashMap<String, Integer>();
    
    void setup() { 
      size (1700, 900);
      data = loadTable("chrissy_project1a.csv", "header");
      rowCount = data.getRowCount();
      println(rowCount);
      textAlign(CENTER);
    
      // Putting key-value pairs in the HashMap weekdays1
      weekdays1.put("Mon", 33);
      weekdays1.put("Tue", 66);
      weekdays1.put("Wed", 99);
      weekdays1.put("Thu", 99+33);
      weekdays1.put("Fri", 99+66);
      weekdays1.put("Sat", 99+99);
      weekdays1.put("Sun", 99+99+33);
    
      // Putting key-value pairs in the HashMap weekdays1
      month1.put("Jun", 133);
      month1.put("Jul", 266);
    }
    
    
    void draw() {
      background (0);
    
      boolean done = false; 
    
      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 < 6 && ! done) {
          text(callTime, mouseX + 20, mouseY - 20);
          done=true;
        }
    
        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");
    
    
        callTimeCheck = callTime.substring(1, 2);
    
        pushMatrix();
        translate (100, 170);
        // We can also access values by their key
        if (weekdays1.get(weekday)!=null) {
          // We can also access values by their key
          int yDay = weekdays1.get(weekday);
          yDay+=66;
          if (month1.get(month)!=null) {
            int yMonth = month1.get(month);
            line(210, yDay+10, 
              19, yMonth+10);
            text(weekday, 222, yDay+10);
            text(month, 0, yMonth+10);
          }
        }
        popMatrix();
      }//for
    
      translate (100, 100);
      //  textFont(f, 16);                  // STEP 3 Specify font to be used
      fill(220);                         // 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
    }
    
  • I added the third row, how can I make them all connect though.

    // Had some help from user: Chrisir on the forum for Processing
    
    
    Table data;
    int rowCount; // for calculating the # of rows in a data file
    int callTimeHours, callTimeMinutes;
    //String callTime, callType;
    
    String callTime, callType, month, weekday, day, callFrom, locationCalled, duration;  
    
    HashMap  <String, Integer> weekdays1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> month1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> day1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> callType1 = new HashMap<String, Integer>();
    
    
    
    
    void setup() { 
      size (1500, 800);
      data = loadTable("chrissy_data.csv", "header");
      rowCount = data.getRowCount();
      println(rowCount);
      textAlign(CENTER);
      smooth();
      strokeWeight(0.5);
    
      // Putting key-value pairs in the HashMap weekdays1
      weekdays1.put("Mon", 50);
      weekdays1.put("Tue", 100);
      weekdays1.put("Wed", 150);
      weekdays1.put("Thu", 200);
      weekdays1.put("Fri", 250);
      weekdays1.put("Sat", 300);
      weekdays1.put("Sun", 350);
    
      // Putting key-value pairs in the HashMap month1
      month1.put("Jun", 110);
      month1.put("Jul", 210);
      month1.put("Aug", 310);
      month1.put("Sep", 410);
    
        // Putting key-value pairs in the HashMap day1
    
      day1.put("1", 0);
      day1.put("2", 15);
      day1.put("3", 30);
      day1.put("4", 45);
      day1.put("5", 60);
       day1.put("6", 75);
      day1.put("7", 90);
      day1.put("8", 105);
      day1.put("9", 120);
      day1.put("10", 135);
      day1.put("11", 150);
      day1.put("12", 165);
      day1.put("13", 180);
      day1.put("14", 195);
      day1.put("15", 210);
       day1.put("16", 225);
      day1.put("17", 240);
      day1.put("18", 255);
      day1.put("19", 270);
      day1.put("20", 285);
       day1.put("21", 300);
      day1.put("22", 315);
      day1.put("23", 330);
      day1.put("24", 345);
      day1.put("25", 360);
       day1.put("26", 375);
      day1.put("27", 390);
      day1.put("28", 405);
      day1.put("29", 420);
      day1.put("30", 435);
        day1.put("31", 450);
    
    }
    
    
    
    void draw() {
      background (0);
    
      boolean done = false; 
    
       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");
         day = data.getString(row, "day");
    
          int calculatedTime = (callTimeHours * 60) + callTimeMinutes;    
    
         stroke(255);
        line(calculatedTime, 30, calculatedTime, 70);
    
        pushMatrix();
        translate (100, 170);
        // We can also access values by their key
        if (weekdays1.get(weekday)!=null) {
          // We can also access values by their key
          int yweekDay = weekdays1.get(weekday);
          yweekDay+=66;
    
          if (month1.get(month)!=null) {
            int yMonth = month1.get(month);
            line(190, yweekDay+10, 19, yMonth+10);
    
    
    
          if (day1.get(day)!=null) {
            int yDay = day1.get(day);
            yDay+=80;
            line(230, yweekDay+10, 400, yDay+50);
    
            text(month, 0, yMonth+10);
            text(weekday, 210, yweekDay+10);
            text(day, 410, yDay+50);
    
    
          } 
        } }
        popMatrix();
      }
    
      translate (100, 100);  fill(220);                         // 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
    }
    
  • edited February 2018

    @Chrisir For some reason when i try to add callTime, it get rid of the numbers? Did I do something wrong with the code?

    // Got some help from user: Chrisir on the forum for Processing helped me understand how to start the code up!
    
    
    Table data;
    int rowCount; // for calculating the # of rows in a data file
    int callTimeHours, callTimeMinutes;
    //String callTime, callType;
    
    String callTime, callType, month, weekday, day, callFrom, locationCalled, duration;  
    
    HashMap  <String, Integer> weekdays1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> month1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> day1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> callType1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> callTime1 = new HashMap<String, Integer>();
    
    
    
    
    void setup() { 
      size (1500, 800);
      data = loadTable("chrissy_data.csv", "header");
      rowCount = data.getRowCount();
      println(rowCount);
      textAlign(CENTER);
      smooth();
      strokeWeight(0.5);
    
      // Putting key-value pairs in the HashMap weekdays1
      weekdays1.put("Mon", 50);
      weekdays1.put("Tue", 100);
      weekdays1.put("Wed", 150);
      weekdays1.put("Thu", 200);
      weekdays1.put("Fri", 250);
      weekdays1.put("Sat", 300);
      weekdays1.put("Sun", 350);
    
      // Putting key-value pairs in the HashMap month1
      month1.put("Jun", 110);
      month1.put("Jul", 210);
      month1.put("Aug", 310);
      month1.put("Sep", 410);
    
        // Putting key-value pairs in the HashMap day1
    
      day1.put("1", 0);
      day1.put("2", 15);
      day1.put("3", 30);
      day1.put("4", 45);
      day1.put("5", 60);
       day1.put("6", 75);
      day1.put("7", 90);
      day1.put("8", 105);
      day1.put("9", 120);
      day1.put("10", 135);
      day1.put("11", 150);
      day1.put("12", 165);
      day1.put("13", 180);
      day1.put("14", 195);
      day1.put("15", 210);
       day1.put("16", 225);
      day1.put("17", 240);
      day1.put("18", 255);
      day1.put("19", 270);
      day1.put("20", 285);
       day1.put("21", 300);
      day1.put("22", 315);
      day1.put("23", 330);
      day1.put("24", 345);
      day1.put("25", 360);
       day1.put("26", 375);
      day1.put("27", 390);
      day1.put("28", 405);
      day1.put("29", 420);
      day1.put("30", 435);
        day1.put("31", 450);
    
        //callTime1
          callTime1.put("1", 0);
       callTime1.put("2", 15);
      callTime1.put("3", 30);
       callTime1.put("4", 45);
       callTime1.put("5", 60);
        callTime1.put("6", 75);
       callTime1.put("7", 90);
       callTime1.put("8", 105);
       callTime1.put("9", 120);
       callTime1.put("10", 135);
       callTime1.put("11", 150);
       callTime1.put("12", 165);
       callTime1.put("13", 180);
       callTime1.put("14", 195);
       callTime1.put("15", 210);
        callTime1.put("16", 225);
       callTime1.put("17", 240);
       callTime1.put("18", 255);
      callTime1.put("19", 270);
       callTime1.put("20", 285);
        callTime1.put("21", 300);
       callTime1.put("22", 315);
       callTime1.put("23", 330);
       callTime1.put("24", 345);
    
    }
    
    
    
    void draw() {
      background (0);
    
      boolean done = false; 
    
       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");
         day = data.getString(row, "day");
    
          int calculatedTime = (callTimeHours * 60) + callTimeMinutes;    
    
         stroke(255);
        line(calculatedTime, 30, calculatedTime, 70);
    
        pushMatrix();
        translate (100, 170);
        // We can also access values by their key
        if (weekdays1.get(weekday)!=null) {
          // We can also access values by their key
          int yweekDay = weekdays1.get(weekday);
          yweekDay+=66;
    
          if (month1.get(month)!=null) {
            int yMonth = month1.get(month);
            line(190, yweekDay+10, 19, yMonth+10);
    
    
    
          if (day1.get(day)!=null) {
            int yDay = day1.get(day);
            yDay+=80;
            line(230, yweekDay+10, 400, yDay+50);
    
    
          if (callTime1.get(callTime)!=null) {
            int yTime = callTime1.get(callTime);
            yTime+=-100;
                  line(500, yDay+10, 400, yTime+50);
    
    
    
    
    
            text(month, 0, yMonth+10);
            text(weekday, 210, yweekDay+10);
            text(day, 410, yDay+50);
                 text(callTime, 0, yTime+50);
    
    
            } }}}
        popMatrix();
    
    
      }
    
      translate (100, 100);  fill(220);                         // 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
    
    }
    
  • 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?

  • Answer ✓

    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:

      weekdays1.put("Mon", 50);
      weekdays1.put("Tue", 100);
    

    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.

        if (callType1.get(callType)!=null) {
          int ycallType = callType1.get(callType);
          fill(255, 0, 0); // RED 
          text( callType, 660, ycallType+150);
          fill(255);  // WHITE
        } else {
          println("fail 179 with "+callType);  // WARNING 
        }
    

    Chrisir

    // Got some help from user: Chrisir on the forum for Processing helped me understand how to start the code up!
    
    
    Table data;
    int rowCount; // for calculating the # of rows in a data file
    int callTimeHours, callTimeMinutes;
    //String callTime, callType;
    
    String callTime, callType, month, weekday, day, callFrom, locationCalled, duration;  
    
    HashMap  <String, Integer> weekdays1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> month1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> day1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> callType1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> callTime1 = new HashMap<String, Integer>();
    
    
    
    
    void setup() { 
      size (1500, 800);
      data = loadTable("chrissy_data.csv", "header");
      rowCount = data.getRowCount();
      println(rowCount);
      textAlign(CENTER);
      smooth();
      strokeWeight(0.5);
    
      // Putting key-value pairs in the HashMap weekdays1
      weekdays1.put("Mon", 50);
      weekdays1.put("Tue", 100);
      weekdays1.put("Wed", 150);
      weekdays1.put("Thu", 200);
      weekdays1.put("Fri", 250);
      weekdays1.put("Sat", 300);
      weekdays1.put("Sun", 350);
    
      // Putting key-value pairs in the HashMap month1
      month1.put("Jun", 110);
      month1.put("Jul", 210);
      month1.put("Aug", 310);
      month1.put("Sep", 410);
    
      // Putting key-value pairs in the HashMap day1
    
      day1.put("1", 0);
      day1.put("2", 15);
      day1.put("3", 30);
      day1.put("4", 45);
      day1.put("5", 60);
      day1.put("6", 75);
      day1.put("7", 90);
      day1.put("8", 105);
      day1.put("9", 120);
      day1.put("10", 135);
      day1.put("11", 150);
      day1.put("12", 165);
      day1.put("13", 180);
      day1.put("14", 195);
      day1.put("15", 210);
      day1.put("16", 225);
      day1.put("17", 240);
      day1.put("18", 255);
      day1.put("19", 270);
      day1.put("20", 285);
      day1.put("21", 300);
      day1.put("22", 315);
      day1.put("23", 330);
      day1.put("24", 345);
      day1.put("25", 360);
      day1.put("26", 375);
      day1.put("27", 390);
      day1.put("28", 405);
      day1.put("29", 420);
      day1.put("30", 435);
      day1.put("31", 450);
    
      //callTime1
      callTime1.put("1", 0);
      callTime1.put("2", 15);
      callTime1.put("3", 30);
      callTime1.put("4", 45);
      callTime1.put("5", 60);
      callTime1.put("6", 75);
      callTime1.put("7", 90);
      callTime1.put("8", 105);
      callTime1.put("9", 120);
      callTime1.put("10", 135);
      callTime1.put("11", 150);
      callTime1.put("12", 165);
      callTime1.put("13", 180);
      callTime1.put("14", 195);
      callTime1.put("15", 210);
      callTime1.put("16", 225);
      callTime1.put("17", 240);
      callTime1.put("18", 255);
      callTime1.put("19", 270);
      callTime1.put("20", 285);
      callTime1.put("21", 300);
      callTime1.put("22", 315);
      callTime1.put("23", 330);
      callTime1.put("24", 345);
    
      callType1.put("OUT", 55);
      callType1.put("MYI", 75);
      callType1.put("INC", 95);
      callType1.put("CALLOUT", 115);
      callType1.put("MYO", 135);
      callType1.put("RBM", 155);
      callType1.put("IRM", 175);
    }
    
    
    
    void draw() {
      background (0);
    
      boolean done = false; 
    
      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");
        day = data.getString(row, "day");
    
        int calculatedTime = (callTimeHours * 60) + callTimeMinutes;    
    
        stroke(255);
        line(calculatedTime, 30, calculatedTime, 70);
    
        pushMatrix();
        translate (100, 170);
        // We can also access values by their key
        if (weekdays1.get(weekday)!=null) {
          // We can also access values by their key
          int yweekDay = weekdays1.get(weekday);
          yweekDay+=66;
    
          if (month1.get(month)!=null) {
            int yMonth = month1.get(month);
            line(190, yweekDay+10, 19, yMonth+10);
    
    
    
            if (day1.get(day)!=null) {
              int yDay = day1.get(day);
              yDay+=80;
              line(230, yweekDay+10, 400, yDay+50);
    
    
              if (callTime1.get(callTime)!=null) {
                int yTime = callTime1.get(callTime);
                yTime+=-100;
                line(500, yDay+10, 400, yTime+50);
    
    
    
    
    
                text(month, 0, yMonth+10);
                text(weekday, 210, yweekDay+10);
                text(day, 410, yDay+50);
                text(callTime, 0, yTime+50);
              }
            }
          }
        }
    
        if (callType1.get(callType)!=null) {
          int ycallType = callType1.get(callType);
          fill(255, 0, 0); // RED 
          text( callType, 660, ycallType+150);
          fill(255);  // WHITE
        } else {
          println("fail 179 with "+callType);
        }
    
        popMatrix();
      }
    
      translate (100, 100);  
      fill(220);                         // 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
    }
    
  • edited March 2018

    @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;

    String callTime, callType, weekday, callFrom, locationCalled, duration, day;
    
    HashMap  <String, Integer> weekdays1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> calltype1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> day1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> duration1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> callTimeHours1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> callTimeMinutes1 = new HashMap<String, Integer>();
    
    
    void setup() { 
      size (1700, 900);
      data = loadTable("chrissy_data.csv", "header");
      rowCount = data.getRowCount();
      println(rowCount);
      textAlign(CENTER);
      strokeWeight(1);
      stroke(255, 20);
      smooth();
    
      // Putting key-value pairs in the HashMap weekdays1
      weekdays1.put("Mon", 55);
      weekdays1.put("Tue", 120);
      weekdays1.put("Wed", 185);
      weekdays1.put("Thu", 250);
      weekdays1.put("Fri", 315);
      weekdays1.put("Sat", 380);
      weekdays1.put("Sun", 445);
    
      // Putting key-value pairs in the HashMap weekdays1
    
    
      calltype1.put("MYO", 55);
      calltype1.put("MYI", 200);
      calltype1.put("OUT", 300);
      calltype1.put("INC", 433);
    
    
    
      day1.put("1", 0);
      day1.put("2", 15);
      day1.put("3", 30);
      day1.put("4", 45);
      day1.put("5", 60);
      day1.put("6", 75);
      day1.put("7", 90);
      day1.put("8", 105);
      day1.put("9", 120);
      day1.put("10", 135);
      day1.put("11", 150);
      day1.put("12", 165);
      day1.put("13", 180);
      day1.put("14", 195);
      day1.put("15", 210);
      day1.put("16", 225);
      day1.put("17", 240);
      day1.put("18", 255);
      day1.put("19", 270);
      day1.put("20", 285);
      day1.put("21", 300);
      day1.put("22", 315);
      day1.put("23", 330);
      day1.put("24", 345);
      day1.put("25", 360);
      day1.put("26", 375);
      day1.put("27", 390);
      day1.put("28", 405);
      day1.put("29", 420);
      day1.put("30", 435);
      day1.put("31", 450);
    
      duration1.put("1", 0);
      duration1.put("2", 15);
      duration1.put("3", 30);
      duration1.put("4", 45);
      duration1.put("5", 50);
      duration1.put("6", 65);
    }
    
    
    void draw() {
      background (0);
    
      boolean done = false; 
    
      for (int row = 0; row < rowCount; row ++) {
    
        callTime = data.getString(row, "callTime");
        callType = data.getString(row, "callType");
        weekday = data.getString(row, "weekday");
        callFrom = data.getString(row, "callFrom");
        locationCalled = data.getString(row, "locationCalled");
        duration = data.getString(row, "duration");
        day= data.getString(row, "day");
    
        pushMatrix();
        translate (100, 170);
        // We can also access values by their key
        if (calltype1.get(callType) !=null) {
          int yType = calltype1.get(callType);
          yType+=10;
    
          if (weekdays1.get(weekday)!=null) {
            // We can also access values by their key
            int yweekDay = weekdays1.get(weekday);
            line (200, yweekDay+10, 40, yType+10);
    
            if (day1.get(day) !=null) {
              int yDayy = day1.get(day);
              line (400, yDayy+55, 200, yweekDay+10);
    
            if (callTimeHours1.get(callTime) !=null) {
              int ycalltimehours = callTimeHours1.get(callTime);
              line (500, ycalltimehours+50, 500, yDayy+55);
    
              //if (duration1.get(duration) !=null){
              // int yDuration = duration1.get(duration);
              // line (800, yDuration+10, 500, yCallTime+10);
    
              text(callType, 10, yType+10);
              text(weekday, 200, yweekDay+10);
              text (day, 420, yDayy+60);
              //text (duration, 620, yDuration+60);
              text (callTime, 520, ycalltimehours+50);
            }
          }
        }}
        popMatrix();
      }
    
      translate (100, 100);
      fill(255);                         // STEP 4 Specify font color 
      text("Call Type", 10, 100);   // STEP 5 Display Text
      text("Week Day", 210, 100);   // STEP 5 Display Text
      text("Day", 410, 100);   // STEP 5 Display Text
      text("Time", 600, 100);   // STEP 5 Display Text
        text("Location", 800, 100);   // STEP 5 Display Text
    
      text("Duration", 1000, 100);   // STEP 5 Display Text
    }
    
  • edited March 2018 Answer ✓

    ??

    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 :

        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));
        }
        print(callTimeHours);
        println(":     "+callTimeMinutes);
    

    3rd : I've shown you how to make callType red.

    • When you want to make the line red, use stroke(255,0,0); // red before it, and after it stroke(255); // white
  • edited March 2018 Answer ✓

    things like that should be written with a for loop by the way:

      day1.put("1", 0);
      day1.put("2", 15);
      day1.put("3", 30);
      day1.put("4", 45);
      day1.put("5", 60);
      day1.put("6", 75);
      day1.put("7", 90);
      day1.put("8", 105);
      day1.put("9", 120);
      day1.put("10", 135);
      day1.put("11", 150);
      day1.put("12", 165);
      day1.put("13", 180);
      day1.put("14", 195);
      day1.put("15", 210);
      day1.put("16", 225);
      day1.put("17", 240);
      day1.put("18", 255);
      day1.put("19", 270);
      day1.put("20", 285);
      day1.put("21", 300);
      day1.put("22", 315);
      day1.put("23", 330);
      day1.put("24", 345);
      day1.put("25", 360);
      day1.put("26", 375);
      day1.put("27", 390);
      day1.put("28", 405);
      day1.put("29", 420);
      day1.put("30", 435);
      day1.put("31", 450);
    

    which is

      for (int i = 0; i<31; i++) 
        day1.put(trim(i+1+""), i*15);
    
  • edited March 2018 Answer ✓

    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.)

    fail call type RBM
    fail call type IRM
    fail call type RBM
    fail call type RBM
    fail call type CALLOUT
    ....
    ....
    
  • edited March 2018

    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

                if (callType1.get(callType)!=null) {
          int yType = callType1.get(callType);
          stroke(255,0,0,20);
                 text(callType, 10, yType+10);
                line (200, yweekDay+10, 40, yType+10);
    
         if (callType.equals("MYO") == true) {
           stroke(245, 255, 0, 120);  
          } else {
            stroke (255, 0, 0, 120);
          }
    

    And for the callTime, it does not seem to work.

        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));
        }
        //print(callTimeHours);
        //println(":"+callTimeMinutes);
    
        if (day1.get(day) !=null) {
                  int yDayy = day1.get(day);
                  line (400, yDayy+55, 200, yweekDay+10);
                  text (day, 420, yDayy+60);
    
    
    
                   if (callTimeHours1.get(callTimeHours)!=null) {
                    int yHours = callTimeHours1.get(callTimeHours);
                    yHours+=-100;
                    line(500, yDayy+10, 400, yHours+50);
                       text(callTimeHours, 0, yHours+50);
    
                 if (callTimeMinutes1.get(callTimeMinutes)!=null) {
                   int yMinutes = callTimeMinutes1.get(callTimeMinutes);
                   yMinutes+=100;
                   line(100, yHours+50, 300, yMinutes+10);
    

    Thanks for answering my questions!

  • First

    when you use those lines, are the values as expected?

      print(callTimeHours);
      println(":"+callTimeMinutes);
    

    Did you fill callTimeHours1 in setup() by using put?

    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

    if (callType.equals("MYO") == true) {
      stroke(245, 255, 0, 120);  
     } else {
       stroke (255, 0, 0, 120);
     }
    

    must be before line to have effect with line, not after line.

    Remark

    == true is not necessary

    this would work too

    if (callType.equals("MYO")) {
      stroke(245, 255, 0, 120);  
     } else {
       stroke (255, 0, 0, 120);
     }
    

    Please post your entire code

    Chrisir

  • for the callTime, it does not seem to work.

    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?

  • edited March 2018
        Table data;
        int rowCount; // for calculating the # of rows in a data file
        int callTimeHours, callTimeMinutes;
        //String callTime, callType;
    
        String callTime, callType, weekday, callFrom, locationCalled, duration, day;
    
        HashMap  <String, Integer> weekdays1 = new HashMap<String, Integer>();
        HashMap  <String, Integer> callType1 = new HashMap<String, Integer>();
        HashMap  <String, Integer> day1 = new HashMap<String, Integer>();
        HashMap  <String, Integer> duration1 = new HashMap<String, Integer>();
        HashMap  <String, Integer> callTimeHours1 = new HashMap<String, Integer>();
        HashMap  <String, Integer> callTimeMinutes1 = new HashMap<String, Integer>();
        HashMap  <String, Integer> callTime1 = new HashMap<String, Integer>();
    
    
        void setup() { 
          size (1700, 900);
          data = loadTable("chrissy_data.csv", "header");
          rowCount = data.getRowCount();
          println(rowCount);
          textAlign(CENTER);
          strokeWeight(1);
          smooth();
    
          // Putting key-value pairs in the HashMap weekdays1
          weekdays1.put("Mon", 60);
          weekdays1.put("Tue", 120);
          weekdays1.put("Wed", 185);
          weekdays1.put("Thu", 250);
          weekdays1.put("Fri", 315);
          weekdays1.put("Sat", 380);
          weekdays1.put("Sun", 445);
    
          // Putting key-value pairs in the HashMap weekdays1
    
    
         callType1.put("OUT", 60);
          callType1.put("MYI", 185);
          callType1.put("INC", 316);
          callType1.put("MYO", 445);
    
    
    
         for (int i = 0; i<31; i++) 
          day1.put(trim(i+1+""), i*15);
    
          for (int m = 0; m<100; m++)
          duration1.put(trim(m+1+""), m*15);
    
        callTimeHours1.put("1", 0);
          callTimeHours1.put("2", 15);
          callTimeHours1.put("3", 30);
          callTimeHours1.put("4", 45);
          callTimeHours1.put("5", 60);
          callTimeHours1.put("6", 75);
          callTimeHours1.put("7", 90);
          callTimeHours1.put("8", 105);
          callTimeHours1.put("9", 120);
          callTimeHours1.put("10", 135);
          callTimeHours1.put("11", 150);
          callTimeHours1.put("12", 165);
          callTimeHours1.put("13", 180);
          callTimeHours1.put("14", 195);
          callTimeHours1.put("15", 210);
          callTimeHours1.put("16", 225);
          callTimeHours1.put("17", 240);
         callTimeHours1.put("18", 255);
          callTimeHours1.put("19", 270);
          callTimeHours1.put("20", 285);
          callTimeHours1.put("21", 300);
          callTimeHours1.put("22", 315);
          callTimeHours1.put("23", 330);
          callTimeHours1.put("24", 345);
    
    
    
          callTimeMinutes1.put("1", 0);
          callTimeMinutes1.put("2", 15);
            callTimeMinutes1.put("3", 15);
                callTimeMinutes1.put("4", 15);
    
    
        //for (int n = 0; n<24; n++)
        //  callTimeHours1.put(trim(n+1+""), n*15);
    
        //  for (int b = 0; b<59; b++)
        //  callTimeMinutes1.put(trim(b+1+""), b*15);
    
    
    
    
          //duration1.put("1", 0);
          //duration1.put("2", 15);
          //duration1.put("3", 30);
          //duration1.put("4", 45);
          //duration1.put("5", 50);
          //duration1.put("6", 65);
        }
    
    
        void draw() {
          background (0);
    
          boolean done = false; 
    
          for (int row = 0; row < rowCount; row ++) {
    
            callTime = data.getString(row, "callTime");
            callType = data.getString(row, "callType");
            weekday = data.getString(row, "weekday");
            callFrom = data.getString(row, "callFrom");
            locationCalled = data.getString(row, "locationCalled");
            duration = data.getString(row, "duration");
            day= data.getString(row, "day");
    
    
    
    
            pushMatrix();
            translate (100, 170);
            // We can also access values by their key
                 if (weekdays1.get(weekday)!=null) {
                // We can also access values by their key
                int yweekDay = weekdays1.get(weekday);
                          text(weekday, 200, yweekDay+10);
    
    
            if (callType1.get(callType)!=null) {
          int yType = callType1.get(callType);
                 text(callType, 10, yType+10);
    
          if (callType.equals("INC")) {
          stroke(255, 255, 255, 20);  
         } 
    
         if (callType.equals("MYO")) {
          stroke(245, 255, 0, 20);  
         } 
    
    
         if (callType.equals("MYI")) {
          stroke(0, 255, 0, 20);  
         } 
    
         if (callType.equals("OUT")) {
          stroke(0, 0, 255, 20);  
         } 
                 line (200, yweekDay+10, 40, yType+10);
    
         stroke(255,20);
    
    
        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));
        }
        //print(callTimeHours);
        //println(":"+callTimeMinutes);
    
        if (day1.get(day) !=null) {
                  int yDayy = day1.get(day);
                  line (400, yDayy+55, 200, yweekDay+10);
                  text (day, 420, yDayy+60);
    
    
    
                   if (callTimeHours1.get(callTimeHours)!=null) {
                    int yHours = callTimeHours1.get(callTimeHours);
                    yHours+=-100;
                    line(500, yDayy+10, 400, yHours+50);
                       text(callTimeHours, 0, yHours+50);
    
                 if (callTimeMinutes1.get(callTimeMinutes)!=null) {
                   int yMinutes = callTimeMinutes1.get(callTimeMinutes);
                   yMinutes+=100;
                   line(100, yHours+50, 300, yMinutes+10);
    
    
            if (duration1.get(duration) !=null){
                   int yDuration = duration1.get(duration);
                   line (800, yDuration+10, 500, yHours+10);
    
    
    
    
                  text (duration, 620, yDuration+60);
    
                }
              }}}
            }}
            popMatrix();
          }
    
          translate (100, 100);
          fill(255);                         // STEP 4 Specify font color 
          text("Call Type", 10, 100);   // STEP 5 Display Text
          text("Week Day", 210, 100);   // STEP 5 Display Text
          text("Day", 410, 100);   // STEP 5 Display Text
          text("Time", 600, 100);   // STEP 5 Display Text
            text("Location", 800, 100);   // STEP 5 Display Text
    
          text("Duration", 1000, 100);   // STEP 5 Display Text
        }
    
  • 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:

    for (int i = 0; i<25; i++) 
        callTimeHours1.put(trim(nf(i, 2)+""), 5+ i*22);
    

    I don't think you need callTimeMinutes1

    Please hit ctrl-t in processing to get a better auto-format (indents)

  • edited March 2018

    I changed it, but the lines still does not show up?

        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));
        }
    
    
        if (day1.get(day) !=null) {
                  int yDayy = day1.get(day);
                  line (600, yDayy+55, 400, yweekDay+80);
                  //text (day, 600, yDayy+60);
    
            //if (location1.get(locationCalled) !=null) {
            //  int yLocations = location1.get(locationCalled); 
            //  line (800, yLocations+250, 600, yDayy+55 );
    
            if (duration1.get(duration) !=null){
                   int yDuration = duration1.get(duration);
                   line (800, yDuration+55, 600, yDayy+55);
    
    
                   if (callTimeHours1.get(callTimeHours)!=null) {
                    int yHours = callTimeHours1.get(callTimeHours);
                    yHours+=100;
                    line(100, yHours+10, 400, yDuration+50);
    
                 if (callTimeMinutes1.get(callTimeMinutes)!=null) {
                   int yMinutes = callTimeMinutes1.get(callTimeMinutes);
                   yMinutes+=100;
                   line(100, yHours+50, 300, yMinutes+10);
    
  • always post your entire code

  • compare these values

    print(callTimeHours);
    println(":"+callTimeMinutes);
    

    to the values you have put into callTimeHours1 in setup() please

  • edited March 2018

    ah, the data type is wrong, you have int, but you want String

    before setup() :

    String callTimeHours, callTimeMinutes;
    

    and these lines have to be changed accordingly (without int( ) :

    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));
    }
    
  • edited March 2018

    Is this correct?

      Table data;
            int rowCount; // for calculating the # of rows in a data file
            //String callTime, callType;
    
            String callTime, callType, weekday, callFrom, locationCalled, duration, day, callTimeHours, callTimeMinutes;
    
            HashMap  <String, Integer> weekdays1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> callType1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> day1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> duration1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> callTimeHours1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> callTimeMinutes1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> callTime1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> location1 = new HashMap<String, Integer>();
    
            PImage img;
    
    
            void setup() { 
              size (1500, 900);
              data = loadTable("chrissy_data.csv", "header");
              rowCount = data.getRowCount();
              println(rowCount);
              textAlign(CENTER);
              strokeWeight(1);
              smooth();
             img = loadImage("background4.png");
    
    
              // Putting key-value pairs in the HashMap weekdays1
              weekdays1.put("Mon", 60);
              weekdays1.put("Tue", 120);
              weekdays1.put("Wed", 185);
              weekdays1.put("Thu", 250);
              weekdays1.put("Fri", 315);
              weekdays1.put("Sat", 380);
              weekdays1.put("Sun", 445);
    
              // Putting key-value pairs in the HashMap weekdays1
    
    
             callType1.put("OUT", 60);
              callType1.put("MYI", 185);
              callType1.put("INC", 316);
              callType1.put("MYO", 445);
    
    
    
             for (int i = 0; i<31; i++) 
              day1.put(trim(i+1+""), i*18);
    
              for (int y = 0; y<110; y++)
              duration1.put(trim(y+1+""), y*5);
    
            for (int i = 0; i<25; i++) 
                callTimeHours1.put(trim(nf(i, 2)+""), 5+ i*22);
    
    
              location1.put("TORONTO", 0);
                location1.put("STREETSVL", 50);
                    location1.put("UNIONVILLE", 100);
                location1.put("HALIFAX", 150);
                location1.put("1-800 CALL", 200);
    
    
            //for (int n = 0; n<24; n++)
            //  callTimeHours1.put(trim(n+1+""), n*15);
    
            //  for (int b = 0; b<59; b++)
            //  callTimeMinutes1.put(trim(b+1+""), b*15);
    
    
    
    
              //duration1.put("1", 0);
              //duration1.put("2", 15);
              //duration1.put("3", 30);
              //duration1.put("4", 45);
              //duration1.put("5", 50);
              //duration1.put("6", 65);
            }
    
    
            void draw() {
              background (0);
              image(img, 100, 25 );
    
              boolean done = false; 
    
              for (int row = 0; row < rowCount; row ++) {
    
                callTime = data.getString(row, "callTime");
                callType = data.getString(row, "callType");
                weekday = data.getString(row, "weekday");
                callFrom = data.getString(row, "callFrom");
                locationCalled = data.getString(row, "locationCalled");
                duration = data.getString(row, "duration");
                day= data.getString(row, "day");
    
    
    
    
                pushMatrix();
                translate (100, 170);
                // We can also access values by their key
                     if (weekdays1.get(weekday)!=null) {
                    // We can also access values by their key
                    int yweekDay = weekdays1.get(weekday);
                              //text(weekday, 400, yweekDay+80);
    
    
                if (callType1.get(callType)!=null) {
              int yType = callType1.get(callType);
                     //text(callType, 10, yType+10);
    
    
             if (callType.equals("OUT")) { // Blue lines
              stroke(0, 0, 255, 20);  
             } 
    
    
    
             if (callType.equals("MYI")) { // Green Lines
              stroke(0, 255, 0, 20);  
             } 
    
    
              if (callType.equals("INC")) { //Red Lines
              stroke(255, 0, 0, 20);  
             } 
    
             if (callType.equals("MYO")) { //Yellow Lines
              stroke(255, 255, 0, 20);  
             } 
    
    
    
    
              line (400, yweekDay+80, 200, yType+80);  //Call Type lines towards Weekday 
    
             stroke(255,20);
    
               line (200, 50,200, 600);
            line(400, 50, 400, 600); // weekday line
            line(600, 50, 600, 600); // day line
            line(800, 50, 800, 600); //time
            line(1000, 50, 1000, 600); // duration
            line(1200, 50, 1200, 600); // location
    
    
             String callTimeCheck = callTime.substring(1, 2);
            if (callTimeCheck.equals (":") == true) {
              callTimeHours  = (callTime.substring(0, 1));
              callTimeMinutes= (callTime.substring(2));
            } else {
              callTimeHours  = (callTime.substring(0, 2));
              callTimeMinutes= (callTime.substring(3));
            }
    
    
            if (day1.get(day) !=null) {
                      int yDayy = day1.get(day);
                      line (600, yDayy+55, 400, yweekDay+80);
                      //text (day, 600, yDayy+60);
    
                //if (location1.get(locationCalled) !=null) {
                //  int yLocations = location1.get(locationCalled); 
                //  line (800, yLocations+250, 600, yDayy+55 );
    
    
    
    
                       if (callTimeHours1.get(callTimeHours)!=null) {
                        int yHours = callTimeHours1.get(callTimeHours);
                        yHours+=100;
                        line(800, yHours+10, 600, yDayy+50);
    
    
    
    
               if (duration1.get(duration) !=null){
                       int yDuration = duration1.get(duration);
                       line (1000, yDuration+50, 800, yHours+10);
    
    
    
    
    
    
    
    
    
                    }}
                  }
                }}
                popMatrix();
              }
    
              translate (100, 100);
              fill(255);                         
              text("Call Type", 200, 80);   
    
              text("WeekDay", 400, 80); 
                text("Monday - Sunday", 400, 100);
    
              text("Days", 600, 80);
                text("1 - 31", 600, 100);   
    
              text("Location - Toronto, Streetsville,", 1200, 80);  
                text(" Unionville, Halifax, & 1-800 CALL", 1200, 100);// STEP 5 Display Text
    
               text("Time", 800, 80);   // STEP 5 Display Text
               text("1- 24 Hour", 800, 100);   // STEP 5 Display Text
    
              text("Duration", 1000, 80);   
                  text("1 - 110 Minutes", 1000, 100);   
                }
    
  • edited March 2018 Answer ✓

    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:

        //for (int n = 0; n<24; n++)
        //  callTimeHours1.put(trim(n+1+""), n*15);
      
        //  for (int b = 0; b<59; b++)
        //  callTimeMinutes1.put(trim(b+1+""), b*15);
      
      
      
      
          //duration1.put("1", 0);
          //duration1.put("2", 15);
          //duration1.put("3", 30);
          //duration1.put("4", 45);
          //duration1.put("5", 50);
          //duration1.put("6", 65);
      

    Chrisir

  • Answer ✓

    This can be a nw function determineStrokeColorFromCallType() :

            if (callType.equals("OUT")) { // Blue lines
              stroke(0, 0, 255, 20);
            } 
    
    
    
            if (callType.equals("MYI")) { // Green Lines
              stroke(0, 255, 0, 20);
            } 
    
    
            if (callType.equals("INC")) { //Red Lines
              stroke(255, 0, 0, 20);
            } 
    
            if (callType.equals("MYO")) { //Yellow Lines
              stroke(255, 255, 0, 20);
            }
    

    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:

            } else println("fail callTimeHours: "+callTimeHours);
          } else println("fail day1");
        } else println("fail weekday");
      } else println("fail call type "+callType);
    

    In this comment: // We can also access values by their key the word also doesn't make sense

  • Answer ✓

    I 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.

  • edited March 2018

    Final code:

     //Christine's Project 1C
    
            // Base code from Chrisir @ Processing Forum.
    
    
            Table data;
            int rowCount; // for calculating the # of rows in a data file
            //String callTime, callType;
    
            String callTime, callType, weekday, callFrom, locationCalled, duration, day, callTimeHours, callTimeMinutes;
    
            HashMap  <String, Integer> weekdays1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> callType1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> day1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> duration1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> callTimeHours1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> callTimeMinutes1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> callTime1 = new HashMap<String, Integer>();
            HashMap  <String, Integer> location1 = new HashMap<String, Integer>();
    
            PImage img;
    
    
            void setup() { 
              size (1300, 900);
              data = loadTable("chrissy_data.csv", "header");
              rowCount = data.getRowCount();
              println(rowCount);
              textAlign(CENTER);
              strokeWeight(1);
              smooth();
              img = loadImage("background4.png");
    
              // Putting key-value pairs in the HashMap weekdays1
              weekdays1.put("Mon", 60);
              weekdays1.put("Tue", 120);
              weekdays1.put("Wed", 185);
              weekdays1.put("Thu", 250);
              weekdays1.put("Fri", 315);
              weekdays1.put("Sat", 380);
              weekdays1.put("Sun", 445);
    
              callType1.put("OUT", 60);
              callType1.put("MYI", 185);
              callType1.put("INC", 316);
              callType1.put("MYO", 445);
    
              for (int i = 0; i<31; i++) 
                day1.put(trim(i+1+""), i*18);
    
              for (int y = 0; y<110; y++)
                duration1.put(trim(y+1+""), y*5);
    
              for (int i = 0; i<25; i++) 
                callTimeHours1.put(trim(nf(i, 2)+""), 5+ i*22);
    
              location1.put("TORONTO", 0);
              location1.put("STREETSVL", 50);
              location1.put("UNIONVILLE", 100);
              location1.put("HALIFAX", 150);
              location1.put("1-800 CALL", 200);
              location1.put("1-877 CALL", 250);
    
            }
    
    
            void draw() {
              background (0);
              image(img, 100, 25 );
    
              boolean done = false; 
    
              for (int row = 0; row < rowCount; row ++) {
    
                callTime = data.getString(row, "callTime");
                callType = data.getString(row, "callType");
                weekday = data.getString(row, "weekday");
                callFrom = data.getString(row, "callFrom");
                locationCalled = data.getString(row, "locationCalled");
                duration = data.getString(row, "duration");
                day= data.getString(row, "day");
    
                pushMatrix();
                translate (100, 170);
                // We can also access values by their key
                if (weekdays1.get(weekday)!=null) {
                  // We can also access values by their key
                  int yweekDay = weekdays1.get(weekday);
    
                  if (callType1.get(callType)!=null) {
                    int yType = callType1.get(callType);
    
                    if (callType.equals("OUT")) { // Blue lines
                      stroke(0, 0, 255, 20);
                    } 
    
                    if (callType.equals("MYI")) { // Green Lines
                      stroke(0, 255, 0, 20);
                    } 
    
                    if (callType.equals("INC")) { //Red Lines
                      stroke(255, 0, 0, 20);
                    } 
    
                    if (callType.equals("MYO")) { //Yellow Lines
                      stroke(255, 255, 0, 20);
                    } 
    
                    line (250, yweekDay+80, 50, yType+80);  //Call Type lines towards Weekday 
    
                    stroke(255, 20);
    
                    line (50, 50, 50, 600);
                    line(250, 50, 250, 600); // weekday line
                    line(450, 50, 450, 600); // day line
                    line(650, 50, 650, 600); //time
                    line(850, 50, 850, 600); // duration
                    line(1050, 50, 1050, 600); // location
    
                    String callTimeCheck = callTime.substring(1, 2);
                    if (callTimeCheck.equals (":") == true) {
                      callTimeHours  = (callTime.substring(0, 1));
                      callTimeMinutes= (callTime.substring(2));
                    } else {
                      callTimeHours  = (callTime.substring(0, 2));
                      callTimeMinutes= (callTime.substring(3));
                    }
    
    
                    if (day1.get(day) !=null) {
                      int yDayy = day1.get(day);
                      line (450, yDayy+55, 250, yweekDay+80);
    
                      if (callTimeHours1.get(callTimeHours)!=null) {
                        int yHours = callTimeHours1.get(callTimeHours);
                        yHours+=100;
                        line(650, yHours+10, 450, yDayy+55);
    
                          if (location1.get(locationCalled) !=null) {
                            int yLocations = location1.get(locationCalled); 
                            line (850, yLocations+50, 650, yHours+10 );
    
                        if (duration1.get(duration) !=null) {
                          int yDuration = duration1.get(duration);
                          line (1050, yDuration+50, 850, yLocations+50);
    
                          }
                        }
                      }
                    }
                  }
                }
                popMatrix();
              }
    
              translate (100, 100);
              fill(255);                         
              text("Call Type", 50, 80);   
    
              text("WeekDay", 250, 80); 
              text("Monday - Sunday", 250, 100);
    
              text("Days", 450, 80);
              text("1 - 31", 450, 100);   
    
              text("Time", 650, 80);   
              text("1- 24 Hour", 650, 100); 
    
              text("Location - Toronto, Streetsville,", 850, 80);  
              text(" Unionville, Halifax, & 1-800 CALL", 850, 100);// STEP 5 Display Text
    
              text("Duration", 1050, 80);   
              text("1 - 110 Minutes", 1050, 100);
            }
    
  • Answer ✓

    Very nice!

    Congratulations!

  • Answer ✓

    just for completeness sake:

    the before mentioned version:

    I made a version where you can browse through the calls (use keys + and - ) additionally

    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 ;-)

    Table data;   // table with all data 
    int rowCount; // for calculating the # of rows in a data file 
    
    String callTime, callType, weekday, callFrom, locationCalled, duration, day;
    String callTimeHours, callTimeMinutes; 
    
    HashMap  <String, Integer> weekdays1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> calltype1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> day1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> duration1 = new HashMap<String, Integer>();
    HashMap  <String, Integer> callTimeHours1 = new HashMap<String, Integer>();
    //HashMap  <String, Integer> callTimeMinutes1 = new HashMap<String, Integer>();
    
    // selected call: green lines, yellow info box: 
    int currentCall=0;
    
    // ------------------------------------------------------
    // setup and draw
    
    void setup() { 
    
      size (1700, 900);
    
      data = loadTable("chrissy_data.csv", "header");
      rowCount = data.getRowCount();
      println("rows: "
        +rowCount);
    
      textAlign(CENTER);
      strokeWeight(1);
      stroke(255, 20);
      smooth();
    
      initHashMaps();
    }
    
    void draw() {
      background(0);
    
      for (int row = 0; row < rowCount; row++) {
        displayOneRow(row);
      }//for
    
      //display the current call 
      displayOneRow(currentCall);
      displayInfoBox(currentCall);
    
      translate (100, 100);
      fill(255);                    // STEP 4 Specify font color 
      text("Call Type", 10, 100);   // STEP 5 Display Text
      text("Week Day", 210, 100);   // STEP 5 Display Text
      text("Day", 410, 100);        // STEP 5 Display Text
      text("Time", 600, 100);       // STEP 5 Display Text
      text("Location", 800, 100);   // STEP 5 Display Text
      text("Duration", 1000, 100);  // STEP 5 Display Text
    }
    
    // -----------------------------------------------------------------
    // Inputs 
    
    void keyPressed() {
      if (key>='0'&&key<='9') {
        //
        currentCall=int(key-48);
        // println(currentCall);
      }//if
      else if (key=='+') {
        if (currentCall<rowCount-1)
          currentCall++;
      }//else if
      else if (key=='-') {
        if (currentCall>0)
          currentCall--;
      }//else if
    }//func 
    
    void mousePressed() {
    
      if (currentCall<rowCount-1)
        currentCall++;
    }
    
    // -----------------------------------------------------------------
    // Other functions 
    
    void displayInfoBox(int row) {
    
      // display yellow Info Box
    
      if (row<0)
        return;
    
      textAlign(LEFT);
    
      String callMonthStr = data.getString(row, "month");
      callTime = data.getString(row, "callTime");
      callType = data.getString(row, "callType");
      weekday = data.getString(row, "weekday");
      callFrom = data.getString(row, "callFrom");
      locationCalled = data.getString(row, "locationCalled");
      duration = data.getString(row, "duration");
      day= data.getString(row, "day");
    
      pushMatrix(); 
      translate (width-210, height-300);
    
      fill(250, 243, 34); 
      stroke(0); 
      rect(0, 60-6, 210-16, 300-64); 
    
      // Headline 
      fill(0, 255, 0);                         // STEP 4 Specify font color
      text("Call Number "+row, 10, 70);   // STEP 5 Display Text
    
      fill(0);                         // STEP 4 Specify font color
      text("Call Type: "+callType, 10, 100);   // STEP 5 Display Text
      text("Week Day: "+weekday, 10, 130);   // STEP 5 Display Text
      text("Date: "+callMonthStr+" "+day, 10, 160);   // STEP 5 Display Text
      text("Time: "+callTime, 10, 190);   // STEP 5 Display Text
      text("Location called: "+locationCalled, 10, 220);   // STEP 5 Display Text
      text("Duration: "+duration, 10, 250);   // STEP 5 Display Text
      text("Press 0..9 / + and - ", 10, 280);   // STEP 5 Display Text
      popMatrix();
    
      textAlign(CENTER); // reset
    }
    
    void displayOneRow(int row) {
    
      if (row<0)
        return;
    
      callTime = data.getString(row, "callTime");
      callType = data.getString(row, "callType");
      weekday = data.getString(row, "weekday");
      callFrom = data.getString(row, "callFrom");
      locationCalled = data.getString(row, "locationCalled");
      duration = data.getString(row, "duration");
      day= data.getString(row, "day");
    
      String callTimeCheck = callTime.substring(1, 2);
      if (callTimeCheck.equals (":") == true) {
        callTimeHours  = (callTime.substring(0, 1));
        callTimeMinutes= (callTime.substring(2));
      } else {
        callTimeHours  = (callTime.substring(0, 2));
        callTimeMinutes= (callTime.substring(3));
      }
      //  print(callTimeHours);
      //  println(":     "+callTimeMinutes);
    
      pushMatrix();
      translate (100, 170);
    
      // We can  access values by their key
      if (calltype1.get(callType) !=null) {
        int yType = calltype1.get(callType);
        yType+=10;
    
        if (weekdays1.get(weekday)!=null) {
          // We can also access values by their key
          int yweekDay = weekdays1.get(weekday);
          setColor( row, color(255, 0, 0) ); // green or red 
          line (200, yweekDay+20, 
            40, yType+10);
    
          if (day1.get(day) !=null) {
            int yDay = day1.get(day);
            setColor( row, color(255) ); // GREEN or white  
            line (210, yweekDay+20, 
              400, yDay+55 );
    
            if (callTimeHours1.get(callTimeHours) !=null) {
              int ycalltimehours = callTimeHours1.get(callTimeHours);
              setColor( row, color(255) ); // GREEN or white
              line (600, ycalltimehours+0, 
                440, yDay+55);
    
              //if (duration1.get(duration) !=null){
              // int yDuration = duration1.get(duration);
              // line (800, yDuration+10, 500, yCallTime+10);
    
              text(callType, 10, yType+10);
              text(weekday, 200, yweekDay+10);
              text (day, 420, yDay+60);
              // text (duration, 620, yDuration+60);
              // text (callTime, 520, ycalltimehours+50);
              text (callTimeHours, 620, ycalltimehours+0);
            } else println("fail callTimeHours: "+callTimeHours);
          } else println("fail day1");
        } else println("fail weekday");
      } else println("fail call type "+callType);
      popMatrix();
      //
    }
    
    void setColor(int row1, color colStandard) {
    
      // distinguish between the selected call (change with 0..9) 
      // in green AND the normal color (which is red or white) named colStandard
    
      if (row1==currentCall)
        stroke( 0, 255, 0); // green
      else
        stroke(colStandard); // red
    }
    
    // ------------------------------------------------------------------
    // Init 
    
    void initHashMaps() {
    
      // Putting key-value pairs in the HashMaps 
    
      // Putting key-value pairs in the HashMap weekdays1
      weekdays1.put("Mon", 55);
      weekdays1.put("Tue", 120);
      weekdays1.put("Wed", 185);
      weekdays1.put("Thu", 250);
      weekdays1.put("Fri", 315);
      weekdays1.put("Sat", 380);
      weekdays1.put("Sun", 445);
    
      // Putting key-value pairs in the HashMap 
      int add1=80;
      calltype1.put("MYO", add1+0*100);
      calltype1.put("MYI", add1+1*100);
      calltype1.put("OUT", add1+2*100);
      calltype1.put("INC", add1+3*100);
      calltype1.put("CALLOUT", add1+4*100);
      calltype1.put("RBM", add1+5*100);
      calltype1.put("IRM", add1+6*100);
    
      // Putting key-value pairs in the HashMaps 
    
      for (int i = 0; i<31; i++) 
        day1.put(trim(i+1+""), i*15);
    
      for (int i = 0; i<6; i++) 
        duration1.put(trim(i+1+""), i*15);
    
      for (int i = 0; i<25; i++) 
        callTimeHours1.put(trim(nf(i, 2)+""), 5+ i*22);
    }
    //
    
Sign In or Register to comment.