Search in sources :

Example 1 with StatsListElement

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);
}
Also used : ListItem(com.thebluealliance.androidclient.listitems.ListItem) StatsListElement(com.thebluealliance.androidclient.listitems.StatsListElement) Test(org.junit.Test)

Example 2 with StatsListElement

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());
    }
}
Also used : StatsListElement(com.thebluealliance.androidclient.listitems.StatsListElement)

Example 3 with StatsListElement

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()));
}
Also used : StatListElementComparator(com.thebluealliance.androidclient.comparators.StatListElementComparator) EventStatsEvent(com.thebluealliance.androidclient.eventbus.EventStatsEvent) JsonObject(com.google.gson.JsonObject) StatsListElement(com.thebluealliance.androidclient.listitems.StatsListElement) EventInsightsRenderer(com.thebluealliance.androidclient.renderers.insights.EventInsightsRenderer) EventInsights2022Renderer(com.thebluealliance.androidclient.renderers.insights.EventInsights2022Renderer) EventInsights2019Renderer(com.thebluealliance.androidclient.renderers.insights.EventInsights2019Renderer) EventInsights2018Renderer(com.thebluealliance.androidclient.renderers.insights.EventInsights2018Renderer) JsonElement(com.google.gson.JsonElement) EventInsights2017Renderer(com.thebluealliance.androidclient.renderers.insights.EventInsights2017Renderer) Team(com.thebluealliance.androidclient.models.Team) EventInsights2016Renderer(com.thebluealliance.androidclient.renderers.insights.EventInsights2016Renderer) EventInsights2020Renderer(com.thebluealliance.androidclient.renderers.insights.EventInsights2020Renderer)

Aggregations

StatsListElement (com.thebluealliance.androidclient.listitems.StatsListElement)3 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 StatListElementComparator (com.thebluealliance.androidclient.comparators.StatListElementComparator)1 EventStatsEvent (com.thebluealliance.androidclient.eventbus.EventStatsEvent)1 ListItem (com.thebluealliance.androidclient.listitems.ListItem)1 Team (com.thebluealliance.androidclient.models.Team)1 EventInsights2016Renderer (com.thebluealliance.androidclient.renderers.insights.EventInsights2016Renderer)1 EventInsights2017Renderer (com.thebluealliance.androidclient.renderers.insights.EventInsights2017Renderer)1 EventInsights2018Renderer (com.thebluealliance.androidclient.renderers.insights.EventInsights2018Renderer)1 EventInsights2019Renderer (com.thebluealliance.androidclient.renderers.insights.EventInsights2019Renderer)1 EventInsights2020Renderer (com.thebluealliance.androidclient.renderers.insights.EventInsights2020Renderer)1 EventInsights2022Renderer (com.thebluealliance.androidclient.renderers.insights.EventInsights2022Renderer)1 EventInsightsRenderer (com.thebluealliance.androidclient.renderers.insights.EventInsightsRenderer)1 Test (org.junit.Test)1