Skip to content

Commit

Permalink
trails and debug buttons. deal with multiple trip files.
Browse files Browse the repository at this point in the history
  • Loading branch information
abawa committed Feb 22, 2011
1 parent e823314 commit 4996002
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 15 deletions.
13 changes: 12 additions & 1 deletion ControlPanel.pde
Expand Up @@ -26,7 +26,9 @@ class ControlPanel
public static final int NET_SELECTOR = 9;
public static final int MODE = 10;
public static final int TRIPS = 11;

public static final int TRAILS = 12;
public static final int DEBUG = 13;

int mode;
public static final int TOPOLOGY = 1;
public static final int FLOW = 2;
Expand Down Expand Up @@ -74,7 +76,10 @@ class ControlPanel
b.add(network,count).setLabel(network.toUpperCase());
count++;
}

this.gui.addToggle("PLAY TRIPS",false,x,370,80,14).setId(ControlPanel.TRIPS);
this.gui.addToggle("TRAILS",false,x,400,80,14).setId(ControlPanel.TRAILS);
this.gui.addToggle("DEBUG",false,x,430,80,14).setId(ControlPanel.DEBUG);
this.gui.addTextlabel("author","Flowprint. Anil Bawa-Cavia 2010",x,height-20);
}

Expand Down Expand Up @@ -201,6 +206,12 @@ class ControlPanel
net.startTripsMode();
}
return;
case ControlPanel.TRAILS:
trails = ((int)theEvent.value() > 0) ? true : false;
return;
case ControlPanel.DEBUG:
debug = ((int)theEvent.value() > 0) ? true : false;
return;
case ControlPanel.HEADWAY:
return;
case ControlPanel.SPEED:
Expand Down
4 changes: 2 additions & 2 deletions Network.pde
Expand Up @@ -136,7 +136,7 @@ class Network

public float getXOffset()
{
float x = (screen.width - PANE_WIDTH)/2 + 50;
float x = (width - PANE_WIDTH)/2 + 50;
return x;
}

