Commit 3d499290 authored by Florian Grabowski's avatar Florian Grabowski
Browse files

Refined Builder

parent fd441de2
......@@ -7,9 +7,10 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import java.io.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.logging.Level;
public class JsonParser {
......@@ -35,8 +36,16 @@ public class JsonParser {
}
JSONArray entities = (JSONArray) jsonObject.get("entities");
ArrayList<Klasse> entitiesList = new ArrayList<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd kk:mm:ss Z");
for (int i=0; i < entities.size(); i++) {
JSONObject object = (JSONObject) entities.get(i);
JSONArray commits = (JSONArray) ((JSONObject) entities.get(i)).get("commits");
ArrayList<LocalDateTime> dates = new ArrayList<>();
for (Object o: commits){
Object date = ((JSONObject) o).get("date");
LocalDateTime time = LocalDateTime.parse(date.toString(),formatter);
dates.add(time);
}
Klasse currentKlasse = new Klasse(
Integer.parseInt(object.get("entity_id").toString()),
object.get("name").toString(),
......@@ -45,8 +54,10 @@ public class JsonParser {
Integer.parseInt(object.get("loc").toString()),
((JSONArray) object.get("commits")).size(),
((JSONArray) object.get("functions")).size(),
((JSONArray) object.get("variables")).size());
entitiesList.add(currentKlasse);
((JSONArray) object.get("variables")).size(),
Math.round(Float.parseFloat(object.get("complexity").toString())),
dates);
if(currentKlasse.depth != -1)entitiesList.add(currentKlasse);
}
entitiesList.sort(new DepthComparator());
DataHolder.generateTreeFromKlassenList(entitiesList);
......
package de._82grfl1bif.KPI_Visualizer.data;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
public class Klasse {
public String name;
public String path;
public int qloc;
public static int qlocMin = Integer.MAX_VALUE;
public static int qlocMax;
public int loc;
public static int locMin= Integer.MAX_VALUE;
public static int locMax;
public int commits;
public static int commitsMin= Integer.MAX_VALUE;
public static int commitsMax;
public int depth;
public static int depthMax;
public int complexity;
public static int complexityMax;
public static int complexityMin= Integer.MAX_VALUE;
public final int id;
public int functions;
public static int functionsMin= Integer.MAX_VALUE;
public static int functionsMax;
public int variables;
public static int variablesMin= Integer.MAX_VALUE;
public static int variablesMax;
public Duration bearbeiteteZeit;
public static Duration bearbeiteteZeitMin;
public static Duration bearbeiteteZeitMax;
public Duration zeitSeitLetzterBearbeitung;
public static Duration zeitSeitLetzterBearbeitungMin;
public static Duration zeitSeitLetzterBearbeitungMax;
public Duration zeitSeitErstemCommit;
public static Duration zeitSeitErstemCommitMin;
public static Duration zeitSeitErstemCommitMax;
ArrayList<LocalDateTime> commitTimes;
public Klasse(int id, String name, String path, int qloc, int loc, int commits, int functions, int variables){
public Klasse(int id, String name, String path, int qloc, int loc, int commits, int functions, int variables,int complexity, ArrayList<LocalDateTime> commitTimes){
this.id = id;
this.commits = commits;
commitsMax = Math.max(commitsMax,commits);
commitsMin = Math.min(commitsMin,commits);
this.depth = getDepthOfPath(path);
depthMax = Math.max(depthMax,depth);
this.loc = loc;
locMax = Math.max(locMax,loc);
locMin = Math.min(locMin,loc);
this.qloc = qloc;
qlocMax = Math.max(qlocMax,qloc);
qlocMin = Math.min(qlocMin,qloc);
this.functions = functions;
functionsMax = Math.max(functionsMax,functions);
functionsMin = Math.min(functionsMin,functions);
this.variables = variables;
variablesMax = Math.max(variablesMax,variables);
variablesMin = Math.min(variablesMin,variables);
this.complexity = complexity;
complexityMax = Math.max(complexityMax,complexity);
complexityMin = Math.min(complexityMin,complexity);
this.name = name;
this.path = path;
this.commitTimes = commitTimes;
this.bearbeiteteZeit = (commitTimes.isEmpty()) ? null:Duration.between(commitTimes.get(commitTimes.size()-1), commitTimes.get(0));
if (bearbeiteteZeit != null) {
if(bearbeiteteZeitMax == null)bearbeiteteZeitMax = Duration.ofMillis(Long.MIN_VALUE);
if(bearbeiteteZeitMin == null)bearbeiteteZeitMin = Duration.ofMillis((Long.MAX_VALUE));
bearbeiteteZeitMax = (bearbeiteteZeitMax.toMillis() >= bearbeiteteZeit.toMillis()) ? bearbeiteteZeitMax:bearbeiteteZeit;
bearbeiteteZeitMin = (bearbeiteteZeitMin.toMillis() <= bearbeiteteZeit.toMillis()) ? bearbeiteteZeitMin:bearbeiteteZeit;
}
this.zeitSeitLetzterBearbeitung = (commitTimes.isEmpty()) ? null:Duration.between(commitTimes.get(0),LocalDateTime.now());
if (zeitSeitLetzterBearbeitung != null) {
if(zeitSeitLetzterBearbeitungMax == null)zeitSeitLetzterBearbeitungMax = Duration.ofMillis(Long.MIN_VALUE);
if(zeitSeitLetzterBearbeitungMin == null)zeitSeitLetzterBearbeitungMin = Duration.ofMillis(Long.MAX_VALUE);
zeitSeitLetzterBearbeitungMax = (zeitSeitLetzterBearbeitungMax.toMillis() >= zeitSeitLetzterBearbeitung.toMillis()) ? zeitSeitLetzterBearbeitungMax:zeitSeitLetzterBearbeitung;
zeitSeitLetzterBearbeitungMin = (zeitSeitLetzterBearbeitungMin.toMillis() <= zeitSeitLetzterBearbeitung.toMillis()) ? zeitSeitLetzterBearbeitungMin:zeitSeitLetzterBearbeitung;
}
this.zeitSeitErstemCommit = (commitTimes.isEmpty()) ? null:Duration.between(commitTimes.get(commitTimes.size()-1),LocalDateTime.now());
if (zeitSeitErstemCommit != null) {
if(zeitSeitErstemCommitMax == null)zeitSeitErstemCommitMax = Duration.ofMillis(Long.MIN_VALUE);
if(zeitSeitErstemCommitMin == null)zeitSeitErstemCommitMin = Duration.ofMillis(Long.MAX_VALUE);
zeitSeitErstemCommitMax = (zeitSeitErstemCommitMax.toMillis() >= zeitSeitErstemCommit.toMillis()) ? zeitSeitErstemCommitMax:zeitSeitErstemCommit;
zeitSeitErstemCommitMin = (zeitSeitErstemCommitMin.toMillis() <= zeitSeitErstemCommit.toMillis()) ? zeitSeitErstemCommitMin:zeitSeitErstemCommit;
}
}
private int getDepthOfPath(String path){
......
......@@ -7,34 +7,37 @@ import java.awt.Point;
public class Building extends Structure{
private final int height;
public Klasse klasse = null;
@Deprecated
public Building(int width, int height, Material material){ //Buildings are Square -> no depth
this.width.x = width;
this.width.y = width;
this.height = height;
this.material = material;
if(this.width.x < 5){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 Gehweg");
throw new IllegalArgumentException("keine Gebäude kleiner 5 wegen 2 Gehweg");
}
}
public Building(Point width, int height, Material material){ //Buildings are Square -> no depth
public Building(Point width/*and depth for complex algorithms*/, int height, Material material){
this.width = width;
this.height = height;
this.material = material;
if(this.width.x < 5 || this.width.y < 5){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 Gehweg");
throw new IllegalArgumentException("keine Gebäude kleiner 5 wegen 2 Gehweg");
}
}
public Building(Material material, Klasse klasse, String name){ //Buildings are Square -> no depth
this.klasse = klasse;
this.material = material;
this.width = new Point(5,5); //TODO: make this work with treemap and square
this.area = klasse.qloc;
this.width = new Point((int)Math.round((klasse.variables+5)),(int)Math.round((klasse.variables+5))); //TODO: make this work with treemap and square
this.area = klasse.variables*25;
this.name = name;
this.height = klasse.commits; // con be changed to likings TODO: find out which fits best.
this.height = klasse.functions;
if(this.width.x < 5 || this.width.y < 5){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 Gehweg");
throw new IllegalArgumentException("keine Gebäude kleiner 5 wegen 2 Gehweg");
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment