Search in sources :

Example 1 with EventInsights2018Renderer

use of com.thebluealliance.androidclient.renderers.insights.EventInsights2018Renderer 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

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 StatsListElement (com.thebluealliance.androidclient.listitems.StatsListElement)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