use of com.thebluealliance.androidclient.renderers.insights.EventInsightsRenderer in project the-blue-alliance-android by the-blue-alliance.
the class StatsListSubscriber method parseData.
@Override
public void parseData() {
mTeamStats.clear();
JsonObject statsData = mAPIData.getStats().getAsJsonObject();
if (!statsData.has("oprs") || !statsData.get("oprs").isJsonObject() || !statsData.has("dprs") || !statsData.get("dprs").isJsonObject() || !statsData.has("ccwms") || !statsData.get("ccwms").isJsonObject()) {
return;
}
JsonObject oprs = statsData.get("oprs").getAsJsonObject();
JsonObject dprs = statsData.get("dprs").getAsJsonObject();
JsonObject ccwms = statsData.get("ccwms").getAsJsonObject();
for (Entry<String, JsonElement> stat : oprs.entrySet()) {
String teamKey = stat.getKey();
String teamNumber = teamKey.substring(3);
Team team = mDb.getTeamsTable().get(teamKey);
String teamName = team == null ? "Team " + teamNumber : team.getNickname();
double opr = stat.getValue().getAsDouble();
double dpr = dprs.has(stat.getKey()) ? dprs.get(stat.getKey()).getAsDouble() : 0;
double ccwm = ccwms.has(stat.getKey()) ? ccwms.get(stat.getKey()).getAsDouble() : 0;
String displayString = mResources.getString(R.string.stats_format, ThreadSafeFormatters.formatDoubleTwoPlaces(opr), ThreadSafeFormatters.formatDoubleTwoPlaces(dpr), ThreadSafeFormatters.formatDoubleTwoPlaces(ccwm));
mTeamStats.add(new StatsListElement(teamKey, teamNumber, teamName, displayString, opr, dpr, ccwm));
}
Collections.sort(mTeamStats, new StatListElementComparator(mStatToSortBy));
// Event stats
EventInsightsRenderer insightsRenderer = null;
switch(mEventYear) {
case 2016:
insightsRenderer = new EventInsights2016Renderer(mEventStats, mResources);
break;
case 2017:
insightsRenderer = new EventInsights2017Renderer(mEventStats, mResources);
break;
case 2018:
insightsRenderer = new EventInsights2018Renderer(mEventStats, mResources);
break;
case 2019:
insightsRenderer = new EventInsights2019Renderer(mEventStats, mResources);
break;
case 2020:
insightsRenderer = new EventInsights2020Renderer(mEventStats, mResources);
break;
case 2022:
insightsRenderer = new EventInsights2022Renderer(mEventStats, mResources);
break;
}
if (insightsRenderer != null) {
insightsRenderer.generateEventInsights(mAPIData.getInsights());
}
mEventBus.post(new EventStatsEvent(getTopStatsString()));
}
Aggregations