Elo history
authorMartin Rexa <martin.rexa@centrum.cz>
Tue, 12 Jan 2010 16:00:16 +0100
changeset 201b919d0796fbf
parent 200 11c1287c7802
child 202 3e75ccd5cdac
Elo history
statistics/src/main/java/cz/xelfi/quoridor/statistics/resources/Elo.java
     1.1 --- a/statistics/src/main/java/cz/xelfi/quoridor/statistics/resources/Elo.java	Tue Jan 12 15:59:59 2010 +0100
     1.2 +++ b/statistics/src/main/java/cz/xelfi/quoridor/statistics/resources/Elo.java	Tue Jan 12 16:00:16 2010 +0100
     1.3 @@ -27,7 +27,6 @@
     1.4  package cz.xelfi.quoridor.statistics.resources;
     1.5  
     1.6  import cz.xelfi.quoridor.statistics.EloList;
     1.7 -import cz.xelfi.quoridor.webidor.Game;
     1.8  import cz.xelfi.quoridor.webidor.GameId;
     1.9  import cz.xelfi.quoridor.webidor.GameStatus;
    1.10  import javax.ws.rs.GET;
    1.11 @@ -35,6 +34,7 @@
    1.12  import javax.ws.rs.PathParam;
    1.13  import javax.ws.rs.Produces;
    1.14  import javax.ws.rs.core.MediaType;
    1.15 +import java.util.ArrayList;
    1.16  
    1.17  /**
    1.18   *
    1.19 @@ -42,18 +42,34 @@
    1.20   */
    1.21  public final class Elo {
    1.22      private EloList list;
    1.23 +    private ArrayList<EloList> listHistory;
    1.24 +    private long now;
    1.25 +    private long current;
    1.26 +    static long day = 1000 * 60 * 60 * 24;
    1.27  
    1.28      public Elo(){
    1.29 +        listHistory = new ArrayList<EloList>();
    1.30          list = new EloList();
    1.31 +        listHistory.add(list);
    1.32 +        now = System.currentTimeMillis();
    1.33 +        current = 0;
    1.34      }
    1.35  
    1.36 -    public void processGame(Game game){
    1.37 -        GameId gId = game.getId();
    1.38 +    public void processGame(GameId gId){
    1.39          GameStatus status = gId.getStatus();
    1.40 +        long modified = gId.getModified();
    1.41 +        if(current==0){
    1.42 +            current = modified;
    1.43 +        }else if(modified - current > day){
    1.44 +            list = new EloList(list);
    1.45 +            listHistory.add(0,list);
    1.46 +            current = modified;
    1.47 +        }
    1.48 +
    1.49          if(status.equals(GameStatus.whiteWon)){
    1.50 -            list.putResult(gId.getWhite(), gId.getBlack());
    1.51 +            list.putResult(gId.getWhite(), gId.getBlack(),modified);
    1.52          }else if(status.equals(GameStatus.blackWon)){
    1.53 -            list.putResult(gId.getBlack(), gId.getWhite());
    1.54 +            list.putResult(gId.getBlack(), gId.getWhite(),modified);
    1.55          }
    1.56      }
    1.57  
    1.58 @@ -65,6 +81,14 @@
    1.59      }
    1.60  
    1.61      @GET
    1.62 +    @Path("list/{id}")
    1.63 +    @Produces({ MediaType.APPLICATION_JSON, MediaType.TEXT_XML })
    1.64 +    public EloList getHistoryList(@PathParam("id") Integer id){
    1.65 +        EloList el = listHistory.get(id);
    1.66 +        return listHistory.get(id);
    1.67 +    }
    1.68 +
    1.69 +    @GET
    1.70      @Path("{username}")
    1.71      @Produces(MediaType.TEXT_PLAIN)
    1.72      public String getElo(@PathParam("username") String id){