Tom Görner 1 年之前
父節點
當前提交
90b2d59719

+ 27 - 0
PlaceDECSVWiggler/build.gradle

@@ -0,0 +1,27 @@
+defaultTasks 'distZip'
+
+apply plugin: 'java-library'
+apply plugin: 'application'
+
+
+sourceCompatibility = 1.17
+version = 'SNAPSHOT'
+mainClassName = 'de.nplusc.izc.placeDE.Cookies.CSVWiggler'
+
+
+jar{
+	manifest{
+		attributes 'Implementation-Title': 'senabitwiggler',
+					'Implementation-Version': 'SNAPSHOT',
+					'Main-Class': 'de.nplusc.izc.placeDE.Cookies.CSVWiggler'
+					
+	}
+}
+
+repositories{
+	mavenCentral()
+}
+
+dependencies{
+	implementation 'com.eclipsesource.minimal-json:minimal-json:0.9.5'
+}

+ 159 - 0
PlaceDECSVWiggler/src/main/java/de/nplusc/izc/placeDE/Cookies/CSVWiggler.java

@@ -0,0 +1,159 @@
+package de.nplusc.izc.placeDE.Cookies;
+
+import java.io.*;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalUnit;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashSet;
+
+import com.eclipsesource.json.*;
+
+public class CSVWiggler {
+    private static final String EVT_SYS_ID = "958372977714540574";
+    public static void main(String[] args) {
+
+        if(args.length<1)
+        {
+            System.err.println("Filename missing");
+        }
+
+
+        File checkme = new File(args[0]);
+        if(!checkme.exists())
+        {
+            System.err.println("File not found");
+        }
+        try {
+            String intermediateFile = args[0] + ".converted.csv";
+            String cookies = args[0] + ".cookiemetadata.csv";
+            String mionutely = args[0] + ".minutemetadata.csv";
+
+            JsonObject obj = Json.parse(new FileReader(args[0])).asObject();
+            JsonArray arr = obj.get("messages").asArray();
+            PrintWriter w = new PrintWriter(new FileWriter(intermediateFile));
+            w.println("type;author;length;cookiecount;timestamp");
+            for (int i = 0; i < arr.size(); i++) {
+                boolean isEventSys = false;
+                JsonObject msg = arr.get(i).asObject();
+                JsonObject author = msg.get("author").asObject();
+                String id = author.getString("id", "---");
+                if (id.equals(EVT_SYS_ID)) {
+                    isEventSys = true;
+                    System.out.println("Eventsys");
+                }
+
+                String message = msg.getString("content", "");
+
+                int len = message.length();
+                String timestamp = msg.getString("timestamp", "");//.substring(0, 19);
+                int cookiecount = 0;
+                String type = "default";
+                if (isEventSys) {
+                    type = "leaderboard";
+                    JsonArray embeds = msg.get("embeds").asArray();
+                    if (!(embeds.size() == 0)) {
+                        JsonObject embed = embeds.get(0).asObject();
+                        String title = embed.getString("title", "");
+                        String content = embed.getString("title", "");
+                        if (title.equals("Gesammelte Cookies")) {
+                            type = "cookie";
+                            String description = embed.getString("description", "0");
+                            String cntS = description.replace("Ihr konntet ", "").replace(" Cookies sammeln.", "").replace(" Cookie sammeln.", "");
+                            cookiecount = Integer.valueOf(cntS);
+                        }
+                        else
+                        {
+                            //TODO edgecase-kekse
+                        }
+                    }
+                }
+                w.println(type + ";" + id + ";" + len + ";" + cookiecount + ";" + timestamp);
+            }
+            w.close();
+
+            w = new PrintWriter(new FileWriter(cookies));
+            PrintWriter w2 = new PrintWriter(new FileWriter(mionutely));
+
+            BufferedReader r = new BufferedReader(new FileReader(intermediateFile));
+            int lns = -100000;
+            int lnsMinutely = -100000;
+            String line = r.readLine();
+            line = r.readLine(); //datei köpfen
+            HashSet<String> users = new HashSet<>();
+            HashSet<String> usersMinutely = new HashSet<>();
+            String previousLineTS = "";
+
+            w.println("cookiedelta;usercount;type;author;length;cookiecount;timestamp");
+            w2.println("usercount;msgsMinute;timestamp");
+            while (line != null) {
+                String[] splitted = line.split(";");
+                if (line.contains("cookie;")) {
+                    String lnp = lns+"";
+                    if (lns < 0) {
+                        lnp = "-";
+                    }
+                    System.out.println(lns+"|"+lnp);
+                    w.println(lnp+";" +users.size()+";"+ line);
+                    lns = 0;
+                    users=new HashSet<>();
+                } else {
+                    String uid = splitted[1];
+                    //if(!uid.equals(EVT_SYS_ID))
+                    //{
+                    lns++;
+                    users.add(uid);
+                    //}
+                }
+
+                String tsMinutely = splitted[4].substring(0, 16);
+                if(!previousLineTS.equals(tsMinutely))
+                {
+                    SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd_hh:mm");
+                    if(previousLineTS.length()>0)//suppress calc on head of file
+                    {
+                        int minutesToSynthesize = 0;
+                        try {
+                            Date old = parser.parse(previousLineTS.replace("T","_"));
+                            Instant calc= old.toInstant();
+                            Date current = parser.parse(tsMinutely.replace("T","_"));
+                            Long gap = ChronoUnit.MINUTES.between(old.toInstant(),current.toInstant());
+                            System.out.println("Gap:"+gap);
+                            for(int g=1;g<gap;g++)
+                            {
+                                String ts = parser.format(Date.from(calc.plus(g, ChronoUnit.MINUTES)));
+                                w2.println("0;0;"+ts);
+                            }
+                        } catch (ParseException e) {
+                            throw new RuntimeException(e);
+                        }
+                    }
+                    previousLineTS=tsMinutely;
+                    if(lnsMinutely>=0)
+                    {
+                        w2.println(+usersMinutely.size()+";"+lnsMinutely+";"+previousLineTS);
+                    }
+                    lnsMinutely=0;
+                    usersMinutely=new HashSet<>();
+                }
+                String uid = splitted[1];
+                if(!uid.equals(EVT_SYS_ID))
+                {
+                    lnsMinutely++;
+                    usersMinutely.add(uid);
+                }
+                line = r.readLine();
+            }
+            w.close();
+            w2.close();
+        }
+        catch (IOException ex)
+        {
+            ex.printStackTrace();
+        }
+    }
+}

+ 1 - 1
settings.gradle

@@ -1,4 +1,4 @@
 include 'ToolKit','iZpl',  'IZSetup','WPCMGr','UpidTK', 'izstreamer', 'LogBlockHeatMapper','iZlaunch',
 'iZpaqSFX','MazeViewer','TWPUtil',"iZplPlugins:WMP","iZplPlugins:foobar2000_others","iZplPlugins:itunes","iZplPlugins:GameRadio",
 "iZplPlugins:Editor","izpl-shared","iZpl-server","iZplPlugins:Smartphonizer","QuickStuff","external:java-progressbar","iZplPlugins:rtsslink","iZplPlugins:JukeBox",
-"iZplPlugins:Extractor","spungit_deathtimer","iZplPlugins:discordjukebox","SenaBitWiggler"
+"iZplPlugins:Extractor","spungit_deathtimer","iZplPlugins:discordjukebox","SenaBitWiggler","PlaceDECSVWiggler"