diff --git a/src/main/java/org/oreland/analysis/Analysis.java b/src/main/java/org/oreland/analysis/Analysis.java index 139fb08..1449b06 100644 --- a/src/main/java/org/oreland/analysis/Analysis.java +++ b/src/main/java/org/oreland/analysis/Analysis.java @@ -6,6 +6,8 @@ import org.oreland.entity.Player; import org.apache.commons.math3.stat.descriptive.SummaryStatistics; +import java.util.Date; +import java.util.HashMap; import java.util.Iterator; /** @@ -16,7 +18,12 @@ public class Analysis { Repository repo; public Analysis(Repository repo) { - this.repo = repo; + this.repo = repo.clone(); + mergeSplitActivities(); + } + + private void mergeSplitActivities() { + HashMap activities = new HashMap<>(); } public void report() { diff --git a/src/main/java/org/oreland/db/Repository.java b/src/main/java/org/oreland/db/Repository.java index ba5eeff..d564072 100644 --- a/src/main/java/org/oreland/db/Repository.java +++ b/src/main/java/org/oreland/db/Repository.java @@ -19,6 +19,32 @@ public class Repository { HashMap playersByName = new HashMap<>(); List levels = new ArrayList<>(); + // "Deep copy" + public Repository clone() { + Repository rep = new Repository(); + for (Player p : playersByName.values()) { + rep.add(p.copy()); // shallow copy + } + for (Activity a : activities.values()) { + Activity new_a = a.copy(); // shallow copy + rep.add(new_a); + for (Activity.Invitation inv : a.invitations) { + Activity.Invitation new_inv = new Activity.Invitation(); + new_inv.invitation_date = inv.invitation_date; + new_inv.player = rep.getPlayer(inv.player.first_name, inv.player.last_name); + new_inv.response = inv.response; + new_inv.response_comment = inv.response_comment; + new_inv.response_date = inv.response_date; + rep.addInvitation(new_a, new_inv); + } + for (Activity.Participant par : a.participants) { + Activity.Participant new_par = new Activity.Participant(); + rep.addParticipant(new_a, rep.getPlayer(par.player.first_name, par.player.last_name)); + } + } + return rep; + } + public Iterable getLevels() { return levels; } @@ -42,8 +68,6 @@ public Pair(T t, U u) { public U second; } - ; - public Player add(Player p) { String key = p.first_name + p.last_name; if (!playersByName.containsKey(key)) diff --git a/src/main/java/org/oreland/entity/Activity.java b/src/main/java/org/oreland/entity/Activity.java index c1446fe..6b4e67c 100644 --- a/src/main/java/org/oreland/entity/Activity.java +++ b/src/main/java/org/oreland/entity/Activity.java @@ -10,6 +10,18 @@ */ public class Activity { + public Activity copy() { + Activity a = new Activity(); + a.id = id; + a.type = type; + a.date = date; + a.title = title; + a.description = description; + a.synced = synced; + a.level = level; + return a; + } + public enum Type { GAME, TRAINING; diff --git a/src/main/java/org/oreland/entity/Player.java b/src/main/java/org/oreland/entity/Player.java index 36a644c..f24be3d 100644 --- a/src/main/java/org/oreland/entity/Player.java +++ b/src/main/java/org/oreland/entity/Player.java @@ -8,13 +8,23 @@ * Created by jonas on 10/1/15. */ public class Player { + + + public Player copy() { + Player p = new Player(); + p.first_name = first_name; + p.last_name = last_name; + p.type = type; + p.level_history.addAll(level_history); + p.target_level = target_level; + return p; + } + static public class LevelHistoryEntry { public Date date; public TargetLevel level; } - ; - public enum Type { PLAYER, LEADER;