use of com.thebluealliance.androidclient.listitems.StatsListElement in project the-blue-alliance-android by the-blue-alliance.
the class StatsListSubscriberTest method testParsedData.
@Test
public void testParsedData() {
StatsListSubscriber.Model model = new StatsListSubscriber.Model(mStats, mInsights);
List<ListItem> data = DatafeedTestDriver.getParsedData(mSubscriber, model);
assertEquals(66, data.size());
assertTrue(data.get(0) instanceof StatsListElement);
StatsListElement actual = ((StatsListElement) data.get(0));
assertEquals(actual.teamNumber, "3419");
assertEquals(actual.teamName, "Team 3419");
assertEquals(actual.opr, 41.76934455450079, 0);
assertEquals(actual.dpr, 18.164742518609433, 0);
assertEquals(actual.ccwm, 23.60460203589137, 0);
}
use of com.thebluealliance.androidclient.listitems.StatsListElement in project the-blue-alliance-android by the-blue-alliance.
the class StatListElementComparator method compare.
@Override
public int compare(ListItem lhs, ListItem rhs) {
if (!(lhs instanceof StatsListElement) || !(rhs instanceof StatsListElement)) {
return 0;
}
StatsListElement left = (StatsListElement) lhs;
StatsListElement right = (StatsListElement) rhs;
switch(mStatToSortBy) {
case "team":
return Integer.compare(left.getTeamNumber(), right.getTeamNumber());
case "opr":
default:
return Double.compare(right.getOpr(), left.getOpr());
case "dpr":
return Double.compare(left.getDpr(), right.getDpr());
case "ccwm":
return Double.compare(right.getCcwm(), left.getCcwm());
}
}
use of com.thebluealliance.androidclient.listitems.StatsListElement 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