I have been trying to create a video mapping location data tagged with dates. I have the dataset such that it is in order by date and I am trying to write a loop that will iterate down my text file:
- check to see if the next date < than the current one
- if it is count the number of days difference between the two
- draw the point associated with that date and all previous ones as a map
- send that drawing as a frame to a video file by the number days difference calculated in step 2 (to reflect that a number of days passed with no event)
I feel that my code is almost complete but I wrote a nested loop to do this and it has been giving me trouble. The code I wrote follows with the troublesome bits highlighted yellow. Any suggestions?
- import processing.video.*;
MovieMaker mm; //declare movimaker object
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Date;
PImage mapImage;
//column numbers in data file (cleanT.tsv)
static final int UID = 0;
static final int Y = 1;
static final int X = 2;
static final int LATITUDE = 3;
static final int LONGITUDE = 4;
static final int DATE = 5;
static final int OCCURANCE = 6;
static final int DAYS = 7;
Date days;//initialize days date
float spanDays; //initialize in to hold number of days from first tea party to most recent
int totalCount; //total number of meetings
Place[] places;
int placeCount;//number of places loaded
//min, max boundary of all points
float minX, maxX;
float minY, maxY;
float mapX1, mapY1;
float mapX2, mapY2;
//initialize beginDate and endDate
String beginDate;
String endDate;
int totLines;
public void setup(){
size(1039, 725, P3D);
mapImage = loadImage("ContiguousUS_albers.png");//load image of us exported from ArcGIS
mapX1 = 65;
mapX2 = width - mapX1;
mapY1 = 87;
mapY2 = height - mapY1;
totLines = readData();
System.out.println(totLines);
mm = new MovieMaker(this,width,height,"Tparties8.mov",30,MovieMaker.H263,MovieMaker.LOSSLESS);
}
public int readData(){
String[] lines = loadStrings("cleanTcontigUSb.tsv");
totlLines = lines.length;
parseInfo(lines[0], totLines);//read the header line
places = new Place[totalCount];
System.out.println(lines.length);
for(int i = 1; i < lines.length; i++){
places[placeCount] = parsePlace(lines[i]);
placeCount++;
}
return totlLines;}
void parseInfo(String line, int totlLines){
// Date days; //intitialize Date object to use in getting milli since epoch
float beginMilli; //initialize integer to place number of milliseconds in loop
float endMilli;
DateFormat formatter;
formatter = new SimpleDateFormat("MM/dd/yyyy"); //fomatter to use in the loop to parse the string date to a date object
String infoString = line.substring(2); //remove the #
String[] infoPieces = split(infoString, ',');
totalCount = int(totLines);
minX = float(infoPieces[1]);
maxX = float(infoPieces[2]);
minY = float(infoPieces[3]);
maxY = float(infoPieces[4]);
beginDate = infoPieces[5];
days = null;
try{
days = formatter.parse(beginDate);
} catch (ParseException e){}
beginMilli = days.getTime()/(1000*60*60*24);
days = null;
endDate = infoPieces[6];
try{
days = formatter.parse(endDate);
} catch (ParseException e){}
endMilli = days.getTime()/(1000*60*60*24);
spanDays = endMilli - beginMilli;
System.out.println(totlLines);
//System.out.println(spanDays);
//System.out.println(endMilli);
}
Place parsePlace(String line){
String pieces[] = split(line,TAB);
int uid = int(pieces[UID]);
float y = float(pieces[Y]);
float x = float(pieces[X]);
String dateString = pieces[DATE];
int occurance = int(pieces[OCCURANCE]);
float days = float(pieces[DAYS]);
return new Place(uid, x , y, dateString, occurance, days);
}
public void draw(){
int i = 1;
int d = 1;
float gap;
background(000);
image(mapImage, 0, 0);
while (i < totlLines){
gap = places[i+1].days - places[i].days;
if (gap >= 1) {
while (0 < gap) {
for (int g = 0; g < i; g++){
places[i].draw();
}
mm.addFrame();
gap--;
}
i++;
} else {
i++;
{
mm.finish();
}
float TX(float x){
return map(x, minX, maxX, mapX1, mapX2);
}
float TY(float y){
return map(y, minY, maxY, mapY2, mapY1);
}
1