Displaying sequences of connected events

Hello, I have a question about displaying sequences of events on a map. I have a database with sequences. Some sequences contain a single events, while others contain up to 4 events. I have managed to display the single events by creating a class, querying the database and populating arraylists. I have used a canvas to display the points (code below).

My question is: with the multiple sequences, do I use the same method as below? In the "canvas" section, the SQL query would obtain locType2, locType 3, locType4, as well as minutes2, minutes3 and so on. This would mean multiple locations (lat/lon) in one class. Is this a problem? I'm sorry for the basic question (it goes without saying that I'm a beginner). I'm unsure how to link locType 2, id_contact_location2 with lat2/lon2, etc.

The next step would then be to connect these sequence events with lines, showing a path. I would be grateful for any tips! Thanks in advance.

import de.fhpotsdam.unfolding.*;
import de.fhpotsdam.unfolding.data.*;
import de.fhpotsdam.unfolding.geo.*;
import de.fhpotsdam.unfolding.utils.*;
import de.fhpotsdam.unfolding.providers.*;
import de.fhpotsdam.unfolding.mapdisplay.MapDisplayFactory;
import java.util.List;
import controlP5.*;
import de.bezier.data.sql.*;

ControlP5 cp5;
MySQL msql;    
Canvas cc_seq1Map;
UnfoldingMap map;

int mapX = 250;
int mapY = 10;
int mapW = 515;
int mapH = 630;

Location mapLocation = new Location(-37.7f, 144.8f);
ArrayList<ContEvents> contevents = new ArrayList();
int maxmins1 = 0;

color col1 = color(127, 201, 127); 
color col2 = color(190, 174, 212); 
color col5 = color(253, 192, 134);
color col7 = color(255, 255, 153); 
color col10 = color(56, 108, 176);
color col14 = color(240, 2, 127);  
//==============================================================

public void setup() {
  size(800, 650, P2D);
  smooth();

  map = new UnfoldingMap(this, "map", mapX, mapY, mapW, mapH, true, false, new Google.GoogleTerrainProvider());
  MapUtils.createDefaultEventDispatcher(this, map);
  map.zoomAndPanTo(mapLocation, 11); 

  cc_seq1Map = new Seq1MapCanvas();

  //CONNECT TO MySQL DATABASE
  String user = "****";
  String pass = "****";
  String database = "database_name";
  msql = new MySQL(this, "localhost", database, user, pass);

  //CANVAS
  cp5 = new ControlP5(this);
  cp5.setControlFont(new ControlFont(createFont("Arial", 14), 14));

  cp5.addButton("MAP")
    //.setValue(0)
    .setPosition(20, 80)
      .setSize(170, 50)
        ;

  cp5.addButton("SEQUENCES")
    // .setValue(100)
    .setPosition(20, 260)
      .setSize(170, 50)
        ;
}

//==============================================================             
public void draw() {
  background(180);
  map.draw();
}    
//==============================================================

//CANVAS
class Seq1MapCanvas extends Canvas {

  public void setup(PApplet p) { 

    if (msql.connect()) {
      //Hume single seq + contact events
      msql.query("SELECT...;");
      msql.next ();
      while (msql.next ())
      {
        //create new empty object to store data
        ContEvents contevent = new ContEvents();

        contevent.participant_id = msql.getInt("participant_id");
        contevent.locType1 = msql.getString("locType1");
        contevent.dayname = msql.getString("Dayname");
        contevent.age = msql.getInt("age");
        contevent.gender = msql.getString("gender");
        contevent.id_contact_location1 = msql.getString("id_contact_location1");
        contevent.minutes1 = msql.getInt("minutes1");
        contevent.number_spoken1 = msql.getInt("number_spoken1");
        float lat1 = msql.getFloat("lat1");
        float lon1 = msql.getFloat("lon1");
        //create location of events 
        contevent.location = new Location(lat1, lon1);
        //add to list of contact events
        contevents.add(contevent);
        //info for creating ellipses (size)
        maxmins1 = max(maxmins1, contevent.minutes1);
      }
    }
  }
  public void draw(PApplet p) { 
    p.noFill(); 
    p.rect(250, 10, 515, 630);
    p.stroke(0);

    for (ContEvents contevent : contevents) {
      ScreenPosition pos = map.getScreenPosition(contevent.location);
      //Check if points within map boundaries. If so, display.
      if ( pos.x > mapX && pos.x < mapX + mapW &&
        pos.y > mapY && pos.y < mapY + mapH  ) {

        if (contevent.locType1.equals("1")) {
          p.fill(col1);
        } else if (contevent.locType1.equals("2")) {
          p.fill(col2);
        } else if (contevent.locType1.equals("5")) {
          p.fill(col5);
        } else if (contevent.locType1.equals("7")) {
          p.fill(col7);
        } else if (contevent.locType1.equals("10")) {
          p.fill(col10);
        } else if (contevent.locType1.equals("14")) {
          p.fill(col14);
        }
        float s = map(contevent.minutes1, 0, maxmins1, 5, 50);      //draw ellipse size according to contact duration
        ellipse(pos.x, pos.y, s, s);

        if (contevent.showLabel) {
          fill(0);
          text(contevent.minutes1 + ", " + contevent.number_spoken1, pos.x - textWidth(contevent.minutes1 + ", " + contevent.number_spoken1)/2, pos.y);
        }
      }
    }
  }
}
//==============================================================

//CLASS to store data for each sequence event
class ContEvents {

  int participant_id;
  String locType1;
  String dayname;
  int age;
  String gender;
  String id_contact_location1;
  float lat1;
  float lon1;
  int minutes1;
  int number_spoken1;
  Location location; 
  boolean showLabel;
}
//==============================================================
void controlEvent(ControlEvent theEvent) {

  if (theEvent.getName() == "MAP") {
    cp5.removeCanvas(cc_seq1Map);
  } else if (theEvent.getName() == "SEQUENCES") {
    cc_seq1Map = new Seq1MapCanvas();
    cp5.addCanvas(cc_seq1Map);
  }
}
Tagged:

Answers

Sign In or Register to comment.