Skip to content
Browse files

final on-hackday changes committed. Lots of cleanup to do.

  • Loading branch information...
1 parent 5166b28 commit 5aee7429810f5c71c293ddbf660f8fa0f0176c41 Gareth Lloyd committed Jan 24, 2011
View
15,598 event_at_coord_by_year.json
15,598 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
23,778 french_event_at_coord_by_year.json
23,778 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
52 geo-vid-gen/src/main/java/com/heychinaski/historyhack/App.java
@@ -7,11 +7,14 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import javax.imageio.ImageIO;
+import com.heychinaski.historyhack.experimental.GenerationalFrameRenderer;
import com.heychinaski.historyhack.model.GeoEventPage;
+import com.heychinaski.historyhack.provider.AllJsonEventsProvider;
import com.heychinaski.historyhack.provider.GeoEventPageProvider;
import com.heychinaski.historyhack.provider.JsonInputGEPProvider;
import com.heychinaski.historyhack.renderer.CompositeFrameRenderer;
@@ -44,44 +47,25 @@ public static void main(String[] args) throws IOException {
long time = System.currentTimeMillis();
- GeoEventPageProvider provider = new JsonInputGEPProvider(inputLocation);
-
- CumulativeGeoFrameRenderer renderer = new CumulativeGeoFrameRenderer(width, height, Color.decode(foregroundHex), Color.decode(backgroundHex), drawHalos, drawDebug);
- YearRenderer yearRenderer = new YearRenderer(width, height);
+ AllJsonEventsProvider englishProvider = new AllJsonEventsProvider(inputLocation);
+ AllJsonEventsProvider frenchProvider = new AllJsonEventsProvider("./fr-data.json");
+
+ List<GeoEventPage> englishPages = englishProvider.getAllAsList();
+ List<GeoEventPage> frenchPages = frenchProvider.getAllAsList();
+
+ TwoLangFrameRenderer twoLangRenderer = new TwoLangFrameRenderer(englishPages, frenchPages, width, height, Color.RED, Color.WHITE);
CompositeFrameRenderer compositeFrameRenderer = new CompositeFrameRenderer(width, height);
+
+ twoLangRenderer.renderNextFrame(null);
- int currentFrame = 0;
- while(provider.hasMoreEvents()) {
- List<GeoEventPage> pages = new ArrayList<GeoEventPage>();
-
- int frame = 0;
- while(provider.hasMoreEvents() && frame < frameSkip) {
- pages.addAll(provider.getNextFrame());
- frame++;
- }
-
- if(pages.size() > 0) {
- renderer.renderNextFrame(pages);
- }
-
- int year = provider.getCurrentYear();
- System.out.println("Current year " + year);
- yearRenderer.renderNextFrame(year);
-
- ArrayList<BufferedImage> overlays = new ArrayList<BufferedImage>();
- BufferedImage geoImage = renderer.getCurrentFrame();
- BufferedImage yearImage = yearRenderer.getCurrentFrame();
- overlays.add(geoImage);
- overlays.add(yearImage);
- compositeFrameRenderer.renderNextFrame(overlays);
-
- RenderedImage image = compositeFrameRenderer.getCurrentFrame();
+ ArrayList<BufferedImage> overlays = new ArrayList<BufferedImage>();
+ BufferedImage englishImage = twoLangRenderer.getCurrentFrame();
+ overlays.add(englishImage);
+ compositeFrameRenderer.renderNextFrame(overlays);
- String frameNumber = String.format("%05d", currentFrame);
- ImageIO.write(image, "png", new File(outputDirectory + "/frame" + frameNumber + ".png"));
+ RenderedImage image = compositeFrameRenderer.getCurrentFrame();
- currentFrame++;
- }
+ ImageIO.write(image, "png", new File(outputDirectory + "/frame" + "engFrench" + ".png"));
long finishTime = System.currentTimeMillis();
System.out.println("Done");
View
84 geo-vid-gen/src/main/java/com/heychinaski/historyhack/GenerationalApp.java
@@ -0,0 +1,84 @@
+package com.heychinaski.historyhack;
+
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.awt.image.RenderedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.imageio.ImageIO;
+
+import com.heychinaski.historyhack.experimental.GenerationalFrameRenderer;
+import com.heychinaski.historyhack.model.GeoEventPage;
+import com.heychinaski.historyhack.provider.GeoEventPageProvider;
+import com.heychinaski.historyhack.provider.JsonInputGEPProvider;
+import com.heychinaski.historyhack.renderer.CompositeFrameRenderer;
+import com.heychinaski.historyhack.renderer.CumulativeGeoFrameRenderer;
+import com.heychinaski.historyhack.renderer.YearRenderer;
+
+/**
+ *
+ *
+ */
+public class GenerationalApp {
+
+ public static void main(String[] args) throws IOException {
+ Properties properties = new Properties();
+ properties.load(Thread.currentThread ().getContextClassLoader ().getResourceAsStream("config.properties"));
+ int width = Integer.parseInt(properties.getProperty("width", "" + 1024));
+ int height = Integer.parseInt(properties.getProperty("height", "" + 1024));
+
+ String foregroundHex = properties.getProperty("foregroundColor", "0xFFFFFF");
+ String backgroundHex = properties.getProperty("backgroundColor", "0x000000");
+
+ int frameSkip = Integer.parseInt(properties.getProperty("frameSkip", "" + 1));
+
+ String inputLocation = properties.getProperty("inputLocation", "./input.json");
+ String outputDirectory = properties.getProperty("outputDirectory", "./frames");
+
+ boolean drawHalos = Boolean.parseBoolean(properties.getProperty("drawHalos", "false"));
+ boolean drawDebug = Boolean.parseBoolean(properties.getProperty("drawDebug", "false"));
+
+
+ long time = System.currentTimeMillis();
+
+ GeoEventPageProvider provider = new JsonInputGEPProvider(inputLocation);
+
+ Map<Integer, List<GeoEventPage>> allPages = provider.allPages();
+ GenerationalFrameRenderer renderer = new GenerationalFrameRenderer(allPages , width, height, Color.decode(foregroundHex), Color.decode(backgroundHex));
+ YearRenderer yearRenderer = new YearRenderer(width, height);
+ CompositeFrameRenderer compositeFrameRenderer = new CompositeFrameRenderer(width, height);
+
+ int currentFrame = 0;
+ int currentYear = -499;
+ while(currentYear <= 2011) {
+ renderer.renderNextFrame(currentYear);
+
+ System.out.println("Current year " + currentYear);
+ yearRenderer.renderNextFrame(currentYear);
+
+ ArrayList<BufferedImage> overlays = new ArrayList<BufferedImage>();
+ BufferedImage geoImage = renderer.getCurrentFrame();
+ BufferedImage yearImage = yearRenderer.getCurrentFrame();
+ overlays.add(geoImage);
+ overlays.add(yearImage);
+ compositeFrameRenderer.renderNextFrame(overlays);
+
+ RenderedImage image = compositeFrameRenderer.getCurrentFrame();
+
+ String frameNumber = String.format("%05d", currentFrame);
+ ImageIO.write(image, "png", new File(outputDirectory + "/frame" + frameNumber + ".png"));
+
+ currentFrame++;
+ currentYear++;
+ }
+
+ long finishTime = System.currentTimeMillis();
+ System.out.println("Done");
+ System.out.println("Took " + (finishTime - time) + "ms");
+ }
+}
View
90 geo-vid-gen/src/main/java/com/heychinaski/historyhack/OldApp.java
@@ -0,0 +1,90 @@
+package com.heychinaski.historyhack;
+
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.awt.image.RenderedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import javax.imageio.ImageIO;
+
+import com.heychinaski.historyhack.model.GeoEventPage;
+import com.heychinaski.historyhack.provider.GeoEventPageProvider;
+import com.heychinaski.historyhack.provider.JsonInputGEPProvider;
+import com.heychinaski.historyhack.renderer.CompositeFrameRenderer;
+import com.heychinaski.historyhack.renderer.CumulativeGeoFrameRenderer;
+import com.heychinaski.historyhack.renderer.YearRenderer;
+
+/**
+ *
+ *
+ */
+public class OldApp {
+
+ public static void main(String[] args) throws IOException {
+ Properties properties = new Properties();
+ properties.load(Thread.currentThread ().getContextClassLoader ().getResourceAsStream("config.properties"));
+ int width = Integer.parseInt(properties.getProperty("width", "" + 1024));
+ int height = Integer.parseInt(properties.getProperty("height", "" + 1024));
+
+ String foregroundHex = properties.getProperty("foregroundColor", "0xFFFFFF");
+ String backgroundHex = properties.getProperty("backgroundColor", "0x000000");
+
+ int frameSkip = Integer.parseInt(properties.getProperty("frameSkip", "" + 1));
+
+ String inputLocation = properties.getProperty("inputLocation", "./input.json");
+ String outputDirectory = properties.getProperty("outputDirectory", "./frames");
+
+ boolean drawHalos = Boolean.parseBoolean(properties.getProperty("drawHalos", "false"));
+ boolean drawDebug = Boolean.parseBoolean(properties.getProperty("drawDebug", "false"));
+
+
+ long time = System.currentTimeMillis();
+
+ GeoEventPageProvider provider = new JsonInputGEPProvider(inputLocation);
+
+ CumulativeGeoFrameRenderer renderer = new CumulativeGeoFrameRenderer(width, height, Color.decode(foregroundHex), Color.decode(backgroundHex), drawHalos, drawDebug);
+ YearRenderer yearRenderer = new YearRenderer(width, height);
+ CompositeFrameRenderer compositeFrameRenderer = new CompositeFrameRenderer(width, height);
+
+ int currentFrame = 0;
+ while(provider.hasMoreEvents()) {
+ List<GeoEventPage> pages = new ArrayList<GeoEventPage>();
+
+ int frame = 0;
+ while(provider.hasMoreEvents() && frame < frameSkip) {
+ pages.addAll(provider.getNextFrame());
+ frame++;
+ }
+
+ if(pages.size() > 0) {
+ renderer.renderNextFrame(pages);
+ }
+
+ int year = provider.getCurrentYear();
+ System.out.println("Current year " + year);
+ yearRenderer.renderNextFrame(year);
+
+ ArrayList<BufferedImage> overlays = new ArrayList<BufferedImage>();
+ BufferedImage geoImage = renderer.getCurrentFrame();
+ BufferedImage yearImage = yearRenderer.getCurrentFrame();
+ overlays.add(geoImage);
+ overlays.add(yearImage);
+ compositeFrameRenderer.renderNextFrame(overlays);
+
+ RenderedImage image = compositeFrameRenderer.getCurrentFrame();
+
+ String frameNumber = String.format("%05d", currentFrame);
+ ImageIO.write(image, "png", new File(outputDirectory + "/frame" + frameNumber + ".png"));
+
+ currentFrame++;
+ }
+
+ long finishTime = System.currentTimeMillis();
+ System.out.println("Done");
+ System.out.println("Took " + (finishTime - time) + "ms");
+ }
+}
View
95 geo-vid-gen/src/main/java/com/heychinaski/historyhack/TwoLangFrameRenderer.java
@@ -0,0 +1,95 @@
+package com.heychinaski.historyhack;
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.image.BufferedImage;
+import java.util.List;
+
+import com.heychinaski.historyhack.model.GeoEventPage;
+import com.heychinaski.historyhack.renderer.FrameRenderer;
+
+public class TwoLangFrameRenderer implements FrameRenderer<Object> {
+ private static final int RESOLUTION_FACTOR = 1000;
+
+ public static final int LONGITUDE_DEGREES = 360;
+ public static final int LATITUDE_DEGREES = 180;
+
+ public static final int LONGITUDE_DEGREES_MULTIPLIED = LONGITUDE_DEGREES * RESOLUTION_FACTOR;
+ public static final int LATITUDE_DEGREES_MULTIPLIED = LATITUDE_DEGREES * RESOLUTION_FACTOR;
+ private final Color langAColor;
+
+ BufferedImage currentFrame;
+ Graphics2D currentG2d;
+
+ private List<GeoEventPage> langAEvents;
+
+ private int width;
+ private int height;
+
+ private List<GeoEventPage> langBEvents;
+
+ private Color langBColor;
+
+ /**
+ *
+ * @param langAEvents ALL year events
+ * @param langBEvents
+ */
+ public TwoLangFrameRenderer(List<GeoEventPage> langAEvents, List<GeoEventPage> langBEvents, int width, int height, Color langAColor, Color langBColor) {
+ this.width = width;
+ this.height = height;
+ this.langAColor = langAColor;
+ this.langBColor = langBColor;
+ this.langAEvents = langAEvents;
+ this.langBEvents = langBEvents;
+
+ // initialize images
+ currentFrame = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
+ currentG2d = currentFrame.createGraphics();
+ currentG2d.setColor(Color.BLACK);
+ currentG2d.fillRect(0, 0, currentFrame.getWidth(), currentFrame.getHeight());
+
+ currentG2d.scale((float)width / (float)LONGITUDE_DEGREES_MULTIPLIED, (float)height / (float)LATITUDE_DEGREES_MULTIPLIED);
+ currentG2d.translate((LONGITUDE_DEGREES_MULTIPLIED) / 2, (LATITUDE_DEGREES_MULTIPLIED) / 2);
+ }
+
+ @Override
+ public BufferedImage getCurrentFrame() {
+ return currentFrame;
+ }
+
+ @Override
+ public void renderNextFrame(Object ignore) {
+ boolean atLeastOneHasEvents = true;
+ int index = 0;
+
+ while (atLeastOneHasEvents) {
+ atLeastOneHasEvents = false;
+ if (langAEvents.size() > index) {
+ drawPoint(langAEvents.get(index), langAColor);
+ atLeastOneHasEvents = true;
+ }
+ if (langBEvents.size() > index) {
+ drawPoint(langBEvents.get(index), langBColor);
+ atLeastOneHasEvents = true;
+ }
+ index++;
+ }
+
+ currentG2d.dispose();
+ }
+
+ private void drawPoint(GeoEventPage page, Color color) {
+ Point point = new Point((int)Math.round(page.getLongitude() * RESOLUTION_FACTOR),
+ -(int)Math.round(page.getLatitude() * RESOLUTION_FACTOR));
+ // do draw
+ currentG2d.setColor(color);
+ currentG2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
+ int radius = 1000;
+ currentG2d.fillOval(point.x - radius, point.y - radius, radius * 2, radius * 2);
+
+ }
+
+}
View
127 ...gen/src/main/java/com/heychinaski/historyhack/experimental/GenerationalFrameRenderer.java
@@ -0,0 +1,127 @@
+package com.heychinaski.historyhack.experimental;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.image.BufferedImage;
+import java.awt.image.ColorModel;
+import java.awt.image.WritableRaster;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import com.heychinaski.historyhack.model.GeoEventPage;
+import com.heychinaski.historyhack.renderer.FrameRenderer;
+
+public class GenerationalFrameRenderer implements FrameRenderer<Integer> {
+ private static final int RESOLUTION_FACTOR = 1000;
+
+ public static final int LONGITUDE_DEGREES = 360;
+ public static final int LATITUDE_DEGREES = 180;
+
+ public static final int LONGITUDE_DEGREES_MULTIPLIED = LONGITUDE_DEGREES * RESOLUTION_FACTOR;
+ public static final int LATITUDE_DEGREES_MULTIPLIED = LATITUDE_DEGREES * RESOLUTION_FACTOR;
+ private final Color foregroundColor;
+
+ BufferedImage imageWithRetireesOnly;
+ Graphics2D retireesImageG2d;
+
+ private int currentYear;
+ private Map<Integer, List<GeoEventPage>> yearPages;
+
+
+ private BufferedImage currentFrame;
+
+ private LinkedList<List<StatefulBlob>> relevantGenerations;
+
+ private int width;
+
+ private int height;
+
+ /**
+ *
+ * @param yearEvents ALL year events
+ */
+ public GenerationalFrameRenderer(Map<Integer, List<GeoEventPage>> yearEvents, int width, int height, Color foregroundColor, Color backgroundColor) {
+ this.width = width;
+ this.height = height;
+ this.foregroundColor = foregroundColor;
+
+ this.yearPages = yearEvents;
+
+ Integer minYear = Integer.MAX_VALUE;
+ for (Integer year : yearEvents.keySet()) {
+ if (year < minYear) {
+ minYear = year;
+ }
+ }
+ currentYear = minYear;
+
+ this.relevantGenerations = new LinkedList<List<StatefulBlob>>();
+
+ // initialize images
+ imageWithRetireesOnly = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
+ retireesImageG2d = imageWithRetireesOnly.createGraphics();
+ retireesImageG2d.setColor(backgroundColor);
+ retireesImageG2d.fillRect(0, 0, width, height);
+
+ retireesImageG2d.scale((float)width / (float)LONGITUDE_DEGREES_MULTIPLIED, (float)height / (float)LATITUDE_DEGREES_MULTIPLIED);
+ retireesImageG2d.translate((LONGITUDE_DEGREES_MULTIPLIED) / 2, (LATITUDE_DEGREES_MULTIPLIED) / 2);
+ }
+
+ @Override
+ public BufferedImage getCurrentFrame() {
+ return currentFrame;
+ }
+
+ @Override
+ public void renderNextFrame(Integer year) {
+ // draw only the retirees onto the stored image
+ if (relevantGenerations.size() == StatefulBlob.TOTAL_STATES) {
+ // after this drawing, we won't need them any more
+ System.out.println();
+ List<StatefulBlob> retirees = relevantGenerations.removeLast();
+ drawGeneration(retirees, retireesImageG2d);
+ }
+
+ // copy this before drawing others
+ currentFrame = deepCopy(imageWithRetireesOnly);
+ Graphics2D currentg2d = currentFrame.createGraphics();
+ currentg2d.scale((float)width / (float)LONGITUDE_DEGREES_MULTIPLIED, (float)height / (float)LATITUDE_DEGREES_MULTIPLIED);
+ currentg2d.translate((LONGITUDE_DEGREES_MULTIPLIED) / 2, (LATITUDE_DEGREES_MULTIPLIED) / 2);
+
+ // create StatefulBlobs for new Generation
+ if (!yearPages.containsKey(year)) {
+ return;
+ }
+ List<StatefulBlob> newGeneration = new ArrayList<StatefulBlob>();
+ for (GeoEventPage page : yearPages.get(year)) {
+ Point point = new Point((int)Math.round(page.getLongitude() * RESOLUTION_FACTOR),
+ -(int)Math.round(page.getLatitude() * RESOLUTION_FACTOR));
+ newGeneration.add(new StatefulBlob(point));
+ }
+ relevantGenerations.addFirst(newGeneration);
+
+ // draw all non-retired generations
+ for (List<StatefulBlob> generation : relevantGenerations) {
+ drawGeneration(generation, currentg2d);
+ }
+ currentg2d.dispose();
+ }
+
+ private void drawGeneration(List<StatefulBlob> generation, Graphics2D g2d) {
+ for (StatefulBlob blob : generation) {
+ blob.drawAndIncrementState(g2d);
+ }
+ }
+
+ private BufferedImage deepCopy(BufferedImage bi) {
+ ColorModel cm = bi.getColorModel();
+ boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
+ WritableRaster raster = bi.copyData(null);
+ BufferedImage cloned = new BufferedImage(cm, raster, isAlphaPremultiplied, null);
+ return cloned;
+ }
+
+}
View
64 geo-vid-gen/src/main/java/com/heychinaski/historyhack/experimental/StatefulBlob.java
@@ -0,0 +1,64 @@
+package com.heychinaski.historyhack.experimental;
+
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Point;
+
+public class StatefulBlob {
+
+ public static final BlobState[] STATES = {
+ new BlobState(0.5f, 200, Color.YELLOW),
+ new BlobState(0.4f, 500, Color.YELLOW),
+ new BlobState(0.3f, 750, Color.YELLOW),
+ new BlobState(0.2f, 950, Color.WHITE),
+ new BlobState(0.1f, 1100, Color.WHITE),
+ new BlobState(0.1f, 1200, Color.WHITE),
+ new BlobState(0.1f, 1300, Color.WHITE),
+ new BlobState(0.05f, 1400, Color.WHITE),
+ new BlobState(0.05f, 1500, Color.WHITE),
+ new BlobState(0.05f, 1600, Color.WHITE)
+ };
+ public static final int TOTAL_STATES = STATES.length;
+
+ private int currentState;
+ private Point point;
+
+ public StatefulBlob(Point point) {
+ this.point = point;
+ this.currentState = 0;
+ }
+
+ public void drawAndIncrementState(Graphics2D g2) {
+ BlobState state = null;
+ if (currentState >= TOTAL_STATES) {
+ state = STATES[TOTAL_STATES - 1];
+ }
+ else {
+ state = STATES[currentState];
+ }
+ g2.setColor(state.color);
+ g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, state.alpha));
+ int radius = state.radius;
+ g2.fillOval(point.x - radius, point.y - radius, radius * 2, radius * 2);
+
+ currentState++;
+ }
+
+ public boolean isRetired() {
+ return currentState == TOTAL_STATES;
+ }
+
+ static class BlobState {
+ float alpha;
+ int radius;
+ Color color;
+
+ public BlobState(float alpha, int radius, Color color) {
+ this.alpha = alpha;
+ this.radius = radius;
+ this.color = color;
+ }
+
+ }
+}
View
62 geo-vid-gen/src/main/java/com/heychinaski/historyhack/experimental/TestStatefulBlob.java
@@ -0,0 +1,62 @@
+package com.heychinaski.historyhack.experimental;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Point;
+
+import javax.swing.JFrame;
+
+public class TestStatefulBlob {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ JFrame f = new JFrame("Test");
+ f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ f.setMinimumSize(new Dimension(1000, 1000));
+ f.setBackground(Color.BLACK);
+
+ StatefulBlob sb = new StatefulBlob(new Point(500, 500));
+ BlobComponent bc = new BlobComponent(sb);
+ bc.setVisible(true);
+ f.add(bc);
+ f.pack();
+ f.setVisible(true);
+
+ while (! sb.isRetired()) {
+ try {
+ Thread.sleep(40);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ bc.repaint();
+ }
+ }
+
+}
+
+class BlobComponent extends Component {
+
+ private StatefulBlob sb;
+
+ public BlobComponent(StatefulBlob sb) {
+ this.sb = sb;
+ }
+
+ public Dimension getPreferredSize(){
+ return new Dimension(200, 200);
+ }
+
+
+ public void paint(Graphics g) {
+ Graphics2D g2 = (Graphics2D) g;
+
+ sb.drawAndIncrementState(g2);
+ }
+
+}
View
9 geo-vid-gen/src/main/java/com/heychinaski/historyhack/model/GeoEventPage.java
@@ -7,19 +7,20 @@
int year;
int month;
int day;
-
+ String title;
int articleLength;
public GeoEventPage() {}
- public GeoEventPage(double longitude, double latitude, int year, int month, int day, int articleLength) {
+ public GeoEventPage(double longitude, double latitude, int year, int month, int day, int articleLength, String title) {
super();
this.longitude = longitude;
this.latitude = latitude;
this.year = year;
this.month = month;
this.day = day;
this.articleLength = articleLength;
+ this.title = title;
}
public double getLongitude() {
@@ -45,4 +46,8 @@ public int getDay() {
public int getArticleLength() {
return articleLength;
}
+
+ public String getTitle() {
+ return title;
+ }
}
View
119 geo-vid-gen/src/main/java/com/heychinaski/historyhack/provider/AllJsonEventsProvider.java
@@ -0,0 +1,119 @@
+package com.heychinaski.historyhack.provider;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.google.gson.Gson;
+import com.heychinaski.historyhack.model.GeoEventPage;
+
+public class AllJsonEventsProvider implements GeoEventPageProvider {
+
+ String currentLine = "";
+ String nextLine = null;
+ private BufferedReader reader;
+
+ int currentYear = -1;
+
+ public AllJsonEventsProvider(String filename) {
+ try {
+ File input = new File(filename);
+ reader = new BufferedReader(new FileReader(input));
+
+ readNextLine();
+ } catch(Exception e) {
+ throw new RuntimeException("Couldn't parse file", e);
+ }
+
+ }
+
+ private void readNextLine() {
+ try {
+ nextLine = reader.readLine();
+ } catch(Exception e) {
+ throw new RuntimeException("Couldn't read line from file", e);
+ }
+ }
+
+ @Override
+ public List<GeoEventPage> getNextFrame() {
+
+ List<GeoEventPage> pages = new ArrayList<GeoEventPage>();
+
+ GeoEventPage nextGeoEventPage = new Gson().fromJson(nextLine, GeoEventPage.class);
+ GeoEventPage initialGeoEventPage = nextGeoEventPage;
+
+ int year;
+ if(initialGeoEventPage != null) {
+ year = initialGeoEventPage.getYear();
+ } else {
+ return pages;
+ }
+
+ // Return empty year
+ if(year - currentYear > 1) {
+ currentYear ++;
+ return pages;
+ } else {
+ currentYear = year;
+ }
+
+ // Stop when we run out or change years
+ while(nextGeoEventPage != null && initialGeoEventPage.getYear() == nextGeoEventPage.getYear()) {
+ pages.add(nextGeoEventPage);
+
+ readNextLine();
+ if(nextLine != null) {
+ nextGeoEventPage = new Gson().fromJson(nextLine, GeoEventPage.class);
+ } else {
+ nextGeoEventPage = null;
+ }
+ }
+ return pages;
+ }
+
+ @Override
+ public boolean hasMoreEvents() {
+ boolean b = nextLine != null;
+ if(!b) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return b;
+ }
+
+ @Override
+ public int getCurrentYear() {
+ return currentYear;
+ }
+
+ @Override
+ public Map<Integer, List<GeoEventPage>> allPages() {
+ Map<Integer, List<GeoEventPage>> allPages = new HashMap<Integer, List<GeoEventPage>>();
+ while (this.hasMoreEvents()) {
+ List<GeoEventPage> pages = getNextFrame();
+ allPages.put(getCurrentYear(), pages);
+ }
+ System.out.println(allPages.size());
+ System.out.println(allPages.get(1865).size());
+ return allPages;
+ }
+
+ public List<GeoEventPage> getAllAsList() {
+ List<GeoEventPage> allPages = new ArrayList<GeoEventPage>();
+ while (this.hasMoreEvents()) {
+ List<GeoEventPage> pages = getNextFrame();
+ allPages.addAll(pages);
+ }
+ return allPages;
+ }
+
+}
View
3 geo-vid-gen/src/main/java/com/heychinaski/historyhack/provider/GeoEventPageProvider.java
@@ -1,6 +1,7 @@
package com.heychinaski.historyhack.provider;
import java.util.List;
+import java.util.Map;
import com.heychinaski.historyhack.model.GeoEventPage;
@@ -10,4 +11,6 @@
public boolean hasMoreEvents();
public int getCurrentYear();
+
+ public Map<Integer, List<GeoEventPage>> allPages();
}
View
14 geo-vid-gen/src/main/java/com/heychinaski/historyhack/provider/JsonInputGEPProvider.java
@@ -5,7 +5,9 @@
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import com.google.gson.Gson;
import com.heychinaski.historyhack.model.GeoEventPage;
@@ -93,4 +95,16 @@ public int getCurrentYear() {
return currentYear;
}
+ @Override
+ public Map<Integer, List<GeoEventPage>> allPages() {
+ Map<Integer, List<GeoEventPage>> allPages = new HashMap<Integer, List<GeoEventPage>>();
+ while (this.hasMoreEvents()) {
+ List<GeoEventPage> pages = getNextFrame();
+ allPages.put(getCurrentYear(), pages);
+ }
+ System.out.println(allPages.size());
+ System.out.println(allPages.get(1865).size());
+ return allPages;
+ }
+
}
View
9 ...id-gen/src/main/java/com/heychinaski/historyhack/provider/RandomGeoEventPageProvider.java
@@ -7,6 +7,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import com.google.gson.Gson;
import com.heychinaski.historyhack.model.GeoEventPage;
@@ -62,7 +63,7 @@ public RandomGeoEventPageProvider(int startFrame, int maxFrames) {
newPoint.y += (Math.random() * distance) - (distance/2);
}
- GeoEventPage randomPage = new GeoEventPage(newPoint.x, newPoint.y, currentCycle, 0, 0, 0);
+ GeoEventPage randomPage = new GeoEventPage(newPoint.x, newPoint.y, currentCycle, 0, 0, 0, "");
list.add(randomPage);
}
@@ -104,4 +105,10 @@ public int getCurrentYear() {
return currentCycle;
}
+ @Override
+ public Map<Integer, List<GeoEventPage>> allPages() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
View
4 geo-vid-gen/src/main/resources/config.properties
@@ -8,10 +8,10 @@ foregroundColor=0xFFFFFF
backgroundColor=0x000000
# Set this higher to have it render less frames (but the same amount of data) so you can generate a test render.
-frameSkip=1
+frameSkip=10
# the location file of the input json file
-inputLocation=./toms_data.json
+inputLocation=./data.json
# Where the individual png frames will end up
outputDirectory= ./frames
View
4 wikipedia_processor/output_json.py
@@ -9,4 +9,6 @@
for link in event['links']:
p = pageCollection.find_one({"_id" : link})
if p:
- print '{"year" : %s, "title" : %s, "latitude": %s, "longitude": %s, "month": 0, "day": 0, "articleLength" : %s}' % (event["year"], p["_id"].encode('utf-8'), p["latitude"], p["longitude"], p["article_length"])
+ print '{"year" : %s, "title" : "%s", "latitude": %s, "longitude": %s, "month": 0, "day": 0, "articleLength" : %s}' % (event["year"], p["_id"].encode('utf-8'), p["latitude"], p["longitude"], p["article_length"])
+
+
View
11 wikipedia_processor/page_parser.py
@@ -22,7 +22,6 @@
eventCollection.ensure_index("year", direction=pymongo.ASCENDING)
pageCollection = db.pages
-
class Coords(object):
PROCESSING_LAT = 0
PROCESSING_LONG = 1
@@ -272,13 +271,10 @@ def characters(self, content):
def analysePage(self):
if (self.currentPage.isYear()):
- #processAndSaveEvents(self.currentPage)
+ processAndSaveEvents(self.currentPage)
pass
elif (self.currentPage.processForCoords()):
- if (len(self.currentPage.coords) > 1):
- global MULTI_COORDS
- MULTI_COORDS += 1
- #savePage(self.currentPage)
+ savePage(self.currentPage)
pass
def savePage(page):
@@ -325,5 +321,4 @@ def saveEvent(event):
print "coord pages saved: %d" % COORD_PAGES
print "year pages processed: %d" % YEARS_PROCESSED
print "events saved: %d" % EVENTS_SAVED
- print "coord errors: %d" % COORD_ERRORS
- print "multi coord: %d" % MULTI_COORDS
+ print "coord errors: %d" % COORD_ERRORS

0 comments on commit 5aee742

Please sign in to comment.
Something went wrong with that request. Please try again.