Skip to content

Commit db340dc

Browse files
authored
Add files via upload
1 parent a97bbf2 commit db340dc

File tree

16 files changed

+470
-3
lines changed

16 files changed

+470
-3
lines changed
Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,94 @@
11
package material.stats;
22

3+
import com.google.gson.JsonElement;
34
import com.google.gson.JsonObject;
5+
import material.user.BungieUser;
46
import utils.HttpUtils;
7+
import utils.StringUtils;
58

9+
import java.util.ArrayList;
10+
import java.util.Date;
11+
import java.util.List;
12+
13+
/**
14+
* An activity in this case is a PGCR (Post Game Carnage Report)
15+
* It contains data about an activity that happened like a raid or crucible match
16+
*/
617
public class Activity {
718

819
HttpUtils hu = new HttpUtils();
920
String activityId;
1021
JsonObject jo;
1122

23+
private Date time;
24+
private String referenceId, directoryActivityHash, instanceId;
25+
private int mode;
26+
1227
public Activity(String activityId) {
1328
this.activityId = activityId;
14-
jo = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/Stats/PostGameCarnageReport/" + activityId + "/");
29+
jo = hu.urlRequestGET("https://stats.bungie.net/Platform/Destiny2/Stats/PostGameCarnageReport/" + activityId + "/").getAsJsonObject("Response");
1530
}
1631

32+
public Date getDatePlayed() {
33+
if(time != null) return time;
34+
time = StringUtils.valueOfZTime(jo.get("period").getAsString());
35+
return time;
36+
}
37+
38+
public String getReferenceId() {
39+
if(referenceId != null) return referenceId;
40+
referenceId = jo.getAsJsonObject("activityDetails").get("referenceId").getAsString();
41+
return referenceId;
42+
}
43+
44+
public String getDirectoryActivityHash() {
45+
if(directoryActivityHash != null) return directoryActivityHash;
46+
directoryActivityHash = jo.getAsJsonObject("activityDetails").get("directorActivityHash").getAsString();
47+
return directoryActivityHash;
48+
}
49+
50+
/**
51+
* Gets the instance id, which happens to be the same as the activityId :)
52+
= */
53+
public String getInstanceId() {
54+
if(instanceId != null) return instanceId;
55+
instanceId = jo.get("instanceId").getAsString();
56+
return instanceId;
57+
}
58+
59+
private int getModeNumber() {
60+
if(mode != 0) return mode;
61+
mode = jo.getAsJsonObject("activityDetails").get("mode").getAsInt();
62+
return mode;
63+
}
64+
65+
/**
66+
* Return the mode of the activity
67+
* Mode list on this page
68+
* https://bungie-net.github.io/multi/schema_Destiny-Definitions-DestinyActivityDefinition.html
69+
*/
70+
public ActivityMode getMode() {
71+
for(ActivityMode am : ActivityMode.values()) {
72+
if(am.getBungieValue() == getModeNumber()) {
73+
return am;
74+
}
75+
}
76+
return null;
77+
}
78+
79+
public List<ActivityParticipant> getParticipants() {
80+
List<ActivityParticipant> temp = new ArrayList<>();
81+
for(JsonElement je : jo.get("entries").getAsJsonArray()) {
82+
temp.add(new ActivityParticipant(je.getAsJsonObject()));
83+
}
84+
return temp;
85+
}
86+
87+
/**
88+
* If you need to get data not inside of this class
89+
*/
1790
public JsonObject getJsonObject() {
1891
return jo;
1992
}
93+
2094
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package material.stats;
2+
3+
/**
4+
* A list of activity mode numbers according to bungie.net
5+
* Some numbers are randomly skipped or "reserved", thus they are not listed here
6+
* https://bungie-net.github.io/multi/schema_Destiny-Definitions-DestinyActivityDefinition.html
7+
*/
8+
public enum ActivityMode {
9+
10+
NONE(0),
11+
STORY(2),
12+
STRIKE(3),
13+
RAID(4),
14+
ALL_PVP(5),
15+
PATROL(6),
16+
ALL_PVE(7),
17+
CONTROL(10),
18+
CLASH(12),
19+
CRIMSON_DOUBLES(15),
20+
NIGHTFALL(16),
21+
HEROIC_NIGHTFALL(17),
22+
ALL_STRIKES(18),
23+
IRON_BANNER(19),
24+
ALL_MAYHEM(25),
25+
SUPREMACY(31),
26+
PRIVATE_MATCHES_ALL(32),
27+
SURVIVAL(37),
28+
COUNTDOWN(38),
29+
TRIALS_OF_THE_NINE(39),
30+
SOCIAL(40),
31+
TRIALS_COUNTDOWN(41),
32+
TRIALS_SURVIVAL(42),
33+
IBCONTROL(43),
34+
IBCLASH(44),
35+
IBSUPREMACY(45),
36+
SCOREDNF(46),
37+
SCOREDHEROICNF(47),
38+
RUMBLE(48),
39+
ALL_DOUBLES(49),
40+
DOUBLES(50),
41+
PM_CLASH(51),
42+
PM_CONTROL(52),
43+
PM_SUPREMACY(53),
44+
PM_COUNTDOWN(54),
45+
PM_SURVIVAL(55),
46+
PM_MAYHEM(56),
47+
PM_RUMBLE(57),
48+
HEROIC_ADVENTURE(58),
49+
SHOWDOWN(59),
50+
LOCKDOWN(60),
51+
SCORCHED(61),
52+
SCORCHED_TEAM(62),
53+
GAMBIT(63),
54+
ALL_PVE_COMP(64),
55+
BREAKTHROUGH(65),
56+
BLACK_ARMORY_RUN(66),
57+
SALVAGE(67),
58+
IRON_BANNER_SALVAGE(68),
59+
PVP_COMP(69),
60+
PVP_QUICKPLAY(70),
61+
CLASH_QUICKPLAY(71),
62+
CLASH_COMP(72),
63+
CONTROL_QUICKPLAY(73),
64+
CONTROL_COMP(74),
65+
GAMBIT_PRIME(75),
66+
RECKONING(76),
67+
MENAGERIE(77),
68+
VEX_OFFENSIVE(78),
69+
NIGHTMARE_HUNT(79),
70+
ELIMINATION(80),
71+
MOMENTUM(81),
72+
DUNGEON(82),
73+
SUNDIAL(83),
74+
TRIALS_OF_OSIRIS(84);
75+
76+
77+
private int bungieValue;
78+
79+
private ActivityMode(int bungieValue) {
80+
this.bungieValue = bungieValue;
81+
}
82+
83+
public int getBungieValue() {
84+
return bungieValue;
85+
}
86+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package material.stats;
2+
3+
import com.google.gson.JsonObject;
4+
import material.user.BungieUser;
5+
6+
public class ActivityParticipant {
7+
8+
private JsonObject jo;
9+
private BungieUser bungieUser;
10+
private String membershipId, characterId;
11+
private int score, assists, deaths, kills, opponentsDefeated, activityDuration, completionReason;
12+
private double kdr, kda, completed, effeciency, startSeconds, timePlayed;
13+
JsonObject values;
14+
15+
public ActivityParticipant(JsonObject entry) {
16+
jo = entry.getAsJsonObject("values");
17+
}
18+
19+
/**
20+
* Get the membership ID of this user
21+
*/
22+
public String getMembershipId() {
23+
if (membershipId != null) return membershipId;
24+
jo.getAsJsonObject("player").getAsJsonObject("destinyUserInfo").get("membershipId").getAsString();
25+
return membershipId;
26+
}
27+
28+
/**
29+
* Gets the bungie user of this
30+
= */
31+
public BungieUser getBungieUser() {
32+
if (bungieUser != null) return bungieUser;
33+
bungieUser = new BungieUser(getMembershipId());
34+
return bungieUser;
35+
}
36+
37+
/**
38+
* Get the character ID of the player
39+
= */
40+
public String getCharacterId() {
41+
if (characterId != null) return characterId;
42+
characterId = jo.get("characterId").getAsString();
43+
return characterId;
44+
}
45+
46+
/**
47+
* Gets the score of the user in this activity
48+
*/
49+
public int getScore() {
50+
if (score != 0) return score;
51+
score = jo.getAsJsonObject("score").getAsJsonObject("basic").get("value").getAsInt();
52+
return score;
53+
}
54+
55+
/**
56+
* Get the assists of the user
57+
- */
58+
public int getAssists() {
59+
if (assists != 0) return assists;
60+
assists = jo.getAsJsonObject("assists").getAsJsonObject("basic").get("value").getAsInt();
61+
return assists;
62+
}
63+
64+
/**
65+
* Get if this user completed the activity
66+
- */
67+
public double getCompleted() {
68+
if(completed != 0) return completed;
69+
completed = jo.getAsJsonObject("completed").getAsJsonObject("basic").get("value").getAsDouble();
70+
return completed;
71+
}
72+
73+
/**
74+
* Get the number of deaths for this user
75+
*/
76+
public int getDeaths() {
77+
if(deaths != 0) return deaths;
78+
deaths = jo.getAsJsonObject("deaths").getAsJsonObject("basic").get("value").getAsInt();
79+
return deaths;
80+
}
81+
82+
/**
83+
* Get the number of kills for this user
84+
*/
85+
public int getKills() {
86+
if(kills != 0) return kills;
87+
kills = jo.getAsJsonObject("kills").getAsJsonObject("basic").get("value").getAsInt();
88+
return kills;
89+
}
90+
91+
/**
92+
* Gets the number of opponents this user defeated
93+
- */
94+
public int getOpponentsDefeated() {
95+
if(opponentsDefeated != 0) return opponentsDefeated;
96+
opponentsDefeated = jo.getAsJsonObject("opponentsDefeated").getAsJsonObject("basic").get("value").getAsInt();
97+
return opponentsDefeated;
98+
}
99+
100+
/**
101+
* Get the effeciency of this user
102+
*/
103+
public double getEffeciency() {
104+
if(effeciency != 0) return effeciency;
105+
effeciency = jo.getAsJsonObject("efficiency").getAsJsonObject("basic").get("value").getAsDouble();
106+
return effeciency;
107+
}
108+
109+
/**
110+
* Gets the Kill-Death Ratio of this user
111+
*/
112+
public double getKdr() {
113+
if(kdr != 0) return kdr;
114+
kdr = jo.getAsJsonObject("killsDeathsRatio").getAsJsonObject("basic").get("value").getAsDouble();
115+
return kdr;
116+
}
117+
118+
/**
119+
* Gets the Kill-Deaths-Assists of this user
120+
*/
121+
public double getKda() {
122+
if(kda != 0) return kda;
123+
kda = jo.getAsJsonObject("killsDeathsAssists").getAsJsonObject("basic").get("value").getAsDouble();
124+
return kda;
125+
}
126+
127+
/**
128+
* Gets the duration, in seconds, of this activity
129+
*/
130+
public int getActivityDuration() {
131+
if(activityDuration != 0) return activityDuration;
132+
activityDuration = jo.getAsJsonObject("activityDurationSeconds").getAsJsonObject("basic").get("value").getAsInt();
133+
return activityDuration;
134+
}
135+
136+
/**
137+
* Gets the reason why this activity was completed
138+
*/
139+
public int getCompletionReason() {
140+
if(completionReason != 0) return completionReason;
141+
completionReason = jo.getAsJsonObject("completionReason").getAsJsonObject("basic").get("value").getAsInt();
142+
return completionReason;
143+
}
144+
145+
/**
146+
* Gets the time the user joined the activity?
147+
*/
148+
public double getStartSeconds() {
149+
if(startSeconds != 0) return startSeconds;
150+
startSeconds = jo.getAsJsonObject("startSeconds").getAsJsonObject("basic").get("value").getAsDouble();
151+
return startSeconds;
152+
}
153+
154+
/**
155+
* Gets how long this user played in this activity
156+
*/
157+
public double getTimePlayed() {
158+
if(timePlayed != 0) return timePlayed;
159+
timePlayed = jo.getAsJsonObject("timePlayedSeconds").getAsJsonObject("basic").get("value").getAsDouble();
160+
return timePlayed;
161+
}
162+
}

0 commit comments

Comments
 (0)