Skip to content

Commit

Permalink
start work on fixing skewed statistics due to artificially split acti…
Browse files Browse the repository at this point in the history
…vities
  • Loading branch information
jonasoreland committed Oct 18, 2015
1 parent 93c19f4 commit c61acf9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/main/java/org/oreland/analysis/Analysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<Date, Activity> activities = new HashMap<>();
}

public void report() {
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/org/oreland/db/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,32 @@ public class Repository {
HashMap<String, Player> playersByName = new HashMap<>();
List<Level> 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<Level> getLevels() {
return levels;
}
Expand All @@ -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))
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/oreland/entity/Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/org/oreland/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c61acf9

Please sign in to comment.