|
14 | 14 | import java.text.ParseException; |
15 | 15 | import java.text.SimpleDateFormat; |
16 | 16 | import java.util.ArrayList; |
| 17 | +import java.util.Calendar; |
17 | 18 | import java.util.Date; |
18 | 19 | import java.util.regex.Pattern; |
19 | 20 |
|
|
27 | 28 | */ |
28 | 29 | public class Player { |
29 | 30 |
|
| 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 | + |
30 | 45 | private int id; |
31 | 46 | private String realm; |
32 | 47 | private String playerName; |
@@ -92,6 +107,7 @@ public class Player { |
92 | 107 | private ArrayList minions; |
93 | 108 | private ArrayList mounts; |
94 | 109 | private Date dateImgLastModified; |
| 110 | + private boolean isActive; |
95 | 111 |
|
96 | 112 | /** |
97 | 113 | * Constructor for player object. |
@@ -161,6 +177,7 @@ public Player(int id) { |
161 | 177 | setHasCompleted3pt1(false); |
162 | 178 | setHasCompleted3pt3(false); |
163 | 179 | setDateImgLastModified(new Date()); |
| 180 | + setActive(false); |
164 | 181 | } |
165 | 182 |
|
166 | 183 | /** |
@@ -1881,12 +1898,31 @@ public static Player getPlayer(int playerID) throws Exception { |
1881 | 1898 | player.setHasSylph(player.doesPlayerHaveMount("Laurel Goobbue")); |
1882 | 1899 | player.setHasCompletedHW(player.doesPlayerHaveMount("Midgardsormr")); |
1883 | 1900 | player.setIsLegacyPlayer(player.doesPlayerHaveMount("Legacy Chocobo")); |
| 1901 | + player.setActive(player.isPlayerActiveInDateRange()); |
1884 | 1902 | } catch (IOException ioEx) { |
1885 | 1903 | throw new Exception("Character " + playerID + " does not exist."); |
1886 | 1904 | } |
1887 | 1905 | return player; |
1888 | 1906 | } |
1889 | 1907 |
|
| 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 | + |
1890 | 1926 | /** |
1891 | 1927 | * Given a lodestone profile page, return the name of the character. |
1892 | 1928 | * |
@@ -2131,4 +2167,20 @@ private static Date getDateLastUpdatedFromPage(Document doc) throws Exception { |
2131 | 2167 | public Date getDateImgLastModified() { |
2132 | 2168 | return dateImgLastModified; |
2133 | 2169 | } |
| 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 | + } |
2134 | 2186 | } |
0 commit comments