Skip to content

Commit e56e485

Browse files
committed
[#1] Added code to determine whether Character 'has been active in last 30 days'
1 parent 92c3b32 commit e56e485

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/main/java/com/ffxivcensus/gatherer/Player.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.text.ParseException;
1515
import java.text.SimpleDateFormat;
1616
import java.util.ArrayList;
17+
import java.util.Calendar;
1718
import java.util.Date;
1819
import java.util.regex.Pattern;
1920

@@ -27,6 +28,20 @@
2728
*/
2829
public class Player {
2930

31+
/**
32+
* Number of days inactivity before character is considered inactive
33+
*/
34+
private final static int ACTIVITY_RANGE_DAYS = 30;
35+
36+
37+
private static final long ONE_MINUTE_IN_MILLIS=60000;
38+
private static final long ONE_DAY_IN_MILLIS=86400000;
39+
40+
/**
41+
* Ignore dates from inside EXCLUDE_RANGE in minutes
42+
*/
43+
private static final long EXCLUDE_RANGE= 5;
44+
3045
private int id;
3146
private String realm;
3247
private String playerName;
@@ -92,6 +107,7 @@ public class Player {
92107
private ArrayList minions;
93108
private ArrayList mounts;
94109
private Date dateImgLastModified;
110+
private boolean isActive;
95111

96112
/**
97113
* Constructor for player object.
@@ -161,6 +177,7 @@ public Player(int id) {
161177
setHasCompleted3pt1(false);
162178
setHasCompleted3pt3(false);
163179
setDateImgLastModified(new Date());
180+
setActive(false);
164181
}
165182

166183
/**
@@ -1881,12 +1898,31 @@ public static Player getPlayer(int playerID) throws Exception {
18811898
player.setHasSylph(player.doesPlayerHaveMount("Laurel Goobbue"));
18821899
player.setHasCompletedHW(player.doesPlayerHaveMount("Midgardsormr"));
18831900
player.setIsLegacyPlayer(player.doesPlayerHaveMount("Legacy Chocobo"));
1901+
player.setActive(player.isPlayerActiveInDateRange());
18841902
} catch (IOException ioEx) {
18851903
throw new Exception("Character " + playerID + " does not exist.");
18861904
}
18871905
return player;
18881906
}
18891907

1908+
/**
1909+
* Determine whether a player is active based upon the last modified date of their full body image
1910+
* @return whether player has been active inside the activity window
1911+
*/
1912+
private boolean isPlayerActiveInDateRange() {
1913+
1914+
Calendar date = Calendar.getInstance();
1915+
long t= date.getTimeInMillis();
1916+
Date nowMinusExcludeRange =new Date(t - (EXCLUDE_RANGE * ONE_MINUTE_IN_MILLIS));
1917+
1918+
Date nowMinusIncludeRange = new Date(t - (ACTIVITY_RANGE_DAYS * ONE_DAY_IN_MILLIS));
1919+
if(this.dateImgLastModified.after(nowMinusExcludeRange)) { //If the date modified is inside the exclude range
1920+
//Reset the last modified date to epoch because we aren't considering it valid
1921+
this.dateImgLastModified = new Date(0);
1922+
return false;
1923+
} else return this.dateImgLastModified.after(nowMinusIncludeRange); //If the date occurs between the include range and now, then return true. Else false
1924+
}
1925+
18901926
/**
18911927
* Given a lodestone profile page, return the name of the character.
18921928
*
@@ -2131,4 +2167,20 @@ private static Date getDateLastUpdatedFromPage(Document doc) throws Exception {
21312167
public Date getDateImgLastModified() {
21322168
return dateImgLastModified;
21332169
}
2170+
2171+
/**
2172+
* Get whether a Player is active
2173+
* @return whether Player is active
2174+
*/
2175+
public boolean isActive() {
2176+
return isActive;
2177+
}
2178+
2179+
/**
2180+
* Set whether Player is active
2181+
* @param active whether player is considered active
2182+
*/
2183+
public void setActive(boolean active) {
2184+
isActive = active;
2185+
}
21342186
}

src/test/java/com/ffxivcensus/gatherer/PlayerTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ public void testGetPlayer() throws Exception {
156156
assertTrue(playerOne.getMountsString().contains("Cavalry Drake,Cavalry Elbst"));
157157
//Test for data from very end
158158
assertTrue(playerOne.getMountsString().contains("Midgardsormr"));
159+
160+
//Is active
161+
assertTrue(playerOne.isActive());
159162
}
160163

161164
/**
@@ -224,7 +227,8 @@ public void testUnplayedPlayer() throws Exception {
224227
assertEquals(player.getBitHasCompleted3pt1(), 0);
225228
assertEquals(player.getBitHasARRCollectors(), 0);
226229
//Tricky to test this - testing here that it was at the very least set to some value other than what it is set to a value other than that which it is initialized
227-
assertTrue(player.getImgLastModified() != new Date());
230+
assertTrue(player.getDateImgLastModified() != new Date());
231+
assertFalse(player.isActive());
228232

229233
//Test get minions method
230234
assertTrue(player.getMinions().size() == 0);

0 commit comments

Comments
 (0)