Looping over csv as nodes in datavisualization

Hello everyone, I'm currently making a network visualization about dj's that play at festivals. I have a CSV which lists those dj's per festival, the csv looks like this:

Beat The Bridge,2012,12:00 - 13:15,Fanatic,,
Beat The Bridge,2012,13:15 - 14:30,Global Soundz,,
Beat The Bridge,2012,14:30 - 16:00,D-Block & S-te-Fan,,
DefQon1,2012,11:00 - 12:00,Activator,,
DefQon1,2012,12:00 - 13:15,Isaac,,
DefQon1,2012,13:15 - 14:15,The Pitcher,,
Intents,2011,13:00 - 14:00,Dark-E,,
Intents,2011,14:00 - 15:15,Coone,,
Intents,2011,15:15 - 16:30,Isaac,,

I need to find a way to create a new node when the csv shows a new festival, but when it reads the same festival it needs to add 1 to a count, this also needs to happen per DJ.

I created a system that would count the festival but it will only work if my csv lists these festivals in order, so this wont work for the DJ's. I figured it might be usefull to create a 2-dimensional table but im not really sure how i can properly implement that in this code.

(Right now the "dj" nodes are not being created by a loop yet but are still static).

Any help would be greatly appriciated.

This is my main program:

Node[] nodes = new Node[1]; //These will be the DJ nodes

festNode[] festnodes = new festNode[0]; //These are the Festival nodes

festData[] festdatas = new festData[0]; //This is just a helper to supply the Festival nodes with data


String[][] festrow;

float wait = 1000;
float last = 0;
int nc = 1;
int fc = 1;

String festival;
String year;
String time;
String dj;

Table table;
int festCount;
String theFestival;
int fci = 0;




void setup() {

  table = loadTable("test.csv", "header");

  println(table.getRowCount() + " total rows in table"); 

  //festnodes[0] = new festNode(random(width), random(height), 50, 50);

  for (TableRow row : table.rows ()) {

    festival = row.getString("Festival");
    year = row.getString("Year");
    time = row.getString("Time");
    dj = row.getString("DJ");


    festData fd = new festData(festival, dj);
    festdatas = (festData[]) append(festdatas, fd);



    if (fci == 0) {
      festCount = 1;
      festNode fn = new festNode(random(300, 1300), random(100, 700),festival, festCount);
      festnodes = (festNode[]) append(festnodes, fn);
      //print(festdatas[0].fest);
      fci++;
      print(fci-1);
    } else {
      //print("reachedelse");
      theFestival = festnodes[fci-1].fest;

      print(fci-1);

      if (theFestival.equals(festival) == true) {
        festCount ++;
        festnodes[fci-1].c = festCount;
      } else {
        festCount = 1;
        print("NEW ");
        festNode fn = new festNode(random(300, 1300), random(100, 700),festival, festCount);
        festnodes = (festNode[]) append(festnodes, fn);
        fci++;
      }
    }
   /*


  for (int i=0; i<festdatas.length; i++) {

    theFestival = festdatas[i].fest;

    if (theFestival.equals(festival) == true) {
        festCount ++;
        festdatas[i].count = festCount;
        print(" aye ");

      } else {
        festCount = 1;
        print(festdatas[i].fest);
        //print("NEW ");
        festNode fn = new festNode(random(300, 1300), random(100, 700),festival, festCount);
        festnodes = (festNode[]) append(festnodes, fn);
        fci++;
      }
    }
    */
  }


  ellipseMode(CENTER);
  size(1200, 600);

  nodes[0] = new Node(100, 250, 30, 30, 0);


}

void draw() {
  background(0);



  if (nc < 10) {

    Node c = new Node(random(0, width), random(0, height), 30, 30, nc); 
    nodes = (Node[]) append(nodes, c);
    //println(nodes);
    //last = millis();
    nc++;
  }


  for (int i=0; i<nodes.length; i++) {


    nodes[i].avoidSelf();
    //nodes[i].edgeSelf();
    nodes[i].edgeFestNode();
    nodes[i].moveToFestNode();
    nodes[i].moveNode(nodes[i]);
    nodes[i].display();
    //nodes[i].mouseDrag();
  }

  //line(xa, ya, xb, yb);
  stroke(255);



  for (int f=0; f<festnodes.length; f++) {

    festnodes[f].display();
    festnodes[f].moveFestNode();
    festnodes[f].avoidSelf();
    festnodes[f].avoidWall();
    festnodes[f].displayName();
  }
}

These are my classes:

/*----------------------------DJ NODES-----------------------------*/
class Node {
  float x;
  float y;
  float w;
  float h;          
  float distToNode;
  float col1 = random(255);
  float col2 = random(255);
  float col3 = random(255);
  float m = 0.01;
  int id;



