|
@@ -0,0 +1,127 @@
|
|
|
+package de.nplusc.izc.placeDE.Cookies;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+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", "");
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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))
|
|
|
+ {
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|