Expand Down Expand Up @@ -283,7 +283,7 @@ class Network
{
int dayOfWeek = 3;
List trips = this.importer.getTrips(dayOfWeek);
for(int i=0;i<1000;i++) {
for(int i=0;i<trips.size();i++) {
Trip trip = (Trip)trips.get(i);
debug(trip.startTime);
Route r = trip.getRoute();
Expand Down
4 changes: 2 additions & 2 deletions NetworkImporter.pde
Expand Up @@ -187,9 +187,9 @@ class NetworkImporter extends Importer
}

private String getTripsFilePath() {
return ROOT_DIR + "/" + NetworkImporter.DATA_DIR + "/xaa";
//return ROOT_DIR + "/" + NetworkImporter.DATA_DIR + "/" + this.filePrefix + "_trips.csv";
return ROOT_DIR + "/" + NetworkImporter.DATA_DIR + "/" + this.filePrefix + "_trips.csv";
}


public boolean hasTrips() {
try {
Expand Down
4 changes: 3 additions & 1 deletion Stop.pde
Expand Up @@ -77,6 +77,7 @@ class Stop {
float dim = net.getDimension();
float dimY = net.getYDimension();
float offset = video ? ControlPanel.WIDTH/2 : 0;
offset=0;
if(!trueAspectRatio) dimY = dim;
this._x = int(map(this.easting,MinX,MaxX,offset,dim));
this._y = int(map(this.northing,MinY,MaxY,offset,dimY));
Expand All @@ -90,6 +91,7 @@ class Stop {

public Point getCoords() {
float offset = video ? ControlPanel.WIDTH/3 : 0;
offset=0;
return new Point(this._x,height-this._y);
}

Expand All @@ -105,7 +107,7 @@ class Stop {
fill(#007FFF,255);
stroke(#007FFF,0);
if(net.firstRun) {
fill(#FF0000,0);
fill(#FF0000,0);
stroke(#FF0000,0);
}

Expand Down
30 changes: 28 additions & 2 deletions TripsImporter.pde
Expand Up @@ -24,23 +24,49 @@ class TripsImporter extends Importer
this.setShortestPaths();
}

public TripsImporter (String[] filepath)
{
this.path = filepath[0];
this.trips = new List[8];

for(int i=1;i<8;i++) {
this.trips[i] = new ArrayList<Trip>();
}

this.load(filepath);
this.loadShortestPaths();
this.setShortestPaths();
}

public void load(String[] filepath) {
for(int i=0;i<filepath.length;i++) {
this.load(filepath[i]);
}
}

public void load(String filepath) {
debug("loading trips from " + filepath + "...");
String[] tripLines = loadStrings(filepath);
debug("parsing " + tripLines.length + " trips...");
this.parseHeaders(split(tripLines[0],","));
int startIndex = (this.hasHeaders()) ? 1 : 0;
int count=0;
for (int i = startIndex; i < tripLines.length; i++) {
String tripStr = tripLines[i];
String[] tripInfo = split(tripStr,",");
int dayOfWeek = int(tripInfo[0]);
this.trips[dayOfWeek].add(new Trip(dayOfWeek,int(tripInfo[1]),int(tripInfo[2]),tripInfo[3],tripInfo[4]));
if(dayOfWeek == 3) {
if(count%4 == 0) {
this.trips[dayOfWeek].add(new Trip(dayOfWeek,int(tripInfo[1]),int(tripInfo[2]),tripInfo[3],tripInfo[4]));
}
count++;
}
}
debug("LOADED TRIPS");
}

public void showTrips() {
for (int i=1;i<3; i++) {
for (int i=3;i<4; i++) {
debug("DAY " + i);
for(int j = 0; j < this.trips[i].size(); j++) {
debug(this.trips[i].get(j).toString());
Expand Down
21 changes: 14 additions & 7 deletions Vessel.pde
Expand Up @@ -26,6 +26,10 @@ class Vessel
int journeyNum = 1;
int nullStops = 0;

float xDist;
float yDist;
float edgeLength;

public Vessel(Route route) {
this.route = route;
this.stops = this.route.getStops().clone();
Expand Down Expand Up @@ -116,12 +120,9 @@ class Vessel
{
float xdiff,ydiff;
if(net.isInTripsMode()) {
float xDist = this.destCoords.x - this.originCoords.x;
float yDist = this.destCoords.y - this.originCoords.y;
//debug("linkdist "+ this.linkLength + " " + this.routeLengthPx);
float edgeLength = (this.linkLength > 0) ? this.linkLength : this.routeLengthPx;
xdiff = xDist * this.speed/edgeLength;
ydiff = yDist * this.speed/edgeLength;
this.edgeLength = (this.linkLength > 0) ? this.linkLength : this.routeLengthPx;
xdiff = this.xDist * this.speed/edgeLength;
ydiff = this.yDist * this.speed/edgeLength;
}
else if(cp.dynamics == ControlPanel.SWARM) {
xdiff = (this.destCoords.x - this._x) * this.speed;
Expand Down Expand Up @@ -205,6 +206,12 @@ class Vessel
destIndex++;
this.refreshDestination();
this.calcLinkLength();
if(net.isInTripsMode()) {
this.xDist = this.destCoords.x - this.originCoords.x;
this.yDist = this.destCoords.y - this.originCoords.y;
//debug("linkdist "+ this.linkLength + " " + this.routeLengthPx);
}

if(cp.dynamics == ControlPanel.BUS) {
this.calcLinkLength();
}
Expand Down Expand Up @@ -245,7 +252,7 @@ class Vessel

public void drawme()
{
int alphax = trails ? 5 : 40;
int alphax = trails ? 7 : 30;
fill(#FFFFFF,alphax);
stroke(#FFFFFF,alphax);

Expand Down

0 comments on commit 4996002

Please sign in to comment.