/* * Copyright (C) 2015 iZc * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package de.nplusc.izc.logblockheatmapper; import ar.com.hjg.pngj.ImageInfo; import ar.com.hjg.pngj.ImageLineHelper; import ar.com.hjg.pngj.ImageLineInt; import ar.com.hjg.pngj.PngWriter; import java.awt.*; import java.awt.geom.Point2D; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import javax.imageio.ImageIO; /** * * @author iZc */ public class LogBlockHeatmapper { //x y static int[ ][ ] dataField ; static int max=0; static int maxx = 0; static int maxy=0; static int targetBlockID=-1; static boolean removalsOnly=false; static boolean placemode = false; static BufferedImage gradient = new BufferedImage(1024,1,BufferedImage.TYPE_4BYTE_ABGR); /** * @param args the command line arguments * @throws java.lang.Exception */ public static void main(String[] args)throws Exception { if(args.length<2) { throw new UnsupportedOperationException("not enough parameters"); } if(args.length>2) { if(args[2].equals("place")) { placemode=true; } else { targetBlockID = Integer.valueOf(args[2]); if(args.length>3) { removalsOnly = Boolean.valueOf(args[3]); } } } int size = Integer.valueOf(args[1]); Point2D start = new Point2D.Float(0, 0); Point2D end = new Point2D.Float(1023, 0); Color[] colors = {Color.blue, Color.green, Color.YELLOW, Color.RED}; float[] steps = {0.0f,0.2f,0.6f,1.0f}; Paint p = new LinearGradientPaint(start,end,steps,colors); Graphics2D lw = (Graphics2D) gradient.getGraphics(); lw.setPaint(p); lw.fillRect(0, 0, 1023, 1); ImageIO.write(gradient,"png",new File("Debug.png")); System.out.println("Initializing Datastructures, this may take a while...."); dataField = new int[size][size]; BufferedReader br = new BufferedReader(new FileReader(args[0])); br.lines().forEach((xx)-> { //4 als 5 und nen bisschen arithmetik gibt seitwärts-schnittansicht //id_0 oldblox_1 newblox_2 newdv_3 X_4 height_5 y_6 //10 5 0 0 -1373 27 4008 xx = xx.replace("\"", ""); xx = xx.replace(",", "\t"); String[] xes = xx.split("\\t"); int l = Integer.parseInt(xes[0]); boolean register=false; int f = 0;//Integer.parseInt(xes[1]); int t = 1;//Integer.parseInt(xes[2]); if((targetBlockID<0||targetBlockID==f||targetBlockID==t)) { register=true; } if(removalsOnly&&t==targetBlockID) { register=false; } int x= Integer.parseInt(xes[4])+size/2,y= Integer.parseInt(xes[6])+size/2; //-y=up if(x=0&&y=0&®ister) { //minecraftlogik..... dataField[y][x]+=1; if(dataField[y][x]>max) { max=dataField[y][x]; maxx= Integer.parseInt(xes[4]); maxy = Integer.parseInt(xes[6]); } } if(l%10000==0) { System.out.print(l+"changes so far\r"); } }); System.out.print("Database crunched to 100%\n maximum changes on coordinates were:" +max + "at x:"+maxx + " y:"+maxy +"\n"); //max=Math.min(max, 1000); //int steps=max/256; //BufferedWriter bw = new BufferedWriter(new FileWriter(new File("D:/emc2/arca_slash/database/crunched.pgm"))); //bw.write("P6"); //bw.newLine(); //bw.write("20000 20000"); //bw.newLine(); //bw.write("255"); //bw.newLine(); //BufferedImage bi = new BufferedImage(size,size, BufferedImage.TYPE_4BYTE_ABGR); //SELECT id, replaced, `type`, `data`, x, y, z //FROM `lb-surv` //INTO OUTFILE 'D:/emc2/arca_slash/database/lbcrunchsurvival.csv'; ImageInfo imi = new ImageInfo(dataField.length, dataField.length, 8, false); // 8 bits per channel, no alpha // open image for writing to a output stream PngWriter png = new PngWriter(new FileOutputStream("map.png"), imi); // add some optional metadata (chunks) png.getMetadata().setDpi(100.0); png.getMetadata().setTimeNow(0); // 0 seconds fron now = now //0-49 1 stufe=1 farbschritt 50 -1049: 10 stufen pro farbschritt: rest gleichmäßig aufgeteilt bis maximum for (int i = 0; i < dataField.length; i++) { ImageLineInt iline = new ImageLineInt(imi); int[] is = dataField[i]; for (int j = 0; j < is.length; j++) { int color=Color.white.getRGB(); int k = is[j]; if(k==0) { color=Color.white.getRGB(); //bw.write("255 255 255"); //bw.write(255);bw.write(255);bw.write(255); } else { if(placemode) { k=k/10; //k/=steps; if(k<50) { color= gradient.getRGB(k*16, 0); } else { if(k<1050) { k-=50; color= gradient.getRGB(800+k/10, 0); } else { k-=1050; int stepWidth = (max-1050)/(123); if(stepWidth==0) stepWidth++; color= gradient.getRGB(Math.min(1023,900+k/stepWidth), 0); } int r=(color&0xFF0000)>>16; int g=(color&0xff00)>>8; int b=color&0xff; //bw.write(r);bw.write(g);bw.write(b); //writeBy(r+" "+g+" "+b); } } else if(max>1050) { //k/=steps; if(k<50) { color= gradient.getRGB(k*16, 0); } else { if(k<1050) { k-=50; color= gradient.getRGB(800+k/10, 0); } else { k-=1050; int stepWidth = (max-1050)/(123); if(stepWidth==0) stepWidth++; color= gradient.getRGB(Math.min(1023,900+k/stepWidth), 0); } int r=(color&0xFF0000)>>16; int g=(color&0xff00)>>8; int b=color&0xff; //bw.write(r);bw.write(g);bw.write(b); //writeBy(r+" "+g+" "+b); } } else { if(k<25) { color= gradient.getRGB(k*32, 0); } else { int stepWidth = (max-50)/(223); if(stepWidth==0) stepWidth++; color= gradient.getRGB(Math.min(1023,800+k/stepWidth+1), 0); } } } ImageLineHelper.setPixelRGB8(iline, j,color); //bi.setRGB(i,j,k<<16&k<<8&k); //if(j<19999) // { //bw.write(" "); // } } //if(i<19999) // bw.newLine(); png.writeRow(iline); System.out.print(i+"lines rasterized\r"); } //bw.close(); png.end(); //ImageIO.write(bi, "png",new File( "map.png")); } } //use mcserver; //mysql> SELECT id,replaced,type,data,x,y,z from `lb-surv` into outfile D:\\emc2\\arca_slash\\heatmap.tsv FIELDS TERMINATED BY `\t` LINES TERMINATED BY `\n`