package uk.ac.soton.ecs.waisfest14;

import java.io.File;
import java.io.IOException;

import org.openimaj.image.FImage;
import org.openimaj.util.data.Context;
import org.openimaj.util.function.Operation;
import org.openimaj.util.stream.Stream;

public class Visualisation {
	public static void main(String[] args) throws IOException {
		new CSVStream(new File("/Users/jsh2/Desktop/results_sorted.csv"))
				.transform(new TimeWindow(16 * 24 * 60 * 60 * 1000L))
				.forEach(new Operation<Context>() {

					@Override
					public void perform(Context ctx) {
						final FImage image = new FImage(360, 180);

						@SuppressWarnings("unchecked")
						final Stream<Context> win = ((Stream<Context>) ctx.get(TimeWindow.WINDOW));

						win.forEach(new Operation<Context>() {

							@Override
							public void perform(Context ctx) {
								final double x = (Double) ctx.get(CSVStream.LONGITUDE) + 180;
								final double y = 90 - (Double) ctx.get(CSVStream.LATITUDE);

								final int xx = (int) (x * (1.0 * img.getWidth() / 360)) - 1;
								final int yy = (int) (y * (1.0 * img.getHeight() / 180)) - 1;

								float v = ctx.getTyped(CSVStream.COLOUR_VALUE);
								v = (1 - v) / 2;

								if (xx >= 0 && xx < image.getWidth() && yy >= 0 && yy < image.getHeight()) {
									image.pixels[yy][xx] += v;

								}
							}
						});

					}
				});
	}
}

@@ -80,16 +80,44 @@
 ption;%0A%0A
+import javax.swing.JFrame;%0A%0A
 import o
@@ -138,16 +138,18 @@
 age.
+MB
 FImage;%0A
 impo
@@ -144,16 +144,60 @@
 FImage;%0A
+import org.openimaj.image.colour.RGBColour;%0A
 import o
@@ -403,16 +403,362 @@
 ption %7B%0A
+%09%09final MBFImage image = FullScreenDemo.createImage();%0A%09%09final JFrame window = FullScreenDemo.display(image, %22Tree Colours%22);%0A%0A%09%09final DrawOperation pointOp = new DrawOperation(image, true);%0A%0A%09%09// final XuggleVideoWriter xvw = new%0A%09%09// XuggleVideoWriter(%22/Users/jsh2/Desktop/leaves-8day.mp4%22,%0A%09%09// image.getWidth(),%0A%09%09// image.getHeight(), 10);%0A%0A
 %09%09new CS
@@ -851,10 +851,9 @@
 dow(
-16
+8
  * 2
@@ -980,48 +980,34 @@
 %09%09%09%09
-final FImage image = new FImage(360, 180
+image.fill(RGBColour.BLACK
 );%0A%0A
@@ -1148,607 +1148,141 @@
 ach(
-new Operation%3CContext%3E() %7B%0A%0A%09%09%09%09%09%09%09@Override%0A%09%09%09%09%09%09%09public void perform(Context ctx) %7B%0A%09%09%09%09%09%09%09%09final double x = (Double) ctx.get(CSVStream.LONGITUDE) + 180;%0A%09%09%09%09%09%09%09%09final double y = 90 - (Double) ctx.get(CSVStream.LATITUDE);%0A%0A%09%09%09%09%09%09%09%09final int xx = (int) (x * (1.0 * img.getWidth() / 360)) - 1;%0A%09%09%09%09%09%09%09%09final int yy = (int) (y * (1.0 * img.getHeight() / 180)) - 1;%0A%0A%09%09%09%09%09%09%09%09float v = ctx.getTyped(CSVStream.COLOUR_VALUE);%0A%09%09%09%09%09%09%09%09v = (1 - v) / 2;%0A%0A%09%09%09%09%09%09%09%09if (xx %3E= 0 && xx %3C image.getWidth() && yy %3E= 0 && yy %3C image.getHeight()) %7B%0A%09%09%09%09%09%09%09%09%09image.pixels%5Byy%5D%5Bxx%5D += v;%0A%0A%09%09%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09%09%7D%0A%09%09
+pointOp);%0A%0A%09%09%09%09%09%09pointOp.windowDrawn(ctx);%0A%0A%09%09%09%09%09%09FullScreenDemo.update(window, image);%0A%09%09%09%09%09%09// xvw.addFrame(image);%0A%09%09%09%09%09%7D%0A
 %09%09%09%09%7D);%0A
 %0A%09%09%09
@@ -1277,29 +1277,31 @@
 %09%09%09%09%7D);%0A
-%0A
 %09%09
-%09%09%09%7D%0A%09%09%09%09%7D
+// xvw.close(
 );%0A%09%7D%0A%7D%0A

put back visualisation to how it should be