  Node(float tempX, float tempY, float tempW, float tempH, int tempId) {

    x = tempX;
    y = tempY;
    w = tempW;
    h = tempH;
    id = tempId;
  }

  void display() {

    for (int i=0; i<nodes.length; i++) {
      fill(col1, col2, col3);
      strokeWeight(0);
      //stroke(255, 0);
      ellipse(x, y, w, h);
    }
  }

  void avoidSelf() {

    for (int j=0; j<nodes.length; j++) {

      if (nodes[j] != this) {

        distToNode = dist(x, y, nodes[j].x, nodes[j].y);
        if (distToNode < 40) {

          PVector p = new PVector( nodes[j].x-x, nodes[j].y-y);
          p.limit(10);

          x-=p.x;
          y-=p.y;
        }
        //print(distToNode);
      }
    }
  }


  void edgeFestNode() {


    for (int j=0; j<festnodes.length; j++) {

      distToNode = dist(x, y, festnodes[j].x, festnodes[j].y); 

      if (distToNode < 200) {

        strokeWeight(12);
      } else if ((distToNode < 400)) {
        strokeWeight(7);
      } else {
        strokeWeight(2);
      }

      stroke(col1, col2, col3);
      line(x, y, festnodes[j].x, festnodes[j].y);
    }
  }


  void moveToFestNode() {

    for (int j=0; j<festnodes.length; j++) {

      distToNode = dist(x, y, festnodes[j].x, festnodes[j].y);
      if (distToNode > 300) {

        x = lerp(x, festnodes[j].x, m);
        y = lerp(y, festnodes[j].y, m);
      }
    }
  }

  void moveNode(Node n) {

    //for (int f=0; f<festnodes.length; f++) {
    //for (int j=0; j<nodes.length; j++) {


    if  (mousePressed == true && mouseX < n.x+30 && mouseX > n.x-30 && mouseY < n.y+30 && mouseY > n.y-30 && n == this) {

      x = mouseX;
      y = mouseY;
    }
  }




  /*----------------------------IGNORE - This is not being called upon-----------------------------*/
  void edgeSelf() {

    for (int j=0; j<nodes.length; j++) {

      if (nodes[j] != this) {

        strokeWeight(2);
        stroke(col1, col2, col3);
        line(x, y, nodes[j].x, nodes[j].y);
      }
    }
  }
}


/*----------------------------FESTIVAL NODE-----------------------------*/

class festNode {
  float x;
  float y;
  float w;
  float h;          
  float distToNode;
  float col1 = random(255);
  float col2 = random(255);
  float col3 = random(255);
  String fest;  
  int c = 0;


  festNode(float tempX, float tempY, String tempFest, int tempCount ) {

    c = tempCount * 100;
    fest = tempFest;  
    x = tempX;
    y = tempY;
    //w = tempW;
    //h = tempH;
  }

  void display() {

    strokeWeight(0);
    stroke(255, 0);
    fill(col1, col2, col3);
    ellipse(x, y, c, c);
  }

  void moveFestNode() {

    for (int f=0; f<festnodes.length; f++) {

      if (mousePressed == true && mouseX < festnodes[f].x+50 && mouseX > festnodes[f].x-50 && mouseY < festnodes[f].y+50 && mouseY > festnodes[f].y-50 && festnodes[f] == this) {
        festnodes[f].x = mouseX;
        festnodes[f].y = mouseY;
      }
    }
  }

  void avoidSelf() {

    for (int j=0; j<festnodes.length; j++) {

      if (festnodes[j] != this) {

        distToNode = dist(x, y, festnodes[j].x, festnodes[j].y);
        if (distToNode < 100) {

          PVector p = new PVector( festnodes[j].x-x, festnodes[j].y-y);
          p.limit(10);

          x-=p.x;
          y-=p.y;
        }
        //print(distToNode);
      }
    }
  }

  void avoidWall() {

    if (x < 0 || x > width) {
      x = random(300,800);
    }
    if (y < 0 || y > height) {
      y = random(300, 600);
    }
  }


  void displayName() {

    textAlign(CENTER, CENTER);
    textSize(32);
    fill(0, 102, 153);
    text(fest, x, y); 

  }






}


/*----------------------------FESTIVAL DATA HELPER-----------------------------*/

class festData {
  String fest;
  String dj;  
  int count = 0;


  festData(String tempFest, String tempDj) {

    fest = tempFest;
    dj = tempDj;
  }


  void trackData() {
    count++;
  }
}

Answers

Sign In or Register to comment.